Skip to content

Commit 7c1cb26

Browse files
committed
libraries/RPC: Update examples.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
1 parent b874b41 commit 7c1cb26

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

libraries/RPC/examples/Basic_AddSub/Basic_AddSub.ino

+27-3
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,46 @@ int add(int a, int b) {
44
return a + b;
55
}
66

7-
void setup() {
7+
int sub(int a, int b) {
8+
return a - b;
9+
}
10+
11+
void setup() {
12+
Serial.begin(115200);
13+
while (!Serial) {
14+
15+
}
16+
817
RPC.begin();
918
RPC.bind("add", add);
19+
RPC.bind("sub", sub);
20+
if (HAL_GetCurrentCPUID() == CM7_CPUID) {
21+
// Introduce a brief delay to allow the M4 sufficient time
22+
// to bind remote functions before invoking them.
23+
delay(100);
24+
}
1025
pinMode(LEDG, OUTPUT);
1126
}
1227

1328
void loop() {
1429
static size_t loop_count = 0;
30+
1531
// Blink every 512 iterations
16-
if ((loop_count++ % 512) == 0) {
32+
if (HAL_GetCurrentCPUID() == CM4_CPUID && (loop_count++ % 512) == 0) {
1733
digitalWrite(LEDG, LOW);
1834
delay(10);
1935
digitalWrite(LEDG, HIGH);
2036
delay(10);
2137
}
38+
2239
int res = RPC.call("add", 1, 2).as<int>();
23-
RPC.call("sub", res, 1).as<int>();
40+
if (HAL_GetCurrentCPUID() == CM7_CPUID) {
41+
Serial.println("add(1, 2) = " + String(res));
42+
}
43+
44+
res = RPC.call("sub", res, 1).as<int>();
45+
if (HAL_GetCurrentCPUID() == CM7_CPUID) {
46+
Serial.println("sub(3, 1) = " + String(res));
47+
}
2448
delay(250);
2549
}

libraries/RPC/examples/MD5_Checksum/MD5_Checksum.ino

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ size_t hash_out_count = 0;
77
#ifdef CORE_CM4
88
size_t data_buf_size = 0;
99
#else
10-
size_t data_buf_size = 512;
10+
size_t data_buf_size = 256;
1111
#endif
1212

1313
typedef std::vector<byte> vec_t;
@@ -59,6 +59,8 @@ void setup() {
5959
#ifdef CORE_CM4
6060
RPC.bind("set_buffer_size", set_buffer_size);
6161
#else
62+
// Introduce a brief delay to allow the M4 sufficient time
63+
// to bind remote functions before invoking them.
6264
delay(100);
6365
auto ret = RPC.call("set_buffer_size", data_buf_size).as<size_t>();
6466
#endif

0 commit comments

Comments
 (0)