Skip to content

Commit 3ab1a73

Browse files
committed
RPC: fix merge conflicts
1 parent 91f7194 commit 3ab1a73

File tree

3 files changed

+34
-46
lines changed

3 files changed

+34
-46
lines changed

Diff for: libraries/RPC/examples/PortentaX8_EchoServer/PortentaX8_EchoServer.ino

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
/*
55
* 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)
6+
* On the board, launch both 'proxy' and 'example' binaries (from https://github.com/bcmi-labs/portentax8-m4-proxy)
77
* The M4 provides the 'subtract' API (which will be invoked by 'example'
88
* It also provides a full duplex Serial-like interface that is proxies through the serial monitor
99
* Last but not leas, when you write 'echo' the corresponding function in 'example' will be triggered
@@ -39,4 +39,4 @@ void loop() {
3939
delay(100);
4040
RPC.send("echo", "test");
4141
}
42-
}
42+
}

Diff for: libraries/RPC/src/RPC.cpp

+30-42
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ arduino::RPCClass RPC;
1212
osThreadId eventHandlerThreadId;
1313
static rtos::Mutex mutex;
1414
static struct rpmsg_endpoint endpoints[2];
15+
#ifdef CORE_CM4
16+
static bool endpoints_init[2] = { 0 };
17+
#endif
1518

1619
void RPCClass::new_service_cb(struct rpmsg_device *rdev, const char *name, uint32_t dest) {
1720
uint8_t buffer[1] = {0};
@@ -31,20 +34,23 @@ void RPCClass::new_service_cb(struct rpmsg_device *rdev, const char *name, uint3
3134

3235
int RPCClass::rpmsg_recv_callback(struct rpmsg_endpoint *ept, void *data, size_t len, uint32_t src, void *priv) {
3336
#ifdef CORE_CM4
34-
static bool ep_init_msg[2] = { 0 };
35-
if (!ep_init_msg[ENDPOINT_ID_RPC] && ept == &endpoints[ENDPOINT_ID_RPC]) {
36-
ep_init_msg[ENDPOINT_ID_RPC] = true;
37+
if (!endpoints_init[ENDPOINT_ID_RPC] && ept == &endpoints[ENDPOINT_ID_RPC]) {
38+
endpoints_init[ENDPOINT_ID_RPC] = true;
3739
return 0;
38-
} else if (!ep_init_msg[ENDPOINT_ID_RAW] && ept == &endpoints[ENDPOINT_ID_RAW]) {
39-
ep_init_msg[ENDPOINT_ID_RAW] = true;
40+
} else if (!endpoints_init[ENDPOINT_ID_RAW] && ept == &endpoints[ENDPOINT_ID_RAW]) {
41+
endpoints_init[ENDPOINT_ID_RAW] = true;
4042
return 0;
4143
}
4244
#endif
4345

4446
if (ept == &endpoints[ENDPOINT_ID_RAW]) {
4547
// data on raw endpoint
4648
if (RPC.raw_callback) {
47-
RPC.raw_callback.call((const uint8_t *) data, len);
49+
RPC.raw_callback.call((uint8_t *) data, len);
50+
} else {
51+
for (size_t i=0; i<len; i++) {
52+
RPC.rx_buffer.store_char(((uint8_t *) data)[i]);
53+
}
4854
}
4955
return 0;
5056
}
@@ -176,6 +182,16 @@ int RPCClass::begin() {
176182
return 0;
177183
}
178184

185+
// Wait for endpoints to be initialized first by the host before allowing
186+
// the remote to use the endpoints.
187+
uint32_t millis_start = millis();
188+
while (!endpoints_init[ENDPOINT_ID_RPC] || !endpoints_init[ENDPOINT_ID_RAW]) {
189+
if ((millis() - millis_start) >= 5000) {
190+
return 0;
191+
}
192+
osDelay(10);
193+
}
194+
179195
return 1;
180196
}
181197
#endif
@@ -217,53 +233,25 @@ void RPCClass::request(uint8_t *buf, size_t len) {
217233
RPCLIB_MSGPACK::unpacked result;
218234
while (unpacker.next(result)) {
219235
auto msg = result.get();
220-
if (msg.via.array.size == 1) {
221-
// raw array
222-
std::tuple<RPCLIB_MSGPACK::object> arr;
223-
msg.convert(arr);
224-
225-
std::vector<uint8_t> buf;
226-
std::get<0>(arr).convert(buf);
227-
228-
for (size_t i = 0; i < buf.size(); i++) {
229-
rx_buffer.store_char(buf[i]);
230-
}
231-
}
232-
233-
if (msg.via.array.size > 2) {
234-
auto resp = rpc::detail::dispatcher::dispatch(msg, false);
235-
auto data = resp.get_data();
236-
if (!resp.is_empty()) {
237-
OPENAMP_send(&endpoints[ENDPOINT_ID_RPC], data.data(), data.size());
238-
}
236+
auto resp = rpc::detail::dispatcher::dispatch(msg, false);
237+
auto data = resp.get_data();
238+
if (!resp.is_empty()) {
239+
OPENAMP_send(&endpoints[ENDPOINT_ID_RPC], data.data(), data.size());
239240
}
240241
}
241242
}
242243

243244
size_t RPCClass::write(uint8_t c) {
244-
return write(&c, 1, true, false);
245+
return write(&c, 1, true);
245246
}
246247

247248
void rpc::client::write(RPCLIB_MSGPACK::sbuffer *buffer) {
248-
RPC.write((const uint8_t *) buffer->data(), buffer->size(), false, false);
249+
RPC.write((const uint8_t *) buffer->data(), buffer->size(), false);
249250
}
250251

251-
size_t RPCClass::write(const uint8_t *buf, size_t len, bool pack, bool raw) {
252-
if (pack) {
253-
std::vector<uint8_t> tx_buffer;
254-
for (size_t i = 0; i < len; i++) {
255-
tx_buffer.push_back(buf[i]);
256-
}
257-
auto call_obj = std::make_tuple(tx_buffer);
258-
259-
RPCLIB_MSGPACK::sbuffer buffer;
260-
RPCLIB_MSGPACK::pack(buffer, call_obj);
261-
len = buffer.size();
262-
buf = (const uint8_t *) buffer.data();
263-
}
264-
252+
size_t RPCClass::write(const uint8_t *buf, size_t len, bool raw) {
265253
mutex.lock();
266254
OPENAMP_send(&endpoints[raw ? ENDPOINT_ID_RAW : ENDPOINT_ID_RPC], buf, len);
267255
mutex.unlock();
268256
return len;
269-
}
257+
}

Diff for: libraries/RPC/src/RPC.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class RPCClass : public Stream, public rpc::detail::dispatcher {
5656
}
5757
void flush(void) {};
5858
size_t write(uint8_t c);
59-
size_t write(const uint8_t *buf, size_t len, bool pack = true, bool raw = false);
59+
size_t write(const uint8_t *buf, size_t len, bool raw = true);
6060

6161
using Print::write; // pull in write(str) and write(buf, size) from Print
6262
operator bool() {
@@ -115,14 +115,14 @@ class RPCClass : public Stream, public rpc::detail::dispatcher {
115115
}
116116

117117
rpc::client* clients[10];
118+
RingBufferN<512> rx_buffer;
118119
mbed::Callback<void(const uint8_t *buf, size_t len)> raw_callback;
119120

120121
private:
121122
bool initialized = false;
122123
uint32_t _timeout = osWaitForever;
123124
bool has_timed_out = false;
124125
rtos::Thread* eventThread;
125-
RingBufferN<512> rx_buffer;
126126
RPCLIB_MSGPACK::unpacker unpacker;
127127

128128
static void new_service_cb(struct rpmsg_device *rdev, const char *name, uint32_t dest);

0 commit comments

Comments
 (0)