Skip to content

Commit 803e4aa

Browse files
authored
Merge pull request #26 from bcmi-labs/development
Development
2 parents 72b0eef + 461a3aa commit 803e4aa

31 files changed

+929
-130
lines changed

LICENSE

Lines changed: 373 additions & 21 deletions
Large diffs are not rendered by default.

examples/decoder_tests/DummyTransport.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
/*
2+
This file is part of the Arduino_RPClite library.
3+
4+
Copyright (c) 2025 Arduino SA
5+
6+
This Source Code Form is subject to the terms of the Mozilla Public
7+
License, v. 2.0. If a copy of the MPL was not distributed with this
8+
file, You can obtain one at http://mozilla.org/MPL/2.0/.
9+
10+
*/
11+
112
#ifndef DUMMY_TRANSPORT_H
213
#define DUMMY_TRANSPORT_H
314
#include "transport.h"
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
This file is part of the Arduino_RPClite library.
3+
4+
Copyright (c) 2025 Arduino SA
5+
6+
This Source Code Form is subject to the terms of the Mozilla Public
7+
License, v. 2.0. If a copy of the MPL was not distributed with this
8+
file, You can obtain one at http://mozilla.org/MPL/2.0/.
9+
10+
*/
11+
12+
#pragma once
13+
#ifndef RPCLITE_DECODER_TESTER_H
14+
#define RPCLITE_DECODER_TESTER_H
15+
16+
class DecoderTester {
17+
18+
RpcDecoder<>& decoder;
19+
20+
public:
21+
22+
DecoderTester(RpcDecoder<>& _d): decoder(_d){}
23+
24+
void crop_bytes(size_t size, size_t offset){
25+
decoder.consume(size, offset);
26+
}
27+
28+
void print_raw_buf(){
29+
30+
Serial.print("Decoder raw buffer content: ");
31+
32+
for (size_t i = 0; i < decoder._bytes_stored; i++) {
33+
34+
Serial.print(decoder._raw_buffer[i], HEX);
35+
Serial.print(" ");
36+
}
37+
Serial.println("");
38+
}
39+
40+
};
41+
42+
#endif // RPCLITE_DECODER_TESTER_H

examples/decoder_tests/decoder_tests.ino

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
1+
/*
2+
This file is part of the Arduino_RPClite library.
3+
4+
Copyright (c) 2025 Arduino SA
5+
6+
This Source Code Form is subject to the terms of the Mozilla Public
7+
License, v. 2.0. If a copy of the MPL was not distributed with this
8+
file, You can obtain one at http://mozilla.org/MPL/2.0/.
9+
10+
*/
11+
112
#include <Arduino_RPClite.h>
213
#include "DummyTransport.h"
14+
#include "decoder_tester.h"
315

416
// Shorthand
517
MsgPack::Packer packer;
@@ -36,6 +48,35 @@ void runDecoderTest(const char* label) {
3648
Serial.println("-- Done --\n");
3749
}
3850

51+
void runDecoderConsumeTest(const char* label, size_t second_packet_sz) {
52+
Serial.println(label);
53+
54+
print_buf();
55+
DummyTransport dummy_transport(packer.data(), packer.size());
56+
RpcDecoder<> decoder(dummy_transport);
57+
58+
DecoderTester dt(decoder);
59+
60+
while (!decoder.packet_incoming()) {
61+
Serial.println("Packet not ready");
62+
decoder.decode();
63+
delay(50);
64+
}
65+
66+
size_t pack_size = decoder.get_packet_size();
67+
Serial.print("1st Packet size: ");
68+
Serial.println(pack_size);
69+
70+
Serial.print("Consuming 2nd packet of given size: ");
71+
Serial.println(second_packet_sz);
72+
73+
dt.crop_bytes(second_packet_sz, pack_size);
74+
75+
dt.print_raw_buf();
76+
77+
Serial.println("-- Done --\n");
78+
}
79+
3980
void testNestedArrayRequest() {
4081
packer.clear();
4182
MsgPack::arr_size_t outer_arr(3);
@@ -120,6 +161,9 @@ void testMultipleRpcPackets() {
120161
packer.serialize(req_sz, 0, 2, "echo", par_sz, "Hello", true);
121162

122163
runDecoderTest("== Test: Multiple RPCs in Buffer ==");
164+
165+
runDecoderConsumeTest("== Test: Mid-buffer consume ==", 5);
166+
123167
}
124168

125169
// Binary parameter (e.g., binary blob)
@@ -170,6 +214,8 @@ void testCombinedComplexBuffer() {
170214

171215
void setup() {
172216
Serial.begin(115200);
217+
while(!Serial);
218+
173219
delay(1000);
174220
Serial.println("=== RPC Decoder Nested Tests ===");
175221

examples/dispatcher_example/dispatcher_example.ino

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
/*
2+
This file is part of the Arduino_RPClite library.
3+
4+
Copyright (c) 2025 Arduino SA
5+
6+
This Source Code Form is subject to the terms of the Mozilla Public
7+
License, v. 2.0. If a copy of the MPL was not distributed with this
8+
file, You can obtain one at http://mozilla.org/MPL/2.0/.
9+
10+
*/
11+
112
#include <Arduino_RPClite.h>
213

314
int add(int x, int y) {

examples/rpc_lite_client/rpc_lite_client.ino

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
/*
2+
This file is part of the Arduino_RPClite library.
3+
4+
Copyright (c) 2025 Arduino SA
5+
6+
This Source Code Form is subject to the terms of the Mozilla Public
7+
License, v. 2.0. If a copy of the MPL was not distributed with this
8+
file, You can obtain one at http://mozilla.org/MPL/2.0/.
9+
10+
*/
11+
112
#include <Arduino_RPClite.h>
213

314
SerialTransport transport(Serial1);

examples/rpc_lite_server/rpc_lite_server.ino

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
/*
2+
This file is part of the Arduino_RPClite library.
3+
4+
Copyright (c) 2025 Arduino SA
5+
6+
This Source Code Form is subject to the terms of the Mozilla Public
7+
License, v. 2.0. If a copy of the MPL was not distributed with this
8+
file, You can obtain one at http://mozilla.org/MPL/2.0/.
9+
10+
*/
11+
112
#include <Arduino_RPClite.h>
213

314
SerialTransport transport(Serial1);

examples/wrapper_example/wrapper_example.ino

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
/*
2+
This file is part of the Arduino_RPClite library.
3+
4+
Copyright (c) 2025 Arduino SA
5+
6+
This Source Code Form is subject to the terms of the Mozilla Public
7+
License, v. 2.0. If a copy of the MPL was not distributed with this
8+
file, You can obtain one at http://mozilla.org/MPL/2.0/.
9+
10+
*/
11+
112
#include <Arduino_RPClite.h>
213

314
int add(int x, int y) {
@@ -55,9 +66,9 @@ void loop() {
5566
out_packer.clear();
5667

5768
blink_before();
58-
int out = wrapped_add(5, 3);
69+
int out = (*wrapped_add)(5, 3);
5970

60-
bool unpack_ok = wrapped_add(unpacker, out_packer);
71+
bool unpack_ok = (*wrapped_add)(unpacker, out_packer);
6172

6273
Serial.print("simple call: ");
6374
Serial.println(out);
@@ -82,7 +93,7 @@ void loop() {
8293
unpacker.feed(packer.data(), packer.size());
8394
out_packer.clear();
8495

85-
bool should_be_false = wrapped_divide(unpacker, out_packer);
96+
bool should_be_false = (*wrapped_divide)(unpacker, out_packer);
8697

8798
if (!should_be_false){
8899
Serial.println("RPC error call divide by zero ");
@@ -103,7 +114,7 @@ void loop() {
103114
unpacker.clear();
104115
unpacker.feed(packer.data(), packer.size());
105116
out_packer.clear();
106-
wrapped_hello(unpacker, out_packer);
117+
(*wrapped_hello)(unpacker, out_packer);
107118

108119
for (size_t i=0; i<out_packer.size(); i++){
109120
Serial.print(out_packer.data()[i], HEX);

extras/examples/serial_client_example.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# This file is part of the Arduino_RPClite library.
2+
#
3+
# Copyright (c) 2025 Arduino SA
4+
#
5+
# This Source Code Form is subject to the terms of the Mozilla Public
6+
# License, v. 2.0. If a copy of the MPL was not distributed with this
7+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
8+
19
from serial_client import SerialClient
210

311
PORT = '/dev/ttySTM0'

extras/examples/serial_server_example.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# This file is part of the Arduino_RPClite library.
2+
#
3+
# Copyright (c) 2025 Arduino SA
4+
#
5+
# This Source Code Form is subject to the terms of the Mozilla Public
6+
# License, v. 2.0. If a copy of the MPL was not distributed with this
7+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
8+
19
import random
210
from serial_server import SerialServer
311

0 commit comments

Comments
 (0)