الوصايا السبع

– “من تتبع عورات الناس تتبع الله عورته” ..

– “من حسن اسلام المرء تركه ما لا يعنيه” .. كل واحد/واحدة حر ..

– ” يَا أَيُّهَا الَّذِينَ آَمَنُوا إِنْ جَاءَكُمْ فَاسِقٌ بِنَبَأٍ فَتَبَيَّنُوا” شير.. شير .. شير

– “يَا أَيُّهَا الَّذِينَ آَمَنُوا لَا يَسْخَرْ قَومٌ مِنْ قَوْمٍ عَسَى أَنْ يَكُونُوا خَيْرًا مِنْهُمْ” .. الخرفان .. عبيد البيادة , “وَلَا تَنَابَزُوا بِالْأَلْقَابِ” .. المارشالجية .. النكسجية ..؟

– “وَلَا يَجْرِمَنَّكُمْ شَنَآنُ قَوْمٍ عَلَىٰ أَلَّا تَعْدِلُوا اعْدِلُوا هُوَ أَقْرَبُ لِلتَّقْوَىٰ ” .. اعدل مع عدوك قبل ما تعدل مع صديقك .. العدل مش عدل لو طبقته على اللى بتحبهم بس ؟ .. “وَإِذَا خَاصَمَ فَجَرَ”

Serial Communication with FTDI D2xx API on Windows

I was performing some testing on the FTDI throughput and I wrote this simple program that measures the throughput of FTDI chip if you connect its Rx pin to the Tx pin.

You are free to use it for any application with FTDI, it proved to be actually faster than using Windows VCP API but remember you need to install D2xx driver and make sure that your FTDI is actually using this driver and not the default ًWindows VCP driver

Note that the D2xx API uses a different method than conventional

    hSerial = CreateFile("COM9",GENERIC_READ | GENERIC_WRITE,
                              0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);

, it uses a string name instead that you can get from
device manager >> Right click on COM >> Details >> From the scroll list choose Device instance id >> you will find it after VID and PID

Code on github 

 

 

 

 

 

Fast DES C++ code

I found an old undergraduate project in a Security course, I and some friends implemented DES encryption algorithm. I don’t remember much but what I do remember is :
– We were Group Number 4 😀
– We tried to optimize it as much as possible to be fast , degrading the code readability and actually our algorithm was the fastest among the class.
– Compile it in Release mode

Code on github

الفتايين نقصوا واحد

العمر قصير عشان تضيعه فى كتابة بوستات منمقة و موثقة و تحليلات لوزعية عن الوضع الحالى ,ده زائد ان الفتايين كتير جدا و الحمد لله آراؤهم مكفية و زيادة , العالم مش ناقصه واحد تانى يقول كلمتين مالهمش لازمة ماحدش عايز يقراهم أو بالكتير اتنين تلاتة هيقروهم و هم بيسكرلو فى الحمام أو فى المطبخ بيقطعوا خيارة.
وجودى فى الجيش و فى نفس الوقت كون معظم اصحابى ضد سياساته ادانى منظور مختلف .

التجربة اثبتت ان المهم ان كل انسان يصلح اللى يقدر عليه فى نفسه و فى اللى حواليه و يتقن شغله , مش معنى كدة أنه يكون غافل بس المهم أن تركيزه يكون فى الحاجة اللى بيفهم و يقدر يأثر فيها و الا هيكون وقت مهدر .. و لو عندك وقت كتير كدة مستعد تضيعه فالعالم مليان حاجات كتير تافهة و مسلية ممكن تحرق بيها وقتك من غير ما تحرق أعصابك .

و ممكن تكون مهمة و مسلية فى نفس الوقت

شوف الفيديو ده مثلا

أو تابع الصفحة دى Awkward Yeti

و لو عندك ب*** قصدى أعصاب حديدية و لا مؤاخذة و عاوز تتفرج على أوسخ فيديوهات كوميدى ممكن تشوفها فى حياتك عشان تعرف أن أنت دمك خفيف جداو صاحبك الثقيل اللى بيقلش عليك طول اليوم ده اصلا نسمة خد دى أرخم كوميديان فى تاريخ البشرية كلها .. أنا حذرتك قبل ما تكليك أو اقعد اتفرج على فراشات مثلا أو برامج طبخ أو أى حاجة تروق بيها دماغك عشان تعرف تركز فى شغلك .. السياسة اوفر راتد جدا على فكرة .

الأبارتهايد الإسرائيلى – الفلسطينى … فى 8 صور : لماذا اسرائيل دولة عنصرية ؟

هذه الصور مقتبسة من الموقع الإلكترونى VisualizingPalestine.org المهتم بتوثيق حقائق التفرقة العنصرية فى اسرائيل فى شكل انفوجرافيك *

ملحوظة : اضغط على الصورة لتعرضها بحجم أكبر.

1.  إلى المنفى ..

يعمل الصهاينة بشكل مستمر على تضييق كل سبل العيش على الفلسطينين لإخراجهم من بلادهم .
اليهود in .. الفسلطينيون out

2. التهجير المستمر ..

لا يكتفى الصهاينة باخراج الفلسطينين من بلادهم .. بل يعملون باجتهاد لاخرج القلة الباقية من منازلهم

3. عنصرية حتى فى الموت ..

لا تتوقف ماكينة القتل الإسرائيلية عن استهداف الأبرياء .. الموت يرى الفلسطينيين بنسبة 6 : 1

4. لكنهم يحرقون أشجار الزيتون ..

كونك فلسطينيا يعنى أنك مستهدف .. تجارتك مستهدفة حتى لو كنت فقط تاجر زيت

 

5. اللوحات الصفراء تعنى رحلة سعيدة ..

اذا كانت سيارتك تحمل لوحة اسرائيلية صفراء فهذا يعنى أن كل الطرق مفتوحة أمامك .. أما اذا كانت لوحاتها بيضاء فخياراتك محدودة  و الأفق مسدود

6. الجدار العازل ..

متجاهلة كل الأعراف و القوانين الدولية تستمر سلطات الاحتلال فى تطويق الضفة الغربية بجدار ليفصل بين “الفلسطينيين” و “البنى أدمين”

7. حقوقك حسب بطاقة هويتك ..

تحدد بطاقة هويتك الأماكن التى يسمح لك بالتواجد فيها و اذا كان يسمح لك بالاقتراع أم لا

8. تفتيش .. تفتيش .. تفتيش ..

اذا كنت فلسطينيا فمن المرجح أنك ولدت فى نقطة تفتيش مقارنة بأقرانك فى الدول الأخرى

* : الصور منشورة تحت رخصة Creative Common license و تبيح الرخصة اعادة النشر و التعديل بشرط أن تنسب العمل لصاحبه الأصلى
* : فكرة المقال مستوحاة من مقال انجليزى بنفس العنوان .

OCRA : OCR for Arabic Cursive Text is now open source !

Hi,
I was working on a MATLAB implementation for Arabic OCR on graduate course project and I decided to release it as as open source software under GPL license.

Disclaimer

This implementation was a part of a graduate course project and actually it achieves very poor results, you can’t rely on it for any real OCR but it will be useful as a starting point to learn from and build on.

Details

You can learn all about it here : My github repo

5 Things Egyptians should know about the Grand Ethiopian Renaissance Dam (GERD)

5 .  What is Grand Ethiopian Renissance Dam (GERD) ??

GERD is a dam built by salini inpreglio construction company for the Ethiopian government on the Blue Nile River . I quote from the company’s page:

“At the end of the works, the Grand Ethiopian Renaissance Dam will be the largest dam in Africa: 1,800 m long, 170 m high and with a total volume of 70 billion m³.The power stations are positioned on the right and left banks of the river and comprise 16 Francis turbines with a total installed power of 6,000 MW and estimated production of 15,000 GWh per year.”

Work started in April 2011 and is expected to complete by July 2017.

 

4. Hmm ….Where is that ??

 

Well .. As we studied in schools (and probably don’t remember now),  there are two main sources for the Nile : the White Nile and the Blue Nile , The GERD is planned to be built on the course of the Blue Nile near the borders with Sudan.

The Blue Nile is vital to the livelihood of Egypt.it contributes more than half of the Nile’s streamflow.

 

River Nile Map ..  Google map grd

 

 

3. How much work is completed till now ??

 

According to Chief Executive Officer (CEO) of the Ethiopian Electric Power Engineer Azeb Worku in April 2014 :
“The construction of the dam is progression well without any problem with a great support of the people and government of Ethiopian people. The dam is now over 30% complete. “

 

2. How do Ethiopians think of Egypt’s political stance and Egyptians ??

Well… they clearly don’t like us
eth comment 7 eth comment 6 eth comment 5 eth comment 4 eth comment 3 eth comment 1

 

1. Ok… I skipped all the bla bla to here…How will GERD affect our lives in Egypt ??

 

First, go and check this animated timeline that I prepared to describe the problem: http://www.timetoast.com/timelines/gerd


GERD Timeline

Then, let’s do some simple Math:

GERD Capacity =70 billion m³

Ethiopians want to fill GERD in 5 years (the sooner they fill, the sooner electricity is generated) 70/5 =  14 billion m³ /year

Egyptian experts suggests that the dam to be filled in 15 years at least 70/15 =  ~5 billion m³ /year

Egypt’s yearly average annual Nile flow according to 1959 treaty = 55.5 billion m³ /year

Effect of filling GERD in 5 years = 14/55.5 = 25% yearly loss for Egypt !

Effect of filling GERD in 15 years = 5/55.5 = 9% yearly loss for Egypt !

 

gerd loss

According to Egyptian experts  that would cause 2,000,000 farmers to lose their income during the period of filling the reservoir, also production of Electricity from the High Dam will be reduced by 20% – 40% !

 

References:

http://en.wikipedia.org/wiki/Grand_Ethiopian_Renaissance_Dam

http://www.internationalrivers.org/resources/the-grand-ethiopian-renaissance-dam-fact-sheet-8213

http://www.aljazeera.com/programmes/insidestory/2013/05/201353081623734349.html

http://www.aljazeera.net/news/pages/237b864d-0553-416a-b507-c8374073a607

http://www.shorouknews.com/news/view.aspx?cdate=27042014&id=15304d92-b50d-4daf-9ff6-29638ae95dd5

http://www.shorouknews.com/mobile/news/view.aspx?cdate=29042014&id=d4e31ad2-e47d-4379-ab2f-3933b040f017

 

al-haitham is open source

I have benefited a lot from the open source community and it’s time to give back, I uploaded the source code of my graduation project which proposes a real time computer vision system  implemented on FPGA to translate human gestures into computer commands 

 First I would like to thank my graduation project team members:

   Ahmed Hafez Khalil

   Asmaa Omar

   Amani Mohamed Sedek

   Mohamed Ismail Khalil

   Mohamed Kamal Ali

   Mohamed Maged Abdel Majed

 

and here are the links to my grad project github repos: 

Hardware repo : https://github.com/aabdelfattah/alhaitham-hardware

Software repo : https://github.com/aabdelfattah/alhaitham-software

Have a look at thd brochure I designed for the EED competition 2012 which we won its 1st place 🙂

project-brochure-1

Cross-compiling a Pie ! The Raspberry Pi Ultimate Guide

Hi,

During the last few weeks I was interested in cross-compiling for the RPi. I have gone through many tutorials and blog posts to get the task done , so I tried to compile as many information as I can in this guide as a future reference and to help everybody else [The post is long, use CTRL+F for navigation].

Topics:

  1. Getting started , setting up the cross-compilation toolchain.
  2. Hello World! Building an RPi C application using shell.
  3. Hello World 2! Building an RPi C application using eclipse.
  4. Remote debugging the RPi with gdb on eclipse + RSE plugin.
  5. Updating your kernel. RPi Kernel cross-compilation.
  6. Extra: How does the bootloader work ?? 

 

Let’s get started with cross-compiling a Pie , there are usually 2 configurations : 

  • either to build the tool chain yourself on your host machine;
  • or to get a pre-compiled toolchain (the Canadian cross).

pi12

pi13

[images from free-electrons embedded training slides]

 

For this guide I will be using pre-built linaro toolchain(the second way),still I encourage you to try to build the toolchain yourself  for the sake of knowledge using one of those excellent tutorials :  A and B

Now, let’s download the Linaro gcc toolchain [source]


$ sudo apt-get install git rsync cmake ia32-libs

$ mkdir raspberrypi

$ cd raspberrypi

$ git clone git://github.com/raspberrypi/tools.git

Add the cross-compile to your $PATH

$ export PATH=$PATH:$HOME/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin

And finally append the very same line to the end of your ~/.bashrc file to make the change permnant

That’s it, now try

$ arm-linux-gnueabihf-gcc -v 

should give you something like this

Using built-in specs.
COLLECT_GCC=arm-linux-gnueabihf-gcc
COLLECT_LTO_WRAPPER=/home/ahmed/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../libexec/gcc/arm-linux-gnueabihf/4.8.3/lto-wrapper
Target: arm-linux-gnueabihf
Configured with: /cbuild/slaves/oorts/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/.build/src/gcc-linaro-4.8-2014.01/configure --build=i686-build_pc-linux-gnu --host=i686-build_pc-linux-gnu --target=arm-linux-gnueabihf --prefix=/cbuild/slaves/oorts/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/install --with-sysroot=/cbuild/slaves/oorts/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/install/arm-linux-gnueabihf/libc --enable-languages=c,c++,fortran --disable-multilib --enable-multiarch --with-arch=armv6 --with-tune=arm1176jz-s --with-fpu=vfp --with-float=hard --with-pkgversion='crosstool-NG linaro-1.13.1-4.8-2014.01 - Linaro GCC 2013.11' --with-bugurl=https://bugs.launchpad.net/gcc-linaro --enable-__cxa_atexit --enable-libmudflap --enable-libgomp --enable-libssp --with-gmp=/cbuild/slaves/oorts/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/.build/arm-linux-gnueabihf/build/static --with-mpfr=/cbuild/slaves/oorts/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/.build/arm-linux-gnueabihf/build/static --with-mpc=/cbuild/slaves/oorts/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/.build/arm-linux-gnueabihf/build/static --with-isl=/cbuild/slaves/oorts/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/.build/arm-linux-gnueabihf/build/static --with-cloog=/cbuild/slaves/oorts/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/.build/arm-linux-gnueabihf/build/static --with-libelf=/cbuild/slaves/oorts/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/.build/arm-linux-gnueabihf/build/static --enable-threads=posix --disable-libstdcxx-pch --enable-linker-build-id --enable-plugin --enable-gold --with-local-prefix=/cbuild/slaves/oorts/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/install/arm-linux-gnueabihf/libc --enable-c99 --enable-long-long --with-float=hard
Thread model: posix
gcc version 4.8.3 20140106 (prerelease) (crosstool-NG linaro-1.13.1-4.8-2014.01 - Linaro GCC 2013.11)

Now let’s build a simple application , use your favorite editor to write helloworld.c

#include <stdio.h>
int main()
{
   printf("Hello world \n");
   return 0;
}

and compile it using the usual gcc way

$ arm-linux-gnueabihf-gcc -o helloworld helloworld.c

Copy this to your Pi with a USB flash memory or on the sd card or whatever suits you, launch it and it should work !

pi@raspberrypi:~$ ./helloworld

Hello world

pi@raspberrypi:~$

Now, Let’s add our toolchain to eclipse : 

  •  install C/C++ cross-compiler support plugin;

pi14

  • from the menu File >> New Project >> C-Project >> Cross-Compile project , input the name of your project and hit next;
  • enter arm-linux-gnueabihf- as Tool command prefix and ~/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin as the tool command path , hit next and finish;

pi16

  • Congratulations 🙂 !!

It’s important to be able to debug your code online on the RPi, so we are going to use a nice plugin called RSE to do this [source]:

You may use this source code HelloDebug.c if you wish:

#include <stdio.h>

int main()
{
	int i = 0;
	printf("Hello world \n");
	while (i < 1000)
	{
		printf("%d \n",i);
		i++;
	}
	return 0;

}
  • install the RSE plugin;

pi15

  • create a new project with the above source, build it in debug mode (not release);
  • add a new connection to your RPi from the Remote Systems window (if you can’t see it , add it from Window >> Show View >> Others >> Remote Systems) , then hit the tiny button to add an ssh connection to your pi;

pi19

  • copy the elf executable to the pi using RSE (right click to copy it and paste it on the dir you wish from the stfp menu);

pi20

  • make sure to chmod+x the execultable;
  • now we will add a new debug configuration , right click on the project and select Debug as >> Debug Configurations  and add a new C/C++ Remote Application configuration;
  • pi17
  • ensure that in Debugger >> Main tab the debugger is arm-linux-gnueabihf-gdb
  • login to your pi using ssh to launch the gdbserver $sudo gdbserver your-linux-pc-ip:any-free-port  HelloDebug

pi18

  • back to eclipse , ensure that you have the right connection parameters in Debugger >> Connection tab where you should pick the RPi IP and the port number you previously picked.
  • That’s it !! click Debug and enjoy debugging 🙂

pi11

Now , there is an excellent tutorial for compiling the kernel [this is not my work,  I am just copying it here for future reference because it’s short and to the point ]also elinux wiki has a good compilation:

Create our working directory:

$ mkdir -p raspberrypi/kernel
$ cd raspberrypi/kernel

Before starting our work, install the necessary tools and source code of Raspberry Pi linux:

$ git clone https://github.com/raspberrypi/tools.git
$ git clone https://github.com/raspberrypi/linux.git

Prepare the .config file from pre-packaged config, bcmrpi_cutdown_defconfig:

$ cd linux
$ make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- bcmrpi_cutdown_defconfig

Build kernel:

$ make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi-
$ mkdir ../modules
$ make modules_install ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- INSTALL_MOD_PATH=../modules/
$ cd ../tools/mkimage/
$ ./imagetool-uncompressed.py ../../linux/arch/arm/boot/Image

Now insert a Raspbian installed SD Card, and run the command:

$ sudo rm /media/<boot-partition>/kernel.img
$ sudo mv kernel.img /media/<boot-partition>/
$ sudo rm -rf /media/<rootfs-partition>/lib/modules/
$ sudo rm -rf /media/<rootfs-partition>/lib/firmware/
$ cd ../../modules/
$ sudo cp -a lib/modules/ /media/<rootfs-partition>/lib/
$ sudo cp -a lib/firmware/ /media/<rootfs-partition>/lib/
$ sync

Now you can remove the SD Card and use it to boot Raspberry Pi with the new kernel.

pi8

Finally , here is a nice answer on stackexchange about How the Pi boots and another nice reference :

  1. When the Raspberry Pi is first turned on, the ARM core is off, and the GPU core is on. At this point the SDRAM is disabled.
  2. The GPU starts executing the first stage bootloader, which is stored in ROM on the SoC. The first stage bootloader reads the SD card, and loads the second stage bootloader (bootcode.bin) into the L2 cache, and runs it.
  3. bootcode.bin enables SDRAM, and reads the third stage bootloader (loader.bin) from the SD card into RAM, and runs it.
  4. loader.bin reads the GPU firmware (start.elf).
  5. start.elf reads config.txtcmdline.txt and kernel.img

loader.bin doesn’t do much. It can handle .elf files, and so is needed to load start.elf at the top of memory (ARM uses SDRAM from address zero). There is a plan to add elf loading support to bootcode.bin, which would make loader.bin unnecessary, but it’s a low priority (I guess it might save you 100ms on boot).