├── 00.Content ├── C++1.png ├── Design Pattern.png ├── Design Pattern2.png ├── Device driver.png ├── Docker.png ├── Linux1.png ├── Linux2.png ├── Linux3.png ├── Python.png ├── Rasberry.png ├── Rasberry2.png ├── Rust.png ├── c++2.png ├── yocta2.png ├── yocto.png └── yocto3.png ├── 01.C++ ├── 1.Introduction Tasks │ ├── 1.ASCII Table.cpp │ ├── 2.Max Between 3 Numbers.cpp │ ├── 3.Right Triangle.cpp │ ├── 4.vowel.cpp │ ├── 5.Multi Table.cpp │ ├── 6.Digit Sum.cpp │ └── 7.from Binary to Decimal vice verse version1.cpp ├── 2.Derived Tasks │ ├── 1.Function max_number in array.cpp │ ├── 2.search for a number in the array.cpp │ ├── 3.delete a number from array.cpp │ ├── 4.merge two arrays together.cpp │ ├── 5.find the even and odd numbers in the array.cpp │ ├── 6.calculate the square.cpp │ ├── 7.sort an array of integers in ascending and descending.cpp │ └── SimpleAddressBook.cpp ├── 3.OOP1 │ ├── 1.character is digit,array is even.cpp │ ├── 2.String Class with length Member.cpp │ ├── 3.interupt signal.cpp │ ├── 4.reference function.cpp │ ├── 5.fill array from 10 to 10000.cpp │ ├── 6.AND OR.cpp │ ├── Backtracing.cpp │ └── Backtracing.hpp ├── 4.OOP2 │ ├── 1.String class.cpp │ ├── 2.Integer class.cpp │ └── 3.Logger class.cpp ├── 5.Polymorphism │ └── Drawable.cpp ├── 6.STL │ ├── 1.Array.cpp │ ├── 2.Vector.cpp │ ├── 3.Set.cpp │ ├── 4.Deque.cpp │ ├── 5.String.cpp │ └── 6.map.cpp ├── PC Control │ ├── Application │ ├── Commands.cpp │ ├── Commands.hpp │ ├── Server.cpp │ ├── Server.hpp │ ├── Studing socket programing │ │ ├── TCP_Client.cpp │ │ ├── TCP_Server.cpp │ │ ├── a.out │ │ ├── cmd │ │ ├── main.cpp │ │ ├── multiTCPClient.cpp │ │ ├── multiTCPServers.cpp │ │ └── server │ ├── destination.txt │ ├── main.cpp │ └── source.txt └── c ├── 02.Python ├── 1.Introduction │ ├── __pycache__ │ │ └── psutil.cpython-312.pyc │ ├── task1.py │ ├── task2.py │ └── task3.py ├── 2.Containers │ ├── calc.py │ ├── convert_text_to_speech.py │ ├── date_now.py │ ├── task1_favorite_sites.py │ ├── task2_location.py │ ├── test OOP.py │ └── test containers.py ├── 3.Advanced │ ├── ASCII.py │ ├── AVR Init │ │ ├── AVR.c │ │ └── Init_AVR_task.py │ ├── Battery_Notfication.py │ ├── CSV │ │ ├── Parsing_FUNC_CSV.py │ │ ├── ismail.csv │ │ └── ismail.h │ ├── Generate and run main_c │ │ ├── Generate_main.py │ │ └── main.cpp │ ├── __pycache__ │ │ └── webBrowsing.cpython-312.pyc │ ├── class Generator │ │ ├── Class_Generator.py │ │ ├── som3a.cpp │ │ └── som3a.h │ ├── pyautogui Install tools │ │ ├── Clangd.png │ │ ├── PyAutoGui_ins_c_tools.py │ │ ├── c++ helper.png │ │ ├── c++ testmate.png │ │ ├── cmake tool.png │ │ ├── cmake.png │ │ └── extenstion.png │ ├── pyautogui read gmail │ │ ├── PyAutoGui_Gmail.py │ │ ├── search.png │ │ └── select.png │ ├── testing pyautogui │ │ └── test1.py │ └── voice_assistant.py ├── 4.GUI │ ├── Canva.py │ ├── Factorial.py │ ├── LED.py │ ├── Socket │ │ ├── Client.py │ │ └── server.py │ ├── Studing_GUI.py │ ├── flask.py │ ├── openCV.py │ └── test.jpg └── Final project │ ├── Alexa.py │ ├── Alexa.txt │ ├── PyWhatKit_DB.txt │ ├── README.md │ ├── c │ ├── cv.py │ └── whats.png ├── 03.Linux&Bash ├── File_Descriptor.c ├── Linux │ ├── Bash.md │ ├── Commands.md │ ├── Network.md │ ├── Process.md │ ├── User and Permissions.md │ └── VIM.md ├── README.md ├── Simple_Shell.c ├── Test_Strace.cpp ├── bash scripts │ ├── 2 │ ├── Automated_backup.sh │ ├── Basic_calc.sh │ ├── Battery_noti.sh │ ├── Class_generator.sh │ ├── Erase_flash.sh │ ├── File_compare.sh │ ├── Log_file_monitoring.sh │ ├── Login_Script.sh │ ├── Logout.sh │ ├── Pass_generater.sh │ ├── Ping_network.sh │ ├── Report.sh │ ├── SC_for_CMD.sh │ ├── Saving_files.sh │ ├── Select_colors.sh │ ├── Translate.sh │ ├── User_managment_automation.sh │ ├── Wiki.sh │ ├── cmdlist │ ├── files.txt │ ├── ismail │ ├── ismail1 │ ├── jojo.cpp │ ├── jojo.h │ ├── log.txt │ ├── report.txt │ ├── testing.sh │ └── ytd.sh └── l ├── 04.Raspberry pi ├── 1.Intro │ ├── LedBlink.c │ ├── LedBlink2.c │ └── a.out ├── 2.Discovery │ ├── Gui_Led.py │ ├── PWM_LED.py │ ├── TestSpi.py │ ├── Test_I2C.c │ ├── Test_I2C_esp32.py │ ├── Test_Led.py │ ├── Test_Spi.c │ ├── a.out │ ├── file.dtb │ ├── gui_mesg.py │ ├── hello_gui.service │ ├── test.dts │ └── uart ├── 3.Bringup │ ├── a.out │ ├── bcm2712-rpi-5-b.dtb │ ├── bluetooth.sh │ ├── dht11 │ ├── dht11.c │ ├── dht11.cpp │ ├── dht11_test │ ├── dht_py.py │ ├── file.dts │ ├── project │ │ ├── Dht11.cpp │ │ ├── dht11 │ │ ├── gui.py │ │ ├── sensor_data.csv │ │ └── transfer.sh │ └── test_Button.c ├── 4.Iot │ ├── Mqtt │ │ ├── CMakeLists.txt │ │ ├── Switcher │ │ ├── build │ │ │ ├── CMakeCache.txt │ │ │ ├── CMakeFiles │ │ │ │ ├── 3.25.1 │ │ │ │ │ ├── CMakeCCompiler.cmake │ │ │ │ │ ├── CMakeCXXCompiler.cmake │ │ │ │ │ ├── CMakeDetermineCompilerABI_C.bin │ │ │ │ │ ├── CMakeDetermineCompilerABI_CXX.bin │ │ │ │ │ ├── CMakeSystem.cmake │ │ │ │ │ ├── CompilerIdC │ │ │ │ │ │ ├── CMakeCCompilerId.c │ │ │ │ │ │ └── a.out │ │ │ │ │ └── CompilerIdCXX │ │ │ │ │ │ ├── CMakeCXXCompilerId.cpp │ │ │ │ │ │ └── a.out │ │ │ │ ├── CMakeDirectoryInformation.cmake │ │ │ │ ├── CMakeOutput.log │ │ │ │ ├── Makefile.cmake │ │ │ │ ├── Makefile2 │ │ │ │ ├── Switcher.dir │ │ │ │ │ ├── DependInfo.cmake │ │ │ │ │ ├── build.make │ │ │ │ │ ├── cmake_clean.cmake │ │ │ │ │ ├── compiler_depend.internal │ │ │ │ │ ├── compiler_depend.make │ │ │ │ │ ├── compiler_depend.ts │ │ │ │ │ ├── depend.make │ │ │ │ │ ├── flags.make │ │ │ │ │ ├── link.txt │ │ │ │ │ ├── main.cpp.o │ │ │ │ │ ├── main.cpp.o.d │ │ │ │ │ ├── progress.make │ │ │ │ │ ├── publisher.cpp.o │ │ │ │ │ └── publisher.cpp.o.d │ │ │ │ ├── TargetDirectories.txt │ │ │ │ ├── cmake.check_cache │ │ │ │ └── progress.marks │ │ │ ├── Makefile │ │ │ ├── Switcher │ │ │ └── cmake_install.cmake │ │ ├── main.cpp │ │ ├── main.o │ │ ├── mqtt.ino │ │ ├── publisher │ │ ├── publisher.cpp │ │ ├── publisher.hpp │ │ ├── publisher.o │ │ ├── subscriber │ │ └── subscriber.cpp │ ├── a.out │ ├── download.php │ ├── download_php.cpp │ ├── gettest.py │ ├── mqttclient.py │ ├── mqttserver.py │ ├── project │ │ ├── button.cpp │ │ ├── button_checker │ │ └── publisher │ │ │ ├── publisher.cpp │ │ │ └── publisher.hpp │ ├── raspiserver.cpp │ ├── socket.cpp │ ├── socketclient.py │ ├── sockettest.py │ └── test.txt ├── DHT.cpp ├── DHT.h ├── a.out ├── button_download ├── button_led ├── dht11_test ├── gpio_test ├── led.cpp ├── publisher.cpp ├── s └── test_button.cpp └── README.md /00.Content/C++1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismailTareq/Embedded_linux2024_diploma/c3ed271e30181868f803f4c217f7b4c2dadf9d2f/00.Content/C++1.png -------------------------------------------------------------------------------- /00.Content/Design Pattern.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismailTareq/Embedded_linux2024_diploma/c3ed271e30181868f803f4c217f7b4c2dadf9d2f/00.Content/Design Pattern.png -------------------------------------------------------------------------------- /00.Content/Design Pattern2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismailTareq/Embedded_linux2024_diploma/c3ed271e30181868f803f4c217f7b4c2dadf9d2f/00.Content/Design Pattern2.png -------------------------------------------------------------------------------- /00.Content/Device driver.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismailTareq/Embedded_linux2024_diploma/c3ed271e30181868f803f4c217f7b4c2dadf9d2f/00.Content/Device driver.png -------------------------------------------------------------------------------- /00.Content/Docker.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismailTareq/Embedded_linux2024_diploma/c3ed271e30181868f803f4c217f7b4c2dadf9d2f/00.Content/Docker.png -------------------------------------------------------------------------------- /00.Content/Linux1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismailTareq/Embedded_linux2024_diploma/c3ed271e30181868f803f4c217f7b4c2dadf9d2f/00.Content/Linux1.png -------------------------------------------------------------------------------- /00.Content/Linux2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismailTareq/Embedded_linux2024_diploma/c3ed271e30181868f803f4c217f7b4c2dadf9d2f/00.Content/Linux2.png -------------------------------------------------------------------------------- /00.Content/Linux3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismailTareq/Embedded_linux2024_diploma/c3ed271e30181868f803f4c217f7b4c2dadf9d2f/00.Content/Linux3.png -------------------------------------------------------------------------------- /00.Content/Python.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismailTareq/Embedded_linux2024_diploma/c3ed271e30181868f803f4c217f7b4c2dadf9d2f/00.Content/Python.png -------------------------------------------------------------------------------- /00.Content/Rasberry.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismailTareq/Embedded_linux2024_diploma/c3ed271e30181868f803f4c217f7b4c2dadf9d2f/00.Content/Rasberry.png -------------------------------------------------------------------------------- /00.Content/Rasberry2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismailTareq/Embedded_linux2024_diploma/c3ed271e30181868f803f4c217f7b4c2dadf9d2f/00.Content/Rasberry2.png -------------------------------------------------------------------------------- /00.Content/Rust.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismailTareq/Embedded_linux2024_diploma/c3ed271e30181868f803f4c217f7b4c2dadf9d2f/00.Content/Rust.png -------------------------------------------------------------------------------- /00.Content/c++2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismailTareq/Embedded_linux2024_diploma/c3ed271e30181868f803f4c217f7b4c2dadf9d2f/00.Content/c++2.png -------------------------------------------------------------------------------- /00.Content/yocta2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismailTareq/Embedded_linux2024_diploma/c3ed271e30181868f803f4c217f7b4c2dadf9d2f/00.Content/yocta2.png -------------------------------------------------------------------------------- /00.Content/yocto.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismailTareq/Embedded_linux2024_diploma/c3ed271e30181868f803f4c217f7b4c2dadf9d2f/00.Content/yocto.png -------------------------------------------------------------------------------- /00.Content/yocto3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismailTareq/Embedded_linux2024_diploma/c3ed271e30181868f803f4c217f7b4c2dadf9d2f/00.Content/yocto3.png -------------------------------------------------------------------------------- /01.C++/1.Introduction Tasks/1.ASCII Table.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | cout << "ASCII Table:\n"; 9 | 10 | cout << "----------------" < 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int num1=0,num2=0,num3=0; 9 | cout << "Enter 3 numbers using space: "; 10 | cin >> num1 >> num2 >> num3; 11 | cout << "max number is: "<< max({num1,num2,num3}); 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /01.C++/1.Introduction Tasks/3.Right Triangle.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | /*int height; 9 | 10 | cout << "Enter the height of the triangle: "; 11 | cin >> height; 12 | 13 | for(int i =1 ; i <= height ; i++) 14 | { 15 | for(int j =1 ; j <= i ; j++) 16 | { 17 | cout<<"*"; 18 | } 19 | cout<> height; 25 | 26 | for(int i =1 ; i <= height ; i++) 27 | { 28 | for(int j =1 ; j <= height - i ; j++) 29 | { 30 | cout<<" "; 31 | } 32 | for(int k = 1; k<=i ; k++) 33 | { 34 | cout<<"*"; 35 | } 36 | cout< 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | char ch; 9 | cout << "Enter a letter:\n"; 10 | cin >> ch; 11 | 12 | ch = tolower(ch); 13 | 14 | if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') { 15 | cout << ch << " is a vowel.\n"; 16 | } else { 17 | cout << ch << " is not a vowel.\n"; 18 | } 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /01.C++/1.Introduction Tasks/5.Multi Table.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | for (int i = 1; i <= 10; i++) 9 | { 10 | for (int j = 1; j <= 10; j++) 11 | { 12 | cout << i << ' ' << '*' << ' ' << j << ' ' << '=' << ' ' << i*j << endl; 13 | } 14 | cout << "*************" << endl; 15 | } 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /01.C++/1.Introduction Tasks/6.Digit Sum.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int num,sum{0}; 9 | cout << "Enter an integer:\n"; 10 | cin >> num; 11 | while(num>0) 12 | { 13 | sum += num%10; 14 | num /= 10; 15 | } 16 | cout << "The sum of the digits is: " << sum << endl; 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /01.C++/1.Introduction Tasks/7.from Binary to Decimal vice verse version1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | void decimaltobinary(int dec_num) 7 | { 8 | int arr[11],i=0; 9 | while(dec_num) 10 | { 11 | arr[i] = dec_num%2; 12 | i++; 13 | dec_num = dec_num / 2; 14 | } 15 | cout<< "Binary representation : "; 16 | for(int j = i-1;j>=0;j--) 17 | { 18 | cout<> dec_num ; 43 | 44 | decimaltobinary(dec_num); 45 | 46 | cout << "input a binary number: "; 47 | cin >> bin_num ; 48 | 49 | 50 | cout << "decimal value: "<> choice; 58 | 59 | if (choice == 1) 60 | { 61 | cout << "Enter a binary number: "; 62 | cin >> binary_string; 63 | 64 | bitset<8> binary(binary_string); 65 | 66 | 67 | cout << "The decimal value is : "<< binary.to_ulong() << endl; 68 | } 69 | else if (choice == 2) 70 | { 71 | cout << "Enter a decimal number: "; 72 | cin >> deciaml; 73 | 74 | bitset<8> binaryNumber(deciaml); 75 | 76 | cout << "The binary value is : "<< binaryNumber << endl; 77 | } 78 | else 79 | { 80 | cout << "Enter Valid Choice " << endl; 81 | } 82 | return 0; 83 | } 84 | -------------------------------------------------------------------------------- /01.C++/2.Derived Tasks/1.Function max_number in array.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | /*template 8 | T max_num(const vector&vec) 9 | { 10 | if(!vec.empty()) 11 | return *max_element(vec.begin(),vec.end()); 12 | else 13 | return 0; 14 | }*/ 15 | 16 | int max_num(int arr[],int length) 17 | { 18 | sort(arr,arr+length); 19 | return arr[length-1]; 20 | } 21 | 22 | int main() 23 | { 24 | //cout << "max = " << max({1.1,-5.8,8.2,9.5}) << endl; 25 | //cout << "max = " << max({1,-5,14,8,9}) << endl; 26 | int arr[]={2,5,6,37,85,22}; 27 | 28 | int n=sizeof(arr)/sizeof(arr[0]); 29 | 30 | int result=max_num(arr, n); 31 | 32 | cout< 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | /* 7 | template 8 | bool search_number(const std::vector& vec, T num) 9 | { 10 | return find(vec.begin(),vec.end(),num) != vec.end(); 11 | }*/ 12 | 13 | int main() 14 | { 15 | /*float num; 16 | cout << "Enter the number : "; 17 | cin >> num; 18 | 19 | cout <arr{1,2,3,4,5}; 22 | for_each(arr.begin(),arr.end(),[](int i){cout<> num; 27 | 28 | auto it = find(arr.begin(),arr.end(),num); 29 | if(it!=arr.end()) 30 | { 31 | int index = distance(arr.begin(),it); 32 | cout << "The number you chose is at index: " << index << endl; 33 | } 34 | else 35 | { 36 | cout << "Number is not found" << endl; 37 | } 38 | 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /01.C++/2.Derived Tasks/3.delete a number from array.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | 6 | using namespace std; 7 | 8 | /*void deleteNumber(std::vector& arr, int number) { 9 | arr.erase(std::remove(arr.begin(), arr.end(), number), arr.end()); 10 | }*/ 11 | 12 | 13 | int main() 14 | { 15 | int arr[5] = {1, 2, 3, 4, 5}; 16 | int New_arr[4]; 17 | int number,j=0; 18 | 19 | cout<<"Enter the number that u want to delete: "; 20 | cin >> number; 21 | 22 | for(int i = 0; i < 5;i++) 23 | { 24 | if(arr[i] == number) 25 | { 26 | j--; 27 | } 28 | else 29 | { 30 | New_arr[j] = arr[i]; 31 | } 32 | j++; 33 | } 34 | for(int k : New_arr) 35 | { 36 | cout << k; 37 | } 38 | 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /01.C++/2.Derived Tasks/4.merge two arrays together.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | 6 | using namespace std; 7 | 8 | /*vector mergeArrays(const vector& arr1, const vector& arr2) { 9 | vector merged = arr1; 10 | merged.insert(merged.end(), arr2.begin(), arr2.end()); 11 | return merged; 12 | }*/ 13 | template 14 | void merge_array(const std::vector &vec1,const std::vector &vec2,std::vector &res){ 15 | res.insert(res.end(),vec1.begin(),vec1.end()); 16 | res.insert(res.end(),vec2.begin(),vec2.end()); 17 | } 18 | 19 | int main() 20 | { 21 | std::vector result; 22 | merge_array({1,2,3,4},{5,6.5f,7,8.4f},result); 23 | 24 | for (float i : result) 25 | { 26 | std::cout << i << ' '; 27 | } 28 | std::cout< 2 | #include 3 | #include 4 | 5 | 6 | using namespace std; 7 | 8 | int odd[10]; 9 | int even[10]; 10 | 11 | int even_odd(int arr[]) 12 | { 13 | int e=0,o=0; 14 | for(int i = 0;i < 10;i++) 15 | { 16 | if(arr[i]%2 == 0) 17 | { 18 | even[e] = arr[i]; 19 | e++; 20 | } 21 | else 22 | { 23 | odd[o] = arr[i]; 24 | o++; 25 | } 26 | } 27 | } 28 | 29 | int main() 30 | { 31 | int arr[10]={1,2,3,4,5,6,7,8,9,10}; 32 | 33 | even_odd(arr); 34 | 35 | for(int i=0;i<10;i++) 36 | { 37 | if(odd[i]!=0) 38 | cout< 2 | #include 3 | #include 4 | 5 | 6 | using namespace std; 7 | 8 | 9 | 10 | int main() 11 | { 12 | int number = 0; 13 | 14 | 15 | cout<<"Enter a number: "; 16 | cin >> number; 17 | 18 | auto square = [](int num){return num*num;}; 19 | 20 | 21 | cout << square(number) << endl; 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /01.C++/2.Derived Tasks/7.sort an array of integers in ascending and descending.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | 6 | using namespace std; 7 | 8 | 9 | 10 | int main() 11 | { 12 | vector numbers = {5, 3, 8, 1, 9, 2, 7}; 13 | 14 | sort(numbers.begin(), numbers.end(), [](int a, int b){return a < b;}); 15 | 16 | cout << "Sorted in ascending order: "; 17 | for (int num : numbers) 18 | { 19 | std::cout << num << " "; 20 | } 21 | 22 | cout << endl; 23 | 24 | sort(numbers.begin(), numbers.end(), [](int a, int b){return a > b;}); 25 | 26 | cout << "Sorted in descending order: "; 27 | for (int num : numbers) 28 | { 29 | std::cout << num << " "; 30 | } 31 | 32 | cout << endl; 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /01.C++/2.Derived Tasks/SimpleAddressBook.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | struct Contact 9 | { 10 | string Name; 11 | string PhoneNumber; 12 | string Email; 13 | 14 | void Display_Contact()const 15 | { 16 | cout << "Name: " << Name << endl; 17 | cout << "Phone Number: " << PhoneNumber << endl; 18 | cout << "Email: " << Email << endl; 19 | } 20 | 21 | }; 22 | 23 | class AddressBook 24 | { 25 | private: 26 | vector contacts; 27 | 28 | public: 29 | void AddContact(const Contact &con) 30 | { 31 | contacts.push_back(con); 32 | } 33 | 34 | void UpdateContact(const string &name) 35 | { 36 | auto it = find_if(contacts.begin(),contacts.end(),[&name](const Contact &con){return con.Name == name;}); 37 | 38 | if(it != contacts.end()) 39 | { 40 | cout << "Enter new details for " << name << '\n'; 41 | cout << "New Phone Number: "; 42 | cin >> it->PhoneNumber; 43 | cout << "New Email: "; 44 | cin >> it->Email; 45 | } 46 | else 47 | { 48 | cout << "Contact can't be found.\n"; 49 | } 50 | } 51 | 52 | void SearchContact(string &name) 53 | { 54 | auto it = find_if(contacts.begin(),contacts.end(),[&name](Contact &con){return con.Name == name;}); 55 | 56 | if(it != contacts.end()) 57 | { 58 | it->Display_Contact(); 59 | } 60 | else 61 | { 62 | cout << "Contact can't be found.\n"; 63 | } 64 | } 65 | }; 66 | 67 | 68 | 69 | 70 | int main() 71 | { 72 | AddressBook Book; 73 | int selected; 74 | string name; 75 | 76 | do 77 | { 78 | cout << "\nAddress Book Menu:\n"; 79 | cout << "1. Add Contact\n"; 80 | cout << "2. Update Contact\n"; 81 | cout << "3. Search Contact\n"; 82 | cout << "4. Exit\n"; 83 | cout << "Enter your choice: "; 84 | cin >> selected; 85 | 86 | switch(selected) 87 | { 88 | case 1: 89 | { 90 | Contact new_person; 91 | cout << "Enter name: "; 92 | cin.ignore(); 93 | getline(cin,new_person.Name); 94 | cout << "Enter phone number: "; 95 | cin >> new_person.PhoneNumber; 96 | cout << "Enter email: "; 97 | cin >> new_person.Email; 98 | Book.AddContact(new_person); 99 | break; 100 | } 101 | case 2: 102 | { 103 | cout << "Enter the name of the contact to Update: "; 104 | cin.ignore(); 105 | getline(cin,name); 106 | Book.UpdateContact(name); 107 | break; 108 | } 109 | case 3: 110 | { 111 | cout << "Enter the name of the contact to Search: "; 112 | cin.ignore(); 113 | getline(cin,name); 114 | Book.SearchContact(name); 115 | 116 | break; 117 | } 118 | default: 119 | cout << "Invalid choice. Please try again.\n"; 120 | } 121 | }while(selected != 4); 122 | 123 | cout << "See you soon"; 124 | return 0; 125 | } 126 | -------------------------------------------------------------------------------- /01.C++/3.OOP1/1.character is digit,array is even.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | class Check 8 | { 9 | public: 10 | int digit(char c) 11 | { 12 | return std::isdigit(c); 13 | } 14 | 15 | int ArrIsEven(int arr[],int size) 16 | { 17 | for(int i = 0; i < size ; i++) 18 | { 19 | if(arr[i]%2==1) 20 | { 21 | return 0; 22 | } 23 | } 24 | return 1; 25 | } 26 | }; 27 | 28 | int main() 29 | { 30 | Check check; 31 | char c = 'a'; 32 | std::cout<<"is "<< c << " a digit? "<< (check.digit(c) ? "yes":"no")< 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | class String 9 | { 10 | private: 11 | char *str; 12 | public: 13 | String() 14 | :str(nullptr) 15 | { 16 | 17 | } 18 | ~String() 19 | { 20 | delete[] str; 21 | } 22 | String(const char *s) 23 | { 24 | str = new char[strlen(s) + 1]; 25 | std::strcpy(str,s); 26 | } 27 | int length() const 28 | { 29 | return strlen(str); 30 | } 31 | void display() const 32 | { 33 | std::cout << "String: " << str << "\nLength: " << length() << std::endl; 34 | } 35 | }; 36 | 37 | int main() 38 | { 39 | String mystring("hi this is ismail"); 40 | mystring.display(); 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /01.C++/3.OOP1/3.interupt signal.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void signal_handler(int Signal) 5 | { 6 | std::cout<< "interrupt signal received"< 2 | 3 | int& func() 4 | { 5 | static int x = 5; 6 | std::cout<< x < 2 | #include 3 | #include 4 | 5 | int main() 6 | { 7 | int start = 10,end = 10000; 8 | int size = end -start +1; 9 | std::vectorvec(size); 10 | std::iota(vec.begin(),vec.end(),start); 11 | 12 | for(int i:vec) 13 | { 14 | std::cout << i << std::endl; 15 | } 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /01.C++/3.OOP1/6.AND OR.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() 6 | { 7 | int var1=0,var2=70; 8 | if(var1 and var2) 9 | { 10 | std::cout << "No zero value has been detected AND"< backtrace::vec; 14 | 15 | void func1(); 16 | void func2(); 17 | void func3(); 18 | 19 | void func1() 20 | { 21 | ENTER 22 | func2(); 23 | EXIT 24 | } 25 | void func2() 26 | { 27 | ENTER 28 | func3(); 29 | EXIT 30 | } 31 | void func3() 32 | { 33 | ENTER 34 | BACKTRACING 35 | EXIT 36 | } 37 | 38 | 39 | int main() 40 | { 41 | ENTER 42 | func1(); 43 | EXIT 44 | } 45 | -------------------------------------------------------------------------------- /01.C++/3.OOP1/Backtracing.hpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | class backtrace 6 | { 7 | private: 8 | public: 9 | static std::vector vec; 10 | backtrace(std::string func); 11 | ~backtrace(); 12 | }; 13 | 14 | 15 | #define ENTER std::cout << "Enter to [" << __FUNCTION__ << ']' << std::endl;backtrace bc(__FUNCTION__); 16 | #define EXIT std::cout << "Exit from [" << __FUNCTION__ << ']' << std::endl; 17 | #define BACKTRACING std::cout << "Backtrace as follow : "< 2 | 3 | class String 4 | { 5 | private: 6 | char *str; 7 | unsigned int length; 8 | 9 | public: 10 | String() 11 | :str(nullptr),length(0) 12 | { 13 | 14 | } 15 | 16 | String(const char *data) 17 | { 18 | std::cout << "constructor" << std::endl; 19 | length = std::strlen(data); 20 | str = new char[length + 1];// the +1 is for the termination 21 | std::strcpy(str,data); 22 | } 23 | //copy 24 | String(const String &data) 25 | { 26 | std::cout << "copy constructor" << std::endl; 27 | length = data.length; 28 | str = new char[length + 1];// the +1 is for the termination 29 | std::strcpy(str,data.str); 30 | } 31 | 32 | //move 33 | String(String &&data) 34 | { 35 | std::cout << "move constructor" << std::endl; 36 | //this->str 37 | str = data.str; 38 | length = data.length; 39 | data.str = nullptr; 40 | data.length = 0; 41 | } 42 | 43 | //copy assignment 44 | String& operator=(const String &data) 45 | { 46 | std::cout << "copy constructor ass" << std::endl; 47 | if(this == &data) 48 | return *this; 49 | delete [] str; 50 | 51 | length = data.length; 52 | str = new char[length+1]; 53 | strcpy(str,data.str); 54 | 55 | return *this; 56 | } 57 | 58 | String& operator=(String &&data) 59 | { 60 | std::cout << "move constructor ass" << std::endl; 61 | if(this == &data) 62 | return *this; 63 | delete [] str; 64 | 65 | str = data.str; 66 | length = data.length; 67 | data.str = nullptr; 68 | data.length = 0; 69 | 70 | return *this; 71 | } 72 | 73 | String operator+(const String &data) 74 | { 75 | unsigned int newlength = length + data.length; 76 | char *newstr = new char[newlength+1]; 77 | strcpy(newstr,str); 78 | strcat(newstr,data.str); 79 | 80 | String newstring; 81 | newstring.length = newlength; 82 | newstring.str = newstr; 83 | 84 | //delete [] newstr; 85 | 86 | return newstring; 87 | } 88 | 89 | void print() 90 | { 91 | if(str) 92 | { 93 | std::cout << str << std::endl; 94 | } 95 | } 96 | 97 | ~String() 98 | { 99 | delete [] str; 100 | } 101 | 102 | }; 103 | int main() 104 | { 105 | String s1("hello "); 106 | String s2("ismail "); 107 | //String s3(std::move(s2));//move 108 | //String s3(s2);//copy 109 | String s3 = s1 + s2; 110 | s3.print(); 111 | } 112 | -------------------------------------------------------------------------------- /01.C++/4.OOP2/2.Integer class.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | class Integer 4 | { 5 | private: 6 | int number; 7 | 8 | public: 9 | Integer(int num) 10 | :number(num) 11 | { 12 | 13 | } 14 | 15 | Integer &operator+=(const Integer &num) 16 | { 17 | //this->number 18 | number += num.number; 19 | return *this; 20 | } 21 | 22 | Integer &operator-=(const Integer &num) 23 | { 24 | //this->number 25 | number -= num.number; 26 | return *this; 27 | } 28 | 29 | Integer &operator*=(const Integer &num) 30 | { 31 | //this->number 32 | number *= num.number; 33 | return *this; 34 | } 35 | 36 | Integer &operator/=(const Integer &num) 37 | { 38 | //this->number 39 | number /= num.number; 40 | return *this; 41 | } 42 | 43 | Integer &operator%=(const Integer &num) 44 | { 45 | //this->number 46 | number %= num.number; 47 | return *this; 48 | } 49 | 50 | int operator+(const Integer &num) 51 | { 52 | return number + num.number; 53 | } 54 | 55 | int operator-(const Integer &num) 56 | { 57 | return number - num.number; 58 | } 59 | 60 | Integer &operator=(const Integer &num) 61 | { 62 | number = num.number; 63 | return *this; 64 | } 65 | 66 | Integer &operator=(const int num) 67 | { 68 | number = num ; 69 | return *this; 70 | } 71 | 72 | Integer &operator+(const int &num) 73 | { 74 | number *= num; 75 | return *this; 76 | } 77 | 78 | Integer &operator++() 79 | { 80 | number++; 81 | return *this; 82 | } 83 | 84 | Integer &operator--() 85 | { 86 | number--; 87 | return *this; 88 | } 89 | 90 | Integer &operator--(int) 91 | { 92 | Integer num = this->number; 93 | number--; 94 | return num; 95 | } 96 | 97 | Integer &operator++(int) 98 | { 99 | Integer num = this->number; 100 | number++; 101 | return num; 102 | } 103 | 104 | bool operator>(const Integer &num) 105 | { 106 | return number > num.number; 107 | } 108 | 109 | bool operator<(const Integer &num) 110 | { 111 | return number < num.number; 112 | } 113 | 114 | bool operator>=(const Integer &num) 115 | { 116 | return number >= num.number; 117 | } 118 | 119 | bool operator<=(const Integer &num) 120 | { 121 | return number <= num.number; 122 | } 123 | 124 | bool operator==(const Integer &num) 125 | { 126 | return number == num.number; 127 | } 128 | 129 | bool operator!=(const Integer &num) 130 | { 131 | return number != num.number; 132 | } 133 | 134 | int operator&(const int num) 135 | { 136 | return number & num; 137 | } 138 | 139 | int operator|(const int num) 140 | { 141 | 142 | return number | num; 143 | } 144 | 145 | int operator^(const int num) 146 | { 147 | return number ^ num; 148 | } 149 | 150 | void print() 151 | { 152 | std::cout << number << std::endl; 153 | } 154 | 155 | }; 156 | int main() 157 | { 158 | Integer num1{10}; 159 | Integer num2{20}; 160 | int x; 161 | /* 162 | num1 += num2; 163 | num1.print(); 164 | 165 | num1 -= num2; 166 | num1.print(); 167 | 168 | num1 *= num2; 169 | num1.print(); 170 | 171 | num1 /= num2; 172 | num1.print(); 173 | 174 | num1 %= num2; 175 | num1.print(); 176 | 177 | x = num1+num2; 178 | std::cout< 2 | 3 | enum class level_t 4 | { 5 | WARN, 6 | INFO, 7 | ERROR, 8 | DEBUG 9 | }; 10 | 11 | class LOG 12 | { 13 | private: 14 | std::vectorlogbuffer; 15 | level_t level; 16 | public: 17 | LOG() 18 | :level(level_t::INFO) 19 | { 20 | 21 | } 22 | 23 | void setlevel(level_t lev) 24 | { 25 | level = lev; 26 | } 27 | 28 | LOG& operator<<(const std::pair &loginfo) 29 | { 30 | level_t lev = loginfo.second; 31 | const std::string message = loginfo.first; 32 | 33 | if((int)lev >= (int)level) 34 | { 35 | logbuffer.push_back(message); 36 | } 37 | return *this; 38 | } 39 | 40 | void dump() 41 | { 42 | for(const auto &mess : logbuffer) 43 | std::cout< 2 | 3 | class Drawable 4 | { 5 | private: 6 | 7 | public: 8 | virtual void draw() = 0; 9 | 10 | virtual ~Drawable() = default; 11 | }; 12 | 13 | class Rectangle : public Drawable 14 | { 15 | private: 16 | int height; 17 | int width; 18 | public: 19 | Rectangle(int h,int w) 20 | :height(h),width(w) 21 | { 22 | 23 | } 24 | void draw() 25 | { 26 | for (int i = 0; i < height; ++i) 27 | { 28 | for (int j = 0; j < width; ++j) 29 | { 30 | std::cout << '*'; 31 | } 32 | std::cout << std::endl; 33 | } 34 | } 35 | virtual ~Rectangle() = default; 36 | }; 37 | 38 | class Circle : public Drawable 39 | { 40 | private: 41 | int radius; 42 | public: 43 | Circle(int r) 44 | :radius(r) 45 | { 46 | 47 | } 48 | void draw() 49 | { 50 | double aspect_ratio = 2.5; 51 | for (int y = radius; y >= -radius; --y) 52 | { 53 | for (int x = -radius * aspect_ratio; x <= radius * aspect_ratio; ++x) 54 | { 55 | double distance = (x / aspect_ratio) * (x / aspect_ratio) + y * y; 56 | if (distance <= radius * radius) 57 | std::cout << '*'; 58 | else 59 | std::cout << ' '; 60 | } 61 | std::cout << std::endl; 62 | } 63 | } 64 | ~Circle() = default; 65 | }; 66 | 67 | class Triangle : public Drawable 68 | { 69 | private: 70 | int height; 71 | public: 72 | Triangle(int h) 73 | :height(h) 74 | { 75 | 76 | } 77 | void draw() 78 | { 79 | int width = 2 * height - 1; 80 | 81 | for (int i = 0; i < height; ++i) 82 | { 83 | int numStars = 2 * i + 1; 84 | int numSpaces = (width - numStars) / 2; 85 | for (int j = 0; j < numSpaces; ++j) 86 | { 87 | std::cout << ' '; 88 | } 89 | for (int j = 0; j < numStars; ++j) 90 | { 91 | std::cout << '*'; 92 | } 93 | for (int j = 0; j < numSpaces; ++j) 94 | { 95 | std::cout << ' '; 96 | } 97 | std::cout << std::endl; 98 | } 99 | } 100 | ~Triangle() = default; 101 | }; 102 | 103 | int main() 104 | { 105 | Drawable* shapes; 106 | 107 | shapes = new Circle(3); 108 | 109 | shapes->draw(); 110 | 111 | delete shapes; 112 | 113 | std::cout << std::endl; 114 | 115 | shapes = new Triangle(10); 116 | 117 | shapes->draw(); 118 | 119 | delete shapes; 120 | 121 | std::cout << std::endl; 122 | 123 | shapes = new Rectangle(5,20); 124 | 125 | shapes->draw(); 126 | 127 | delete shapes; 128 | 129 | std::cout << std::endl; 130 | 131 | } 132 | -------------------------------------------------------------------------------- /01.C++/6.STL/1.Array.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | int main() 6 | { 7 | std::arrayarr1 = {1,2,3,4,5}; 8 | std::arrayarr2 = {10,20,30,40,50}; 9 | 10 | arr1 = arr2; 11 | 12 | //bool status = (arr1 == arr2); 13 | 14 | //std::cout << std::boolalpha << status << std::endl; 15 | std::cout << *(arr1.begin()) << std::endl; 16 | std::cout << *(arr1.rbegin()) << std::endl; 17 | std::cout << *(arr1.end()-1) << std::endl; 18 | std::cout << *(arr1.rend()-1) << std::endl; 19 | 20 | std::cout << arr1.front() << std::endl; 21 | std::cout << arr1.back() << std::endl; 22 | 23 | for(int i = 0; i 2 | #include 3 | 4 | template 5 | void print(std::vector v){ 6 | 7 | for(const auto &elem : v) 8 | { 9 | std::cout << elem << " "; 10 | } 11 | std::cout << std::endl; 12 | } 13 | 14 | int main() 15 | { 16 | std::vectorv {1,2,3,4,5}; 17 | print(v); 18 | std::vectorv2 (std::move(v)); 19 | print(v); 20 | print(v2); 21 | std::vectorv3; 22 | v3 = v2; 23 | print(v3); 24 | v.assign(4,10); 25 | v.push_back(15); 26 | v.emplace_back(11); 27 | print(v); 28 | 29 | auto it = v.at(5); 30 | std::cout << it << std::endl; 31 | 32 | std::cout << std::boolalpha << v.empty()<< std::endl; 33 | 34 | v.resize(3); 35 | print(v); 36 | v.resize(7,5); 37 | print(v); 38 | 39 | v.reserve(8); 40 | print(v); 41 | std::cout << v.capacity() << std::endl; 42 | 43 | std::cout<<*(v.data()+5)< 2 | #include 3 | #include 4 | 5 | #define ORDERED 6 | 7 | void print(auto& container){ 8 | for (auto i : container) 9 | { 10 | std::cout << i << ' '; 11 | } 12 | std::cout << std::endl; 13 | } 14 | 15 | #ifdef ORDERED 16 | int main() 17 | { 18 | std::sets{1,2,3,4,5}; 19 | std::setss{10,20,30,40,50}; 20 | print(s); 21 | 22 | std::cout << s.size() << ' ' << s.max_size() << std::endl; 23 | 24 | s.insert(13); 25 | s.insert(20); 26 | s.insert(8); 27 | print(s); 28 | 29 | s.erase(15); 30 | print(s); 31 | 32 | s.swap(ss); 33 | print(s); 34 | print(ss); 35 | 36 | ss.clear(); 37 | 38 | s.emplace_hint(s.begin(),50); 39 | print(s); 40 | 41 | auto it = s.find(11); 42 | std::cout << std::boolalpha << *it << std::endl; 43 | 44 | std::cout << s.count(30) << ' ' << s.count(20) << std::endl; 45 | 46 | auto it1 = s.lower_bound(30); 47 | auto it2 = s.upper_bound(30); 48 | 49 | std::cout << *it1 << ' ' << *it2 << std::endl; 50 | print(s); 51 | 52 | auto it3 = s.lower_bound(41); 53 | auto it4 = s.upper_bound(44); 54 | 55 | std::cout << *it3 << ' ' << *it4 << std::endl; 56 | print(s); 57 | 58 | auto it5 = s.equal_range(10); 59 | it5.swap(it5); 60 | print(s); 61 | } 62 | #else 63 | 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /01.C++/6.STL/4.Deque.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | 6 | void print(auto& container){ 7 | for (auto i : container) 8 | { 9 | std::cout << i << ' '; 10 | } 11 | std::cout << std::endl; 12 | } 13 | 14 | int main() 15 | { 16 | std::dequeq {1,2,3,4,5}; 17 | std::dequeq2 ; 18 | q2.assign({6,4,8,9}); 19 | 20 | for (int i = 0; i < q.size(); i++) 21 | { 22 | std::cout< 2 | #include 3 | 4 | 5 | 6 | void print(auto& container){ 7 | for (auto i : container) 8 | { 9 | std::cout << i << ' '; 10 | } 11 | std::cout << std::endl; 12 | } 13 | 14 | int main() 15 | { 16 | std::string s = "hello"; 17 | 18 | std::string s2(s); 19 | //std::string s3(std::move(s)); 20 | //std::cout << s3 << std::endl; 21 | std::cout << s << std::endl; 22 | 23 | //std::string s2 = s ; 24 | std::cout << s2 << std::endl; 25 | //std::string s2 = std::move(s); 26 | std::cout << s2 << std::endl; 27 | 28 | auto it = s.begin(); 29 | std::cout << *it << std::endl; 30 | 31 | auto it1 = s.begin().base(); //is equal auto it = s.data(); 32 | std::cout << it1 << std::endl; 33 | auto it2 = s.end(); 34 | std::cout << *(it2-1) << std::endl; 35 | 36 | std::cout << s.back() << std::endl; 37 | std::cout << s.size() << std::endl; 38 | std::cout << s.empty() << std::endl; 39 | std::cout << s.capacity() << std::endl; 40 | s.insert(5,"world"); 41 | std::cout<< s << std::endl; 42 | s.erase(6,1); 43 | std::cout<< s << std::endl; 44 | s.clear(); 45 | std::cout << s << std::endl; 46 | s.append("hi ismail"); 47 | std::cout << s << std::endl; 48 | s.replace(3,6,"jomana"); 49 | std::cout << s << std::endl; 50 | s.resize(3); 51 | std::cout << s << std::endl; 52 | s.append("ahmed"); 53 | std::cout << s << std::endl; 54 | s.resize(9,'?'); 55 | std::cout << s << std::endl; 56 | s.assign("hi mohamed"); 57 | std::cout << s << std::endl; 58 | char ch = s.at(3); 59 | std::cout < 2 | #include 3 | 4 | 5 | void print(auto& container){ 6 | for (auto i : container) 7 | { 8 | std::cout << i.first << ' ' << i.second << std::endl; 9 | } 10 | } 11 | 12 | class Student{ 13 | private: 14 | std::string name; 15 | float gpa; 16 | public: 17 | Student(std::string name,float gpa):name(name),gpa(gpa){} 18 | bool is_passed(){ 19 | return gpa > 2; 20 | } 21 | std::string get_name(){ 22 | return name; 23 | } 24 | bool operator<(const Student& student) const{ 25 | return name < student.name; 26 | } 27 | friend std::ostream& operator<<(std::ostream& os,const Student& student){ 28 | os< m= 39 | { 40 | {student1,5000}, 41 | {student2,15000}, 42 | {student3,10000}, 43 | }; 44 | 45 | print(m); 46 | 47 | std::cout << "Empty " << m.empty()< m2= 62 | { 63 | {Student("Kamal",3),900}, 64 | {Student("Saad" ,0.5),2000}, 65 | }; 66 | //m.merge(m2); 67 | print(m); 68 | 69 | m.erase(Student("ismail",3.2)); 70 | 71 | std::cout << "Count1 " << m.count(student1) << std::endl; 72 | std::cout << "Count2 " << m.count(Student("jomana" ,0.5)) << std::endl; 73 | 74 | print(m); 75 | 76 | //auto it = m.find(Student("Hassan" ,0.5)); 77 | auto it = m.find(Student("jomana" ,0.5)); 78 | if(it==m.end()) 79 | std::cout << "Not Found" << std::endl; 80 | else 81 | std::cout << "Find " << it->first << it->second << std::endl; 82 | 83 | m.clear(); 84 | print(m); 85 | return 0; 86 | } 87 | -------------------------------------------------------------------------------- /01.C++/PC Control/Application: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismailTareq/Embedded_linux2024_diploma/c3ed271e30181868f803f4c217f7b4c2dadf9d2f/01.C++/PC Control/Application -------------------------------------------------------------------------------- /01.C++/PC Control/Commands.hpp: -------------------------------------------------------------------------------- 1 | #ifndef COMMANDS_HPP 2 | #define COMMANDS_HPP 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | class Command { 9 | public: 10 | private: 11 | std::string buffer; 12 | 13 | public: 14 | 15 | std::string openTerminal(const std::string& command); 16 | std::string youtube(const std::string& command); 17 | std::string openFolder(const std::string& folderName); 18 | std::string openBrowser(const std::string& query); 19 | void createFile(const std::string& fileName); 20 | void deleteFile(const std::string& fileName); 21 | void copyFile(const std::string& sourcePath, const std::string& destinationPath); 22 | std::string openCamera(); 23 | std::string Takephoto(); 24 | std::string openVScode(); 25 | std::string openCalculator(); 26 | std::string shutdown(); 27 | std::string Restart(); 28 | std::string linkedin(); 29 | std::string github(); 30 | }; 31 | 32 | #endif // COMMANDS_HPP -------------------------------------------------------------------------------- /01.C++/PC Control/Server.cpp: -------------------------------------------------------------------------------- 1 | #include "Server.hpp" 2 | 3 | Server::Server() : serverSockFD(-1), clientSockFD(-1) { 4 | memset(buffer, 0, sizeof(buffer)); 5 | } 6 | 7 | Server::~Server() { 8 | CloseClientSocket(); 9 | CloseServerSocket(); 10 | } 11 | 12 | bool Server::CreateSocket() { 13 | serverSockFD = socket(AF_INET, SOCK_STREAM, 0); 14 | if (serverSockFD <= 0) { 15 | std::cerr << "Cannot create socket" << std::endl; 16 | return false; 17 | } 18 | return true; 19 | } 20 | 21 | bool Server::Bind(int port) { 22 | sockaddr_in serverAddress; 23 | memset(&serverAddress, 0, sizeof(serverAddress)); 24 | serverAddress.sin_family = AF_INET; 25 | serverAddress.sin_addr.s_addr = INADDR_ANY; 26 | serverAddress.sin_port = htons(port); 27 | 28 | if (bind(serverSockFD, (struct sockaddr *)&serverAddress, sizeof(serverAddress)) == -1) { 29 | std::cerr << "Failed to bind TCP socket. Exiting..." << std::endl; 30 | return false; 31 | } 32 | return true; 33 | } 34 | 35 | bool Server::Listen(int backlog) { 36 | if (listen(serverSockFD, backlog) == -1) { 37 | std::cerr << "Failed to listen on TCP socket. Exiting..." << std::endl; 38 | return false; 39 | } 40 | return true; 41 | } 42 | 43 | bool Server::AcceptConnection() { 44 | struct sockaddr_in clientAddress; 45 | socklen_t clientAddressLen = sizeof(clientAddress); 46 | clientSockFD = accept(serverSockFD, (struct sockaddr *)&clientAddress, &clientAddressLen); 47 | if (clientSockFD == -1) { 48 | std::cerr << "Failed to accept incoming TCP connection." << std::endl; 49 | return false; 50 | } 51 | std::cout << "Client connected with socket FD: " << clientSockFD << std::endl; 52 | return true; 53 | } 54 | 55 | void Server::SendDataToClient(const std::string &message) { 56 | int bytes_sent = send(clientSockFD, message.c_str(), message.size(), 0); 57 | std::cout << "sent message: " << message << std::endl; 58 | 59 | if(bytes_sent == -1){ 60 | std::cerr << "failed to send" << std::endl; 61 | //return -1; 62 | } 63 | //return true; 64 | } 65 | 66 | std::string Server::ReceiveDataFromClient() { 67 | if (clientSockFD == -1) { 68 | return "ERROR: No client connected"; 69 | } 70 | 71 | ssize_t bytesRead = recv(clientSockFD, buffer, sizeof(buffer), 0); 72 | if (bytesRead < 0) { 73 | std::cerr << "Error, data not received" << std::endl; 74 | return "ERROR"; 75 | } else if (bytesRead == 0) { 76 | std::cerr << "Client closed the connection" << std::endl; 77 | return "CLOSED"; 78 | } 79 | 80 | std::string receivedData(buffer, bytesRead); 81 | Trim(receivedData); // Trim whitespace 82 | return receivedData; 83 | } 84 | 85 | void Server::CloseClientSocket() { 86 | if (clientSockFD != -1) { 87 | close(clientSockFD); 88 | clientSockFD = -1; 89 | } 90 | } 91 | 92 | void Server::CloseServerSocket() { 93 | if (serverSockFD != -1) { 94 | close(serverSockFD); 95 | serverSockFD = -1; 96 | } 97 | } 98 | 99 | void Server::Trim(std::string &str) { 100 | str.erase(std::find_if(str.rbegin(), str.rend(), [](unsigned char ch) { 101 | return !std::isspace(ch); 102 | }).base(), str.end()); 103 | } -------------------------------------------------------------------------------- /01.C++/PC Control/Server.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SERVER_HPP 2 | #define SERVER_HPP 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | class Server { 15 | public: 16 | Server(); 17 | ~Server(); 18 | 19 | bool CreateSocket(); 20 | bool Bind(int port); 21 | bool Listen(int backlog = 5); 22 | bool AcceptConnection(); 23 | void SendDataToClient(const std::string &message); 24 | std::string ReceiveDataFromClient(); 25 | void CloseClientSocket(); 26 | void CloseServerSocket(); 27 | void Trim(std::string &str); 28 | 29 | private: 30 | int serverSockFD; // Listening socket file descriptor 31 | int clientSockFD; // Client socket file descriptor 32 | char buffer[1024]; // Buffer for receiving data 33 | }; 34 | 35 | #endif // SERVER_HPP -------------------------------------------------------------------------------- /01.C++/PC Control/Studing socket programing/TCP_Client.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | constexpr int BUFFER_SIZE = 1024; 10 | 11 | int main() 12 | { 13 | // Create socket for the client 14 | int clientSockFD = socket(AF_INET, SOCK_STREAM, 0); 15 | if (clientSockFD == -1) { 16 | std::cerr << "Failed to create a socket. Exiting..." << std::endl; 17 | return -1; 18 | } else { 19 | std::cout << "Socket created successfully with FD: " << clientSockFD << std::endl; 20 | } 21 | 22 | // Define server address 23 | struct sockaddr_in serverAddr; 24 | memset(&serverAddr, 0, sizeof(serverAddr)); 25 | serverAddr.sin_family = AF_INET; 26 | serverAddr.sin_port = htons(8080); 27 | if (inet_pton(AF_INET, "127.0.0.1", &serverAddr.sin_addr) <= 0) { 28 | std::cerr << "Invalid address/ Address not supported. Exiting..." << std::endl; 29 | return -1; 30 | } 31 | 32 | // Connect to the server 33 | if (connect(clientSockFD, (struct sockaddr *)&serverAddr, sizeof(serverAddr)) == -1) { 34 | std::cerr << "Failed to connect to the server. Exiting..." << std::endl; 35 | return -1; 36 | } else { 37 | std::cout << "Connected to the server successfully." << std::endl; 38 | } 39 | 40 | // Send data to the server 41 | char buffer[BUFFER_SIZE] = "Hello from the client!"; 42 | send(clientSockFD, buffer, strlen(buffer), 0); 43 | 44 | // Receive data from the server 45 | memset(buffer, 0, sizeof(buffer)); 46 | ssize_t bytesRead = recv(clientSockFD, buffer, sizeof(buffer), 0); 47 | if (bytesRead == -1) { 48 | std::cerr << "Failed to receive data from the server. Exiting..." << std::endl; 49 | } else { 50 | std::cout << "Data received from the server: " << buffer << std::endl; 51 | } 52 | 53 | // Close the socket 54 | close(clientSockFD); 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /01.C++/PC Control/Studing socket programing/TCP_Server.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | int main() 10 | { 11 | //create socket for the server 12 | int serverSockFD = socket(AF_INET, SOCK_STREAM, 0); 13 | if (serverSockFD == -1) { 14 | std::cerr << "Failed to create a socket. Exiting..." << std::endl; 15 | return -1; 16 | } 17 | else 18 | { 19 | std::cout << "Socket created successfully with FD: "<< serverSockFD << std::endl; 20 | } 21 | //bind this socket to a specific port 22 | struct sockaddr_in serverAddr; 23 | 24 | memset(&serverAddr, 0, sizeof(serverAddr)); 25 | serverAddr.sin_family = AF_INET; 26 | serverAddr.sin_addr.s_addr = INADDR_ANY; // Bind to any available network interface 27 | serverAddr.sin_port = htons(8080); 28 | 29 | if(bind(serverSockFD, (struct sockaddr *)&serverAddr, sizeof(serverAddr)) == -1) 30 | { 31 | std::cerr << "Failed to bind the socket to the port. Exiting..." << std::endl; 32 | return -1; 33 | } 34 | else 35 | { 36 | std::cout << "Socket binded to the port successfully." << std::endl; 37 | } 38 | 39 | //listen for incoming connections 40 | if(listen(serverSockFD, 1) == 0) 41 | { 42 | std::cout << "Listening for incoming connections..." << std::endl; 43 | } 44 | else 45 | { 46 | std::cerr << "Failed to listen for incoming connections. Exiting..." << std::endl; 47 | return -1; 48 | } 49 | //accept the incoming connection 50 | struct sockaddr_in connectedClientAddr; 51 | memset(&connectedClientAddr, 0, sizeof(connectedClientAddr)); 52 | socklen_t client_len = sizeof(connectedClientAddr); 53 | int connectedClientSockFD = accept(serverSockFD, (struct sockaddr *)&connectedClientAddr, (socklen_t *)&client_len); 54 | if(connectedClientSockFD == -1) 55 | { 56 | std::cerr << "Failed to accept the incoming connection. Exiting..." << std::endl; 57 | return -1; 58 | } 59 | else 60 | { 61 | std::cout << "Accepted the incoming connection." << std::endl; 62 | } 63 | 64 | //send or receive data from the client 65 | char buffer[1024] = {0} ; 66 | recv(connectedClientSockFD, buffer, sizeof(buffer), 0); 67 | std::cout << "Data received from the client: " << buffer << std::endl; 68 | 69 | //close sockets 70 | close(connectedClientSockFD); 71 | close(serverSockFD); 72 | 73 | return 0; 74 | } -------------------------------------------------------------------------------- /01.C++/PC Control/Studing socket programing/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismailTareq/Embedded_linux2024_diploma/c3ed271e30181868f803f4c217f7b4c2dadf9d2f/01.C++/PC Control/Studing socket programing/a.out -------------------------------------------------------------------------------- /01.C++/PC Control/Studing socket programing/cmd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismailTareq/Embedded_linux2024_diploma/c3ed271e30181868f803f4c217f7b4c2dadf9d2f/01.C++/PC Control/Studing socket programing/cmd -------------------------------------------------------------------------------- /01.C++/PC Control/Studing socket programing/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | constexpr int BUFFER_SIZE = 1024; 10 | constexpr int PORT = 8080; 11 | 12 | void handle_tcp_client(int clientSockFD) 13 | { 14 | char buffer[BUFFER_SIZE]; 15 | while (true) { 16 | memset(buffer, 0, sizeof(buffer)); 17 | ssize_t bytesRead = recv(clientSockFD, buffer, sizeof(buffer), 0); 18 | if (bytesRead <= 0) { 19 | std::cout << "Client disconnected or error receiving data." << std::endl; 20 | break; 21 | } 22 | std::cout << "TCP Data received: " << buffer << std::endl; 23 | send(clientSockFD, buffer, bytesRead, 0); 24 | } 25 | close(clientSockFD); 26 | } 27 | 28 | int main() 29 | { 30 | // Create a socket 31 | int TCPSockFD = socket(AF_INET, SOCK_STREAM, 0); 32 | if (TCPSockFD == -1) { 33 | std::cerr << "Failed to create TCP socket. Exiting..." << std::endl; 34 | return -1; 35 | } 36 | 37 | int option = 1; 38 | setsockopt(TCPSockFD, SOL_SOCKET, SO_REUSEADDR, &option, sizeof(option)); 39 | 40 | // Bind 41 | struct sockaddr_in ServerAddress; 42 | memset(&ServerAddress, 0, sizeof(ServerAddress)); 43 | ServerAddress.sin_addr.s_addr = INADDR_ANY; 44 | ServerAddress.sin_family = AF_INET; 45 | ServerAddress.sin_port = htons(PORT); 46 | if (bind(TCPSockFD, (struct sockaddr *)&ServerAddress, sizeof(ServerAddress)) == -1) { 47 | std::cerr << "Failed to bind TCP socket. Exiting..." << std::endl; 48 | return -1; 49 | } 50 | 51 | // Listen 52 | if (listen(TCPSockFD, 5) == -1) { 53 | std::cerr << "Failed to listen on TCP socket. Exiting..." << std::endl; 54 | return -1; 55 | } 56 | std::cout << "TCP server listening on port " << PORT << "..." << std::endl; 57 | 58 | while (true) { 59 | // Accept a new connection 60 | struct sockaddr_in ClientAddress; 61 | socklen_t ClientAddressLen = sizeof(ClientAddress); 62 | int clientSockFD = accept(TCPSockFD, (struct sockaddr *)&ClientAddress, &ClientAddressLen); 63 | if (clientSockFD == -1) { 64 | std::cerr << "Failed to accept incoming TCP connection." << std::endl; 65 | continue; 66 | } 67 | std::cout << "Accepted TCP connection from client." << std::endl; 68 | 69 | // Handle the client 70 | handle_tcp_client(clientSockFD); 71 | 72 | std::cout << "Client disconnected. Waiting for a new connection..." << std::endl; 73 | } 74 | 75 | // Close the listening socket 76 | close(TCPSockFD); 77 | return 0; 78 | } -------------------------------------------------------------------------------- /01.C++/PC Control/Studing socket programing/multiTCPClient.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | constexpr int buffer = 50; 10 | 11 | void Write(int sock,char *buf); 12 | void Read(int sock,char *buf); 13 | 14 | 15 | int main() 16 | { 17 | //create socket for the client 18 | int clientSockFD = socket(AF_INET, SOCK_STREAM, 0); 19 | if (clientSockFD == -1) { 20 | std::cerr << "Failed to create a socket. Exiting..." << std::endl; 21 | return -1; 22 | } 23 | else 24 | { 25 | std::cout << "Socket created successfully with FD: "<< clientSockFD << std::endl; 26 | } 27 | struct sockaddr_in serverAddr; 28 | memset(&serverAddr, 0, sizeof(serverAddr)); 29 | serverAddr.sin_family = AF_INET; 30 | serverAddr.sin_port = htons(1984); 31 | serverAddr.sin_addr.s_addr = inet_addr("127.0.0.1"); 32 | if(connect(clientSockFD,(struct sockaddr *)&serverAddr, sizeof(serverAddr)) == -1) 33 | { 34 | std::cerr << "Failed to connect to the server. Exiting..." << std::endl; 35 | return -1; 36 | } 37 | else 38 | { 39 | 40 | std::cout << "Connected to the server successfully." << std::endl; 41 | } 42 | char buffer[buffer]; 43 | pid_t PID = fork(); 44 | if(PID == 0) 45 | { 46 | //chiled process 47 | Write(clientSockFD,buffer); 48 | } 49 | else 50 | { 51 | //parent process 52 | Read(clientSockFD,buffer); 53 | } 54 | 55 | 56 | 57 | return 0; 58 | } 59 | void Write(int sock,char *buf) 60 | { 61 | while(1) 62 | { 63 | std::cin.getline(buf, sizeof(buf)); 64 | send(sock, buf, sizeof(buf), 0); 65 | if(buf[0] == 'q' && buf[1] == '\0') 66 | { 67 | std::cout << "Disconnected from the server." << std::endl; 68 | close(sock); 69 | return; 70 | } 71 | memset(buf, 0, buffer); 72 | } 73 | } 74 | void Read(int sock,char *buf) 75 | { 76 | while(1) 77 | { 78 | if(buf[0] == 'q' && buf[1] == '\0') 79 | { 80 | //std::cout << "Disconnected from the server." << std::endl; 81 | close(sock); 82 | return; 83 | } 84 | recv(sock, buf, buffer, 0); 85 | std::cout << "Data received from the server: " << buf << std::endl; 86 | memset(buf, 0, buffer); 87 | break; 88 | } 89 | } -------------------------------------------------------------------------------- /01.C++/PC Control/Studing socket programing/multiTCPServers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | constexpr int TRUE = 1; 10 | constexpr int FALSE = 0; 11 | constexpr int BUFFER_SIZE = 1024; 12 | 13 | int main() 14 | { 15 | //create socket for the client 16 | int clientSockFD = socket(AF_INET, SOCK_STREAM, 0); 17 | if (clientSockFD == -1) { 18 | std::cerr << "Failed to create a socket. Exiting..." << std::endl; 19 | return -1; 20 | } 21 | else 22 | { 23 | std::cout << "Socket created successfully with FD: "<< clientSockFD << std::endl; 24 | } 25 | int option = TRUE; 26 | if(setsockopt(clientSockFD, SOL_SOCKET, SO_REUSEADDR, &option, sizeof(option)) == -1) 27 | { 28 | std::cerr << "Failed to set socket options. Exiting..." << std::endl; 29 | return -1; 30 | } 31 | struct sockaddr_in clientAddr; 32 | 33 | memset(&clientAddr, 0, sizeof(clientAddr)); 34 | clientAddr.sin_family = AF_INET; 35 | clientAddr.sin_addr.s_addr = htonl(INADDR_ANY); 36 | clientAddr.sin_port = htons(1984); 37 | 38 | if(bind(clientSockFD, (struct sockaddr *)&clientAddr, sizeof(clientAddr)) == -1) 39 | { 40 | std::cerr << "Failed to bind the socket to the port. Exiting..." << std::endl; 41 | return -1; 42 | } 43 | else 44 | { 45 | std::cout << "Socket binded to the port successfully." << std::endl; 46 | } 47 | //Connect to the client 48 | if(listen(clientSockFD, 4) == 0) 49 | { 50 | std::cout << "Listening for incoming connections..." << std::endl; 51 | } 52 | else 53 | { 54 | std::cerr << "Failed to listen for incoming connections. Exiting..." << std::endl; 55 | return -1; 56 | } 57 | //Accept the incoming connection 58 | struct sockaddr_in connectedClientAddr; 59 | socklen_t client_len = sizeof(connectedClientAddr); 60 | while(1) 61 | { 62 | memset(&connectedClientAddr, 0, sizeof(connectedClientAddr)); 63 | int connectedClientSockFD = accept(clientSockFD, (struct sockaddr *)&connectedClientAddr, (socklen_t *)&client_len); 64 | if(connectedClientSockFD == -1) 65 | { 66 | std::cerr << "Failed to accept the incoming connection. Exiting..." << std::endl; 67 | return -1; 68 | } 69 | else 70 | { 71 | std::cout << "Accepted the incoming connection." << std::endl; 72 | } 73 | 74 | pid_t PID = fork(); 75 | if(PID == -1) 76 | { 77 | //failed to fork repeat 78 | close (connectedClientSockFD); 79 | continue; 80 | } 81 | 82 | if(PID == 0) 83 | { 84 | //child process so close because the sub prosses will handle the send and receive only will not listten 85 | close(clientSockFD); 86 | char buffer[BUFFER_SIZE] = {0} ; 87 | while (1) 88 | { 89 | //receive data from the client 90 | memset(buffer, 0, sizeof(buffer)); 91 | recv(connectedClientSockFD, buffer, sizeof(buffer), 0); 92 | std::cout << "Data received from the client: " << buffer << std::endl; 93 | if(buffer[0] == 'q' && buffer[1] == '\0') 94 | { 95 | std::cout << "Client disconnected." << std::endl; 96 | close(connectedClientSockFD); 97 | break; 98 | } 99 | else 100 | { 101 | //send data to the client 102 | send(connectedClientSockFD, buffer, strlen(buffer), 0); 103 | } 104 | } 105 | break; 106 | 107 | } 108 | else 109 | { 110 | //parent process close so i can receive another connection 111 | close(connectedClientSockFD); 112 | 113 | 114 | } 115 | } 116 | 117 | 118 | 119 | return 0; 120 | } 121 | 122 | -------------------------------------------------------------------------------- /01.C++/PC Control/Studing socket programing/server: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismailTareq/Embedded_linux2024_diploma/c3ed271e30181868f803f4c217f7b4c2dadf9d2f/01.C++/PC Control/Studing socket programing/server -------------------------------------------------------------------------------- /01.C++/PC Control/destination.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismailTareq/Embedded_linux2024_diploma/c3ed271e30181868f803f4c217f7b4c2dadf9d2f/01.C++/PC Control/destination.txt -------------------------------------------------------------------------------- /01.C++/PC Control/source.txt: -------------------------------------------------------------------------------- 1 | hi this is ismail am being copied help!!! -------------------------------------------------------------------------------- /01.C++/c: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /02.Python/1.Introduction/__pycache__/psutil.cpython-312.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismailTareq/Embedded_linux2024_diploma/c3ed271e30181868f803f4c217f7b4c2dadf9d2f/02.Python/1.Introduction/__pycache__/psutil.cpython-312.pyc -------------------------------------------------------------------------------- /02.Python/1.Introduction/task1.py: -------------------------------------------------------------------------------- 1 | import pyfiglet as pf 2 | import os 3 | ''' 4 | print(pf.figlet_format("task 1 a")) 5 | while True: 6 | try: 7 | data = input("enter list separated by commas: ") 8 | num = input("enter the number to search for in list: ") 9 | 10 | List = [i.strip() for i in data.split(',')] 11 | print(f"number{num} is counted: ",List.count(num)) 12 | break 13 | except KeyboardInterrupt: 14 | print("\nprogrram terminated by user") 15 | break 16 | 17 | while True: 18 | print(pf.figlet_format("task 1 b")) 19 | character = input("enter the character: ") 20 | print("vowel") if character in ['a','e','i','o','u'] else print("not vowel") 21 | ''' 22 | print(pf.figlet_format("task 1 c")) 23 | #print(os.environ["PATH"]) 24 | #print(os.environ.get('PATH')) 25 | #print(os.getcwd()) #get the current directory 26 | #for key,value in os.environ.items(): #get all enviroment variables 27 | # print(f"{key}: {value}") 28 | 29 | #get specific enviroment variables 30 | def get_Enviroment(vars): 31 | v = os.environ[vars] 32 | return f"{vars}: {v}" 33 | vars = ['HOME','PATH','USER','SHELL'] 34 | 35 | for i in vars: 36 | print(get_Enviroment(i)) 37 | -------------------------------------------------------------------------------- /02.Python/1.Introduction/task2.py: -------------------------------------------------------------------------------- 1 | import math as m 2 | import pyfiglet as pf 3 | 4 | 5 | print(pf.figlet_format("task 2")) 6 | 7 | radius = float(input("enter the radius of circle: ")) 8 | print("Area:" ,round(m.pi * m.pow(radius,2),4)) 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /02.Python/1.Introduction/task3.py: -------------------------------------------------------------------------------- 1 | import pyfiglet as pf 2 | import calendar as c 3 | 4 | 5 | 6 | print(pf.figlet_format("task 3")) 7 | 8 | year = int(input("enter the year: ")) 9 | month = int(input("enter the month: ")) 10 | 11 | print(c.month(year,month,w=1,l=2)) 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /02.Python/2.Containers/calc.py: -------------------------------------------------------------------------------- 1 | def sum(a,b): 2 | return a+b 3 | def sub(a,b): 4 | return a-b 5 | def mul(a,b): 6 | return a*b 7 | def div(a,b): 8 | return a/b -------------------------------------------------------------------------------- /02.Python/2.Containers/convert_text_to_speech.py: -------------------------------------------------------------------------------- 1 | from gtts import gTTS 2 | import vlc 3 | 4 | text = 'hello ismail am proud of u' 5 | lang = 'en' 6 | slow = False 7 | 8 | # Save audio in mp3 format 9 | obj = gTTS(text=text, lang=lang, slow=slow) 10 | obj.save("ismail.mp3") 11 | 12 | # Play the audio using VLC 13 | p = vlc.MediaPlayer("./ismail.mp3") 14 | p.play() 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /02.Python/2.Containers/date_now.py: -------------------------------------------------------------------------------- 1 | import datetime 2 | 3 | now = datetime.datetime.now() 4 | print("date and time: ",str(now)[0:-7])#to print only the seconds 5 | -------------------------------------------------------------------------------- /02.Python/2.Containers/task1_favorite_sites.py: -------------------------------------------------------------------------------- 1 | import webbrowser 2 | 3 | dic = { 4 | "1":'https://www.facebook.com/', 5 | "2":'https://web.whatsapp.com/', 6 | "3":'https://www.youtube.com/', 7 | "4":'https://github.com/', 8 | "5":'https://www.gmail.com/' 9 | } 10 | 11 | def brave(url): 12 | webbrowser.open_new_tab(url) 13 | 14 | while True: 15 | print("Enter the number of the website you will use:") 16 | print("1 - Facebook") 17 | print("2 - WhatsApp") 18 | print("3 - YouTube") 19 | print("4 - github") 20 | print("5 - gmail") 21 | 22 | x = input("enter ur choice") 23 | 24 | url = dic.get(x) 25 | brave(url) 26 | -------------------------------------------------------------------------------- /02.Python/2.Containers/task2_location.py: -------------------------------------------------------------------------------- 1 | import requests 2 | 3 | x=requests.get('https://api.ipify.org/?format=json') 4 | print(x.json()) 5 | 6 | 7 | x=requests.get(' https://ipinfo.io/156.192.247.109/geo') 8 | print(x.json()) 9 | -------------------------------------------------------------------------------- /02.Python/2.Containers/test OOP.py: -------------------------------------------------------------------------------- 1 | class animal : 2 | def __init__(self): 3 | self.name = 'animal' 4 | print("animal created") 5 | def speak(self): 6 | print("am a animal") 7 | def __del__(self): 8 | print("animal destractor") 9 | 10 | class cat(animal): 11 | def __init__(self): 12 | super.__init__() 13 | self.name = 'cat' 14 | print("cat created") 15 | def eat(self): 16 | print("eat") 17 | def __del__(self): 18 | print("cat destractor") 19 | super.__del__() 20 | 21 | obj = cat() 22 | obj.speak() 23 | obj.eat() 24 | 25 | -------------------------------------------------------------------------------- /02.Python/2.Containers/test containers.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | ''' 3 | name = "ismail tarek" 4 | print(name.capitalize()) 5 | name = "ISMAIL Tarek" 6 | print(name.casefold()) 7 | name = "ISMAIL Tarek" 8 | print(name.lower()) 9 | name = "ISMAIL" 10 | print(name.center(14)) 11 | print(name.center(14,"-")) 12 | print(name.count('I')) 13 | 14 | name = "ISMAIL" 15 | enc = name.encode('utf-8') 16 | print(enc) 17 | print(type(enc)) 18 | dec = enc.decode('utf-8') 19 | print(dec) 20 | print(type(dec)) 21 | 22 | name = "ismail tarek" 23 | print(name.startswith("ismail")) 24 | print(name.endswith("tarEk")) 25 | 26 | print(name.find("s")) 27 | print(name.find("s",2)) 28 | print(name.find("tarek")) 29 | 30 | name = " ismail tarek " 31 | print(name.strip()) 32 | 33 | name = " ismail tarek " 34 | print(name.replace("i","e")) 35 | 36 | name = "ismail takre elsayed" 37 | print(name.split(" ")) 38 | print(name.split(" ")[1]) 39 | 40 | age = 30 41 | name = "ismail" 42 | 43 | x = "name {} and age {} ".format(name,age) 44 | print(x) 45 | x = f"name {name} and age {age} " 46 | print(x) 47 | x = "name {0} and age {1}".format(name,age) 48 | print(x) 49 | x = "name %s and age %d"%(name,age) 50 | print(x) 51 | 52 | names = ["hi","iam","ismail"] 53 | print(" ".join(names)) 54 | 55 | def func(): 56 | print("ismail is here") 57 | 58 | func(); 59 | 60 | def func(name): 61 | print(f"{name} is here") 62 | 63 | func("7amo"); 64 | 65 | def func(child3,child2,child1): 66 | print("the child1 is " + child1) 67 | print("the child1 is " + child2) 68 | print("the child1 is " + child3) 69 | 70 | func("ismail",child2="jomana",child1="safia") 71 | 72 | def func(country = "Egypt"): 73 | print("Iam from " + country) 74 | 75 | func("sweden") 76 | func("gboty") 77 | func() 78 | 79 | def func(arg): 80 | for x in arg: 81 | print(x) 82 | list1 = ["apple","kiwi","banana"] 83 | tuple1 = (1,"ismail",3.5) 84 | 85 | func(list1) 86 | func(tuple1) 87 | 88 | def func(*arg): 89 | print(type(arg)) 90 | print(arg[0]) 91 | print(arg[1]) 92 | print(arg[2]) 93 | 94 | func(1,"ismail",3.5) 95 | 96 | def func(**arg): 97 | print(type(arg)) 98 | print(arg["name"]) 99 | print(arg["age"]) 100 | print(arg["email"]) 101 | dic = {"name":"ismail","age":25, "email":"ismailelghawas12@gmail.com"} 102 | func(name = "ismail",age = "25", email = "ismailelghawas12@gmail.com") 103 | func(**dic) 104 | 105 | x =55 106 | def func(): 107 | global x 108 | x = 77 109 | print(x) 110 | print(id(x)) 111 | func() 112 | print(x) 113 | print(id(x)) 114 | 115 | ls = [1,2,3,4,5,6,7,8,9] 116 | 117 | print(list(filter(lambda x:x%2==0,ls))) 118 | 119 | import calc 120 | 121 | print(calc.sum(5,5)) 122 | 123 | import calc as c 124 | print(c.sum(5,5)) 125 | 126 | 127 | ls = [1,2,3,4,5,6,"ismail","zain","safia"] 128 | 129 | ls.append("jomana") 130 | print(ls) 131 | ls2 = ls.copy() 132 | ls.append("7amza") 133 | print(ls) 134 | print(ls2) 135 | ls.extend([1,2,3,4]) 136 | print(ls) 137 | ls.insert(2,"akram") 138 | print(ls) 139 | ''' 140 | fruits = ("apple","banana","cherry","kiwi","zink") 141 | (green,long,*fruit) = fruits 142 | print(green) 143 | print(long) 144 | print(type(fruit)) 145 | print(fruit) 146 | 147 | 148 | 149 | 150 | 151 | -------------------------------------------------------------------------------- /02.Python/3.Advanced/ASCII.py: -------------------------------------------------------------------------------- 1 | char=str(input("Please enter your character:")) 2 | print(ord(char)) -------------------------------------------------------------------------------- /02.Python/3.Advanced/AVR Init/AVR.c: -------------------------------------------------------------------------------- 1 | void Init_PORTA (void){ 2 | DDRA = 0b111010; 3 | } -------------------------------------------------------------------------------- /02.Python/3.Advanced/AVR Init/Init_AVR_task.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | data = 0 4 | for bit in range(8): 5 | mode = input(f"please Enter bit {bit} mode: ").casefold().strip() 6 | if mode == "in": 7 | data |= 0< main.cpp") 6 | 7 | f=open("main.cpp",'w') 8 | f.write("#include \nint main()\n{\n return 0;\n}\n") 9 | f.close() -------------------------------------------------------------------------------- /02.Python/3.Advanced/Generate and run main_c/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /02.Python/3.Advanced/__pycache__/webBrowsing.cpython-312.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismailTareq/Embedded_linux2024_diploma/c3ed271e30181868f803f4c217f7b4c2dadf9d2f/02.Python/3.Advanced/__pycache__/webBrowsing.cpython-312.pyc -------------------------------------------------------------------------------- /02.Python/3.Advanced/class Generator/Class_Generator.py: -------------------------------------------------------------------------------- 1 | import os 2 | from datetime import datetime 3 | 4 | x = datetime.now() 5 | date = x.strftime("%Y %B %d - %H:%M%S") 6 | #print(date) 7 | 8 | name = input("plz enter ur name") 9 | 10 | class_name = input("please enter your class name:").strip() 11 | namespace = input("please enter your name space: ").strip() 12 | 13 | os.system(f"touch {class_name}.h") 14 | 15 | #RAII 16 | with open(f"{class_name}.h","w") as file: 17 | file.write(f"#pragma once \n\ 18 | \n/***** copyright {name} *****/") 19 | file.write(f"/*\n\ 20 | author : {name} \n\ 21 | date : {date} \n\ 22 | brief:\n\ 23 | \n*/\n") 24 | 25 | 26 | 27 | file.write(f"namespace {namespace}") 28 | file.write("{\n") 29 | file.write(f"class {class_name}") 30 | file.write("{\n\npublic:\n") 31 | 32 | file.write(f" {class_name}::{class_name}();") 33 | file.write(f"\n {class_name}::~{class_name}();\n \n") 34 | 35 | file.write("private:\n") 36 | file.write("\n \n \n};") 37 | file.write("\n}") 38 | 39 | os.system(f"touch {class_name}.cpp") 40 | with open(f"{class_name}.cpp","w") as file1: 41 | file1.write(f"\ 42 | \n/***** copyright {name} *****/") 43 | file1.write(f"/*\n\ 44 | author : {name} \n\ 45 | date : {date} \n\ 46 | brief:\n\ 47 | \n*/\n") 48 | 49 | file1.write(f"#include \"{class_name}.h\" \n\ 50 | namespace {namespace}") 51 | 52 | file1.write("{\n") 53 | file1.write(f" {class_name}::{class_name}()") 54 | file1.write(r"{}") 55 | file1.write(f"\n {class_name}::~{class_name}()") 56 | file1.write(r"{}") 57 | file1.write("\n}") 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /02.Python/3.Advanced/class Generator/som3a.cpp: -------------------------------------------------------------------------------- 1 | 2 | /***** copyright ismail *****//* 3 | author : ismail 4 | date : 2024 December 25 - 19:4120 5 | brief: 6 | 7 | */ 8 | #include "som3a.h" 9 | namespace std{ 10 | som3a::som3a(){} 11 | som3a::~som3a(){} 12 | } -------------------------------------------------------------------------------- /02.Python/3.Advanced/class Generator/som3a.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /***** copyright ismail *****//* 4 | author : ismail 5 | date : 2024 December 25 - 19:4120 6 | brief: 7 | 8 | */ 9 | namespace std{ 10 | class som3a{ 11 | 12 | public: 13 | som3a::som3a(); 14 | som3a::~som3a(); 15 | 16 | private: 17 | 18 | 19 | 20 | }; 21 | } -------------------------------------------------------------------------------- /02.Python/3.Advanced/pyautogui Install tools/Clangd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismailTareq/Embedded_linux2024_diploma/c3ed271e30181868f803f4c217f7b4c2dadf9d2f/02.Python/3.Advanced/pyautogui Install tools/Clangd.png -------------------------------------------------------------------------------- /02.Python/3.Advanced/pyautogui Install tools/PyAutoGui_ins_c_tools.py: -------------------------------------------------------------------------------- 1 | import pyautogui as p 2 | from time import sleep 3 | 4 | sleep(3) 5 | #print(p.position()) 6 | 7 | '''''' 8 | p.press('win') 9 | #sleep(2) 10 | p.write('vscode') 11 | p.press('enter') 12 | sleep(2) 13 | 14 | try: 15 | loc = None 16 | while loc is None: 17 | loc = p.locateOnScreen('extenstion.png') 18 | sleep(2) 19 | except p.ImageNotFoundException: 20 | print('ImageNotFoundException') 21 | exit() 22 | 23 | p.click(loc.left,loc.top,duration=1) 24 | p.moveTo(247,152) 25 | sleep(2) 26 | p.click() 27 | p.write('clangd') 28 | p.moveTo(228,211) 29 | sleep(2) 30 | p.click() 31 | #p.moveTo(718,261) 32 | #sleep(2) 33 | #p.click() 34 | sleep(2) 35 | loc = p.locateOnScreen('Clangd.png') 36 | if loc: 37 | x,y = p.center(loc) 38 | #print(x,y) 39 | p.click(x-87,y+40) 40 | 41 | 42 | 43 | p.moveTo(247,152) 44 | p.click() 45 | p.hotkey('ctrl','a') 46 | sleep(2) 47 | p.press('delete') 48 | sleep(3) 49 | #p.click() 50 | p.write('c++ testmate') 51 | p.moveTo(228,211) 52 | sleep(2) 53 | p.click() 54 | sleep(2) 55 | loc = p.locateOnScreen('c++ testmate.png') 56 | if loc: 57 | x,y = p.center(loc) 58 | #print(x,y) 59 | p.click(x-87,y+40) 60 | 61 | p.moveTo(247,152) 62 | p.click() 63 | p.hotkey('ctrl','a') 64 | sleep(2) 65 | p.press('delete') 66 | sleep(3) 67 | #p.click() 68 | p.write('c++ helper') 69 | p.moveTo(228,211) 70 | sleep(2) 71 | p.click() 72 | sleep(2) 73 | loc = p.locateOnScreen('c++ helper.png') 74 | if loc: 75 | x,y = p.center(loc) 76 | print(x,y) 77 | p.click(x-87,y+40) 78 | 79 | p.moveTo(247,152) 80 | p.click() 81 | p.hotkey('ctrl','a') 82 | sleep(2) 83 | p.press('delete') 84 | sleep(3) 85 | 86 | p.write('cmake') 87 | p.moveTo(228,211) 88 | sleep(2) 89 | p.click() 90 | 91 | loc = p.locateOnScreen('cmake.png') 92 | if loc: 93 | x,y = p.center(loc) 94 | p.click(x-101,y+35) 95 | 96 | p.moveTo(235,287) 97 | p.click() 98 | 99 | loc = p.locateOnScreen('cmake tool.png') 100 | if loc: 101 | x,y = p.center(loc) 102 | p.click(x-101,y+35) 103 | 104 | 105 | -------------------------------------------------------------------------------- /02.Python/3.Advanced/pyautogui Install tools/c++ helper.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismailTareq/Embedded_linux2024_diploma/c3ed271e30181868f803f4c217f7b4c2dadf9d2f/02.Python/3.Advanced/pyautogui Install tools/c++ helper.png -------------------------------------------------------------------------------- /02.Python/3.Advanced/pyautogui Install tools/c++ testmate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismailTareq/Embedded_linux2024_diploma/c3ed271e30181868f803f4c217f7b4c2dadf9d2f/02.Python/3.Advanced/pyautogui Install tools/c++ testmate.png -------------------------------------------------------------------------------- /02.Python/3.Advanced/pyautogui Install tools/cmake tool.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismailTareq/Embedded_linux2024_diploma/c3ed271e30181868f803f4c217f7b4c2dadf9d2f/02.Python/3.Advanced/pyautogui Install tools/cmake tool.png -------------------------------------------------------------------------------- /02.Python/3.Advanced/pyautogui Install tools/cmake.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismailTareq/Embedded_linux2024_diploma/c3ed271e30181868f803f4c217f7b4c2dadf9d2f/02.Python/3.Advanced/pyautogui Install tools/cmake.png -------------------------------------------------------------------------------- /02.Python/3.Advanced/pyautogui Install tools/extenstion.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismailTareq/Embedded_linux2024_diploma/c3ed271e30181868f803f4c217f7b4c2dadf9d2f/02.Python/3.Advanced/pyautogui Install tools/extenstion.png -------------------------------------------------------------------------------- /02.Python/3.Advanced/pyautogui read gmail/PyAutoGui_Gmail.py: -------------------------------------------------------------------------------- 1 | import pyautogui 2 | import webbrowser 3 | from time import sleep 4 | 5 | url = "https://mail.google.com/mail/u/1/#inbox" 6 | 7 | webbrowser.open(url,new=2) 8 | sleep(10) 9 | try: 10 | location = None 11 | while location is None: 12 | location = pyautogui.locateOnScreen('search.png') 13 | sleep(1) 14 | pyautogui.click(location.left+15,location.top+10) 15 | sleep(1) 16 | pyautogui.typewrite('label:') 17 | pyautogui.typewrite('unread') 18 | sleep(1) 19 | pyautogui.click(location.left,location.top) 20 | sleep(5) 21 | location2 = pyautogui.locateOnScreen('select.png') 22 | sleep(1) 23 | pyautogui.click(location2.left+15,location2.top+5) 24 | sleep(2) 25 | pyautogui.click(location2.left+215,location2.top+5) 26 | 27 | except pyautogui.ImageNotFoundException: 28 | print("Image not found") -------------------------------------------------------------------------------- /02.Python/3.Advanced/pyautogui read gmail/search.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismailTareq/Embedded_linux2024_diploma/c3ed271e30181868f803f4c217f7b4c2dadf9d2f/02.Python/3.Advanced/pyautogui read gmail/search.png -------------------------------------------------------------------------------- /02.Python/3.Advanced/pyautogui read gmail/select.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismailTareq/Embedded_linux2024_diploma/c3ed271e30181868f803f4c217f7b4c2dadf9d2f/02.Python/3.Advanced/pyautogui read gmail/select.png -------------------------------------------------------------------------------- /02.Python/3.Advanced/testing pyautogui/test1.py: -------------------------------------------------------------------------------- 1 | import pyautogui as p 2 | import time 3 | #print(p.size()) 4 | #print(p.position()) 5 | #print(p.position()) 6 | 7 | #while True: 8 | # print(p.displayMousePosition()) 9 | 10 | #p.moveTo(0,0,duration=0) 11 | #print(p.position()) 12 | #p.click(128,146,duration=0) 13 | #p.dragTo(100,100,duration=4) 14 | 15 | #p.scroll(1000) 16 | ''' 17 | for i in range(10): 18 | p.moveTo(100,100,duration=0.25) 19 | p.moveTo(200,100,duration=0.25) 20 | p.moveTo(200,200,duration=0.25) 21 | p.moveTo(100,100,duration=0.25) 22 | ''' 23 | #time.sleep(3) 24 | 25 | #p.mouseUp(100,100,button="left") 26 | #p.mouseDown(100,100,button="left") 27 | ''' 28 | #example 29 | p.mouseDown(300,400,button="left") 30 | p.moveTo(800,400,3) 31 | p.mouseUp() 32 | p.moveTo(1000,400,3) 33 | # project drawing 34 | time.sleep(3) 35 | distance = 300 36 | while distance > 0: 37 | p.dragRel(distance,0,1,button="left") 38 | distance = distance - 20 39 | p.dragRel(0,distance,1,button="left") 40 | p.dragRel(-distance,0,1,button="left") 41 | distance = distance - 20 42 | p.dragRel(0,-distance,1,button="left") 43 | time.sleep(2) 44 | 45 | #tiktok liked 46 | time.sleep(3) 47 | #print(p.position()) 48 | 49 | for i in range(10): 50 | #p.moveTo(450,500) 51 | time.sleep(1) 52 | #p.doubleClick() 53 | #time.sleep(1) 54 | p.moveTo(645,415) 55 | time.sleep(1) 56 | p.leftClick() 57 | 58 | time.sleep(2) 59 | 60 | p.write("hello ismail") 61 | p.press("enter") 62 | 63 | #dino game 64 | time.sleep(3) 65 | for i in range(20): 66 | p.press("space") 67 | time.sleep(1) 68 | ''' 69 | p.screenshot("screen.png") 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | -------------------------------------------------------------------------------- /02.Python/3.Advanced/voice_assistant.py: -------------------------------------------------------------------------------- 1 | import speech_recognition as sr 2 | import pyttsx3 3 | import webbrowser 4 | from datetime import datetime 5 | from time import sleep 6 | import wikipedia 7 | import pywhatkit 8 | import calendar 9 | 10 | def Listen_to_User(): 11 | 12 | rec = sr.Recognizer() 13 | 14 | # properly opened and closed 15 | # Reading Microphone as source 16 | # listening the speech and store in audio_text variable 17 | with sr.Microphone() as source: 18 | print("Listening.....") 19 | audio = rec.listen(source) 20 | try: 21 | CMD = rec.recognize_google(audio,language = 'en') 22 | print(f"you said {CMD}") 23 | #to make sure it goes to the write command 24 | return CMD.lower() 25 | except sr.UnknownValueError: 26 | print("Speech Recognition could not understand audio") 27 | return "" 28 | 29 | def Respond_Voice(Respones): 30 | TTS = pyttsx3.init() 31 | 32 | # Slowing down the speech rate 33 | rate = TTS.getProperty('rate') # Getting current speech rate 34 | TTS.setProperty('rate', rate - 80) # Reducing the rate by 80 units 35 | 36 | TTS.say(Respones) 37 | TTS.runAndWait() 38 | 39 | def User_greating(): 40 | cur_time = datetime.now().strftime("%H") 41 | if cur_time < "12": 42 | response = "Good morning Ismail." 43 | elif cur_time < "18": 44 | response = "Good afternoon Ismail." 45 | else: 46 | response = "Good Evening Ismail." 47 | Respond_Voice(response) 48 | 49 | def Get_time_now(): 50 | return datetime.now().strftime("%H:%M:%S") 51 | 52 | def Get_date(): 53 | now = datetime.now() 54 | month = calendar.month_name[now.month] 55 | return f"{now.strftime('%A')} {now.day} {month} {now.year}" 56 | 57 | def get_wikipedia_summary(command): 58 | search_query = command.replace('tell me ', '') 59 | response = wikipedia.summary(search_query, sentences=1) 60 | try: 61 | response = wikipedia.summary(search_query, sentences=1) 62 | 63 | except wikipedia.exceptions.DisambiguationError as e: 64 | response = f"Multiple options found. {str(e)}" 65 | except wikipedia.exceptions.PageError as e: 66 | response = f"No information found. {str(e)}" 67 | return response 68 | def play_song(command): 69 | #to remove any white spaces 70 | song_name = command.replace('play', '').strip() 71 | try: 72 | pywhatkit.playonyt(song_name) 73 | response = f"Playing {song_name} on YouTube." 74 | except Exception as e: 75 | response = f"Failed to play {song_name}: {str(e)}" 76 | 77 | print(response) 78 | return response 79 | 80 | def main(): 81 | User_greating() 82 | 83 | CMD = Listen_to_User() 84 | 85 | if 'google' in CMD: 86 | webbrowser.open("https://gemini.google.com/app") 87 | response = "opening google." 88 | Respond_Voice(response) 89 | elif 'tell me about' in CMD: 90 | response = get_wikipedia_summary(CMD) 91 | Respond_Voice(response) 92 | elif 'date' in CMD: 93 | response = Get_date() 94 | Respond_Voice(response) 95 | elif 'time' in CMD: 96 | response = Get_time_now() 97 | Respond_Voice(response) 98 | elif 'play' in CMD: 99 | response = play_song(CMD) 100 | Respond_Voice(response) 101 | 102 | if __name__ == "__main__": 103 | main() 104 | 105 | 106 | 107 | 108 | 109 | -------------------------------------------------------------------------------- /02.Python/4.GUI/Canva.py: -------------------------------------------------------------------------------- 1 | import tkinter as tk 2 | import math 3 | 4 | class Gauge(tk.Canvas): 5 | def __init__(self, master, size=200, *args, **kwargs): 6 | super().__init__(master, width=size, height=size, *args, **kwargs) 7 | self.size = size 8 | self.configure(bg='white', highlightthickness=0) 9 | self.draw_gauge() 10 | 11 | def draw_gauge(self): 12 | center = self.size // 2 13 | radius = center - 10 14 | 15 | # Draw outer circle 16 | self.create_oval(10, 10, self.size - 10, self.size - 10, outline='black', width=2) 17 | 18 | angle = 135 19 | value = 0.4 20 | angle_offset = 270 # Offset the gauge position 21 | indicator_angle = angle_offset + (value * 270) 22 | 23 | x1 = center + radius * math.cos(math.radians(angle_offset)) 24 | y1 = center + radius * math.sin(math.radians(angle_offset)) 25 | x2 = center + radius * math.cos(math.radians(indicator_angle)) 26 | y2 = center + radius * math.sin(math.radians(indicator_angle)) 27 | self.create_line(center, center, x2, y2, fill='red', width=3) 28 | 29 | # Draw center circle 30 | self.create_oval(center - 10, center - 10, center + 10, center + 10, fill='black') 31 | 32 | # Display value 33 | self.create_text(center, center + 30, text=f'{int(value * 100)}%', font=('Arial', 14), fill='black') 34 | 35 | if __name__ == "__main__": 36 | root = tk.Tk() 37 | root.title("Gauge Example") 38 | 39 | gauge = Gauge(root) 40 | gauge.pack(pady=20) 41 | 42 | root.mainloop() -------------------------------------------------------------------------------- /02.Python/4.GUI/Factorial.py: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | from tkinter import messagebox 3 | 4 | root = Tk() 5 | root.geometry("300x300+300+450") 6 | root.title("factorial") 7 | 8 | var = IntVar() 9 | 10 | def Factorial(): 11 | num = var.get() 12 | fact = 1 13 | for i in range(1,num+1): 14 | fact *= i 15 | messagebox.showinfo("Factorial Result", f"The factorial of {num} is {fact}") 16 | 17 | 18 | Label(root,text="Enter the number ").grid(row=0) 19 | 20 | Entry(root,bg="white",textvariable=var).grid(row=0,column=1) 21 | 22 | Button(root,text="Click here",command=Factorial).grid(row=1,column=1) 23 | 24 | root.mainloop() 25 | -------------------------------------------------------------------------------- /02.Python/4.GUI/LED.py: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | 3 | root = Tk() 4 | root.title("Led") 5 | 6 | def Send_Signal(sig): 7 | if sig == 'on': 8 | root.configure(bg='red') 9 | elif sig == 'off': 10 | root.configure(bg='white') 11 | 12 | button_on = Button(root, text="on", bg="green", fg="white", padx=20, pady=10,command=lambda: Send_Signal('on')) 13 | button_off = Button(root, text="off", bg="red", padx=20, pady=10,command=lambda: Send_Signal('off')) 14 | 15 | button_on.pack(padx=20, pady=10) 16 | button_off.pack(padx=20, pady=10) 17 | 18 | root.mainloop() 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /02.Python/4.GUI/Socket/Client.py: -------------------------------------------------------------------------------- 1 | import socket 2 | 3 | client = socket.socket(socket.AF_INET ,socket.SOCK_STREAM) 4 | 5 | client.connect(("127.0.0.1",65432)) 6 | 7 | msg = str(input("enter message you want to send: ")) 8 | msg1 = msg.encode('UTF-8') 9 | client.send(msg1) 10 | 11 | data = client.recv(1024) 12 | print(f"127.0.0.1 is sending this message {data.decode('UTF-8')}") 13 | client.close() 14 | -------------------------------------------------------------------------------- /02.Python/4.GUI/Socket/server.py: -------------------------------------------------------------------------------- 1 | import socket 2 | 3 | soc = socket.socket(socket.AF_INET ,socket.SOCK_STREAM) 4 | 5 | soc.bind(("127.0.0.1",65432)) 6 | soc.listen(10) 7 | 8 | while True: 9 | client , address = soc.accept() 10 | data = client.recv(1024) 11 | print(f"{address} is sending this message {data.decode('UTF-8')}") 12 | msg = str(input("enter message you want to send: ")) 13 | msg1 = msg.encode('UTF-8') 14 | client.send(msg1) 15 | client.close() 16 | -------------------------------------------------------------------------------- /02.Python/4.GUI/Studing_GUI.py: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | import threading 3 | import timer 4 | 5 | 6 | ''' 7 | root = tkinter.Tk() 8 | root.title("ismail's GUI") 9 | root.geometry("300x300+300+450") 10 | #root.configure(background="red") 11 | ''' 12 | ''' 13 | tkinter.Label(root,text="ismail",bg="black",fg="red").pack(pady=10) 14 | tkinter.Label(root,text="safia",bg="black",fg="red").pack(pady=10) 15 | tkinter.Label(root,text="jomana",bg="black",fg="red").pack(pady=10) 16 | tkinter.Label(root,text="tarek",bg="black",fg="red").pack(pady=10) 17 | ''' 18 | ''' 19 | tkinter.Label(root,text="ismail",bg="black",fg="red").place(x=10) 20 | tkinter.Label(root,text="safia",bg="black",fg="red").place(x=30) 21 | tkinter.Label(root,text="jomana",bg="black",fg="red").place(x=50) 22 | tkinter.Label(root,text="tarek",bg="black",fg="red").place(x=70) 23 | ''' 24 | ''' 25 | tkinter.Label(root,text="ismail",bg="black",fg="red").grid(row=0) 26 | tkinter.Label(root,text="safia",bg="black",fg="red").grid(row=1) 27 | tkinter.Label(root,text="jomana",bg="black",fg="red").grid(row=2) 28 | ''' 29 | ''' 30 | tkinter.Label(root,text="ismail",bg="black",fg="red").pack(pady=10) 31 | tkinter.Button(root,command=root.destroy,text="close").pack(pady=50) 32 | 33 | 34 | root.mainloop() 35 | ''' 36 | ''' 37 | root = Tk() 38 | root.title("ismail's GUI") 39 | root.geometry("300x300+300+450") 40 | frame = Frame(root) 41 | frame.pack() 42 | 43 | BTNframe = Frame(root) 44 | Red_button = Button(frame,text="red",fg='red') 45 | Red_button.pack(side= LEFT) 46 | 47 | Green_button = Button(frame,text="green",fg='red') 48 | Green_button.pack(side= LEFT) 49 | 50 | Blue_button = Button(frame,text="blue",fg='red') 51 | Blue_button.pack(side= LEFT) 52 | 53 | BTNframe = Frame(root) 54 | BTNframe.pack(side=BOTTOM) 55 | 56 | Yellow_button = Button(BTNframe,text="yellow",fg='red') 57 | Yellow_button.pack(side= BOTTOM) 58 | 59 | 60 | root.mainloop() 61 | ''' 62 | ''' 63 | def BTN_Handler(): 64 | print(f"you sent {var.get()}") 65 | var.set("") 66 | 67 | root = Tk() 68 | root.title("ismail's GUI") 69 | root.geometry("300x300+300+450") 70 | var = StringVar() 71 | frame = Frame(root,bg="brown",border=5,relief=SOLID) 72 | frame.pack(expand=True,fill="both",side="left") 73 | 74 | 75 | entry = Entry(frame,font=("arial",10,"bold"),bd = 5,textvariable= var) 76 | button = Button(frame,text="send",fg='red',command=BTN_Handler) 77 | button.pack() 78 | entry.pack() 79 | root.mainloop() 80 | ''' 81 | ''' 82 | def items_selected(event): 83 | index = lb.curselection() 84 | print(index) 85 | print(lb.get(index)) 86 | 87 | root = Tk() 88 | root.title("ismail's GUI") 89 | root.geometry("300x300+300+450") 90 | 91 | lb = Listbox() 92 | lb.insert(1,"python") 93 | lb.insert(2,"c") 94 | lb.insert(3,"c++") 95 | 96 | lb.pack() 97 | lb.bind('<>',items_selected) 98 | root.mainloop() 99 | ''' 100 | ''' 101 | root = Tk() 102 | root.title("ismail's GUI") 103 | root.geometry("300x300+300+450") 104 | var = IntVar() 105 | 106 | Radiobutton(root,text="c",value=1,variable=var).pack() 107 | Radiobutton(root,text="c++",value=2,variable=var).pack() 108 | button = Button(root,text="send",fg='red',command=lambda:print(var.get())) 109 | button.pack() 110 | root.mainloop() 111 | ''' 112 | ''' 113 | root = Tk() 114 | root.title("ismail's GUI") 115 | root.geometry("300x300+300+450") 116 | 117 | var = IntVar() 118 | 119 | Radiobutton(root,text="c",value=1,variable=var).pack() 120 | Radiobutton(root,text="c++",value=2,variable=var).pack() 121 | 122 | def show(): 123 | global t 124 | print(var.get()) 125 | if var.get() == 1: 126 | print("c") 127 | elif var.get() == 2: 128 | print("c++") 129 | 130 | t = threading.Timer(1,show) 131 | t.start() 132 | 133 | threading.Timer(1,show).start() 134 | 135 | try: 136 | root.mainloop() 137 | t.cancel() 138 | except: 139 | exit() 140 | ''' 141 | ''' 142 | root = Tk() 143 | root.title("ismail's GUI") 144 | root.geometry("300x300+300+450") 145 | 146 | var = IntVar() 147 | 148 | def show(): 149 | global t 150 | print(var.get()) 151 | t = threading.Timer(1,show) 152 | t.start() 153 | 154 | threading.Timer(1,show).start() 155 | Scale(root,from_=0,to=100,variable=var).pack() 156 | try: 157 | root.mainloop() 158 | t.cancel() 159 | except: 160 | exit() 161 | ''' 162 | ''' 163 | root = Tk() 164 | root.title("ismail's GUI") 165 | root.geometry("300x300+300+450") 166 | 167 | var = IntVar() 168 | 169 | def show(): 170 | global t 171 | print(text.get("1.0",END)) 172 | t = threading.Timer(0.5,show) 173 | t.start() 174 | text = Text(root) 175 | threading.Timer(0.5,show).start() 176 | text.pack() 177 | try: 178 | root.mainloop() 179 | t.cancel() 180 | except: 181 | exit() 182 | ''' 183 | ''' 184 | root = Tk() 185 | root.title("ismail's GUI") 186 | root.geometry("300x300+300+450") 187 | 188 | def NewWindow(): 189 | new = Toplevel(root) 190 | new.title("the new window") 191 | root.geometry("300x300+300+450") 192 | Label(new,text="ismail is here",bg="black",fg="red").pack() 193 | 194 | btn = Button(root,text="open new window",fg='red',command=NewWindow) 195 | btn.pack() 196 | root.mainloop() 197 | ''' 198 | 199 | 200 | -------------------------------------------------------------------------------- /02.Python/4.GUI/flask.py: -------------------------------------------------------------------------------- 1 | import flask -------------------------------------------------------------------------------- /02.Python/4.GUI/openCV.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | 3 | def main(): 4 | cap = cv2.VideoCapture(0) 5 | if not cap.isOpened(): 6 | print("error opening webcam") 7 | exit() 8 | while True: 9 | ret,frame = cap.read() 10 | if not ret: 11 | print("can't receive frame") 12 | break 13 | cv2.imshow('frame',frame) 14 | key = cv2.waitKey(1) 15 | if key == ord('q'): 16 | break 17 | if key == ord('c'): 18 | cv2.imwrite('test.jpg',frame) 19 | 20 | cap.release() 21 | cv2.destroyAllWindows() 22 | main() -------------------------------------------------------------------------------- /02.Python/4.GUI/test.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismailTareq/Embedded_linux2024_diploma/c3ed271e30181868f803f4c217f7b4c2dadf9d2f/02.Python/4.GUI/test.jpg -------------------------------------------------------------------------------- /02.Python/Final project/Alexa.txt: -------------------------------------------------------------------------------- 1 | hello -------------------------------------------------------------------------------- /02.Python/Final project/PyWhatKit_DB.txt: -------------------------------------------------------------------------------- 1 | Date: 10/1/2025 2 | Time: 13:9 3 | Phone Number: +20102792293 4 | Message: hello 5 | -------------------- 6 | Date: 10/1/2025 7 | Time: 13:12 8 | Phone Number: +201002792293 9 | Message: 10 | -------------------- 11 | Date: 10/1/2025 12 | Time: 13:20 13 | Phone Number: +201002792293 14 | Message: hello 15 | -------------------- 16 | Date: 10/1/2025 17 | Time: 13:24 18 | Phone Number: +201002792293 19 | Message: summer 20 | -------------------- 21 | Date: 10/1/2025 22 | Time: 13:25 23 | Phone Number: +201002792293 24 | Message: ismail 25 | -------------------- 26 | Date: 10/1/2025 27 | Time: 13:27 28 | Phone Number: +201002792293 29 | Message: 30 | -------------------- 31 | Date: 10/1/2025 32 | Time: 13:50 33 | Phone Number: +201002792293 34 | Message: 35 | -------------------- 36 | -------------------------------------------------------------------------------- /02.Python/Final project/README.md: -------------------------------------------------------------------------------- 1 | ### Alexa voice assistant 2 | I'm thrilled to announce to you all a major accomplishment: the release of my most recent Python project, "Alexa: Your Personal Voice Assistant." 3 | 4 | This innovative project presents a state-of-the-art voice assistant that does more than just recognise speech. Alexa has been painstakingly built to carry out a variety of instructions that are designed to improve your everyday activities and expedite your work. Alexa's fluency in Arabic allows for smooth communication and interaction, which is what makes it unique. 5 | 6 | Permit me to give you a summary of the amazing features and capabilities built within Alexa: 7 | 8 | 🔹1.Sending the recipient a customized welcome based on the time of day, such as morning or afternoon. 9 | 10 | 🔹2.Getting the most recent weather information. 11 | 12 | 🔹3.Searching for anything on Google. 13 | 14 | 🔹4.Telling jokes for a little giggle. 15 | 16 | 🔹5.Sending emails. 17 | 18 | 🔹6.Sending any message to any phone number on WhatsApp Use voice-activated messaging to stay in touch. 19 | 20 | 🔹7.Playing any song directly from YouTube. 21 | 22 | 🔹8.Supplying the time as of this moment. 23 | 24 | 🔹9.Gives the current date. 25 | 26 | 🔹10.Translating between Arabic, English, German. 27 | 28 | 🔹11.Notifications are sent out every 60 seconds. 29 | 30 | 🔹12.Reminder for the things you would like to be reminded of at a specific moment. 31 | 32 | 🔹13.Tell you who am I. 33 | 34 | 🔹14.Takes screenshot. 35 | 36 | 🔹15.Indicates the five prayers' azan time. 37 | 38 | 🔹16.Creating new file and you may give it whatever name you choose. 39 | 40 | 🔹17.Put your thoughts in a designated file by saying the file name. 41 | 42 | 🔹18. Easily read any particular file you want just say it's name. 43 | 44 | 🔹19.Fast Wikipedia search. 45 | -------------------------------------------------------------------------------- /02.Python/Final project/c: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /02.Python/Final project/cv.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import mediapipe as mp 3 | 4 | # Initialize Mediapipe Hands 5 | mp_hands = mp.solutions.hands 6 | hands = mp_hands.Hands() 7 | mp_drawing = mp.solutions.drawing_utils 8 | 9 | # Initialize webcam 10 | cap = cv2.VideoCapture(0) 11 | 12 | def detect_finger_movements(hand_landmarks): 13 | finger_chars = ["A", "B", "C", "D", "E"] 14 | finger_states = [] 15 | 16 | # Thumb 17 | if hand_landmarks.landmark[mp_hands.HandLandmark.THUMB_TIP].x < hand_landmarks.landmark[mp_hands.HandLandmark.THUMB_IP].x: 18 | finger_states.append(1) 19 | else: 20 | finger_states.append(0) 21 | 22 | # Fingers 23 | for id in range(1, 5): 24 | if hand_landmarks.landmark[mp_hands.HandLandmark(id * 4)].y < hand_landmarks.landmark[mp_hands.HandLandmark(id * 4 - 2)].y: 25 | finger_states.append(1) 26 | 27 | else: 28 | finger_states.append(0) 29 | 30 | closed_fingers = [finger_chars[i] for i, state in enumerate(finger_states) if state == 0] 31 | if closed_fingers: 32 | print("Closed fingers:", closed_fingers) 33 | 34 | while cap.isOpened(): 35 | success, image = cap.read() 36 | if not success: 37 | break 38 | 39 | # Flip the image horizontally for a later selfie-view display 40 | image = cv2.flip(image, 1) 41 | image_rgb = cv2.cvtColor(image, cv2.COLOR_RGB2BGR) 42 | 43 | # Process the image and find hands 44 | results = hands.process(image_rgb) 45 | 46 | if results.multi_hand_landmarks: 47 | for hand_landmarks in results.multi_hand_landmarks: 48 | mp_drawing.draw_landmarks(image, hand_landmarks, mp_hands.HAND_CONNECTIONS) 49 | detect_finger_movements(hand_landmarks) 50 | 51 | cv2.imshow('Hand Tracking', image) 52 | if cv2.waitKey(5) & 0xFF == 27: 53 | break 54 | 55 | cap.release() 56 | cv2.destroyAllWindows() 57 | -------------------------------------------------------------------------------- /02.Python/Final project/whats.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismailTareq/Embedded_linux2024_diploma/c3ed271e30181868f803f4c217f7b4c2dadf9d2f/02.Python/Final project/whats.png -------------------------------------------------------------------------------- /03.Linux&Bash/File_Descriptor.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | 6 | int main() 7 | { 8 | int fd = open("file8", O_RDONLY); 9 | if(fd == -1) 10 | { 11 | perror("open"); 12 | return 1; 13 | } 14 | char buf[200]; 15 | unsigned int read_byte = read(fd, buf, sizeof(buf)); 16 | if(read_byte == -1) 17 | { 18 | perror("read"); 19 | return 1; 20 | } 21 | buf[read_byte] = '\0'; 22 | 23 | printf("read %d bytes:\n %s",read_byte,buf); 24 | close(fd); 25 | return 0; 26 | 27 | } -------------------------------------------------------------------------------- /03.Linux&Bash/Linux/VIM.md: -------------------------------------------------------------------------------- 1 | # Linux Revision Course 2 | 3 | Welcome to the **Vim Section**! 4 | 5 | ## All of the commands we used 6 | 7 | ### 1. Normal mode 8 | - `h` - Move cursor left 9 | - `l` - Move cursor right 10 | - `j` - Move cursor down 11 | - `k` - Move cursor up 12 | - `dd` - Delete the current line 13 | - `yy` - Yank (copy) the current line 14 | - `p` - Paste after the cursor 15 | - `u` - Undo the last action 16 | - `Ctrl+r` - Redo the undone action 17 | - `:w` - Save the file 18 | - `:q` - Quit Vim 19 | - `:wq` - Save and quit 20 | - `:q!` - Quit without saving 21 | ### 2. Insert mode 22 | - `i` - Insert before the cursor 23 | - `I` - Insert at the beginning of the line 24 | - `a` - Append after the cursor 25 | - `A` - Append at the end of the line 26 | - `o` - Open a new line below the current line 27 | - `O` - Open a new line above the current line 28 | - `x` - Delete the character under the cursor 29 | - `dw` - Delete from the cursor to the end of the current word 30 | - `dd` - Delete the current line 31 | - `d$` - Delete from the cursor to the end of the line 32 | - `dgg` - Delete from the cursor to the beginning of the file 33 | - `dG` - Delete from the cursor to the end of the file 34 | - `cw` - Change the current word 35 | - `cc` - Change the current line 36 | - `c$` - Change from the cursor to the end of the line 37 | ### 3. Visual mode 38 | - `v` - Start visual mode (character-wise selection) 39 | - `V` - Start visual line mode (line-wise selection) 40 | - `Ctrl+v` - Start visual block mode (block-wise selection) 41 | - `y` - Yank (copy) the selected text 42 | - `d` - Delete the selected text 43 | - `c` - Change the selected text 44 | - `>` - Indent the selected text 45 | - `<` - Unindent the selected text 46 | - `=` - Auto-indent the selected text 47 | - `u` - Convert selected text to lowercase 48 | - `U` - Convert selected text to uppercase 49 | 50 | ### 4. Command-line mode 51 | - `:` - Enter command-line mode 52 | - `:set nu` - Show line numbers 53 | - `:set nonu` - Hide line numbers 54 | - `:set hlsearch` - Highlight search results 55 | - `:set nohlsearch` - Remove search highlights 56 | - `:set ignorecase` - Ignore case in search patterns 57 | - `:set noignorecase` - Case-sensitive search 58 | - `:set incsearch` - Incremental search 59 | - `:set noincsearch` - Disable incremental search 60 | - `:!` - Run a shell command 61 | - `:r` - Read content from a file into the current buffer 62 | - `:e` - Open a file in Vim 63 | - `:bd` - Close the current buffer 64 | - `:sp` - Split the window horizontally 65 | - `:vsp` - Split the window vertically 66 | - `:tabnew` - Open a new tab 67 | - `:tabn` - Switch to the next tab 68 | - `:tabp` - Switch to the previous tab 69 | - `:tabc` - Close the current tab 70 | 71 | ### 5. Recording and Macros 72 | - `q` - Start recording a macro into the specified register (e.g., `qa` to record into register `a`). 73 | - `q` - Stop recording the macro. 74 | - `@` - Play back the macro stored in the specified register (e.g., `@a` to play back the macro in register `a`). 75 | - `@@` - Replay the last executed macro. 76 | - `:reg` - View the contents of all registers, including recorded macros. 77 | 78 | ### 6. Search and Replace 79 | - `/pattern` - Search forward for "pattern". 80 | - `?pattern` - Search backward for "pattern". 81 | - `n` - Repeat the last search in the same direction. 82 | - `N` - Repeat the last search in the opposite direction. 83 | - `:%s/old/new/g` - Replace all occurrences of "old" with "new" in the entire file. 84 | - `:%s/old/new/gc` - Replace all occurrences of "old" with "new" in the entire file, with confirmation. 85 | - `:s/old/new/` - Replace the first occurrence of "old" with "new" in the current line. 86 | - `:s/old/new/g` - Replace all occurrences of "old" with "new" in the current line. 87 | - `:noh` - Clear search highlighting. 88 | 89 | -------------------------------------------------------------------------------- /03.Linux&Bash/README.md: -------------------------------------------------------------------------------- 1 | # 🐧 Unified Linux Engineering: RHCSA & Embedded Linux Systems in 7 Sessions 2 | 3 | **Master Enterprise Administration and Embedded Development Through 22 Hours of Integrated Learning** 4 | 5 | ## 🚀 Course Philosophy 6 | This unique 7-video series breaks down artificial barriers For Linux, teaching you to: 7 | 8 | 1. [**Video 0: Course Content**](#video0) 9 | *Duration: 15min* 10 | 11 | 1. [**Video 1: All Concepts about Linux and Kernel**](#video1) 12 | *Duration: 1.5h* 13 | 14 | 2. [**Video 2: Shell & Basic Commands**](#video2) 15 | *Duration: 1.5h* 16 | 17 | 3. [**Video 3: Commands | Vim | FileSystem**](#video3) 18 | *Duration: 4h* 19 | 20 | 4. [**Video 4: User and Permissions**](#video4) 21 | *Duration: 3h* 22 | 23 | 6. [**Video 5: Process | daemon | Service**](#video6) 24 | *Duration: 3.5h* 25 | 26 | 7. [**Video 6: Network**](#video7) 27 | *Duration: 4h* 28 | 29 | 7. [**Video : Bash Scripting**](#video7) 30 | *Duration: 5h* 31 | 32 | --- 33 | 34 | ## 📽️ Video Details 35 | ### Video 0: Course Content 36 | [![Watch Now](https://img.shields.io/badge/Watch-Video_0-blue)](https://drive.google.com/drive/u/1/folders/1kXVxTkuUF-9aFqNqef9wOC6IeSnzHQpY) 37 | 38 | ### Video 1: All Concepts about Linux and Kernel 39 | [![Watch Now](https://img.shields.io/badge/Watch-Video_1-blue)](https://drive.google.com/drive/u/1/folders/1RLKHAUlWzAInVcn9aegeHexHOYiEYzJo) 40 | 41 | ### Video 2: Shell & Basic Commands 42 | [![Watch Now](https://img.shields.io/badge/Watch-Video_2-blue)](https://drive.google.com/drive/u/1/folders/1UHJhD-7MxFI5t4CLhxdf_HkiPSs0albz) 43 | 44 | ### Video 3: Commands | Vim | FileSystem 45 | [![Watch Now](https://img.shields.io/badge/Watch-Video_3-blue)](https://drive.google.com/drive/u/1/folders/1aUgh8XaSOTVLQOHzyoBlih4QjqNFp4Be) 46 | 47 | ### Video 4: User and Permissions 48 | [![Watch Now](https://img.shields.io/badge/Watch-Video_4-blue)](https://drive.google.com/drive/u/1/folders/13rxydd4b48O_rQxIpF_QMWKT7wsffZdO) 49 | 50 | ### Video 5: Process | daemon | Service 51 | [![Watch Now](https://img.shields.io/badge/Watch-Video_5-blue)](https://drive.google.com/drive/u/1/folders/1RXrk_4M7kgiQoSBoZAtzx2EYtGyKUWXW) 52 | 53 | ### Video 6: Network 54 | [![Watch Now](https://img.shields.io/badge/Watch-Video_6-blue)](https://drive.google.com/drive/u/1/folders/1xw9nW4jpT7hjfgyD8ViRocej2HEsVMV7) 55 | 56 | ### Video 7: Bash Scripting 57 | [![Watch Now](https://img.shields.io/badge/Watch-Video_7-blue)](https://drive.google.com/drive/u/1/folders/1IfL4yXgWhKZ8Gx3yfEvia1cvAFm9TeyM) 58 | 59 | 60 | -------------------------------------------------------------------------------- /03.Linux&Bash/Simple_Shell.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "signal.h" 4 | 5 | //#define MAX_LENGTH 50 6 | void signal_handler(int signum) 7 | { 8 | printf("Signal %d received\n", signum); 9 | } 10 | 11 | void sighand() 12 | { 13 | for(int i = 0; i < NSIG; i++) 14 | signal(i, signal_handler); 15 | } 16 | 17 | int main() 18 | { 19 | 20 | signal(SIGINT, sighand); 21 | printf("process id: %d pressed ctlr + c tp trigger \n", getpid()); 22 | 23 | while(1) 24 | { 25 | printf("Waiting for signal...\n"); 26 | sleep(1); 27 | } 28 | 29 | /*char Input[MAX_LENGTH]; 30 | while(1) 31 | { 32 | printf("super shell$ "); 33 | fgets(Input, sizeof(Input), stdin); 34 | 35 | 36 | if(Input[0] == '\n') 37 | { 38 | continue; 39 | } 40 | 41 | Input[strcspn(Input,"\n")] = '\0'; 42 | 43 | if(strcmp(Input, "exit") == 0 || strcmp(Input, "q") == 0) 44 | { 45 | printf("Goodbye! Thank you for using the shell.\n"); 46 | break; 47 | } 48 | 49 | char *cmd = strtok(Input, " "); 50 | char *args[MAX_LENGTH]; 51 | int i = 0; 52 | while(cmd != NULL) 53 | { 54 | args[i++] = cmd; 55 | cmd = strtok(NULL, " "); 56 | } 57 | args[i] = NULL; 58 | 59 | pid_t child_pid = fork(); 60 | if(child_pid == -1) 61 | { 62 | perror("fork failed"); 63 | exit(EXIT_FAILURE); 64 | 65 | } 66 | else if (child_pid == 0) 67 | { 68 | execvp(args[0], args); 69 | perror("Execution failed"); 70 | exit(EXIT_FAILURE); 71 | } 72 | else 73 | { 74 | int status; 75 | waitpid(child_pid,&status,0); 76 | 77 | } 78 | }*/ 79 | 80 | 81 | 82 | return 0; 83 | } -------------------------------------------------------------------------------- /03.Linux&Bash/Test_Strace.cpp: -------------------------------------------------------------------------------- 1 | #include "iostream" 2 | #include "string" 3 | #include "string.h" 4 | #include "unistd.h" 5 | #include 6 | 7 | int main() 8 | { 9 | const char *mesg = "ismail is awesome\n"; 10 | ssize_t bytes_written = write(STDOUT_FILENO, mesg, strlen(mesg)); 11 | if (bytes_written == -1) 12 | { 13 | std::cerr << "write() failed" << std::endl; 14 | return 1; 15 | } 16 | 17 | return 0; 18 | } -------------------------------------------------------------------------------- /03.Linux&Bash/bash scripts/2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismailTareq/Embedded_linux2024_diploma/c3ed271e30181868f803f4c217f7b4c2dadf9d2f/03.Linux&Bash/bash scripts/2 -------------------------------------------------------------------------------- /03.Linux&Bash/bash scripts/Automated_backup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | Source_DIR="/home/ismail/maindir" 4 | Backup_DIR="/home/ismail/backup" 5 | Log_FILE="/home/ismail/backup/backup.log" 6 | Timestamp=$(date +"%Y-%m-%d %H:%M:%S") 7 | Backupfilename="backup_$Timestamp.tar.gz" 8 | 9 | if [ ! -d "$Source_DIR" ]; then 10 | echo "Source directory does not exist. Exiting." >> "$Log_FILE" 11 | exit 1 12 | fi 13 | if [ ! -d "$Backup_DIR" ]; then 14 | echo "Backup directory does not exist. Creating it." >> "$Log_FILE" 15 | exit 1 16 | fi 17 | echo "Starting backup at $Timestamp" >> "$Log_FILE" 18 | tar -czf "$Backup_DIR/$Backupfilename" "$Source_DIR" 19 | 20 | find "$Backup_DIR" -type f -name "backup_*.tar.gz" -mtime +7 -delete 21 | 22 | if [ $? -eq 0 ]; then 23 | echo "Backup completed successfully at $(date +"%Y-%m-%d %H:%M:%S")" 24 | else 25 | echo "Backup failed at $(date +"%Y-%m-%d %H:%M:%S")" >> "$Log_FILE" 26 | fi -------------------------------------------------------------------------------- /03.Linux&Bash/bash scripts/Basic_calc.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | show_menu() { 4 | echo "1. Add" 5 | echo "2. Subtract" 6 | echo "3. Multiply" 7 | echo "4. Divide" 8 | echo "5. Exit" 9 | } 10 | 11 | add() { 12 | echo "enter two numbers to add" 13 | read -r a b 14 | result=$((a + b)) 15 | echo "Result: $result" 16 | } 17 | subtract() { 18 | echo "enter two numbers to subtract" 19 | read -r a b 20 | result=$((a - b)) 21 | echo "Result: $result" 22 | } 23 | multiply() { 24 | echo "enter two numbers to multiply" 25 | read -r a b 26 | result=$((a * b)) 27 | echo "Result: $result" 28 | } 29 | divide() { 30 | echo "enter two numbers to divide" 31 | read -r a b 32 | if [ "$b" -eq 0 ]; then 33 | echo "Error: Division by zero is not allowed." 34 | else 35 | result=$((a / b)) 36 | echo "Result: $result" 37 | fi 38 | } 39 | 40 | while true; do 41 | show_menu 42 | echo "Enter your choice (1-5):" 43 | read -r choice 44 | 45 | case $choice in 46 | 1) add ;; 47 | 2) subtract ;; 48 | 3) multiply ;; 49 | 4) divide ;; 50 | 5) echo "Exiting..."; exit 0 ;; 51 | *) echo "Invalid choice. Please try again." ;; 52 | esac 53 | done 54 | 55 | -------------------------------------------------------------------------------- /03.Linux&Bash/bash scripts/Battery_noti.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | Battery=$(acpi -b) 4 | 5 | read -a array <<< "$Battery" 6 | Battery_per=${array[3]::-1} 7 | 8 | tmp=$(echo $Battery_per | tr -d '%') 9 | 10 | 11 | while true; do 12 | if [ "${tmp}" -lt 100 ]; then 13 | notify-send "please charge your battery dummass your battery is ${tmp}%" 14 | sleep 5 15 | fi 16 | acpi -a | grep "on" 17 | if [ $? -eq 0 ]; then 18 | notify-send "your battery is charging thanks bitch" 19 | sleep 5 20 | break 21 | fi 22 | 23 | done -------------------------------------------------------------------------------- /03.Linux&Bash/bash scripts/Class_generator.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | read -p "enter your name: " name 4 | read -p "enter your classname: " classname 5 | read -p "enter your namespace: " namespace 6 | 7 | echo " 8 | /******************************************************************************/ 9 | // 10 | // copyright (c) 2023 11 | // All rights reserved 12 | // 13 | // This is a generated file by $name 14 | // Do not edit this file manually 15 | // 16 | /*******************************************************************************/ 17 | /* 18 | author: $name 19 | date: $(date +%Y-%m-%d) 20 | description: this is a generated file by $name 21 | */ 22 | #ifndef ${classname^^}_H 23 | #define ${classname^^}_H 24 | 25 | namespace $namespace 26 | { 27 | class $classname 28 | { 29 | public: 30 | $classname(); 31 | ~${classname}(); 32 | private: 33 | // private members 34 | }; 35 | } 36 | 37 | #endif // ${classname^^}_H 38 | " > $classname.h 39 | read -p "do you want to create a cpp file? (y/n): " choice 40 | if [ "$choice" == "y" ]; then 41 | echo " 42 | /******************************************************************************/ 43 | // 44 | // copyright (c) 2023 45 | // All rights reserved 46 | // 47 | // This is a generated file by $name 48 | // Do not edit this file manually 49 | // 50 | /*******************************************************************************/ 51 | /* 52 | author: $name 53 | date: $(date +%Y-%m-%d) 54 | brief: this is a generated file by $name 55 | */ 56 | #include \"$classname.h\" 57 | namespace $namespace 58 | { 59 | $classname::$classname() 60 | { 61 | // constructor implementation 62 | } 63 | $classname::~$classname() 64 | { 65 | // destructor implementation 66 | } 67 | } 68 | " > $classname.cpp 69 | echo "$classname.cpp file created successfully" 70 | fi -------------------------------------------------------------------------------- /03.Linux&Bash/bash scripts/Erase_flash.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | file=$1 4 | 5 | select opt in Erase flash 6 | do 7 | case $opt in 8 | "Erase") 9 | echo "Erasing flash..." 10 | sudo umount /dev/sdb 11 | sudo dd if=/dev/zero of=/dev/sdb bs=1M count=100 12 | echo "Flash erased successfully." 13 | break 14 | ;; 15 | "flash") 16 | echo "Flashing..." 17 | sudo dd if=$file of=/dev/sdb1 bs=4M 18 | echo "Flash completed successfully." 19 | break 20 | ;; 21 | *) 22 | echo "Invalid option. Please try again." 23 | ;; 24 | esac 25 | 26 | done 27 | -------------------------------------------------------------------------------- /03.Linux&Bash/bash scripts/File_compare.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ -z "$1" -o -z "$2" ]; then 4 | echo "Usage: $0 " 5 | exit 1 6 | fi 7 | 8 | file1=$(md5sum "$1" | awk '{print $1}') 9 | file2=$(md5sum "$2" | awk '{print $1}') 10 | 11 | if [ "$file1" = "$file2" ]; then 12 | echo "Files are identical" 13 | else 14 | echo "Files are different" 15 | fi -------------------------------------------------------------------------------- /03.Linux&Bash/bash scripts/Log_file_monitoring.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | Log_FILE="./log.txt" 4 | Keyword="ERROR" 5 | 6 | send_notification() { 7 | notify-send "Log Alert" "Keyword '$Keyword' found in log file." --icon=dialog-warning 8 | } 9 | 10 | tail -Fn0 "$Log_FILE" | \ 11 | while read line; do 12 | if echo "$line" | grep "$Keyword"; then 13 | send_notification 14 | fi 15 | done 16 | 17 | -------------------------------------------------------------------------------- /03.Linux&Bash/bash scripts/Login_Script.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | Username="ismail" 4 | Password="0812" 5 | 6 | read -rp "Enter username: " user 7 | read -srp "Enter password: " pass 8 | echo 9 | if [ "$user" == "$Username" ] && [ "$pass" == "$Password" ]; then 10 | echo "Login successful" 11 | else 12 | echo "Login failed" 13 | fi 14 | 15 | 16 | -------------------------------------------------------------------------------- /03.Linux&Bash/bash scripts/Logout.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | select=$(echo -e "logout\nshutdown\nreboot" | rofi -dmenu -p "Select an option:") 4 | 5 | case $select in 6 | logout) 7 | pkill -u "$(id -u)" 8 | ;; 9 | shutdown) 10 | systemctl poweroff 11 | ;; 12 | reboot) 13 | systemctl reboot 14 | ;; 15 | *) 16 | echo "Invalid option" 17 | ;; 18 | esac -------------------------------------------------------------------------------- /03.Linux&Bash/bash scripts/Pass_generater.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | Pass_length=8 4 | charset="a-zA-Z0-9!@#$%^&*()_+" 5 | 6 | generate_password() { 7 | local length=$1 8 | local charset=$2 9 | 10 | tr -dc "$charset" < /dev/urandom | head -c "$length";echo 11 | } 12 | while getopts ":l:c:" opt; do 13 | case $opt in 14 | l) 15 | Pass_length=$OPTARG 16 | ;; 17 | c) 18 | charset=$OPTARG 19 | ;; 20 | *) 21 | echo "Invalid option: -$OPTARG" >&2 22 | exit 1 23 | ;; 24 | esac 25 | done 26 | 27 | pass=$(generate_password "$Pass_length" "$charset") 28 | echo "Generated password: $pass" -------------------------------------------------------------------------------- /03.Linux&Bash/bash scripts/Ping_network.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | word=" 0% packet loss" 4 | 5 | for i in {1..20} 6 | do 7 | result=$(ping "192.168.1.$i" -c 1 -W 1) 8 | if [[ $result == *"${word}"* ]]; then 9 | echo "192.168.1.$i is reachable" 10 | fi 11 | done 12 | -------------------------------------------------------------------------------- /03.Linux&Bash/bash scripts/Report.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | file="report.txt" 4 | 5 | addseperator() { 6 | echo "----------------------------------------" >> "$file" 7 | echo "--------------------$1------------------" >> "$file" 8 | echo "----------------------------------------" >> "$file" 9 | } 10 | addseperator "report file" 11 | 12 | hostname >> "$file" 13 | whoami >> "$file" 14 | echo "----------------------------------------" >> "$file" 15 | addseperator "system info" 16 | uname -a >> "$file" 17 | echo "----------------------------------------" >> "$file" 18 | addseperator "disk usage" 19 | df -h >> "$file" 20 | echo "----------------------------------------" >> "$file" 21 | addseperator "network info" 22 | ifconfig >> "$file" 23 | echo "----------------------------------------" >> "$file" 24 | addseperator "cpu info" 25 | lscpu >> "$file" 26 | echo "----------------------------------------" >> "$file" 27 | addseperator "memory info" 28 | free -h >> "$file" 29 | echo "----------------------------------------" >> "$file" 30 | -------------------------------------------------------------------------------- /03.Linux&Bash/bash scripts/SC_for_CMD.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cmdlist="./cmdlist" 4 | 5 | if [ $# -eq 0 ]; then 6 | echo "Usage: $0 " 7 | cat "$cmdlist" 8 | echo 9 | exit 1 10 | fi 11 | 12 | key=$1 13 | while read -r line 14 | do 15 | if echo "${line}" | grep -q "^$key"; then 16 | cmd=$(echo "${line}" | cut -d "=" -f 2) 17 | echo "Command found: $cmd" 18 | fi 19 | done < "$cmdlist" 20 | 21 | if [ -z "$cmd" ]; then 22 | echo "Command not found in cmdlist" 23 | cat "$cmdlist" 24 | echo 25 | else 26 | echo "Executing command: $cmd" 27 | if eval "$cmd"; then 28 | echo "Command executed successfully" 29 | else 30 | echo "Command execution failed" 31 | fi 32 | 33 | # echo ${cmd} > "$tmpfile" 34 | # echo "Command saved to $tmpfile" 35 | # bash ${tmpfile} 36 | fi 37 | 38 | 39 | -------------------------------------------------------------------------------- /03.Linux&Bash/bash scripts/Saving_files.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | file=$(cat /home/ismail/Desktop/bash\ script/files.txt) 4 | 5 | selected=$(echo -e "select\nadd" | rofi -dmenu -p "Select add/select") 6 | if [ "$selected" = "add" ]; then 7 | selected=$(echo -e "" | rofi -dmenu -p "path to file:") 8 | if [ -n "$selected" ]; then 9 | echo "$selected" >> /home/ismail/Desktop/bash\ script/files.txt 10 | echo "File added to list" 11 | fi 12 | elif [ "$selected" = "select" ]; then 13 | selected=$(echo -e "${file[@]}" | rofi -dmenu -p "Select file:") 14 | code "$selected" 15 | 16 | fi 17 | 18 | -------------------------------------------------------------------------------- /03.Linux&Bash/bash scripts/Select_colors.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | declare -A colors=( 4 | [Red]="\e[31m" 5 | [Green]="\e[32m" 6 | [Yellow]="\e[33m" 7 | [Blue]="\e[34m" 8 | [Magenta]="\e[35m" 9 | [Cyan]="\e[36m" 10 | [White]="\e[37m" 11 | [BLACK]="\e[30m" 12 | [BOLD]="\e[1m" 13 | [UNDERLINE]="\e[4m" 14 | [RESET]="\e[0m" 15 | ) 16 | 17 | names=( 18 | "Red" 19 | "Green" 20 | "Yellow" 21 | "Blue" 22 | "Magenta" 23 | "Cyan" 24 | "White" 25 | "BLACK" 26 | "BOLD" 27 | "UNDERLINE" 28 | "RESET" 29 | ) 30 | 31 | select=$(printf "%s\n" "${names[@]}" | rofi -dmenu -p "Select a color:") 32 | 33 | xdotool type "${colors[$select]}}" -------------------------------------------------------------------------------- /03.Linux&Bash/bash scripts/Translate.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | word=$(xclip -o) 3 | url="https://translate.google.com.eg/?hl=ar&sl=auto&tl=ar&text=${word}&op=translate" 4 | firefox "$url" -------------------------------------------------------------------------------- /03.Linux&Bash/bash scripts/User_managment_automation.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ "$EUID" -ne 0 ]; then 4 | echo "Please run as root" 5 | exit 1 6 | fi 7 | 8 | add_user() { 9 | read -p "Enter username: " username 10 | read -p "Enter password: " password 11 | useradd -m -s /bin/bash "$username" 12 | echo "$username:$password" | chpasswd 13 | echo "User $username added successfully." 14 | } 15 | 16 | delete_user() { 17 | read -p "Enter username to delete: " username 18 | userdel -r "$username" 19 | if [ $? -ne 0 ]; then 20 | echo "Failed to delete user $username. User may not exist." 21 | exit 1 22 | fi 23 | echo "User $username deleted successfully." 24 | } 25 | 26 | echo "Choose an option:" 27 | echo "1. Add user" 28 | echo "2. Delete user" 29 | read -p "Enter your choice: " choice 30 | 31 | case $choice in 32 | 1) 33 | add_user 34 | ;; 35 | 2) 36 | delete_user 37 | ;; 38 | *) 39 | echo "Invalid choice." 40 | ;; 41 | esac -------------------------------------------------------------------------------- /03.Linux&Bash/bash scripts/Wiki.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | show_cpp(){ 4 | echo "==============================" 5 | echo "==========C++ example=========" 6 | echo "==============================" 7 | cat << EOF 8 | #include 9 | 10 | int main() 11 | { 12 | std::cout << "Hello, World!" << std::endl; 13 | return 0; 14 | } 15 | EOF 16 | read -p "Press enter to continue" 17 | } 18 | 19 | show_python(){ 20 | echo "==============================" 21 | echo "==========Python example=======" 22 | echo "==============================" 23 | cat << EOF 24 | print("Hello, World!") 25 | EOF 26 | read -p "Press enter to continue" 27 | } 28 | 29 | show_bash(){ 30 | echo "==============================" 31 | echo "==========Bash example=========" 32 | echo "==============================" 33 | cat << EOF 34 | #!/bin/bash 35 | echo "Hello, World!" 36 | EOF 37 | read -p "Press enter to continue" 38 | } 39 | 40 | show_linux(){ 41 | echo "==============================" 42 | echo "==========Linux example=========" 43 | echo "==============================" 44 | cat << EOF 45 | # file operations 46 | ls - list directory contents 47 | cd - change directory 48 | pwd - print working directory 49 | mkdir - create a new directory 50 | rm - remove files or directories 51 | cp - copy files or directories 52 | mv - move or rename files or directories 53 | # process management 54 | ps - display information about running processes 55 | top - display real-time information about system processes 56 | kill - terminate a process 57 | # network operations 58 | ping - check connectivity to a host 59 | ifconfig - display network interface configuration 60 | netstat - display network connections 61 | ssh - secure shell for remote login 62 | scp - secure copy for file transfer 63 | # system information 64 | uname - display system information 65 | df - display disk space usage 66 | free - display memory usage 67 | uptime - display system uptime 68 | # package management 69 | apt-get - package manager for Debian-based systems 70 | yum - package manager for Red Hat-based systems 71 | # user management 72 | useradd - add a new user 73 | userdel - delete a user 74 | passwd - change user password 75 | chown - change file ownership 76 | chmod - change file permissions 77 | # file permissions 78 | r - read permission 79 | w - write permission 80 | x - execute permission 81 | # file types 82 | f - regular file 83 | d - directory 84 | l - symbolic link 85 | b - block device 86 | c - character device 87 | s - socket 88 | p - named pipe 89 | EOF 90 | read -p "Press enter to continue" 91 | } 92 | 93 | show_menu(){ 94 | echo "==============================" 95 | echo "==========Wiki.sh=============" 96 | echo "==============================" 97 | echo "1. C++ example" 98 | echo "2. Python example" 99 | echo "3. Bash example" 100 | echo "4. Linux example" 101 | echo "5. Exit" 102 | read -p "Select an option: " option 103 | } 104 | 105 | while true; do 106 | show_menu 107 | 108 | case $option in 109 | 1) show_cpp ;; 110 | 2) show_python ;; 111 | 3) show_bash ;; 112 | 4) show_linux ;; 113 | 5) exit 0 ;; 114 | *) echo "Invalid option" ;; 115 | esac 116 | done 117 | 118 | -------------------------------------------------------------------------------- /03.Linux&Bash/bash scripts/cmdlist: -------------------------------------------------------------------------------- 1 | ls=ls -la 2 | nm=notify-send "hello ismail" 3 | dev=lsblk 4 | yt=firefox "https://www.youtube.com/@SMii7Y" -------------------------------------------------------------------------------- /03.Linux&Bash/bash scripts/files.txt: -------------------------------------------------------------------------------- 1 | /home/ismail/Desktop/bash script/ 2 | /home/ismail/Desktop/ 3 | /home/ismail/Desktop/lec4/ 4 | -------------------------------------------------------------------------------- /03.Linux&Bash/bash scripts/ismail: -------------------------------------------------------------------------------- 1 | ismailm csvsfdb 2 | asfavdbb 3 | 4 | sacdd 5 | dfbdfbfgbf 6 | 7 | bfgbfbg 8 | Running tests... 9 | abc 10 | -------------------------------------------------------------------------------- /03.Linux&Bash/bash scripts/ismail1: -------------------------------------------------------------------------------- 1 | ismailm csvsfdb 2 | asfavdbb 3 | 4 | sacdd 5 | dfbdfbfgbf 6 | 7 | bfgbfbg 8 | Running tests... 9 | abc 10 | -------------------------------------------------------------------------------- /03.Linux&Bash/bash scripts/jojo.cpp: -------------------------------------------------------------------------------- 1 | 2 | /******************************************************************************/ 3 | // 4 | // copyright (c) 2023 5 | // All rights reserved 6 | // 7 | // This is a generated file by ismail 8 | // Do not edit this file manually 9 | // 10 | /*******************************************************************************/ 11 | /* 12 | author: ismail 13 | date: 2025-04-25 14 | brief: this is a generated file by ismail 15 | */ 16 | #include "jojo.h" 17 | namespace students 18 | { 19 | jojo::jojo() 20 | { 21 | // constructor implementation 22 | } 23 | jojo::~jojo() 24 | { 25 | // destructor implementation 26 | } 27 | } 28 | 29 | -------------------------------------------------------------------------------- /03.Linux&Bash/bash scripts/jojo.h: -------------------------------------------------------------------------------- 1 | 2 | /******************************************************************************/ 3 | // 4 | // copyright (c) 2023 5 | // All rights reserved 6 | // 7 | // This is a generated file by ismail 8 | // Do not edit this file manually 9 | // 10 | /*******************************************************************************/ 11 | /* 12 | author: ismail 13 | date: 2025-04-25 14 | description: this is a generated file by ismail 15 | */ 16 | #ifndef JOJO_H 17 | #define JOJO_H 18 | 19 | namespace students 20 | { 21 | class jojo 22 | { 23 | public: 24 | jojo(); 25 | ~jojo(); 26 | private: 27 | // private members 28 | }; 29 | } 30 | 31 | #endif // JOJO_H 32 | 33 | -------------------------------------------------------------------------------- /03.Linux&Bash/bash scripts/log.txt: -------------------------------------------------------------------------------- 1 | kancdv 2 | scascdv 3 | svsd 4 | vsdv 5 | fvfdv 6 | sdvadvadvadv 7 | 8 | vavdda 9 | vavddaadvad 10 | 11 | ismail is a fuckin bitch 12 | bitch 13 | ismail 14 | bitch 15 | d 16 | ismail 17 | ERROR 18 | -------------------------------------------------------------------------------- /03.Linux&Bash/bash scripts/testing.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /03.Linux&Bash/bash scripts/ytd.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | download_videos(){ 4 | videourl=$1 5 | outputdir="ytdownload" 6 | 7 | echo "Downloading video from $videourl..." 8 | yt-dlp -f 'bestvideo+bestaudio' --merge-output-format mp4 -o "$outputdir/%(title)s.%(ext)s" "$videourl" 9 | if [ $? -eq 0 ]; then 10 | echo "Download completed successfully." 11 | else 12 | echo "Download failed." 13 | fi 14 | } 15 | 16 | 17 | 18 | download_videos $1 19 | -------------------------------------------------------------------------------- /03.Linux&Bash/l: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /04.Raspberry pi/1.Intro/LedBlink.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #define PATH_EXPORT "/sys/class/gpio/export" 8 | #define PATH_DIRECTION "/sys/class/gpio/gpio588/direction" 9 | #define PATH_VALUE "/sys/class/gpio/gpio588/value" 10 | #define LED_PIN "588" 11 | #define LED_DIRECTION "out" 12 | void direction_init() 13 | { 14 | int fd= open(PATH_DIRECTION, O_WRONLY); 15 | if( fd ==-1 ) 16 | { 17 | printf("file [Direction] cannot open "); 18 | return ; 19 | } 20 | 21 | write( fd, LED_DIRECTION, strlen(LED_DIRECTION)); 22 | close(fd); 23 | } 24 | 25 | void export_init() 26 | { 27 | int fd= open(PATH_EXPORT, O_WRONLY); 28 | if( fd ==-1 ) 29 | { 30 | printf("file [Export] cannot open "); 31 | return ; 32 | } 33 | write( fd, LED_PIN, strlen(LED_PIN)); 34 | close(fd); 35 | } 36 | 37 | int main() 38 | { 39 | export_init(); 40 | sleep(2); 41 | direction_init(); 42 | 43 | int fd= open(PATH_VALUE, O_WRONLY); 44 | if( fd ==-1 ) 45 | { 46 | printf("file [Export] cannot open "); 47 | return -1; 48 | } 49 | while(1) 50 | { 51 | write( fd, "1", strlen("1")); 52 | sleep(1); 53 | write( fd, "0", strlen("0")); 54 | sleep(1); 55 | 56 | } 57 | close(fd); 58 | return 0; 59 | } 60 | 61 | 62 | -------------------------------------------------------------------------------- /04.Raspberry pi/1.Intro/LedBlink2.c: -------------------------------------------------------------------------------- 1 | // file blink.c 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | struct gpiod_chip *chip; 10 | struct gpiod_line_request_config config; 11 | struct gpiod_line_bulk lines; 12 | 13 | int main(int argc, char *argv[]) 14 | { 15 | unsigned int offsets[1]; 16 | 17 | int values[1]; 18 | int err; 19 | 20 | chip = gpiod_chip_open("/dev/gpiochip0"); 21 | if(!chip) 22 | { 23 | perror("gpiod_chip_open"); 24 | goto cleanup; 25 | } 26 | 27 | offsets[0] = 17; 28 | values[0] = 0; 29 | err = gpiod_chip_get_lines(chip, offsets, 1, &lines); 30 | if(err) 31 | { 32 | perror("gpiod_chip_get_lines"); 33 | goto cleanup; 34 | } 35 | 36 | memset(&config, 0, sizeof(config)); 37 | config.consumer = "blink"; 38 | config.request_type = GPIOD_LINE_REQUEST_DIRECTION_OUTPUT; 39 | config.flags = 0; 40 | err = gpiod_line_request_bulk(&lines, &config, values); 41 | // if(err) 42 | // { 43 | // perror("gpiod_line_request_bulk"); 44 | // goto cleanup; 45 | // } 46 | 47 | values[0] = 1; 48 | err = gpiod_line_set_value_bulk(&lines, values); 49 | if(err) 50 | { 51 | perror("gpiod_line_set_value_bulk"); 52 | goto cleanup; 53 | } 54 | 55 | sleep(1); 56 | 57 | values[0] = 0; 58 | err = gpiod_line_set_value_bulk(&lines, values); 59 | if(err) 60 | { 61 | perror("gpiod_line_set_value_bulk"); 62 | goto cleanup; 63 | } 64 | 65 | cleanup: 66 | gpiod_line_release_bulk(&lines); 67 | gpiod_chip_close(chip); 68 | 69 | return EXIT_SUCCESS; 70 | } 71 | 72 | -------------------------------------------------------------------------------- /04.Raspberry pi/1.Intro/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismailTareq/Embedded_linux2024_diploma/c3ed271e30181868f803f4c217f7b4c2dadf9d2f/04.Raspberry pi/1.Intro/a.out -------------------------------------------------------------------------------- /04.Raspberry pi/2.Discovery/Gui_Led.py: -------------------------------------------------------------------------------- 1 | from gpiozero import LED 2 | import tkinter as gui 3 | 4 | # Setup LED 5 | led = LED(17) 6 | 7 | def LED_Toggle(): 8 | led.toggle() 9 | print("pressed") 10 | 11 | # Main window 12 | main_window = gui.Tk() 13 | main_window.title("Control Led") 14 | main_window.geometry("400x200+230+130") 15 | main_window.resizable(False, False) 16 | main_window.configure(background="white") 17 | 18 | # Widgets 19 | buttontoggle = gui.Button(main_window, text="LED ON/OFF", 20 | command=LED_Toggle, bg="pink", fg="black") 21 | 22 | # Places 23 | buttontoggle.place(x=50, y=50) 24 | 25 | main_window.mainloop() 26 | -------------------------------------------------------------------------------- /04.Raspberry pi/2.Discovery/PWM_LED.py: -------------------------------------------------------------------------------- 1 | from gpiozero import PWMLED 2 | from signal import pause 3 | from time import sleep 4 | 5 | led = PWMLED(12) 6 | 7 | try: 8 | while True: 9 | for brightness in range(0, 101): 10 | led.value = brightness / 100.0 11 | sleep(0.01) 12 | 13 | for brightness in range(100, -1, -1): 14 | led.value = brightness / 100.0 15 | sleep(0.01) 16 | 17 | except KeyboardInterrupt: 18 | # When Ctrl+C is pressed, exit the loop and clean up 19 | print("Exiting program.") 20 | 21 | finally: 22 | # Ensure the LED is off when the program exits 23 | led.off() 24 | -------------------------------------------------------------------------------- /04.Raspberry pi/2.Discovery/TestSpi.py: -------------------------------------------------------------------------------- 1 | import spidev 2 | import time 3 | 4 | # Set SPI bus and device 5 | spi_bus = 0 6 | spi_device = 0 7 | 8 | # Open SPI connection with mode 0 9 | spi = spidev.SpiDev() 10 | spi.open(spi_bus, spi_device) 11 | spi.max_speed_hz = 50000 # You may need to adjust the speed based on your setup 12 | spi.mode = 0 # Set SPI mode to 0 (CPOL=0, CPHA=0) 13 | 14 | # Define the data to be sent 15 | data_to_send = "niggas" 16 | 17 | # Convert string to list of ASCII values 18 | ascii_values = [ord(char) for char in data_to_send] 19 | 20 | try: 21 | # Send data 22 | spi.xfer2(ascii_values) 23 | print("Data sent successfully") 24 | 25 | finally: 26 | # Close SPI connection 27 | spi.close() 28 | 29 | -------------------------------------------------------------------------------- /04.Raspberry pi/2.Discovery/Test_I2C.c: -------------------------------------------------------------------------------- 1 | 2 | #include //Needed for I2C port 3 | #include //Needed for I2C port 4 | #include //Needed for I2C port 5 | #include //Needed for I2C port 6 | #include 7 | int main(){ 8 | 9 | 10 | int file_i2c; 11 | int length; 12 | unsigned char buffer[60] = {0}; 13 | //----- OPEN THE I2C BUS ----- 14 | char *filename = (char*)"/dev/i2c-1"; 15 | if ((file_i2c = open(filename, O_RDWR)) < 0) 16 | { 17 | //ERROR HANDLING: you can check errno to see what went wrong 18 | printf("Failed to open the i2c bus"); 19 | return -1; 20 | } 21 | int addr = 0x0b; //<<<< ") 15 | print("...") 16 | i2cWrite(msg) 17 | 18 | if __name__ == "__main__": 19 | main() 20 | 21 | -------------------------------------------------------------------------------- /04.Raspberry pi/2.Discovery/Test_Led.py: -------------------------------------------------------------------------------- 1 | from gpiozero import LED 2 | from time import sleep 3 | 4 | led = LED(17) 5 | 6 | try: 7 | while True: 8 | x=input("enter on | off") 9 | if x == "on": 10 | led.on() 11 | elif x == "off": 12 | led.off() 13 | except KeyboardInterrupt: 14 | print("Program exited cleanly") 15 | -------------------------------------------------------------------------------- /04.Raspberry pi/2.Discovery/Test_Spi.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #define SPI_DEVICE "/dev/spidev0.0" 11 | 12 | void pabort(const char *s) 13 | { 14 | perror(s); 15 | abort(); 16 | } 17 | 18 | int main(void) 19 | { 20 | int fd; 21 | uint8_t mode = SPI_MODE_0; 22 | uint8_t bits = 8; 23 | uint32_t speed = 50000; 24 | 25 | // Open SPI device 26 | if ((fd = open(SPI_DEVICE, O_RDWR)) < 0) 27 | pabort("can't open SPI device"); 28 | 29 | // Set SPI mode 30 | if (ioctl(fd, SPI_IOC_WR_MODE, &mode) == -1) 31 | pabort("can't set SPI mode"); 32 | 33 | // Set bits per word 34 | if (ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &bits) == -1) 35 | pabort("can't set bits per word"); 36 | 37 | // Set max speed 38 | if (ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed) == -1) 39 | pabort("can't set max speed hz"); 40 | 41 | // Data to be sent 42 | char data_to_send[] = "ismail is here bitchs"; 43 | int length = strlen(data_to_send); 44 | 45 | // Prepare SPI transfer structure 46 | struct spi_ioc_transfer transfer = { 47 | .tx_buf = (unsigned long)data_to_send, 48 | .len = length, 49 | .speed_hz = speed, 50 | .bits_per_word = bits, 51 | }; 52 | 53 | // Perform SPI transfer 54 | if (ioctl(fd, SPI_IOC_MESSAGE(1), &transfer) < 0) 55 | pabort("can't send spi message"); 56 | 57 | 58 | // Close SPI device 59 | close(fd); 60 | 61 | return 0; 62 | } 63 | 64 | 65 | -------------------------------------------------------------------------------- /04.Raspberry pi/2.Discovery/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismailTareq/Embedded_linux2024_diploma/c3ed271e30181868f803f4c217f7b4c2dadf9d2f/04.Raspberry pi/2.Discovery/a.out -------------------------------------------------------------------------------- /04.Raspberry pi/2.Discovery/file.dtb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismailTareq/Embedded_linux2024_diploma/c3ed271e30181868f803f4c217f7b4c2dadf9d2f/04.Raspberry pi/2.Discovery/file.dtb -------------------------------------------------------------------------------- /04.Raspberry pi/2.Discovery/gui_mesg.py: -------------------------------------------------------------------------------- 1 | import tkinter as tk 2 | 3 | wd=tk.Tk() 4 | wd.geometry("200x200+50+50") 5 | lbl=tk.Label(wd,text="whass good nigga") 6 | lbl.pack() 7 | wd.mainloop() 8 | 9 | -------------------------------------------------------------------------------- /04.Raspberry pi/2.Discovery/hello_gui.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description="hello gui app" 3 | [Service] 4 | User=pi 5 | ExecStartPre=sleep 20 6 | #Restart=on-failure 7 | ExecStart=/usr/bin/python3.11 /home/pi/C_project/2.Discovery/gui_mesg.py 8 | Environment="DISPLAY=:0" 9 | [Install] 10 | WantedBy=graphical.target 11 | 12 | -------------------------------------------------------------------------------- /04.Raspberry pi/2.Discovery/test.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | / { 3 | model = "testing"; 4 | compatible = "arm-test"; 5 | #address-cells = <1>; 6 | #size-cells = <1>; 7 | node1{ 8 | compatible = "ismail,node1"; 9 | me,string-test = "nigga"; 10 | me,string-list = "hello" , "ismail"; 11 | me,int-word = <0x11223344>; 12 | me,int-word64 = <0x11223344 0x55667788>; 13 | me,cell = <2>; 14 | child { 15 | compatible = "ismail,child"; 16 | me,array = <1 2 3 4>; 17 | }; 18 | }; 19 | i2c: node@abcd { 20 | compatible = "i2c"; 21 | reg = <0xabcd 0x01>; 22 | 23 | }; 24 | }; 25 | -------------------------------------------------------------------------------- /04.Raspberry pi/2.Discovery/uart: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismailTareq/Embedded_linux2024_diploma/c3ed271e30181868f803f4c217f7b4c2dadf9d2f/04.Raspberry pi/2.Discovery/uart -------------------------------------------------------------------------------- /04.Raspberry pi/3.Bringup/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismailTareq/Embedded_linux2024_diploma/c3ed271e30181868f803f4c217f7b4c2dadf9d2f/04.Raspberry pi/3.Bringup/a.out -------------------------------------------------------------------------------- /04.Raspberry pi/3.Bringup/bcm2712-rpi-5-b.dtb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismailTareq/Embedded_linux2024_diploma/c3ed271e30181868f803f4c217f7b4c2dadf9d2f/04.Raspberry pi/3.Bringup/bcm2712-rpi-5-b.dtb -------------------------------------------------------------------------------- /04.Raspberry pi/3.Bringup/bluetooth.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -x 3 | echo -e 'power on \nconnect 36:95:FB:D1:5B:02 \nquit ' | bluetoothctl 4 | while true; do 5 | out=$(echo -e 'info' | bluetoothctl) 6 | if [[ "${out}" == *"Connected: yes"* ]] 7 | then 8 | break 9 | fi 10 | sleep 1 11 | done 12 | mpg123 ~/Downloads/ytmp3free.cc_lord-huron-the-night-we-met-official-audio-youtubemp3free.org.mp3 13 | 14 | -------------------------------------------------------------------------------- /04.Raspberry pi/3.Bringup/dht11: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismailTareq/Embedded_linux2024_diploma/c3ed271e30181868f803f4c217f7b4c2dadf9d2f/04.Raspberry pi/3.Bringup/dht11 -------------------------------------------------------------------------------- /04.Raspberry pi/3.Bringup/dht11.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #define DHT11_PIN 0 // GPIO pin where DHT11 is connected 7 | 8 | int readDHT11(int *data) { 9 | int lastState = HIGH; 10 | int counter = 0; 11 | int j = 0; 12 | 13 | // Send start signal 14 | pinMode(DHT11_PIN, OUTPUT); 15 | digitalWrite(DHT11_PIN, LOW); 16 | delay(18); 17 | digitalWrite(DHT11_PIN, HIGH); 18 | delayMicroseconds(40); 19 | pinMode(DHT11_PIN, INPUT); 20 | 21 | // Read data 22 | for (int i = 0; i < 85; i++) { 23 | counter = 0; 24 | while (digitalRead(DHT11_PIN) == lastState) { 25 | counter++; 26 | delayMicroseconds(1); 27 | if (counter == 255) break; 28 | } 29 | lastState = digitalRead(DHT11_PIN); 30 | 31 | if (counter == 255) break; 32 | 33 | // Skip the first 3 transitions 34 | if ((i >= 4) && (i % 2 == 0)) { 35 | data[j / 8] <<= 1; 36 | if (counter > 16) data[j / 8] |= 1; 37 | j++; 38 | } 39 | } 40 | 41 | // Verify checksum 42 | if (j >= 40 && (data[4] == ((data[0] + data[1] + data[2] + data[3]) & 0xFF))) { 43 | return 1; // Success 44 | } else { 45 | return 0; // Failure 46 | } 47 | } 48 | 49 | int main(void) { 50 | int data[5] = {0}; 51 | 52 | if (wiringPiSetup() == -1) { 53 | fprintf(stderr, "WiringPi initialization failed!\n"); 54 | return 1; 55 | } 56 | 57 | printf("Reading DHT11 sensor...\n"); 58 | 59 | if (readDHT11(data)) { 60 | printf("Humidity: %d.%d%%\n", data[0], data[1]); 61 | printf("Temperature: %d.%d°C\n", data[2], data[3]); 62 | } else { 63 | fprintf(stderr, "Failed to read from DHT11 sensor.\n"); 64 | } 65 | 66 | return 0; 67 | } 68 | -------------------------------------------------------------------------------- /04.Raspberry pi/3.Bringup/dht11.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #define DHT11_PIN 0 // GPIO pin where DHT11 is connected 7 | 8 | using namespace std; 9 | 10 | vector readDHT11() { 11 | vector data(5, 0); 12 | uint8_t lastState = HIGH; 13 | uint8_t counter = 0; 14 | uint8_t j = 0; 15 | 16 | // Send start signal 17 | pinMode(DHT11_PIN, OUTPUT); 18 | digitalWrite(DHT11_PIN, LOW); 19 | delay(18); 20 | digitalWrite(DHT11_PIN, HIGH); 21 | delayMicroseconds(40); 22 | pinMode(DHT11_PIN, INPUT); 23 | 24 | // Read data 25 | for (int i = 0; i < 85; i++) { 26 | counter = 0; 27 | while (digitalRead(DHT11_PIN) == lastState) { 28 | counter++; 29 | delayMicroseconds(1); 30 | if (counter == 255) break; 31 | } 32 | lastState = digitalRead(DHT11_PIN); 33 | 34 | if (counter == 255) break; 35 | 36 | // Skip the first 3 transitions 37 | if ((i >= 4) && (i % 2 == 0)) { 38 | data[j / 8] <<= 1; 39 | if (counter > 16) data[j / 8] |= 1; 40 | j++; 41 | } 42 | } 43 | 44 | // Verify checksum 45 | if (j >= 40 && (data[4] == ((data[0] + data[1] + data[2] + data[3]) & 0xFF))) { 46 | return data; 47 | } else { 48 | return vector(); // Return empty vector on failure 49 | } 50 | } 51 | 52 | int main() { 53 | if (wiringPiSetup() == -1) { 54 | cerr << "WiringPi initialization failed!" << endl; 55 | return 1; 56 | } 57 | 58 | cout << "Reading DHT11 sensor..." << endl; 59 | 60 | vector data = readDHT11(); 61 | if (!data.empty()) { 62 | cout << "Humidity: " << data[0] << "." << data[1] << "%" << endl; 63 | cout << "Temperature: " << data[2] << "." << data[3] << "°C" << endl; 64 | } else { 65 | cerr << "Failed to read from DHT11 sensor." << endl; 66 | } 67 | 68 | return 0; 69 | } 70 | -------------------------------------------------------------------------------- /04.Raspberry pi/3.Bringup/dht11_test: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismailTareq/Embedded_linux2024_diploma/c3ed271e30181868f803f4c217f7b4c2dadf9d2f/04.Raspberry pi/3.Bringup/dht11_test -------------------------------------------------------------------------------- /04.Raspberry pi/3.Bringup/dht_py.py: -------------------------------------------------------------------------------- 1 | import Adafruit_DHT 2 | import time 3 | 4 | # Define the sensor type and GPIO pin 5 | sensor = Adafruit_DHT.DHT11 6 | pin = 17 # GPIO pin number (BCM numbering) 7 | 8 | def read_sensor(): 9 | humidity, temperature = Adafruit_DHT.read_retry(sensor, pin) 10 | if humidity is not None and temperature is not None: 11 | print(f"Temperature: {temperature:.1f}°C") 12 | print(f"Humidity: {humidity:.1f}%") 13 | else: 14 | print("Failed to read from DHT11 sensor. Try again.") 15 | 16 | if __name__ == "__main__": 17 | while True: 18 | read_sensor() 19 | time.sleep(2) # Wait for 2 seconds before reading again 20 | -------------------------------------------------------------------------------- /04.Raspberry pi/3.Bringup/project/Dht11.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #define DHT11_PIN 0 // GPIO pin where DHT11 is connected 11 | #define LEDPIN 1 // GPIO pin for LED 12 | 13 | using namespace std; 14 | 15 | vector readDHT11() { 16 | vector data(5, 0); 17 | uint8_t lastState = HIGH; 18 | uint8_t counter = 0; 19 | uint8_t j = 0; 20 | 21 | // Send start signal 22 | pinMode(DHT11_PIN, OUTPUT); 23 | digitalWrite(DHT11_PIN, LOW); 24 | delay(18); 25 | digitalWrite(DHT11_PIN, HIGH); 26 | delayMicroseconds(40); 27 | pinMode(DHT11_PIN, INPUT); 28 | 29 | // Read data 30 | for (int i = 0; i < 85; i++) { 31 | counter = 0; 32 | while (digitalRead(DHT11_PIN) == lastState) { 33 | counter++; 34 | delayMicroseconds(1); 35 | if (counter == 255) break; 36 | } 37 | lastState = digitalRead(DHT11_PIN); 38 | 39 | if (counter == 255) break; 40 | 41 | // Skip the first 3 transitions 42 | if ((i >= 4) && (i % 2 == 0)) { 43 | data[j / 8] <<= 1; 44 | if (counter > 16) data[j / 8] |= 1; 45 | j++; 46 | } 47 | } 48 | 49 | // Verify checksum 50 | if (j >= 40 && (data[4] == ((data[0] + data[1] + data[2] + data[3]) & 0xFF))) { 51 | return data; 52 | } else { 53 | return vector(); // Return empty vector on failure 54 | } 55 | } 56 | 57 | void blinkLed() { 58 | digitalWrite(LEDPIN, HIGH); 59 | this_thread::sleep_for(chrono::milliseconds(300)); 60 | digitalWrite(LEDPIN, LOW); 61 | } 62 | 63 | int main() { 64 | if (wiringPiSetup() == -1) { 65 | cerr << "WiringPi initialization failed!" << endl; 66 | return 1; 67 | } 68 | 69 | pinMode(LEDPIN, OUTPUT); 70 | 71 | ofstream csvfile; 72 | csvfile.open("sensor_data.csv", ios::out); 73 | csvfile << "Timestamp,Temperature,Humidity\n"; 74 | csvfile.close(); 75 | 76 | while (true) { 77 | vector data = readDHT11(); 78 | if (!data.empty()) { 79 | float humidity = data[0] + data[1] / 10.0; 80 | float temperature = data[2] + data[3] / 10.0; 81 | 82 | time_t now = time(nullptr); 83 | char* dt = ctime(&now); 84 | 85 | // Append to CSV 86 | csvfile.open("sensor_data.csv", ios::app); 87 | csvfile << dt << "," << temperature << "," << humidity << "\n"; 88 | csvfile.close(); 89 | 90 | blinkLed(); 91 | } else { 92 | cerr << "Failed to read from DHT11 sensor." << endl; 93 | } 94 | 95 | this_thread::sleep_for(chrono::seconds(10)); 96 | } 97 | 98 | return 0; 99 | } 100 | -------------------------------------------------------------------------------- /04.Raspberry pi/3.Bringup/project/dht11: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismailTareq/Embedded_linux2024_diploma/c3ed271e30181868f803f4c217f7b4c2dadf9d2f/04.Raspberry pi/3.Bringup/project/dht11 -------------------------------------------------------------------------------- /04.Raspberry pi/3.Bringup/project/gui.py: -------------------------------------------------------------------------------- 1 | import tkinter as tk 2 | import pandas as pd 3 | from datetime import datetime 4 | 5 | class CSVViewer: 6 | def __init__(self, root): 7 | self.root = root 8 | self.root.title("Sensor Data Viewer") 9 | 10 | self.label_temp = tk.Label(root, text="Average Temperature: --", font=('Arial', 14)) 11 | self.label_temp.pack(pady=10) 12 | 13 | self.label_humid = tk.Label(root, text="Average Humidity: --", font=('Arial', 14)) 14 | self.label_humid.pack(pady=10) 15 | 16 | self.update_button = tk.Button(root, text="Update Data", command=self.update_data) 17 | self.update_button.pack(pady=20) 18 | 19 | def update_data(self): 20 | try: 21 | df = pd.read_csv("sensor_data.csv") 22 | avg_temp = df['Temperature'].mean() 23 | avg_humid = df['Humidity'].mean() 24 | 25 | self.label_temp.config(text=f"Average Temperature: {avg_temp:.1f}°C") 26 | self.label_humid.config(text=f"Average Humidity: {avg_humid:.1f}%") 27 | except Exception as e: 28 | self.label_temp.config(text=f"Error: {str(e)}") 29 | self.label_humid.config(text="") 30 | 31 | if __name__ == "__main__": 32 | root = tk.Tk() 33 | app = CSVViewer(root) 34 | root.mainloop() 35 | -------------------------------------------------------------------------------- /04.Raspberry pi/3.Bringup/project/sensor_data.csv: -------------------------------------------------------------------------------- 1 | Timestamp,Temperature,Humidity 2 | Thu Jun 12 15:28:24 2025 3 | ,25.8,81.5 4 | Thu Jun 12 15:28:34 2025 5 | ,25.8,82.7 6 | Thu Jun 12 15:28:44 2025 7 | ,25.6,82.5 8 | -------------------------------------------------------------------------------- /04.Raspberry pi/3.Bringup/project/transfer.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Configuration 4 | CSV_FILE="sensor_data.csv" 5 | REMOTE_USER="ismail" 6 | REMOTE_HOST="192.168.1.18" 7 | REMOTE_DIR="~/Desktop" 8 | 9 | while true; do 10 | echo "Transferring CSV file..." 11 | 12 | # Transfer file using SCP 13 | scp "$CSV_FILE" "${REMOTE_USER}@${REMOTE_HOST}:${REMOTE_DIR}" && \ 14 | echo "Transfer successful" || echo "Transfer failed" 15 | 16 | echo "Waiting for next transfer..." 17 | sleep 60 # 1 minute interval 18 | done 19 | -------------------------------------------------------------------------------- /04.Raspberry pi/3.Bringup/test_Button.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #define EXIT_SUCCESS 0 9 | #define EXIT_FAILURE 1 10 | 11 | int main() { 12 | const char *device_path = "/dev/input/event1"; // Replace X with the correct number 13 | int fd = open(device_path, O_RDONLY); 14 | if (fd == -1) { 15 | perror("Error opening input device"); 16 | return EXIT_FAILURE; 17 | } 18 | 19 | struct input_event ev; 20 | ssize_t bytesRead; 21 | while ((bytesRead = read(fd, &ev, sizeof(struct input_event))) > 0) { 22 | if (ev.type == EV_KEY) { 23 | printf("Key event: code=%d, value=%d, time=%ld\n", ev.code, ev.value, (long)ev.time.tv_sec); 24 | } 25 | } 26 | if (bytesRead == -1) { 27 | perror("Error reading input event"); 28 | close(fd); 29 | return EXIT_FAILURE; 30 | } 31 | 32 | close(fd); 33 | 34 | return EXIT_SUCCESS; 35 | } 36 | -------------------------------------------------------------------------------- /04.Raspberry pi/4.Iot/Mqtt/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.16) 2 | 3 | project(Switcher) 4 | set(SRC_FILES 5 | main.cpp 6 | publisher.cpp 7 | ) 8 | set(CMAKE_PREFIX_PATH "/usr/lib/aarch64-linux-gnu/") 9 | find_library(PAHO_MQTT_CPP_LIB NAMES paho-mqttpp3 PATHS ${CMAKE_PREFIX_PATH} NO_DEFAULT_PATH) 10 | find_library(PAHO_MQTT_C_LIB NAMES paho-mqtt3as PATHS ${CMAKE_PREFIX_PATH} NO_DEFAULT_PATH) 11 | find_library(WIRINGPI_LIB NAMES wiringPi PATHS /usr/lib /usr/local/lib NO_DEFAULT_PATH) 12 | 13 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g") 14 | include_directories(publisher) 15 | 16 | add_executable(${PROJECT_NAME} ${SRC_FILES}) 17 | target_link_libraries(${PROJECT_NAME} ${PAHO_MQTT_CPP_LIB} ${WIRINGPI_LIB} ${PAHO_MQTT_C_LIB} pthread ssl crypto) 18 | -------------------------------------------------------------------------------- /04.Raspberry pi/4.Iot/Mqtt/Switcher: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismailTareq/Embedded_linux2024_diploma/c3ed271e30181868f803f4c217f7b4c2dadf9d2f/04.Raspberry pi/4.Iot/Mqtt/Switcher -------------------------------------------------------------------------------- /04.Raspberry pi/4.Iot/Mqtt/build/CMakeFiles/3.25.1/CMakeCCompiler.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_C_COMPILER "/usr/bin/cc") 2 | set(CMAKE_C_COMPILER_ARG1 "") 3 | set(CMAKE_C_COMPILER_ID "GNU") 4 | set(CMAKE_C_COMPILER_VERSION "12.2.0") 5 | set(CMAKE_C_COMPILER_VERSION_INTERNAL "") 6 | set(CMAKE_C_COMPILER_WRAPPER "") 7 | set(CMAKE_C_STANDARD_COMPUTED_DEFAULT "17") 8 | set(CMAKE_C_EXTENSIONS_COMPUTED_DEFAULT "ON") 9 | set(CMAKE_C_COMPILE_FEATURES "c_std_90;c_function_prototypes;c_std_99;c_restrict;c_variadic_macros;c_std_11;c_static_assert;c_std_17;c_std_23") 10 | set(CMAKE_C90_COMPILE_FEATURES "c_std_90;c_function_prototypes") 11 | set(CMAKE_C99_COMPILE_FEATURES "c_std_99;c_restrict;c_variadic_macros") 12 | set(CMAKE_C11_COMPILE_FEATURES "c_std_11;c_static_assert") 13 | set(CMAKE_C17_COMPILE_FEATURES "c_std_17") 14 | set(CMAKE_C23_COMPILE_FEATURES "c_std_23") 15 | 16 | set(CMAKE_C_PLATFORM_ID "Linux") 17 | set(CMAKE_C_SIMULATE_ID "") 18 | set(CMAKE_C_COMPILER_FRONTEND_VARIANT "") 19 | set(CMAKE_C_SIMULATE_VERSION "") 20 | 21 | 22 | 23 | 24 | set(CMAKE_AR "/usr/bin/ar") 25 | set(CMAKE_C_COMPILER_AR "/usr/bin/gcc-ar-12") 26 | set(CMAKE_RANLIB "/usr/bin/ranlib") 27 | set(CMAKE_C_COMPILER_RANLIB "/usr/bin/gcc-ranlib-12") 28 | set(CMAKE_LINKER "/usr/bin/ld") 29 | set(CMAKE_MT "") 30 | set(CMAKE_COMPILER_IS_GNUCC 1) 31 | set(CMAKE_C_COMPILER_LOADED 1) 32 | set(CMAKE_C_COMPILER_WORKS TRUE) 33 | set(CMAKE_C_ABI_COMPILED TRUE) 34 | 35 | set(CMAKE_C_COMPILER_ENV_VAR "CC") 36 | 37 | set(CMAKE_C_COMPILER_ID_RUN 1) 38 | set(CMAKE_C_SOURCE_FILE_EXTENSIONS c;m) 39 | set(CMAKE_C_IGNORE_EXTENSIONS h;H;o;O;obj;OBJ;def;DEF;rc;RC) 40 | set(CMAKE_C_LINKER_PREFERENCE 10) 41 | 42 | # Save compiler ABI information. 43 | set(CMAKE_C_SIZEOF_DATA_PTR "8") 44 | set(CMAKE_C_COMPILER_ABI "ELF") 45 | set(CMAKE_C_BYTE_ORDER "LITTLE_ENDIAN") 46 | set(CMAKE_C_LIBRARY_ARCHITECTURE "aarch64-linux-gnu") 47 | 48 | if(CMAKE_C_SIZEOF_DATA_PTR) 49 | set(CMAKE_SIZEOF_VOID_P "${CMAKE_C_SIZEOF_DATA_PTR}") 50 | endif() 51 | 52 | if(CMAKE_C_COMPILER_ABI) 53 | set(CMAKE_INTERNAL_PLATFORM_ABI "${CMAKE_C_COMPILER_ABI}") 54 | endif() 55 | 56 | if(CMAKE_C_LIBRARY_ARCHITECTURE) 57 | set(CMAKE_LIBRARY_ARCHITECTURE "aarch64-linux-gnu") 58 | endif() 59 | 60 | set(CMAKE_C_CL_SHOWINCLUDES_PREFIX "") 61 | if(CMAKE_C_CL_SHOWINCLUDES_PREFIX) 62 | set(CMAKE_CL_SHOWINCLUDES_PREFIX "${CMAKE_C_CL_SHOWINCLUDES_PREFIX}") 63 | endif() 64 | 65 | 66 | 67 | 68 | 69 | set(CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES "/usr/lib/gcc/aarch64-linux-gnu/12/include;/usr/local/include;/usr/include/aarch64-linux-gnu;/usr/include") 70 | set(CMAKE_C_IMPLICIT_LINK_LIBRARIES "gcc;gcc_s;c;gcc;gcc_s") 71 | set(CMAKE_C_IMPLICIT_LINK_DIRECTORIES "/usr/lib/gcc/aarch64-linux-gnu/12;/usr/lib/aarch64-linux-gnu;/usr/lib;/lib/aarch64-linux-gnu;/lib") 72 | set(CMAKE_C_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES "") 73 | -------------------------------------------------------------------------------- /04.Raspberry pi/4.Iot/Mqtt/build/CMakeFiles/3.25.1/CMakeDetermineCompilerABI_C.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismailTareq/Embedded_linux2024_diploma/c3ed271e30181868f803f4c217f7b4c2dadf9d2f/04.Raspberry pi/4.Iot/Mqtt/build/CMakeFiles/3.25.1/CMakeDetermineCompilerABI_C.bin -------------------------------------------------------------------------------- /04.Raspberry pi/4.Iot/Mqtt/build/CMakeFiles/3.25.1/CMakeDetermineCompilerABI_CXX.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismailTareq/Embedded_linux2024_diploma/c3ed271e30181868f803f4c217f7b4c2dadf9d2f/04.Raspberry pi/4.Iot/Mqtt/build/CMakeFiles/3.25.1/CMakeDetermineCompilerABI_CXX.bin -------------------------------------------------------------------------------- /04.Raspberry pi/4.Iot/Mqtt/build/CMakeFiles/3.25.1/CMakeSystem.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_HOST_SYSTEM "Linux-6.12.25+rpt-rpi-2712") 2 | set(CMAKE_HOST_SYSTEM_NAME "Linux") 3 | set(CMAKE_HOST_SYSTEM_VERSION "6.12.25+rpt-rpi-2712") 4 | set(CMAKE_HOST_SYSTEM_PROCESSOR "aarch64") 5 | 6 | 7 | 8 | set(CMAKE_SYSTEM "Linux-6.12.25+rpt-rpi-2712") 9 | set(CMAKE_SYSTEM_NAME "Linux") 10 | set(CMAKE_SYSTEM_VERSION "6.12.25+rpt-rpi-2712") 11 | set(CMAKE_SYSTEM_PROCESSOR "aarch64") 12 | 13 | set(CMAKE_CROSSCOMPILING "FALSE") 14 | 15 | set(CMAKE_SYSTEM_LOADED 1) 16 | -------------------------------------------------------------------------------- /04.Raspberry pi/4.Iot/Mqtt/build/CMakeFiles/3.25.1/CompilerIdC/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismailTareq/Embedded_linux2024_diploma/c3ed271e30181868f803f4c217f7b4c2dadf9d2f/04.Raspberry pi/4.Iot/Mqtt/build/CMakeFiles/3.25.1/CompilerIdC/a.out -------------------------------------------------------------------------------- /04.Raspberry pi/4.Iot/Mqtt/build/CMakeFiles/3.25.1/CompilerIdCXX/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismailTareq/Embedded_linux2024_diploma/c3ed271e30181868f803f4c217f7b4c2dadf9d2f/04.Raspberry pi/4.Iot/Mqtt/build/CMakeFiles/3.25.1/CompilerIdCXX/a.out -------------------------------------------------------------------------------- /04.Raspberry pi/4.Iot/Mqtt/build/CMakeFiles/CMakeDirectoryInformation.cmake: -------------------------------------------------------------------------------- 1 | # CMAKE generated file: DO NOT EDIT! 2 | # Generated by "Unix Makefiles" Generator, CMake Version 3.25 3 | 4 | # Relative path conversion top directories. 5 | set(CMAKE_RELATIVE_PATH_TOP_SOURCE "/home/pi/projects/4.Iot/mqtt") 6 | set(CMAKE_RELATIVE_PATH_TOP_BINARY "/home/pi/projects/4.Iot/mqtt/build") 7 | 8 | # Force unix paths in dependencies. 9 | set(CMAKE_FORCE_UNIX_PATHS 1) 10 | 11 | 12 | # The C and CXX include file regular expressions for this directory. 13 | set(CMAKE_C_INCLUDE_REGEX_SCAN "^.*$") 14 | set(CMAKE_C_INCLUDE_REGEX_COMPLAIN "^$") 15 | set(CMAKE_CXX_INCLUDE_REGEX_SCAN ${CMAKE_C_INCLUDE_REGEX_SCAN}) 16 | set(CMAKE_CXX_INCLUDE_REGEX_COMPLAIN ${CMAKE_C_INCLUDE_REGEX_COMPLAIN}) 17 | -------------------------------------------------------------------------------- /04.Raspberry pi/4.Iot/Mqtt/build/CMakeFiles/Makefile2: -------------------------------------------------------------------------------- 1 | # CMAKE generated file: DO NOT EDIT! 2 | # Generated by "Unix Makefiles" Generator, CMake Version 3.25 3 | 4 | # Default target executed when no arguments are given to make. 5 | default_target: all 6 | .PHONY : default_target 7 | 8 | #============================================================================= 9 | # Special targets provided by cmake. 10 | 11 | # Disable implicit rules so canonical targets will work. 12 | .SUFFIXES: 13 | 14 | # Disable VCS-based implicit rules. 15 | % : %,v 16 | 17 | # Disable VCS-based implicit rules. 18 | % : RCS/% 19 | 20 | # Disable VCS-based implicit rules. 21 | % : RCS/%,v 22 | 23 | # Disable VCS-based implicit rules. 24 | % : SCCS/s.% 25 | 26 | # Disable VCS-based implicit rules. 27 | % : s.% 28 | 29 | .SUFFIXES: .hpux_make_needs_suffix_list 30 | 31 | # Command-line flag to silence nested $(MAKE). 32 | $(VERBOSE)MAKESILENT = -s 33 | 34 | #Suppress display of executed commands. 35 | $(VERBOSE).SILENT: 36 | 37 | # A target that is always out of date. 38 | cmake_force: 39 | .PHONY : cmake_force 40 | 41 | #============================================================================= 42 | # Set environment variables for the build. 43 | 44 | # The shell in which to execute make rules. 45 | SHELL = /bin/sh 46 | 47 | # The CMake executable. 48 | CMAKE_COMMAND = /usr/bin/cmake 49 | 50 | # The command to remove a file. 51 | RM = /usr/bin/cmake -E rm -f 52 | 53 | # Escaping for special characters. 54 | EQUALS = = 55 | 56 | # The top-level source directory on which CMake was run. 57 | CMAKE_SOURCE_DIR = /home/pi/projects/4.Iot/mqtt 58 | 59 | # The top-level build directory on which CMake was run. 60 | CMAKE_BINARY_DIR = /home/pi/projects/4.Iot/mqtt/build 61 | 62 | #============================================================================= 63 | # Directory level rules for the build root directory 64 | 65 | # The main recursive "all" target. 66 | all: CMakeFiles/Switcher.dir/all 67 | .PHONY : all 68 | 69 | # The main recursive "preinstall" target. 70 | preinstall: 71 | .PHONY : preinstall 72 | 73 | # The main recursive "clean" target. 74 | clean: CMakeFiles/Switcher.dir/clean 75 | .PHONY : clean 76 | 77 | #============================================================================= 78 | # Target rules for target CMakeFiles/Switcher.dir 79 | 80 | # All Build rule for target. 81 | CMakeFiles/Switcher.dir/all: 82 | $(MAKE) $(MAKESILENT) -f CMakeFiles/Switcher.dir/build.make CMakeFiles/Switcher.dir/depend 83 | $(MAKE) $(MAKESILENT) -f CMakeFiles/Switcher.dir/build.make CMakeFiles/Switcher.dir/build 84 | @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --progress-dir=/home/pi/projects/4.Iot/mqtt/build/CMakeFiles --progress-num=1,2,3 "Built target Switcher" 85 | .PHONY : CMakeFiles/Switcher.dir/all 86 | 87 | # Build rule for subdir invocation for target. 88 | CMakeFiles/Switcher.dir/rule: cmake_check_build_system 89 | $(CMAKE_COMMAND) -E cmake_progress_start /home/pi/projects/4.Iot/mqtt/build/CMakeFiles 3 90 | $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 CMakeFiles/Switcher.dir/all 91 | $(CMAKE_COMMAND) -E cmake_progress_start /home/pi/projects/4.Iot/mqtt/build/CMakeFiles 0 92 | .PHONY : CMakeFiles/Switcher.dir/rule 93 | 94 | # Convenience name for target. 95 | Switcher: CMakeFiles/Switcher.dir/rule 96 | .PHONY : Switcher 97 | 98 | # clean rule for target. 99 | CMakeFiles/Switcher.dir/clean: 100 | $(MAKE) $(MAKESILENT) -f CMakeFiles/Switcher.dir/build.make CMakeFiles/Switcher.dir/clean 101 | .PHONY : CMakeFiles/Switcher.dir/clean 102 | 103 | #============================================================================= 104 | # Special targets to cleanup operation of make. 105 | 106 | # Special rule to run CMake to check the build system integrity. 107 | # No rule that depends on this can have commands that come from listfiles 108 | # because they might be regenerated. 109 | cmake_check_build_system: 110 | $(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0 111 | .PHONY : cmake_check_build_system 112 | 113 | -------------------------------------------------------------------------------- /04.Raspberry pi/4.Iot/Mqtt/build/CMakeFiles/Switcher.dir/DependInfo.cmake: -------------------------------------------------------------------------------- 1 | 2 | # Consider dependencies only in project. 3 | set(CMAKE_DEPENDS_IN_PROJECT_ONLY OFF) 4 | 5 | # The set of languages for which implicit dependencies are needed: 6 | set(CMAKE_DEPENDS_LANGUAGES 7 | ) 8 | 9 | # The set of dependency files which are needed: 10 | set(CMAKE_DEPENDS_DEPENDENCY_FILES 11 | "/home/pi/projects/4.Iot/mqtt/main.cpp" "CMakeFiles/Switcher.dir/main.cpp.o" "gcc" "CMakeFiles/Switcher.dir/main.cpp.o.d" 12 | "/home/pi/projects/4.Iot/mqtt/publisher.cpp" "CMakeFiles/Switcher.dir/publisher.cpp.o" "gcc" "CMakeFiles/Switcher.dir/publisher.cpp.o.d" 13 | ) 14 | 15 | # Targets to which this target links. 16 | set(CMAKE_TARGET_LINKED_INFO_FILES 17 | ) 18 | 19 | # Fortran module output directory. 20 | set(CMAKE_Fortran_TARGET_MODULE_DIR "") 21 | -------------------------------------------------------------------------------- /04.Raspberry pi/4.Iot/Mqtt/build/CMakeFiles/Switcher.dir/cmake_clean.cmake: -------------------------------------------------------------------------------- 1 | file(REMOVE_RECURSE 2 | "CMakeFiles/Switcher.dir/main.cpp.o" 3 | "CMakeFiles/Switcher.dir/main.cpp.o.d" 4 | "CMakeFiles/Switcher.dir/publisher.cpp.o" 5 | "CMakeFiles/Switcher.dir/publisher.cpp.o.d" 6 | "Switcher" 7 | "Switcher.pdb" 8 | ) 9 | 10 | # Per-language clean rules from dependency scanning. 11 | foreach(lang CXX) 12 | include(CMakeFiles/Switcher.dir/cmake_clean_${lang}.cmake OPTIONAL) 13 | endforeach() 14 | -------------------------------------------------------------------------------- /04.Raspberry pi/4.Iot/Mqtt/build/CMakeFiles/Switcher.dir/compiler_depend.ts: -------------------------------------------------------------------------------- 1 | # CMAKE generated file: DO NOT EDIT! 2 | # Timestamp file for compiler generated dependencies management for Switcher. 3 | -------------------------------------------------------------------------------- /04.Raspberry pi/4.Iot/Mqtt/build/CMakeFiles/Switcher.dir/depend.make: -------------------------------------------------------------------------------- 1 | # Empty dependencies file for Switcher. 2 | # This may be replaced when dependencies are built. 3 | -------------------------------------------------------------------------------- /04.Raspberry pi/4.Iot/Mqtt/build/CMakeFiles/Switcher.dir/flags.make: -------------------------------------------------------------------------------- 1 | # CMAKE generated file: DO NOT EDIT! 2 | # Generated by "Unix Makefiles" Generator, CMake Version 3.25 3 | 4 | # compile CXX with /usr/bin/c++ 5 | CXX_DEFINES = 6 | 7 | CXX_INCLUDES = -I/home/pi/projects/4.Iot/mqtt/publisher 8 | 9 | CXX_FLAGS = -g 10 | 11 | -------------------------------------------------------------------------------- /04.Raspberry pi/4.Iot/Mqtt/build/CMakeFiles/Switcher.dir/link.txt: -------------------------------------------------------------------------------- 1 | /usr/bin/c++ -g CMakeFiles/Switcher.dir/main.cpp.o CMakeFiles/Switcher.dir/publisher.cpp.o -o Switcher /usr/lib/aarch64-linux-gnu/libpaho-mqttpp3.so /usr/lib/libwiringPi.so /usr/lib/aarch64-linux-gnu/libpaho-mqtt3as.so -lpthread -lssl -lcrypto 2 | -------------------------------------------------------------------------------- /04.Raspberry pi/4.Iot/Mqtt/build/CMakeFiles/Switcher.dir/main.cpp.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismailTareq/Embedded_linux2024_diploma/c3ed271e30181868f803f4c217f7b4c2dadf9d2f/04.Raspberry pi/4.Iot/Mqtt/build/CMakeFiles/Switcher.dir/main.cpp.o -------------------------------------------------------------------------------- /04.Raspberry pi/4.Iot/Mqtt/build/CMakeFiles/Switcher.dir/progress.make: -------------------------------------------------------------------------------- 1 | CMAKE_PROGRESS_1 = 1 2 | CMAKE_PROGRESS_2 = 2 3 | CMAKE_PROGRESS_3 = 3 4 | 5 | -------------------------------------------------------------------------------- /04.Raspberry pi/4.Iot/Mqtt/build/CMakeFiles/Switcher.dir/publisher.cpp.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismailTareq/Embedded_linux2024_diploma/c3ed271e30181868f803f4c217f7b4c2dadf9d2f/04.Raspberry pi/4.Iot/Mqtt/build/CMakeFiles/Switcher.dir/publisher.cpp.o -------------------------------------------------------------------------------- /04.Raspberry pi/4.Iot/Mqtt/build/CMakeFiles/TargetDirectories.txt: -------------------------------------------------------------------------------- 1 | /home/pi/projects/4.Iot/mqtt/build/CMakeFiles/Switcher.dir 2 | /home/pi/projects/4.Iot/mqtt/build/CMakeFiles/edit_cache.dir 3 | /home/pi/projects/4.Iot/mqtt/build/CMakeFiles/rebuild_cache.dir 4 | -------------------------------------------------------------------------------- /04.Raspberry pi/4.Iot/Mqtt/build/CMakeFiles/cmake.check_cache: -------------------------------------------------------------------------------- 1 | # This file is generated by cmake for dependency checking of the CMakeCache.txt file 2 | -------------------------------------------------------------------------------- /04.Raspberry pi/4.Iot/Mqtt/build/CMakeFiles/progress.marks: -------------------------------------------------------------------------------- 1 | 3 2 | -------------------------------------------------------------------------------- /04.Raspberry pi/4.Iot/Mqtt/build/Switcher: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismailTareq/Embedded_linux2024_diploma/c3ed271e30181868f803f4c217f7b4c2dadf9d2f/04.Raspberry pi/4.Iot/Mqtt/build/Switcher -------------------------------------------------------------------------------- /04.Raspberry pi/4.Iot/Mqtt/build/cmake_install.cmake: -------------------------------------------------------------------------------- 1 | # Install script for directory: /home/pi/projects/4.Iot/mqtt 2 | 3 | # Set the install prefix 4 | if(NOT DEFINED CMAKE_INSTALL_PREFIX) 5 | set(CMAKE_INSTALL_PREFIX "/usr/local") 6 | endif() 7 | string(REGEX REPLACE "/$" "" CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}") 8 | 9 | # Set the install configuration name. 10 | if(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME) 11 | if(BUILD_TYPE) 12 | string(REGEX REPLACE "^[^A-Za-z0-9_]+" "" 13 | CMAKE_INSTALL_CONFIG_NAME "${BUILD_TYPE}") 14 | else() 15 | set(CMAKE_INSTALL_CONFIG_NAME "") 16 | endif() 17 | message(STATUS "Install configuration: \"${CMAKE_INSTALL_CONFIG_NAME}\"") 18 | endif() 19 | 20 | # Set the component getting installed. 21 | if(NOT CMAKE_INSTALL_COMPONENT) 22 | if(COMPONENT) 23 | message(STATUS "Install component: \"${COMPONENT}\"") 24 | set(CMAKE_INSTALL_COMPONENT "${COMPONENT}") 25 | else() 26 | set(CMAKE_INSTALL_COMPONENT) 27 | endif() 28 | endif() 29 | 30 | # Install shared libraries without execute permission? 31 | if(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE) 32 | set(CMAKE_INSTALL_SO_NO_EXE "1") 33 | endif() 34 | 35 | # Is this installation the result of a crosscompile? 36 | if(NOT DEFINED CMAKE_CROSSCOMPILING) 37 | set(CMAKE_CROSSCOMPILING "FALSE") 38 | endif() 39 | 40 | # Set default install directory permissions. 41 | if(NOT DEFINED CMAKE_OBJDUMP) 42 | set(CMAKE_OBJDUMP "/usr/bin/objdump") 43 | endif() 44 | 45 | if(CMAKE_INSTALL_COMPONENT) 46 | set(CMAKE_INSTALL_MANIFEST "install_manifest_${CMAKE_INSTALL_COMPONENT}.txt") 47 | else() 48 | set(CMAKE_INSTALL_MANIFEST "install_manifest.txt") 49 | endif() 50 | 51 | string(REPLACE ";" "\n" CMAKE_INSTALL_MANIFEST_CONTENT 52 | "${CMAKE_INSTALL_MANIFEST_FILES}") 53 | file(WRITE "/home/pi/projects/4.Iot/mqtt/build/${CMAKE_INSTALL_MANIFEST}" 54 | "${CMAKE_INSTALL_MANIFEST_CONTENT}") 55 | -------------------------------------------------------------------------------- /04.Raspberry pi/4.Iot/Mqtt/main.cpp: -------------------------------------------------------------------------------- 1 | #include "publisher.hpp" 2 | #include 3 | #include "wiringPi.h" 4 | #include 5 | 6 | #define BTN_PIN 0 // GPIO pin for the button 7 | 8 | 9 | int main() 10 | { 11 | mqtt::publisher Publisher; 12 | bool ledState = true; 13 | if(wiringPiSetup() == -1) { 14 | std::cerr << "Failed to initialize wiringPi" << std::endl; 15 | return 1; 16 | } 17 | pinMode(BTN_PIN, INPUT); 18 | pullUpDnControl(BTN_PIN, PUD_UP); // Enable pull-up resistor 19 | 20 | while(true) 21 | { 22 | int buttonState = digitalRead(BTN_PIN); 23 | if(buttonState == LOW) 24 | { 25 | std::cout << "Button pressed, toggling LED state." << std::endl; 26 | ledState = !ledState; // Toggle the LED state 27 | Publisher.TriggerLed(ledState); // Publish the new state 28 | std::this_thread::sleep_for(std::chrono::milliseconds(500)); // Debounce delay 29 | } 30 | else if(buttonState == HIGH) 31 | { 32 | std::this_thread::sleep_for(std::chrono::milliseconds(100)); // Polling delay 33 | } 34 | 35 | } 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /04.Raspberry pi/4.Iot/Mqtt/main.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismailTareq/Embedded_linux2024_diploma/c3ed271e30181868f803f4c217f7b4c2dadf9d2f/04.Raspberry pi/4.Iot/Mqtt/main.o -------------------------------------------------------------------------------- /04.Raspberry pi/4.Iot/Mqtt/mqtt.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // WiFi credentials 5 | const char* ssid = ""; 6 | const char* password = ""; 7 | 8 | // MQTT broker details 9 | const char* mqtt_server = "test.mosquitto.org"; 10 | const int mqtt_port = 1883; 11 | 12 | const int ledPin = 21; // GPIO 21 13 | 14 | // Create a WiFi client 15 | WiFiClient espClient; 16 | 17 | // Create an MQTT client 18 | PubSubClient client(espClient); 19 | 20 | // Callback function to handle incoming messages 21 | void callback(char* topic, byte* payload, unsigned int length) { 22 | Serial.print("Message arrived ["); 23 | Serial.print(topic); 24 | Serial.print("] "); 25 | 26 | // Convert payload to string 27 | char message[length + 1]; 28 | for (unsigned int i = 0; i < length; i++) { 29 | message[i] = (char)payload[i]; 30 | Serial.print(message[i]); 31 | } 32 | message[length] = '\0'; 33 | Serial.println(); 34 | 35 | // Act based on message 36 | if (strcmp(message, "ON") == 0) { 37 | digitalWrite(ledPin, HIGH); 38 | Serial.println("LED turned ON"); 39 | } else if (strcmp(message, "OFF") == 0) { 40 | digitalWrite(ledPin, LOW); 41 | Serial.println("LED turned OFF"); 42 | } 43 | } 44 | 45 | 46 | void setup() { 47 | Serial.begin(115200); 48 | pinMode(ledPin, OUTPUT); 49 | digitalWrite(ledPin, LOW); // start with LED off 50 | 51 | WiFi.begin(ssid, password); 52 | while (WiFi.status() != WL_CONNECTED) { 53 | delay(500); 54 | Serial.print("."); 55 | } 56 | Serial.println("WiFi connected"); 57 | 58 | client.setServer(mqtt_server, mqtt_port); // <-- Add this 59 | client.setCallback(callback); // <-- And this 60 | 61 | if (client.connect("ESP32_ClientID")) { 62 | Serial.println("Connected to MQTT broker"); 63 | client.subscribe("led/control"); 64 | } else { 65 | Serial.print("Failed to connect to MQTT broker, rc="); 66 | Serial.print(client.state()); 67 | } 68 | } 69 | 70 | 71 | void loop() { 72 | // Maintain the connection to the MQTT broker 73 | if (!client.connected()) { 74 | Serial.println("MQTT connection lost, attempting to reconnect..."); 75 | if (client.connect("ESP32_ClientID")) { // Use the client ID here 76 | Serial.println("Connected to MQTT broker"); 77 | client.subscribe("led/control"); // Re-subscribe to the topic 78 | } else { 79 | Serial.print("Failed to reconnect to MQTT broker, rc="); 80 | Serial.print(client.state()); 81 | } 82 | } 83 | 84 | client.loop(); 85 | } 86 | -------------------------------------------------------------------------------- /04.Raspberry pi/4.Iot/Mqtt/publisher: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismailTareq/Embedded_linux2024_diploma/c3ed271e30181868f803f4c217f7b4c2dadf9d2f/04.Raspberry pi/4.Iot/Mqtt/publisher -------------------------------------------------------------------------------- /04.Raspberry pi/4.Iot/Mqtt/publisher.cpp: -------------------------------------------------------------------------------- 1 | #include "publisher.hpp" 2 | #include 3 | 4 | const std::string SERVER_ADDRESS ="tcp://test.mosquitto.org:1883"; 5 | const std::string CLIENT_ID = "mqtt_publisher"; 6 | namespace mqtt { 7 | publisherCallback callback; 8 | 9 | void publisherCallback::connection_lost(const std::string &cause) { 10 | std::cout << "Connection lost: " << cause << std::endl; 11 | } 12 | void publisherCallback::delivery_complete(mqtt::delivery_token_ptr token) { 13 | std::cout << "Delivery complete for token: " << (token ? token->get_message_id() : 0) << std::endl; 14 | } 15 | void publisherCallback::message_arrived(mqtt::const_message_ptr msg) { 16 | std::cout << "Message arrived: " << msg->get_payload_str() << std::endl; 17 | } 18 | publisher::publisher() : client(SERVER_ADDRESS, CLIENT_ID) 19 | { 20 | client.connect()->wait(); 21 | client.set_callback(callback); 22 | } 23 | publisher::~publisher() { 24 | client.disconnect()->wait(); 25 | } 26 | void publisher::TriggerLed(bool value) 27 | { 28 | try { 29 | std::string topic = "led/control"; 30 | std::string data = value ? "ON" : "OFF"; 31 | int qos = 1; 32 | bool retain = false; 33 | client.publish(topic, data, qos, retain)->wait(); 34 | std::this_thread::sleep_for(std::chrono::seconds(2)); 35 | 36 | } 37 | catch (const mqtt::exception &e) { 38 | std::cerr << "MQTT Exception: " << e.what() << std::endl; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /04.Raspberry pi/4.Iot/Mqtt/publisher.hpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | namespace mqtt { 4 | class publisherCallback : public virtual mqtt::callback { 5 | 6 | public: 7 | void connection_lost(const std::string &cause) override; 8 | void delivery_complete(mqtt::delivery_token_ptr token) override; 9 | void message_arrived(mqtt::const_message_ptr msg) override; 10 | }; 11 | 12 | class publisher : public virtual mqtt::callback { 13 | public: 14 | publisher(); 15 | ~publisher(); 16 | 17 | void TriggerLed(bool value); 18 | 19 | private: 20 | mqtt::async_client client; 21 | publisherCallback callback; 22 | }; 23 | } 24 | 25 | -------------------------------------------------------------------------------- /04.Raspberry pi/4.Iot/Mqtt/publisher.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismailTareq/Embedded_linux2024_diploma/c3ed271e30181868f803f4c217f7b4c2dadf9d2f/04.Raspberry pi/4.Iot/Mqtt/publisher.o -------------------------------------------------------------------------------- /04.Raspberry pi/4.Iot/Mqtt/subscriber: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismailTareq/Embedded_linux2024_diploma/c3ed271e30181868f803f4c217f7b4c2dadf9d2f/04.Raspberry pi/4.Iot/Mqtt/subscriber -------------------------------------------------------------------------------- /04.Raspberry pi/4.Iot/Mqtt/subscriber.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | const std::string SERVER_ADDRESS("tcp://localhost:1883"); 6 | const std::string CLIENT_ID("raspi_sub"); 7 | const std::string TOPIC("raspi/test"); 8 | 9 | class SubscriberCallback : public mqtt::callback { 10 | public: 11 | void message_arrived(mqtt::const_message_ptr msg) override { 12 | std::cout << "Received on [" << msg->get_topic() << "]: " 13 | << msg->get_payload_str() << std::endl; 14 | } 15 | }; 16 | 17 | int main() { 18 | try { 19 | // 1. Create client 20 | mqtt::async_client client(SERVER_ADDRESS, CLIENT_ID); 21 | 22 | // 2. Set callback 23 | SubscriberCallback cb; 24 | client.set_callback(cb); 25 | 26 | // 3. Configure connection 27 | mqtt::connect_options connOpts; 28 | connOpts.set_clean_session(true); 29 | 30 | // 4. Connect and subscribe 31 | client.connect(connOpts)->wait(); 32 | client.subscribe(TOPIC, 1)->wait(); 33 | 34 | std::cout << "Subscribed to " << TOPIC << "\nWaiting for messages..." << std::endl; 35 | 36 | // 5. Keep running until Enter is pressed 37 | std::cin.get(); 38 | 39 | // 6. Clean disconnect 40 | client.unsubscribe(TOPIC)->wait(); 41 | client.disconnect()->wait(); 42 | } 43 | catch (const mqtt::exception& exc) { 44 | std::cerr << "Error: " << exc.what() << std::endl; 45 | return 1; 46 | } 47 | 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /04.Raspberry pi/4.Iot/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismailTareq/Embedded_linux2024_diploma/c3ed271e30181868f803f4c217f7b4c2dadf9d2f/04.Raspberry pi/4.Iot/a.out -------------------------------------------------------------------------------- /04.Raspberry pi/4.Iot/download.php: -------------------------------------------------------------------------------- 1 | 21 | -------------------------------------------------------------------------------- /04.Raspberry pi/4.Iot/download_php.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define BUTTON_PIN 4 6 | #define LED_PIN 0 7 | 8 | void downloadFile() { 9 | CURL *curl; 10 | CURLcode res; 11 | FILE *fp; 12 | 13 | // Update with your server URL and filename 14 | char *url = "http://192.168.1.16/download.php?file=example.txt"; 15 | char outfile[100]; 16 | sprintf(outfile, "/home/pi/downloads/downloaded_file.txt"); 17 | 18 | curl = curl_easy_init(); 19 | if(curl) { 20 | fp = fopen(outfile, "wb"); 21 | if(fp == NULL) { 22 | printf("Failed to open file for writing\n"); 23 | return; 24 | } 25 | 26 | curl_easy_setopt(curl, CURLOPT_URL, url); 27 | curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL); 28 | curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp); 29 | res = curl_easy_perform(curl); 30 | if(res != CURLE_OK) { 31 | fprintf(stderr, "curl_easy_perform() failed: %s\n", 32 | curl_easy_strerror(res)); 33 | } else { 34 | printf("File downloaded successfully\n"); 35 | digitalWrite(LED_PIN, HIGH); 36 | } 37 | curl_easy_cleanup(curl); 38 | fclose(fp); 39 | } 40 | } 41 | 42 | int main() { 43 | if (wiringPiSetup() == -1) { 44 | printf("WiringPi setup failed!\n"); 45 | return 1; 46 | } 47 | 48 | // Initialize button pin 49 | pinMode(BUTTON_PIN, INPUT); 50 | pullUpDnControl(BUTTON_PIN, PUD_UP); 51 | 52 | // Initialize LED pin 53 | pinMode(LED_PIN, OUTPUT); 54 | digitalWrite(LED_PIN, LOW); 55 | 56 | printf("Waiting for button press...\n"); 57 | 58 | while(1) { 59 | if (digitalRead(BUTTON_PIN) == LOW) { 60 | printf("Button pressed, downloading file...\n"); 61 | downloadFile(); 62 | delay(1000); // Debounce delay 63 | break; 64 | } 65 | delay(100); 66 | } 67 | 68 | return 0; 69 | } 70 | -------------------------------------------------------------------------------- /04.Raspberry pi/4.Iot/gettest.py: -------------------------------------------------------------------------------- 1 | import requests 2 | 3 | url=requests.get("http://192.168.1.20:8000/test.txt") 4 | print(url.text) 5 | -------------------------------------------------------------------------------- /04.Raspberry pi/4.Iot/mqttclient.py: -------------------------------------------------------------------------------- 1 | import paho.mqtt.client as mqtt 2 | 3 | def on_connect(client, userdata, flags, rc): 4 | print("Connected with result code {rc}") 5 | client.subscribe("test/topic1") 6 | client.subscribe("test/topic2") 7 | 8 | def on_message(client, userdata, msg): 9 | print(msg.topic + " " + str(msg.payload)) 10 | if str(msg.payload).find("hello") != -1: 11 | print("Hello message received!") 12 | if msg.payload == 'world!': 13 | print("world message received ") 14 | 15 | client = mqtt.Client() 16 | client.on_connect = on_connect 17 | client.on_message = on_message 18 | client.connect("test.mosquitto.org", 1883, 60) 19 | client.loop_forever() 20 | -------------------------------------------------------------------------------- /04.Raspberry pi/4.Iot/mqttserver.py: -------------------------------------------------------------------------------- 1 | import paho.mqtt.publish as publish 2 | 3 | publish.single("test/topic1", "hello", hostname="test.mosquitto.org") 4 | publish.single("test/topic2", "world!", hostname="test.mosquitto.org") 5 | print("Messages published to test/topic1 and test/topic2") -------------------------------------------------------------------------------- /04.Raspberry pi/4.Iot/project/button.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define BUTTON_PIN 0 // GPIO pin number (BCM) connected to the button 5 | 6 | int main() { 7 | // Initialize WiringPi 8 | if (wiringPiSetup() == -1) { 9 | std::cerr << "Failed to initialize WiringPi" << std::endl; 10 | return 1; 11 | } 12 | 13 | // Set the button pin as an input 14 | pinMode(BUTTON_PIN, INPUT); 15 | 16 | // Enable the internal pull-up resistor 17 | pullUpDnControl(BUTTON_PIN, PUD_UP); 18 | 19 | std::cout << "Button checker started. Press Ctrl+C to exit." << std::endl; 20 | 21 | while (true) { 22 | // Read the button state 23 | int buttonState = digitalRead(BUTTON_PIN); 24 | 25 | if (buttonState == LOW) { 26 | std::cout << "Button is pressed!" << std::endl; 27 | } else { 28 | std::cout << "Button is not pressed." << std::endl; 29 | } 30 | 31 | // Delay for a short period to avoid flooding the console 32 | delay(500); 33 | } 34 | 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /04.Raspberry pi/4.Iot/project/button_checker: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismailTareq/Embedded_linux2024_diploma/c3ed271e30181868f803f4c217f7b4c2dadf9d2f/04.Raspberry pi/4.Iot/project/button_checker -------------------------------------------------------------------------------- /04.Raspberry pi/4.Iot/project/publisher/publisher.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismailTareq/Embedded_linux2024_diploma/c3ed271e30181868f803f4c217f7b4c2dadf9d2f/04.Raspberry pi/4.Iot/project/publisher/publisher.cpp -------------------------------------------------------------------------------- /04.Raspberry pi/4.Iot/project/publisher/publisher.hpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | namespace mqtt { 4 | const std::string SERVER_ADDRESS("tcp://192.168.1.24:1883"); 5 | const std::string CLIENT_ID("mqtt_client"); 6 | class publisherCallback : public virtual mqtt::callback { 7 | 8 | public: 9 | void connection_lost(const std::string &cause) override; 10 | void delivery_complete(mqtt::delivery_token_ptr token) override; 11 | void message_arrived(mqtt::const_message_ptr msg) override; 12 | }; 13 | 14 | class publisher : public virtual mqtt::callback { 15 | public: 16 | publisher(); 17 | ~publisher(); 18 | 19 | void TriggerLed(bool value); 20 | 21 | private: 22 | mqtt::async_client client; 23 | publisherCallback callback; 24 | }; 25 | } 26 | -------------------------------------------------------------------------------- /04.Raspberry pi/4.Iot/raspiserver.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using std::string; 7 | using std::endl; 8 | 9 | string Read(boost::asio::ip::tcp::socket& socket) 10 | { 11 | boost::asio::streambuf buffer; 12 | boost::asio::read_until(socket, buffer, "\n"); 13 | 14 | string data = boost::asio::buffer_cast(buffer.data()); 15 | return data; 16 | } 17 | 18 | void Send(boost::asio::ip::tcp::socket& socket ,const string& message) 19 | { 20 | boost::asio::write(socket, boost::asio::buffer(message + "\n")); 21 | } 22 | 23 | int main() 24 | { 25 | boost::asio::io_service io_service; 26 | boost::asio::ip::tcp::acceptor Acceptor(io_service, 27 | boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), 1234)); 28 | std::cout << "Server is running on port 1234..." << std::endl; 29 | boost::asio::ip::tcp::socket Socket(io_service); 30 | Acceptor.accept(Socket); 31 | std::cout << "Client connected." << std::endl; 32 | string message = Read(Socket); 33 | std::cout << "Received: " << message << endl; 34 | Send(Socket, "Hello from server!"); 35 | std::cout << "Sent: Hello from server!" << endl; 36 | Socket.close(); 37 | std::cout << "Connection closed." << std::endl; 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /04.Raspberry pi/4.Iot/socket.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace boost::asio; 6 | using ip::tcp; 7 | using std::string; 8 | 9 | int main() 10 | { 11 | boost::asio::io_service io_service; 12 | tcp::socket socket(io_service); 13 | socket.connect( 14 | tcp::endpoint(boost::asio::ip::address::from_string("127.0.0.1"), 1234) 15 | ); 16 | const string message = "Hello from client\n"; 17 | boost::system::error_code error; 18 | boost::asio::write(socket, boost::asio::buffer(message), error); 19 | if (error) { 20 | std::cerr << "Error sending message: " << error.message() << std::endl; 21 | } else { 22 | std::cout << "Message sent successfully!" << std::endl; 23 | } 24 | boost::asio::streambuf response; 25 | boost::asio::read(socket, response, boost::asio::transfer_all(), error); 26 | if (error && error != boost::asio::error::eof) { 27 | std::cerr << "Error reading response: " << error.message() << std::endl; 28 | } else { 29 | std::cout << "Response received: " << boost::asio::buffer_cast(response.data()) << std::endl; 30 | } 31 | socket.close(); 32 | return 0; 33 | 34 | } 35 | -------------------------------------------------------------------------------- /04.Raspberry pi/4.Iot/socketclient.py: -------------------------------------------------------------------------------- 1 | import socket 2 | 3 | def run_client(server_host='127.0.0.1', server_port=1234): 4 | with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: 5 | s.connect((server_host, server_port)) 6 | 7 | message = "Hello from client\n" 8 | s.sendall(message.encode()) 9 | print(f"Sent: {message}") 10 | 11 | data = s.recv(1024) 12 | print(f"Received: {data.decode()}") 13 | 14 | if __name__ == "__main__": 15 | run_client() 16 | -------------------------------------------------------------------------------- /04.Raspberry pi/4.Iot/sockettest.py: -------------------------------------------------------------------------------- 1 | import socket 2 | 3 | def run_server(host='127.0.0.1', port=1234): 4 | with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: 5 | s.bind((host, port)) 6 | s.listen() 7 | print(f"Server listening on {host}:{port}") 8 | 9 | conn, addr = s.accept() 10 | with conn: 11 | print(f"Connected by {addr}") 12 | while True: 13 | data = conn.recv(1024) 14 | if not data: 15 | break 16 | conn.sendall(data) # Echo back the received data 17 | print(f"Received and sent back: {data.decode()}") 18 | 19 | if __name__ == "__main__": 20 | run_server() 21 | -------------------------------------------------------------------------------- /04.Raspberry pi/4.Iot/test.txt: -------------------------------------------------------------------------------- 1 | ismail is here bitch 2 | -------------------------------------------------------------------------------- /04.Raspberry pi/DHT.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file DHT.h 3 | * 4 | * This is a library for DHT series of low cost temperature/humidity sensors. 5 | * 6 | * You must have Adafruit Unified Sensor Library library installed to use this 7 | * class. 8 | * 9 | * Adafruit invests time and resources providing this open source code, 10 | * please support Adafruit andopen-source hardware by purchasing products 11 | * from Adafruit! 12 | * 13 | * Written by Adafruit Industries. 14 | * 15 | * MIT license, all text above must be included in any redistribution 16 | */ 17 | 18 | #ifndef DHT_H 19 | #define DHT_H 20 | 21 | #include "Arduino.h" 22 | 23 | /* Uncomment to enable printing out nice debug messages. */ 24 | //#define DHT_DEBUG 25 | 26 | #define DEBUG_PRINTER \ 27 | Serial /**< Define where debug output will be printed. \ 28 | */ 29 | 30 | /* Setup debug printing macros. */ 31 | #ifdef DHT_DEBUG 32 | #define DEBUG_PRINT(...) \ 33 | { DEBUG_PRINTER.print(__VA_ARGS__); } 34 | #define DEBUG_PRINTLN(...) \ 35 | { DEBUG_PRINTER.println(__VA_ARGS__); } 36 | #else 37 | #define DEBUG_PRINT(...) \ 38 | {} /**< Debug Print Placeholder if Debug is disabled */ 39 | #define DEBUG_PRINTLN(...) \ 40 | {} /**< Debug Print Line Placeholder if Debug is disabled */ 41 | #endif 42 | 43 | /* Define types of sensors. */ 44 | static const uint8_t DHT11{11}; /**< DHT TYPE 11 */ 45 | static const uint8_t DHT12{12}; /**< DHY TYPE 12 */ 46 | static const uint8_t DHT21{21}; /**< DHT TYPE 21 */ 47 | static const uint8_t DHT22{22}; /**< DHT TYPE 22 */ 48 | static const uint8_t AM2301{21}; /**< AM2301 */ 49 | 50 | #if defined(TARGET_NAME) && (TARGET_NAME == ARDUINO_NANO33BLE) 51 | #ifndef microsecondsToClockCycles 52 | /*! 53 | * As of 7 Sep 2020 the Arduino Nano 33 BLE boards do not have 54 | * microsecondsToClockCycles defined. 55 | */ 56 | #define microsecondsToClockCycles(a) ((a) * (SystemCoreClock / 1000000L)) 57 | #endif 58 | #endif 59 | 60 | /*! 61 | * @brief Class that stores state and functions for DHT 62 | */ 63 | class DHT { 64 | public: 65 | DHT(uint8_t pin, uint8_t type, uint8_t count = 6); 66 | void begin(uint8_t usec = 55); 67 | float readTemperature(bool S = false, bool force = false); 68 | float convertCtoF(float); 69 | float convertFtoC(float); 70 | float computeHeatIndex(bool isFahrenheit = true); 71 | float computeHeatIndex(float temperature, float percentHumidity, 72 | bool isFahrenheit = true); 73 | float readHumidity(bool force = false); 74 | bool read(bool force = false); 75 | 76 | private: 77 | uint8_t data[5]; 78 | uint8_t _pin, _type; 79 | #ifdef __AVR 80 | // Use direct GPIO access on an 8-bit AVR so keep track of the port and 81 | // bitmask for the digital pin connected to the DHT. Other platforms will use 82 | // digitalRead. 83 | uint8_t _bit, _port; 84 | #endif 85 | uint32_t _lastreadtime, _maxcycles; 86 | bool _lastresult; 87 | uint8_t pullTime; // Time (in usec) to pull up data line before reading 88 | 89 | uint32_t expectPulse(bool level); 90 | }; 91 | 92 | /*! 93 | * @brief Class that defines Interrupt Lock Avaiability 94 | */ 95 | class InterruptLock { 96 | public: 97 | InterruptLock() { 98 | #if !defined(ARDUINO_ARCH_NRF52) 99 | noInterrupts(); 100 | #endif 101 | } 102 | ~InterruptLock() { 103 | #if !defined(ARDUINO_ARCH_NRF52) 104 | interrupts(); 105 | #endif 106 | } 107 | }; 108 | 109 | #endif 110 | -------------------------------------------------------------------------------- /04.Raspberry pi/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismailTareq/Embedded_linux2024_diploma/c3ed271e30181868f803f4c217f7b4c2dadf9d2f/04.Raspberry pi/a.out -------------------------------------------------------------------------------- /04.Raspberry pi/button_download: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismailTareq/Embedded_linux2024_diploma/c3ed271e30181868f803f4c217f7b4c2dadf9d2f/04.Raspberry pi/button_download -------------------------------------------------------------------------------- /04.Raspberry pi/button_led: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismailTareq/Embedded_linux2024_diploma/c3ed271e30181868f803f4c217f7b4c2dadf9d2f/04.Raspberry pi/button_led -------------------------------------------------------------------------------- /04.Raspberry pi/dht11_test: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismailTareq/Embedded_linux2024_diploma/c3ed271e30181868f803f4c217f7b4c2dadf9d2f/04.Raspberry pi/dht11_test -------------------------------------------------------------------------------- /04.Raspberry pi/gpio_test: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ismailTareq/Embedded_linux2024_diploma/c3ed271e30181868f803f4c217f7b4c2dadf9d2f/04.Raspberry pi/gpio_test -------------------------------------------------------------------------------- /04.Raspberry pi/led.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define LED_PIN 0 // GPIO17 (WiringPi pin 0) 5 | 6 | int main() { 7 | // Initialize WiringPi 8 | if (wiringPiSetup() == -1) { 9 | std::cerr << "Failed to initialize WiringPi" << std::endl; 10 | return 1; 11 | } 12 | 13 | // Set LED_PIN as output 14 | pinMode(LED_PIN, OUTPUT); 15 | 16 | std::cout << "Blinking LED. Press Ctrl+C to stop." << std::endl; 17 | 18 | while (true) { 19 | digitalWrite(LED_PIN, HIGH); // Turn LED on 20 | delay(500); // Wait 500ms 21 | digitalWrite(LED_PIN, LOW); // Turn LED off 22 | delay(500); // Wait 500ms 23 | } 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /04.Raspberry pi/publisher.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | const std::string SERVER_ADDRESS("tcp://localhost:1883"); 5 | const std::string CLIENT_ID("mqtt_client"); 6 | 7 | class ClientCallback : public virtual mqtt::callback { 8 | public: 9 | void connection_lost(const std::string &cause) override { 10 | std::cout << "Connection lost: " << cause << std::endl; 11 | } 12 | 13 | void delivery_complete(mqtt::delivery_token_ptr token) override {} 14 | 15 | void message_arrived(mqtt::const_message_ptr msg) override {} 16 | }; 17 | 18 | int main() { 19 | mqtt::async_client client(SERVER_ADDRESS, CLIENT_ID); 20 | 21 | try { 22 | ClientCallback callback; 23 | client.set_callback(callback); 24 | 25 | mqtt::connect_options conn_opts; 26 | conn_opts.set_keep_alive_interval(20); 27 | conn_opts.set_clean_session(true); 28 | 29 | client.connect(conn_opts)->wait(); 30 | 31 | std::string topic = "test/topic"; 32 | std::string payload = "Hello, MQTT!"; 33 | int qos = 1; 34 | bool retained = false; 35 | 36 | client.publish(topic, payload, qos, retained)->wait(); 37 | 38 | std::this_thread::sleep_for(std::chrono::seconds(2)); 39 | 40 | client.disconnect()->wait(); 41 | } catch (const mqtt::exception &exc) { 42 | std::cerr << "Error: " << exc.what() << std::endl; 43 | return 1; 44 | } 45 | 46 | return 0; 47 | } 48 | 49 | -------------------------------------------------------------------------------- /04.Raspberry pi/s: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /04.Raspberry pi/test_button.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | #define BUTTON_PIN 29 // WiringPi pin 4 corresponds to GPIO 23 7 | #define LED_PIN 0 // WiringPi pin 0 corresponds to GPIO 17 8 | 9 | void setup() { 10 | // Initialize WiringPi 11 | if (wiringPiSetup() == -1) { 12 | cerr << "Error initializing WiringPi" << endl; 13 | exit(1); 14 | } 15 | 16 | // Set up the button pin as input with a pull-up resistor 17 | pinMode(BUTTON_PIN, INPUT); 18 | pullUpDnControl(BUTTON_PIN, PUD_UP); 19 | 20 | // Set up the LED pin as output 21 | pinMode(LED_PIN, OUTPUT); 22 | } 23 | 24 | void loop() { 25 | // Read the button state 26 | int buttonState = digitalRead(BUTTON_PIN); 27 | 28 | // Check if the button is pressed (LOW) 29 | if (buttonState == LOW) { 30 | // Turn on the LED 31 | digitalWrite(LED_PIN, HIGH); 32 | cout << "Button pressed. LED turned ON." << endl; 33 | } else { 34 | // Turn off the LED 35 | digitalWrite(LED_PIN, LOW); 36 | cout << "Button not pressed. LED turned OFF." << endl; 37 | } 38 | 39 | // Small delay to debounce the button 40 | delay(200); 41 | } 42 | 43 | int main() { 44 | setup(); 45 | while (true) { 46 | loop(); 47 | } 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Embedded_linux2024_diploma 2 | ## content: 3 | --- 4 | ## C++ 5 | ![gitHub](https://github.com/ismailTareq/Embedded_linux2024_diploma/blob/main/00.Content/C%2B%2B1.png) 6 | ![gitHub](https://github.com/ismailTareq/Embedded_linux2024_diploma/blob/main/00.Content/c%2B%2B2.png) 7 | --- 8 | ## Python 9 | ![gitHub](https://github.com/ismailTareq/Embedded_linux2024_diploma/blob/main/00.Content/Python.png) 10 | --- 11 | ## Linux & Bash 12 | ![gitHub](https://github.com/ismailTareq/Embedded_linux2024_diploma/blob/main/00.Content/Linux1.png) 13 | ![gitHub](https://github.com/ismailTareq/Embedded_linux2024_diploma/blob/main/00.Content/Linux2.png) 14 | ![gitHub](https://github.com/ismailTareq/Embedded_linux2024_diploma/blob/main/00.Content/Linux3.png) 15 | --- 16 | ## Raspberry pi 17 | ![gitHub](https://github.com/ismailTareq/Embedded_linux2024_diploma/blob/main/00.Content/Rasberry.png) 18 | ![gitHub](https://github.com/ismailTareq/Embedded_linux2024_diploma/blob/main/00.Content/Rasberry2.png) 19 | --- 20 | ## Yocto 21 | ![gitHub](https://github.com/ismailTareq/Embedded_linux2024_diploma/blob/main/00.Content/yocto.png) 22 | ![gitHub](https://github.com/ismailTareq/Embedded_linux2024_diploma/blob/main/00.Content/yocta2.png) 23 | ![gitHub](https://github.com/ismailTareq/Embedded_linux2024_diploma/blob/main/00.Content/yocto3.png) 24 | --- 25 | ## Device Driver 26 | ![gitHub](https://github.com/ismailTareq/Embedded_linux2024_diploma/blob/main/00.Content/Device%20driver.png) 27 | --- 28 | ## Design Pattern 29 | ![gitHub](https://github.com/ismailTareq/Embedded_linux2024_diploma/blob/main/00.Content/Design%20Pattern.png) 30 | ![gitHub](https://github.com/ismailTareq/Embedded_linux2024_diploma/blob/main/00.Content/Design%20Pattern2.png) 31 | --- 32 | ## Docker 33 | ![gitHub](https://github.com/ismailTareq/Embedded_linux2024_diploma/blob/main/00.Content/Docker.png) 34 | --- 35 | ## Rust 36 | ![gitHub](https://github.com/ismailTareq/Embedded_linux2024_diploma/blob/main/00.Content/Rust.png) 37 | 38 | 39 | 40 | --------------------------------------------------------------------------------