Skip to content

Commit 47b6c71

Browse files
authored
Merge pull request #1 from bcmi-labs/zephyr_threading
Zephyr threading
2 parents ed5da89 + 63d1bf0 commit 47b6c71

File tree

8 files changed

+229
-110
lines changed

8 files changed

+229
-110
lines changed

README.md

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,56 @@
1-
In this repo it will be implemented an Arduino library wrapper for RPClite to be run on Imola boards.
1+
In this repo it will be implemented an Arduino library wrapper for RPClite to be run on Arduino UNO Q boards.
22

3-
The desired API is shown in https://github.com/bcmi-labs/Arduino_BridgeImola/blob/main/desired.ino.
3+
The desired API is shown in https://github.com/bcmi-labs/Arduino_RouterBridge/blob/main/desired.ino.
44

55
This is WIP. Expects changes soon.
6+
7+
## The Bridge object ##
8+
9+
Including Arduino_RouterBridge.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 pre-defined on Serial1 and automatically initialized inside the main setup()
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+
pinMode(LED_BUILTIN, OUTPUT);
33+
34+
if (!Bridge.provide("set_led", set_led)) {
35+
Serial.println("Error providing method: set_led");
36+
} else {
37+
Serial.println("Registered method: set_led");
38+
}
39+
40+
Bridge.provide_safe("greet", greet);
41+
42+
}
43+
44+
void loop() {
45+
float res;
46+
if (!Bridge.call("multiply", res, 1.0, 2.0)) {
47+
Serial.println("Error calling method: multiply");
48+
Serial.println(Bridge.get_error_code());
49+
Serial.println(Bridge.get_error_message());
50+
};
51+
52+
Bridge.notify("signal", 200);
53+
54+
//Bridge.update(); // Thread-unsafe update execution is granted in its own thread. It can be called manually with caution
55+
}
56+
```

desired.ino

Lines changed: 0 additions & 40 deletions
This file was deleted.
Lines changed: 23 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,47 @@
1-
#include <Arduino_BridgeImola.h>
1+
#include <Arduino_RouterBridge.h>
22

3-
Bridge bridge(Serial1);
3+
//BridgeClass Bridge(Serial1);
4+
5+
bool set_led(bool state) {
6+
digitalWrite(LED_BUILTIN, state);
7+
return state;
8+
}
9+
10+
int add(int a, int b) {
11+
return a + b;
12+
}
13+
14+
String greet() {
15+
return String("Hello Friend");
16+
}
417

518
void setup() {
619
Serial.begin(115200);
720
while (!Serial);
8-
9-
Serial1.begin(115200);
10-
while (!Serial1);
1121

1222
pinMode(LED_BUILTIN, OUTPUT);
1323

14-
if (!bridge.begin()) {
15-
Serial.println("Error initializing bridge");
16-
while(1);
17-
} else {
18-
Serial.println("Bridge initialized successfully");
19-
}
20-
21-
if (!bridge.provide("set_led", set_led)) {
24+
if (!Bridge.provide("set_led", set_led)) {
2225
Serial.println("Error providing method: set_led");
2326
} else {
2427
Serial.println("Registered method: set_led");
2528
}
2629

27-
bridge.provide("add", add);
30+
Bridge.provide("add", add);
2831

29-
bridge.provide("greet", greet);
30-
31-
}
32+
Bridge.provide_safe("greet", greet);
3233

33-
bool set_led(bool state) {
34-
digitalWrite(LED_BUILTIN, state);
35-
return state;
36-
}
37-
38-
int add(int a, int b) {
39-
return a + b;
40-
}
41-
42-
String greet() {
43-
return String("Hello Friend");
4434
}
4535

4636
void loop() {
4737
float res;
48-
if (!bridge.call("multiply", res, 1.0, 2.0)) {
38+
if (!Bridge.call("multiply", res, 1.0, 2.0)) {
4939
Serial.println("Error calling method: multiply");
50-
Serial.println(bridge.get_error_code());
51-
Serial.println(bridge.get_error_message());
52-
delay(1000);
40+
Serial.println(Bridge.get_error_code());
41+
Serial.println(Bridge.get_error_message());
5342
};
5443

55-
bridge.notify("signal", 200);
44+
Bridge.notify("signal", 200);
5645

57-
bridge.update();
46+
//Bridge.update(); // Thread-unsafe update execution is granted in its own thread. It can be called manually with caution
5847
}

library.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
{
2-
"name": "Arduino_BridgeImola",
2+
"name": "Arduino_RouterBridge",
33
"keywords": "rpclite,msgpack",
4-
"description": "A RPC bridge for Imola boards",
4+
"description": "A RPC bridge for Arduino UNO Q boards",
55
"repository": {
66
"type": "git",
7-
"url": "https://github.com/bcmi-labs/Arduino_BridgeImola"
7+
"url": "https://github.com/bcmi-labs/Arduino_RouterBridge"
88
},
99
"authors": {
1010
"name": "BCMI-labs",
11-
"url": "https://github.com/bcmi-labs/Arduino_BridgeImola",
11+
"url": "https://github.com/bcmi-labs/Arduino_RouterBridge",
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: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
name=Arduino_BridgeImola
2-
version=0.0.1
1+
name=Arduino_RouterBridge
2+
version=0.1.0
33
author=BCMI-labs
44
maintainer=BCMI-labs
5-
sentence=A RPC bridge for Imola boards
6-
paragraph=This library provides a simple RPC bridge for Imola boards, allowing communication between the board and other devices using MsgPack serialization.
5+
sentence=A RPC bridge for Arduino UNO Q boards
6+
paragraph=This library provides a simple RPC bridge for Arduino UNO Q 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)

src/Arduino_BridgeImola.h

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

src/Arduino_RouterBridge.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#ifndef ARDUINO_ROUTER_BRIDGE_H
2+
#define ARDUINO_ROUTER_BRIDGE_H
3+
4+
#include "Arduino.h"
5+
#include "bridge.h"
6+
7+
#endif //ARDUINO_ROUTER_BRIDGE_H

0 commit comments

Comments
 (0)