1
- #include " RPC.h"
2
1
#include " SerialRPC.h"
2
+ #include " RPC.h"
3
3
4
4
/*
5
- * This sketch demonstrates how to interact with the Portenta X8 Serial port (over USB)
6
- * On the board, launch both 'proxy' and 'example' binaries (from https://github.com/bcmi-labs /portentax8-m4-proxy)
7
- * The M4 provides the 'subtract' API (which will be invoked by 'example'
8
- * It also provides a full duplex Serial-like interface that is proxies through the serial monitor
9
- * Last but not leas, when you write 'echo' the corresponding function in 'example' will be triggered
10
- */
5
+ This sketch demonstrates how to interact with the Portenta X8 Serial port (over USB)
6
+ On the board, launch both 'proxy' and 'example' binaries (from https://github.com/arduino /portentax8-m4-proxy)
7
+ The M4 provides the 'subtract' API (which will be invoked by 'example'
8
+ It also provides a full duplex Serial-like interface that is proxies through the serial monitor
9
+ Last but not leas, when you write 'echo' the corresponding function in 'example' will be triggered
10
+ */
11
11
12
12
int subtract (int a, int b) {
13
- return a- b;
13
+ return a - b;
14
14
}
15
15
16
+ int led_status = 0 ;
17
+
16
18
void setup () {
17
19
// put your setup code here, to run once:
18
20
Serial.begin (115200 );
21
+ pinMode (LED_BUILTIN, OUTPUT);
19
22
RPC.bind (" subtract" , subtract);
20
23
delay (1000 );
21
24
}
22
25
23
26
int i = 0 ;
24
27
void loop () {
25
28
26
- // RPC.print("hello");
27
- // RPC.send("echo", "test ");
28
- // auto res = RPC.call("add", 5, 8).as<int>( );
29
- // RPC.send("echo", String(res).c_str());
29
+ if ( millis () % 1000 == 0 ) {
30
+ Serial. println ( " loop " );
31
+ delay ( 2 );
32
+ }
30
33
31
34
String str = " " ;
32
35
while (Serial.available ()) {
33
36
str += (char )Serial.read ();
34
37
}
35
38
if (str != " " ) {
36
- Serial.print (str);
39
+ // Serial.print(str);
40
+ }
41
+
42
+ if (str.startsWith (" whoami" )) {
43
+ digitalWrite (LED_BUILTIN, HIGH);
44
+ auto res = RPC.call (" whoami" ).as <std::string>();
45
+ Serial.println (res.c_str ());
46
+ digitalWrite (LED_BUILTIN, LOW);
37
47
}
48
+
49
+ if (str.startsWith (" divide" )) {
50
+ float a = random () % 15000 ;
51
+ float b = random () % 15000 ;
52
+ Serial.println (String (a) + " / " + String (b));
53
+ auto res = RPC.call (" divide" , a, b).as <float >();
54
+ Serial.println (String (a) + " / " + String (b) + " = " + String (res));
55
+ }
56
+
57
+ if (str.startsWith (" add" )) {
58
+ int a = random () % 15000 ;
59
+ int b = random () % 15000 ;
60
+ Serial.println (String (a) + " + " + String (b));
61
+ auto res = RPC.call (" add" , a, b).as <int >();
62
+ Serial.println (String (a) + " + " + String (b) + " = " + String (res));
63
+ }
64
+
38
65
if (str.startsWith (" echo" )) {
39
- delay ( 100 );
40
- RPC. send ( " echo " , " test " );
66
+ auto res = RPC. call ( " echo " , " X8 " ). as <std::string>( );
67
+ Serial. println (res. c_str () );
41
68
}
42
69
}
0 commit comments