File tree Expand file tree Collapse file tree 6 files changed +35
-24
lines changed
Expand file tree Collapse file tree 6 files changed +35
-24
lines changed Original file line number Diff line number Diff line change @@ -29,12 +29,9 @@ void runDecoderTest(const char* label) {
2929 delay (50 );
3030 }
3131
32- while (decoder.packet_incoming ()) {
33- size_t removed = decoder.discard_packet ();
34- Serial.print (" Removed bytes: " );
35- Serial.println (removed);
36- decoder.decode ();
37- }
32+ size_t pack_size = decoder.get_packet_size ();
33+ Serial.print (" 1st Packet size: " );
34+ Serial.println (pack_size);
3835
3936 Serial.println (" -- Done --\n " );
4037}
Original file line number Diff line number Diff line change 11#include < Arduino_RPClite.h>
22
3- RPCClient client (Serial1);
3+ SerialTransport transport (Serial1);
4+ RPCClient client (transport);
45
56void setup () {
67 Serial1.begin (115200 );
78 while (!Serial1);
89
910 pinMode (LED_BUILTIN, OUTPUT);
10-
11- Serial.begin (9600 );
11+ delay (10 );
12+
13+ Serial.begin (115200 );
1214 while (!Serial);
1315}
1416
@@ -30,7 +32,7 @@ void blink_before(){
3032void loop () {
3133 float result;
3234 blink_before ();
33-
35+
3436 String str_res;
3537 bool ok = client.call (" loopback" , str_res, " Sending a greeting" );
3638 Serial.println (str_res);
@@ -75,5 +77,4 @@ void loop() {
7577 Serial.println (" Server could not handle a notification as a call" );
7678 }
7779
78- delay (2000 );
7980}
Original file line number Diff line number Diff line change 11#include < Arduino_RPClite.h>
22
3- RPCServer server (Serial1);
3+ SerialTransport transport (Serial1);
4+ RPCServer server (transport);
45
56int add (int a, int b){
67 return a+b;
78}
89
10+ int add2 (int a, int b){
11+ return a+b;
12+ }
13+
914String greet (){
1015 return String (" Hello Friend" );
1116}
@@ -24,6 +29,10 @@ public:
2429};
2530
2631
32+ float multip (float a, float b) {
33+ return a*b;
34+ }
35+
2736void setup () {
2837 Serial1.begin (115200 );
2938 while (!Serial1);
@@ -34,10 +43,16 @@ void setup() {
3443 while (!Serial);
3544
3645 server.bind (" add" , add);
46+
47+ if (!server.bind (" add" , add2)){
48+ Serial.println (" server refused to bind same name twice" );
49+ }
50+
3751 server.bind (" greet" , greet);
3852 server.bind (" loopback" , loopback);
3953 server.bind (" another_greeting" , [] {return MsgPack::str_t (" This is a lambda greeting" );});
4054 server.bind (" object_multi" , &multiplier::mult);
55+ server.bind (" multip" , multip);
4156
4257}
4358
Original file line number Diff line number Diff line change @@ -14,11 +14,11 @@ class RPCClient {
1414
1515 RPCClient (ITransport& t) : decoder(&RpcDecoderManager<>::getDecoder(t)) {}
1616
17- // TODO This is problematic becasue 'new' makes different Transport objs and different transports make different decoders
18- RPCClient (Stream& stream) {
19- ITransport* transport = (ITransport*) new SerialTransport (stream);
20- decoder = &RpcDecoderManager<>::getDecoder (*transport);
21- }
17+ // This constructor was removed because it leads to decoder duplication
18+ // RPCClient(Stream& stream) {
19+ // ITransport* transport = (ITransport*) new SerialTransport(stream);
20+ // decoder = &RpcDecoderManager<>::getDecoder(*transport);
21+ // }
2222
2323 template <typename ... Args>
2424 void notify (const MsgPack::str_t method, Args&&... args) {
Original file line number Diff line number Diff line change @@ -16,11 +16,11 @@ class RPCServer {
1616public:
1717 RPCServer (ITransport& t) : decoder(&RpcDecoderManager<>::getDecoder(t)) {}
1818
19- // TODO This is problematic becasue 'new' makes different Transport objs and different transports make different decoders
20- RPCServer (Stream& stream) {
21- ITransport* transport = (ITransport*) new SerialTransport (stream);
22- decoder = &RpcDecoderManager<>::getDecoder (*transport);
23- }
19+ // This constructor was removed because it leads to decoder duplication
20+ // RPCServer(Stream& stream) {
21+ // ITransport* transport = (ITransport*) new SerialTransport(stream);
22+ // decoder = &RpcDecoderManager<>::getDecoder(*transport);
23+ // }
2424
2525 template <typename F>
2626 bool bind (const MsgPack::str_t & name, F&& func){
Original file line number Diff line number Diff line change 11#ifndef RPCLITE_TRANSPORT_H
22#define RPCLITE_TRANSPORT_H
33
4- #include < Arduino.h>
5-
64class ITransport {
75// Transport abstraction interface
86
You can’t perform that action at this time.
0 commit comments