Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5499bd3

Browse files
committed
RPC: fix examples (again)
1 parent 9bcf502 commit 5499bd3

File tree

2 files changed

+43
-16
lines changed

2 files changed

+43
-16
lines changed

‎libraries/RPC/examples/PingPong_RAW/PingPong_RAW.ino‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ void recv_callback(const uint8_t *buf, size_t len) {
1616
Serial.println();
1717
#else
1818
const uint8_t msg[] = "Pong!";
19-
RPC.write(&msg[0], sizeof(msg), false, true);
19+
RPC.write(&msg[0], sizeof(msg), true);
2020
#endif
2121
}
2222

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,69 @@
1-
#include "RPC.h"
21
#include "SerialRPC.h"
2+
#include "RPC.h"
33

44
/*
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+
*/
1111

1212
int subtract(int a, int b) {
13-
return a-b;
13+
return a - b;
1414
}
1515

16+
int led_status = 0;
17+
1618
void setup() {
1719
// put your setup code here, to run once:
1820
Serial.begin(115200);
21+
pinMode(LED_BUILTIN, OUTPUT);
1922
RPC.bind("subtract", subtract);
2023
delay(1000);
2124
}
2225

2326
int i = 0;
2427
void loop() {
2528

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+
}
3033

3134
String str = "";
3235
while (Serial.available()) {
3336
str += (char)Serial.read();
3437
}
3538
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);
3747
}
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+
3865
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());
4168
}
4269
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /