Skip to content

Commit 104cef4

Browse files
committed
rpc: rename header and singleton
1 parent e4d03a0 commit 104cef4

File tree

6 files changed

+45
-45
lines changed

6 files changed

+45
-45
lines changed

libraries/RPC/examples/RPC_m4/RPC_m4.ino

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "Arduino.h"
2-
#include "RPC_internal.h"
2+
#include "RPC.h"
33

44
using namespace rtos;
55

@@ -40,11 +40,11 @@ void callSubstractFromM4() {
4040
delay(700); // Wait 700ms with the next calculation
4141
int a = random(100); // Generate a random number
4242
int b = random(100); // Generate a random number
43-
RPC1.println(currentCPU() + ": calling subtract with " + String(a) + " and " + String(b));
43+
RPC.println(currentCPU() + ": calling subtract with " + String(a) + " and " + String(b));
4444

45-
auto result = RPC1.call("remoteSubtract", a, b).as<int>();
45+
auto result = RPC.call("remoteSubtract", a, b).as<int>();
4646
// Prints the result of the calculation
47-
RPC1.println(currentCPU() + ": Result is " + String(a) + " - " + String(b) + " = " + String(result));
47+
RPC.println(currentCPU() + ": Result is " + String(a) + " - " + String(b) + " = " + String(result));
4848
}
4949
}
5050

@@ -53,7 +53,7 @@ void setup() {
5353
pinMode(LED_BUILTIN, OUTPUT);
5454

5555
// Initialize RPC library; this also boots the M4 core
56-
RPC1.begin();
56+
RPC.begin();
5757
Serial.begin(115200);
5858
//while (!Serial) {} // Uncomment this to wait until the Serial connection is ready
5959

@@ -62,8 +62,8 @@ void setup() {
6262

6363
if (currentCPU() == "M7") {
6464
// M7 CPU becomes the server, so it makes two functions available under the defined names
65-
RPC1.bind("remoteAdd", addOnM7);
66-
RPC1.bind("remoteSubtract", subtractOnM7);
65+
RPC.bind("remoteAdd", addOnM7);
66+
RPC.bind("remoteSubtract", subtractOnM7);
6767
}
6868

6969
if (currentCPU() == "M4") {
@@ -86,20 +86,20 @@ void loop() {
8686
int b = random(100);
8787
// PRC.print works like a Serial port, but it needs a receiver (in this case the M7)
8888
// to actually print the strings to the Serial port
89-
RPC1.println(currentCPU() + ": calling add with " + String(a) + " and " + String(b));
89+
RPC.println(currentCPU() + ": calling add with " + String(a) + " and " + String(b));
9090
// Let's invoke addOnM7() and wait for a result.
9191
// This will be delayed by the forced delay() in addOnM7() function
9292
// Exercise: if you are not interested in the result of the operation, what operation would you invoke?
93-
auto result = RPC1.call("remoteAdd", a, b).as<int>();
94-
RPC1.println(currentCPU() + ": Result is " + String(a) + " + " + String(b) + " = " + String(result));
93+
auto result = RPC.call("remoteAdd", a, b).as<int>();
94+
RPC.println(currentCPU() + ": Result is " + String(a) + " + " + String(b) + " = " + String(result));
9595
}
9696

9797
if (currentCPU() == "M7") {
9898
// On M7, let's print everything that is received over the RPC1 stream interface
9999
// Buffer it, otherwise all characters will be interleaved by other prints
100100
String buffer = "";
101-
while (RPC1.available()) {
102-
buffer += (char)RPC1.read(); // Fill the buffer with characters
101+
while (RPC.available()) {
102+
buffer += (char)RPC.read(); // Fill the buffer with characters
103103
}
104104

105105
if (buffer.length() > 0) {
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
#include "Arduino.h"
2-
#include "RPC_internal.h"
2+
#include "RPC.h"
33

44
void setup() {
55
Serial.begin(115200);
6-
RPC1.begin();
6+
RPC.begin();
77
}
88

99
void loop() {
1010
String data = "";
11-
while (RPC1.available()) {
12-
data += (char)RPC1.read();
11+
while (RPC.available()) {
12+
data += (char)RPC.read();
1313
}
1414
if (data != "") {
1515
Serial.write(data.c_str(), data.length());
@@ -19,6 +19,6 @@ void loop() {
1919
data += (char)Serial.read();
2020
}
2121
if (data != "") {
22-
RPC1.write(data.c_str(), data.length());
22+
RPC.write(data.c_str(), data.length());
2323
}
2424
}

libraries/RPC/src/RPC_Primary.cpp renamed to libraries/RPC/src/RPC.cpp

+18-18
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "RPC_internal.h"
1+
#include "RPC.h"
22

33
static struct rpmsg_endpoint rp_endpoints[4];
44

@@ -16,10 +16,10 @@ static RingBufferN<256> intermediate_buffer_resp;
1616
//static uint8_t intermediate_buffer_resp[256];
1717
static rtos::Mutex rx_mtx;
1818

19-
int RPC::rpmsg_recv_callback(struct rpmsg_endpoint *ept, void *data,
19+
int RPCClass::rpmsg_recv_callback(struct rpmsg_endpoint *ept, void *data,
2020
size_t len, uint32_t src, void *priv)
2121
{
22-
RPC* rpc = (RPC*)priv;
22+
RPCClass* rpc = (RPCClass*)priv;
2323

2424
for (size_t i = 0; i < len; i++) {
2525
intermediate_buffer.store_char(((uint8_t*)data)[i]);
@@ -33,10 +33,10 @@ int RPC::rpmsg_recv_callback(struct rpmsg_endpoint *ept, void *data,
3333

3434
static bool first_message = true;
3535

36-
int RPC::rpmsg_recv_response_callback(struct rpmsg_endpoint *ept, void *data,
36+
int RPCClass::rpmsg_recv_response_callback(struct rpmsg_endpoint *ept, void *data,
3737
size_t len, uint32_t src, void *priv)
3838
{
39-
RPC* rpc = (RPC*)priv;
39+
RPCClass* rpc = (RPCClass*)priv;
4040

4141
#ifdef CORE_CM4
4242
if (first_message) {
@@ -57,7 +57,7 @@ int RPC::rpmsg_recv_response_callback(struct rpmsg_endpoint *ept, void *data,
5757
return 0;
5858
}
5959

60-
void RPC::new_service_cb(struct rpmsg_device *rdev, const char *name, uint32_t dest)
60+
void RPCClass::new_service_cb(struct rpmsg_device *rdev, const char *name, uint32_t dest)
6161
{
6262
if (strcmp(name, "raw") == 0) {
6363
OPENAMP_create_endpoint(&rp_endpoints[ENDPOINT_RAW], name, dest, rpmsg_recv_callback, NULL);
@@ -127,7 +127,7 @@ static void disableCM4Autoboot() {
127127
}
128128
}
129129

130-
int RPC::begin() {
130+
int RPCClass::begin() {
131131

132132
OpenAMP_MPU_Config();
133133

@@ -141,10 +141,10 @@ int RPC::begin() {
141141
eventThread->start(&eventHandler);
142142

143143
dispatcherThread = new rtos::Thread(osPriorityNormal);
144-
dispatcherThread->start(mbed::callback(this, &RPC::dispatch));
144+
dispatcherThread->start(mbed::callback(this, &RPCClass::dispatch));
145145

146146
responseThread = new rtos::Thread(osPriorityNormal);
147-
responseThread->start(mbed::callback(this, &RPC::response));
147+
responseThread->start(mbed::callback(this, &RPCClass::response));
148148

149149
/* Initialize OpenAmp and libmetal libraries */
150150
if (MX_OPENAMP_Init(RPMSG_MASTER, new_service_cb) != HAL_OK) {
@@ -182,16 +182,16 @@ int RPC::begin() {
182182

183183
#ifdef CORE_CM4
184184

185-
int RPC::begin() {
185+
int RPCClass::begin() {
186186

187187
eventThread = new rtos::Thread(osPriorityHigh);
188188
eventThread->start(&eventHandler);
189189

190190
dispatcherThread = new rtos::Thread(osPriorityNormal);
191-
dispatcherThread->start(mbed::callback(this, &RPC::dispatch));
191+
dispatcherThread->start(mbed::callback(this, &RPCClass::dispatch));
192192

193193
responseThread = new rtos::Thread(osPriorityNormal);
194-
responseThread->start(mbed::callback(this, &RPC::response));
194+
responseThread->start(mbed::callback(this, &RPCClass::response));
195195

196196
/* Initialize OpenAmp and libmetal libraries */
197197
if (MX_OPENAMP_Init(RPMSG_REMOTE, NULL) != 0) {
@@ -221,7 +221,7 @@ int RPC::begin() {
221221

222222
using raw_call_t = std::tuple<RPCLIB_MSGPACK::object>;
223223

224-
void RPC::response() {
224+
void RPCClass::response() {
225225
responseThreadId = osThreadGetId();
226226

227227
for (int i = 0; i< 10; i++) {
@@ -269,7 +269,7 @@ void RPC::response() {
269269
}
270270
}
271271

272-
void RPC::dispatch() {
272+
void RPCClass::dispatch() {
273273

274274
dispatcherThreadId = osThreadGetId();
275275

@@ -322,16 +322,16 @@ void RPC::dispatch() {
322322
}
323323

324324

325-
size_t RPC::write(uint8_t c) {
325+
size_t RPCClass::write(uint8_t c) {
326326
write(&c, 1);
327327
return 1;
328328
}
329329

330-
size_t RPC::write(const uint8_t* buf, size_t len) {
330+
size_t RPCClass::write(const uint8_t* buf, size_t len) {
331331
return write(ENDPOINT_RAW, buf, len);
332332
}
333333

334-
size_t RPC::write(uint8_t ep, const uint8_t* buf, size_t len) {
334+
size_t RPCClass::write(uint8_t ep, const uint8_t* buf, size_t len) {
335335

336336
std::vector<uint8_t> tx_buffer;
337337
for (size_t i = 0; i < len; i++) {
@@ -347,4 +347,4 @@ size_t RPC::write(uint8_t ep, const uint8_t* buf, size_t len) {
347347
return len;
348348
}
349349

350-
arduino::RPC RPC1;
350+
arduino::RPCClass RPC;

libraries/RPC/src/RPC_internal.h renamed to libraries/RPC/src/RPC.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ typedef struct _service_request {
4141

4242
namespace arduino {
4343

44-
class RPC : public Stream, public rpc::detail::dispatcher {
44+
class RPCClass : public Stream, public rpc::detail::dispatcher {
4545
public:
46-
RPC() {};
46+
RPCClass() {};
4747
int begin();
4848
void end() {};
4949
int available(void) {
@@ -132,7 +132,7 @@ class RPC : public Stream, public rpc::detail::dispatcher {
132132
};
133133
}
134134

135-
extern arduino::RPC RPC1;
135+
extern arduino::RPCClass RPC;
136136

137137
#endif
138138
#endif

libraries/RPC/src/RPC_client.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
//forward declaration
66
namespace arduino {
7-
class RPC;
7+
class RPCClass;
88
}
99

1010
namespace rpc {
@@ -62,7 +62,7 @@ class client {
6262

6363
protected:
6464
osThreadId callThreadId;
65-
friend class arduino::RPC;
65+
friend class arduino::RPCClass;
6666
RPCLIB_MSGPACK::object_handle result;
6767

6868
private:

libraries/RPC/src/SerialRPC.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "RPC_internal.h"
1+
#include "RPC.h"
22
#include "Arduino.h"
33

44
namespace arduino {
@@ -45,22 +45,22 @@ class SerialRPCClass : public Stream {
4545
for (size_t i=0; i < len; i++) {
4646
tx_buffer.push_back(buf[i]);
4747
}
48-
RPC1.call("on_write", tx_buffer);
48+
RPC.call("on_write", tx_buffer);
4949
return len;
5050
}
5151

5252
using Print::write;
5353

5454
int begin() {
55-
if (RPC1.begin() == 0) {
55+
if (RPC.begin() == 0) {
5656
return 0;
5757
}
58-
RPC1.bind("on_write", mbed::callback(this, &SerialRPCClass::onWrite));
58+
RPC.bind("on_write", mbed::callback(this, &SerialRPCClass::onWrite));
5959
return 1;
6060
}
6161

6262
operator bool() {
63-
return RPC1;
63+
return RPC;
6464
}
6565

6666
void attach(void (*fptr)(void))

0 commit comments

Comments
 (0)