Skip to content

Commit 10aecc2

Browse files
committed
WIP: add attach() API to RPC
1 parent b3e5b1e commit 10aecc2

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

libraries/RPC/RPC.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ int RPC::rpmsg_recv_raw_callback(struct rpmsg_endpoint *ept, void *data,
4444
for (int i=0; i<len; i++) {
4545
rpc->rx_buffer.store_char(buf[i]);
4646
}
47+
// call attached function
48+
if (rpc->_rx) {
49+
rpc->_rx.call();
50+
}
51+
4752
return 0;
4853
}
4954

libraries/RPC/RPC_internal.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ class RPC : public Stream, public rpc::detail::dispatcher {
7171
return initialized;
7272
}
7373

74+
void attach(void (*fptr)(void))
75+
{
76+
if (fptr != NULL) {
77+
_rx = mbed::Callback<void()>(fptr);
78+
}
79+
}
80+
7481
template <typename... Args>
7582
RPCLIB_MSGPACK::object_handle call(std::string const &func_name,
7683
Args... args) {
@@ -112,6 +119,7 @@ class RPC : public Stream, public rpc::detail::dispatcher {
112119
rtos::Thread* eventThread;
113120
rtos::Thread* dispatcherThread;
114121
RPCLIB_MSGPACK::unpacker pac_;
122+
mbed::Callback<void()> _rx;
115123

116124
//rpc::detail::response response;
117125
RPCLIB_MSGPACK::object_handle call_result;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include "Arduino.h"
2+
#include "RPC_internal.h"
3+
4+
void setup() {
5+
Serial.begin(115200);
6+
RPC1.begin();
7+
}
8+
9+
void loop() {
10+
String data = "";
11+
while (RPC1.available()) {
12+
data += (char)RPC1.read();
13+
}
14+
if (data != "") {
15+
Serial.write(data.c_str(), data.length());
16+
}
17+
data = "";
18+
while (Serial.available()) {
19+
data += (char)Serial.read();
20+
}
21+
if (data != "") {
22+
RPC1.write(data.c_str(), data.length());
23+
}
24+
}

0 commit comments

Comments
 (0)