Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 53 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,56 @@
In this repo it will be implemented an Arduino library wrapper for RPClite to be run on Imola boards.
In this repo it will be implemented an Arduino library wrapper for RPClite to be run on Arduino UNO Q boards.

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

This is WIP. Expects changes soon.

## The Bridge object ##

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.

- The Bridge object is pre-defined on Serial1 and automatically initialized inside the main setup()
- The Bridge.call method is blocking and works the same as in RPClite
- The Bridge can provide callbacks to incoming RPC requests both in a thread-unsafe and thread-safe fashion (provide & provide_safe)
- Thread-safe methods execution is granted in the main loop thread where update_safe is called. By design users cannot access .update_safe() freely
- 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


```cpp
bool set_led(bool state) {
digitalWrite(LED_BUILTIN, state);
return state;
}

String greet() {
return String("Hello Friend");
}

void setup() {
Serial.begin(115200);
while (!Serial);

pinMode(LED_BUILTIN, OUTPUT);

if (!Bridge.provide("set_led", set_led)) {
Serial.println("Error providing method: set_led");
} else {
Serial.println("Registered method: set_led");
}

Bridge.provide_safe("greet", greet);

}

void loop() {
float res;
if (!Bridge.call("multiply", res, 1.0, 2.0)) {
Serial.println("Error calling method: multiply");
Serial.println(Bridge.get_error_code());
Serial.println(Bridge.get_error_message());
};

Bridge.notify("signal", 200);

//Bridge.update(); // Thread-unsafe update execution is granted in its own thread. It can be called manually with caution
}
```
40 changes: 0 additions & 40 deletions desired.ino

This file was deleted.

57 changes: 23 additions & 34 deletions examples/simple_bridge/simple_bridge.ino
Original file line number Diff line number Diff line change
@@ -1,58 +1,47 @@
#include <Arduino_BridgeImola.h>
#include <Arduino_RouterBridge.h>

Bridge bridge(Serial1);
//BridgeClass Bridge(Serial1);

bool set_led(bool state) {
digitalWrite(LED_BUILTIN, state);
return state;
}

int add(int a, int b) {
return a + b;
}

String greet() {
return String("Hello Friend");
}

void setup() {
Serial.begin(115200);
while (!Serial);

Serial1.begin(115200);
while (!Serial1);

pinMode(LED_BUILTIN, OUTPUT);

if (!bridge.begin()) {
Serial.println("Error initializing bridge");
while(1);
} else {
Serial.println("Bridge initialized successfully");
}

if (!bridge.provide("set_led", set_led)) {
if (!Bridge.provide("set_led", set_led)) {
Serial.println("Error providing method: set_led");
} else {
Serial.println("Registered method: set_led");
}

bridge.provide("add", add);
Bridge.provide("add", add);

bridge.provide("greet", greet);

}
Bridge.provide_safe("greet", greet);

bool set_led(bool state) {
digitalWrite(LED_BUILTIN, state);
return state;
}

int add(int a, int b) {
return a + b;
}

String greet() {
return String("Hello Friend");
}

void loop() {
float res;
if (!bridge.call("multiply", res, 1.0, 2.0)) {
if (!Bridge.call("multiply", res, 1.0, 2.0)) {
Serial.println("Error calling method: multiply");
Serial.println(bridge.get_error_code());
Serial.println(bridge.get_error_message());
delay(1000);
Serial.println(Bridge.get_error_code());
Serial.println(Bridge.get_error_message());
};

bridge.notify("signal", 200);
Bridge.notify("signal", 200);

bridge.update();
//Bridge.update(); // Thread-unsafe update execution is granted in its own thread. It can be called manually with caution
}
12 changes: 6 additions & 6 deletions library.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
{
"name": "Arduino_BridgeImola",
"name": "Arduino_RouterBridge",
"keywords": "rpclite,msgpack",
"description": "A RPC bridge for Imola boards",
"description": "A RPC bridge for Arduino UNO Q boards",
"repository": {
"type": "git",
"url": "https://github.com/bcmi-labs/Arduino_BridgeImola"
"url": "https://github.com/bcmi-labs/Arduino_RouterBridge"
},
"authors": {
"name": "BCMI-labs",
"url": "https://github.com/bcmi-labs/Arduino_BridgeImola",
"url": "https://github.com/bcmi-labs/Arduino_RouterBridge",
"maintainer": true
},
"version": "0.0.1",
"version": "0.1.0",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*",
"dependencies":
{
"bcmi-labs/Arduino_RPClite": ">=0.0.1"
"bcmi-labs/Arduino_RPClite": ">=0.1.0"
}
}
10 changes: 5 additions & 5 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name=Arduino_BridgeImola
version=0.0.1
name=Arduino_RouterBridge
version=0.1.0
author=BCMI-labs
maintainer=BCMI-labs
sentence=A RPC bridge for Imola boards
paragraph=This library provides a simple RPC bridge for Imola boards, allowing communication between the board and other devices using MsgPack serialization.
sentence=A RPC bridge for Arduino UNO Q boards
paragraph=This library provides a simple RPC bridge for Arduino UNO Q boards, allowing communication between the board and other devices using MsgPack serialization.
category=Communication
url=https://www.arduino.cc/
architectures=*
depends=Arduino_RPClite (>=0.0.1)
depends=Arduino_RPClite (>=0.1.0)
7 changes: 0 additions & 7 deletions src/Arduino_BridgeImola.h

This file was deleted.

7 changes: 7 additions & 0 deletions src/Arduino_RouterBridge.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#ifndef ARDUINO_ROUTER_BRIDGE_H
#define ARDUINO_ROUTER_BRIDGE_H

#include "Arduino.h"
#include "bridge.h"

#endif //ARDUINO_ROUTER_BRIDGE_H
Loading