Skip to content

Commit 350d5fe

Browse files
committed
doc: README with usage example ver: 0.1.0
1 parent 16b6933 commit 350d5fe

File tree

5 files changed

+67
-17
lines changed

5 files changed

+67
-17
lines changed

README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,64 @@ In this repo it will be implemented an Arduino library wrapper for RPClite to be
33
The desired API is shown in https://github.com/bcmi-labs/Arduino_BridgeImola/blob/main/desired.ino.
44

55
This is WIP. Expects changes soon.
6+
7+
## The Bridge object ##
8+
9+
Including Arduino_BridgeImola.h gives the user access to a Bridge object that can be used both as a RPC client and/or server to execute and serve RPCs to/from the CPU Host running a GOLANG router.
10+
11+
- The Bridge object is defined on Serial1
12+
- The Bridge.call method is blocking and works the same as in RPClite
13+
- The Bridge can provide callbacks to incoming RPC requests both in a thread-unsafe and thread-safe fashion (provide & provide_safe)
14+
- Thread-safe methods execution is granted in the main loop thread where update_safe is called. By design users cannot access .update_safe() freely
15+
- Thread-unsafe methods are served in an update callback, whose execution is granted in a separate thread. Nonetheless users can access .update() freely with caution
16+
17+
18+
```cpp
19+
bool set_led(bool state) {
20+
digitalWrite(LED_BUILTIN, state);
21+
return state;
22+
}
23+
24+
String greet() {
25+
return String("Hello Friend");
26+
}
27+
28+
void setup() {
29+
Serial.begin(115200);
30+
while (!Serial);
31+
32+
Serial1.begin(115200);
33+
while (!Serial1);
34+
35+
pinMode(LED_BUILTIN, OUTPUT);
36+
37+
if (!Bridge.begin()) {
38+
Serial.println("Error initializing Bridge");
39+
while(1);
40+
} else {
41+
Serial.println("Bridge initialized successfully");
42+
}
43+
44+
if (!Bridge.provide("set_led", set_led)) {
45+
Serial.println("Error providing method: set_led");
46+
} else {
47+
Serial.println("Registered method: set_led");
48+
}
49+
50+
Bridge.provide_safe("greet", greet);
51+
52+
}
53+
54+
void loop() {
55+
float res;
56+
if (!Bridge.call("multiply", res, 1.0, 2.0)) {
57+
Serial.println("Error calling method: multiply");
58+
Serial.println(Bridge.get_error_code());
59+
Serial.println(Bridge.get_error_message());
60+
};
61+
62+
Bridge.notify("signal", 200);
63+
64+
//Bridge.update(); // Thread-unsafe update execution is granted in its own thread. It can be called manually with caution
65+
}
66+
```

examples/simple_bridge/simple_bridge.ino

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ void setup() {
3838

3939
Bridge.provide("add", add);
4040

41-
Bridge.provide("greet", greet);
41+
Bridge.provide_safe("greet", greet);
4242

4343
}
4444

@@ -48,10 +48,9 @@ void loop() {
4848
Serial.println("Error calling method: multiply");
4949
Serial.println(Bridge.get_error_code());
5050
Serial.println(Bridge.get_error_message());
51-
delay(1000);
5251
};
5352

5453
Bridge.notify("signal", 200);
5554

56-
//Bridge.update();
55+
//Bridge.update(); // Thread-unsafe update execution is granted in its own thread. It can be called manually with caution
5756
}

examples/zephyr_thread/zephyr_thread.ino

Lines changed: 0 additions & 10 deletions
This file was deleted.

library.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
"url": "https://github.com/bcmi-labs/Arduino_BridgeImola",
1212
"maintainer": true
1313
},
14-
"version": "0.0.1",
14+
"version": "0.1.0",
1515
"license": "MIT",
1616
"frameworks": "arduino",
1717
"platforms": "*",
1818
"dependencies":
1919
{
20-
"bcmi-labs/Arduino_RPClite": ">=0.0.1"
20+
"bcmi-labs/Arduino_RPClite": ">=0.1.0"
2121
}
2222
}

library.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
name=Arduino_BridgeImola
2-
version=0.0.1
2+
version=0.1.0
33
author=BCMI-labs
44
maintainer=BCMI-labs
55
sentence=A RPC bridge for Imola boards
66
paragraph=This library provides a simple RPC bridge for Imola boards, allowing communication between the board and other devices using MsgPack serialization.
77
category=Communication
88
url=https://www.arduino.cc/
99
architectures=*
10-
depends=Arduino_RPClite (>=0.0.1)
10+
depends=Arduino_RPClite (>=0.1.0)

0 commit comments

Comments
 (0)