update Rpi4 build script, update recursive test: add array of struct in nested struct

This commit is contained in:
QuangNguyenMinh123
2025-11-14 23:45:04 +07:00
parent 15fd277e9d
commit 1678028e39
7 changed files with 122 additions and 21 deletions
+3
View File
@@ -2,6 +2,9 @@
DEVICE:=
default:
/bin/bash build_Rpi4_owrt.sh
install_docker:
bash install_docker.sh
+1 -1
View File
@@ -9,7 +9,7 @@ Debugging hardware will be more laborious than debugging PC application.
# Build Rpi4 image
+ `make build_docker` to build docker
+ `make docker` to enter docker container
+ `./build_Rpi4_owrt.sh` inside docker to automatically build image for Rpi4. Wait for 1 or 2 hours, depends on your internet speed and PC specs
+ `make` inside docker to automatically build image for Rpi4. Wait for 1 or 2 hours, depends on your internet speed and PC specs
+ Final image will be: openwrt-bcm27xx-bcm2711-rpi-4-squashfs-factory.img
# Flash image to your microSD card
Please read this carefully before deployment
+2 -1
View File
@@ -16,7 +16,8 @@ git config --global http.maxRequestBuffer 100M
git config --global http.version HTTP/1.1
git config --global http.maxRequests 100
git config --global core.compression 0
git config --global --unset http.proxy
git config --global --unset https.proxy
# Define variables
TOPDIR=$PWD
OPENWRT_DIR="$PWD/openwrt"
+26
View File
@@ -0,0 +1,26 @@
################################################################################
# Bootloader configuration - config.txt
################################################################################
################################################################################
# For overclocking and various other settings, see:
# https://www.raspberrypi.com/documentation/computers/config_txt.html
################################################################################
# OpenWrt config
include distroconfig.txt
[all]
# Place your custom settings here.
[all]
enable_jtag_gpio=1
gpio=22-27=a4
[pi1]
gpio=4=a5
[pi2]
gpio=4=a5
[pi3]
gpio=4=a5
+16 -6
View File
@@ -5,17 +5,27 @@
#include <chrono>
#include <unistd.h>
#include <string>
#include <vector>
struct childStruct
{
int childId;
std::string childString;
int age;
std::string name;
};
struct structTetst
struct parentStruct
{
int id;
std::string b;
childStruct child;
int age;
std::string name;
childStruct childArr[100];
};
struct familyStruct
{
parentStruct dad;
int numberOfNumber;
char familyName[50];
parentStruct mom;
};
int factorial(int n);
+38 -6
View File
@@ -46,15 +46,47 @@
*
*/
int factorial(int n) {
struct structTetst testStruct = {-2, "test", {-1, "childTest"}};
testStruct.id ++;
testStruct.id ++;
testStruct.id ++;
struct familyStruct family = {
// DAD
{
50,
"DAD_NAME",
{
{1,
"1st_child"},
{2,
"2nd_child"},
{3,
"3rd_child"},
}
},
4, "FAMILY",
// MOM
{
45,
"MOM_NAME",
{
{'a',
"a_child"},
{'b',
"b_child"},
{'c',
"c_child"},
}
}
};
family.numberOfNumber ++;
family.numberOfNumber ++;
family.numberOfNumber ++;
int abc = 0;
abc ++;
abc *= 2;
testStruct.child.childId ++;
testStruct.child.childString = "childTest " + std::to_string(abc);
family.dad.childArr[0].age ++;
family.dad.childArr[1].name = "childTest " + std::to_string(abc);
family.mom.childArr[1].age ++;
family.mom.childArr[0].name = "childTest " + std::to_string(abc) + std::to_string(abc);
if (n <= 1) return 1;
return n * factorial(n - 1);
}
+36 -7
View File
@@ -7,7 +7,36 @@
using namespace std;
struct structTetst globalStruct = {-2, "test", {-1, "childTest"}};
struct familyStruct globalStruct = {
// DAD
{
50,
"DAD_NAME",
{
{1,
"1st_child"},
{2,
"2nd_child"},
{3,
"3rd_child"},
}
},
4, "FAMILY",
// MOM
{
45,
"MOM_NAME",
{
{'a',
"a_child"},
{'b',
"b_child"},
{'c',
"c_child"},
}
}
};
/***
*
*
@@ -55,15 +84,15 @@ struct structTetst globalStruct = {-2, "test", {-1, "childTest"}};
*
*/
int main() {
globalStruct.id =0;
globalStruct.numberOfNumber =0;
int a = 10, b = 3;
pid_t pid = getpid();
std::cout << "Process ID: " << pid << std::endl;
while (globalStruct.id < 100)
while (globalStruct.numberOfNumber < 100)
{
globalStruct.id++;
globalStruct.child.childId = globalStruct.id;
globalStruct.child.childString = "Child String " + std::to_string(globalStruct.id);
globalStruct.numberOfNumber++;
globalStruct.dad.age = globalStruct.numberOfNumber;
globalStruct.dad.name = "Dad String " + std::to_string(globalStruct.numberOfNumber);
cout << "Basic Arithmetic:" << endl;
cout << a << " + " << b << " = " << add(a, b) << endl;
cout << a << " - " << b << " = " << subtract(a, b) << endl;
@@ -73,7 +102,7 @@ int main() {
cout << "\nAdvanced Math:" << endl;
cout << "Factorial of 5 = " << factorial(5) << endl;
cout << "Fibonacci of 7 = " << fibonacci(7) << endl;
globalStruct.child.childId ++;
globalStruct.dad.age ++;
std::this_thread::sleep_for(std::chrono::seconds(2));
}
return 0;