Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
394 changes: 373 additions & 21 deletions LICENSE

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions examples/decoder_tests/DummyTransport.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/*
This file is part of the Arduino_RPClite library.

Copyright (c) 2025 Arduino SA

This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.

*/

#ifndef DUMMY_TRANSPORT_H
#define DUMMY_TRANSPORT_H
#include "transport.h"
Expand Down
42 changes: 42 additions & 0 deletions examples/decoder_tests/decoder_tester.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
This file is part of the Arduino_RPClite library.

Copyright (c) 2025 Arduino SA

This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.

*/

#pragma once
#ifndef RPCLITE_DECODER_TESTER_H
#define RPCLITE_DECODER_TESTER_H

class DecoderTester {

RpcDecoder<>& decoder;

public:

DecoderTester(RpcDecoder<>& _d): decoder(_d){}

void crop_bytes(size_t size, size_t offset){
decoder.consume(size, offset);
}

void print_raw_buf(){

Serial.print("Decoder raw buffer content: ");

for (size_t i = 0; i < decoder._bytes_stored; i++) {

Serial.print(decoder._raw_buffer[i], HEX);
Serial.print(" ");
}
Serial.println("");
}

};

#endif // RPCLITE_DECODER_TESTER_H
46 changes: 46 additions & 0 deletions examples/decoder_tests/decoder_tests.ino
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
/*
This file is part of the Arduino_RPClite library.

Copyright (c) 2025 Arduino SA

This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.

*/

#include <Arduino_RPClite.h>
#include "DummyTransport.h"
#include "decoder_tester.h"

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

void runDecoderConsumeTest(const char* label, size_t second_packet_sz) {
Serial.println(label);

print_buf();
DummyTransport dummy_transport(packer.data(), packer.size());
RpcDecoder<> decoder(dummy_transport);

DecoderTester dt(decoder);

while (!decoder.packet_incoming()) {
Serial.println("Packet not ready");
decoder.decode();
delay(50);
}

size_t pack_size = decoder.get_packet_size();
Serial.print("1st Packet size: ");
Serial.println(pack_size);

Serial.print("Consuming 2nd packet of given size: ");
Serial.println(second_packet_sz);

dt.crop_bytes(second_packet_sz, pack_size);

dt.print_raw_buf();

Serial.println("-- Done --\n");
}

void testNestedArrayRequest() {
packer.clear();
MsgPack::arr_size_t outer_arr(3);
Expand Down Expand Up @@ -120,6 +161,9 @@ void testMultipleRpcPackets() {
packer.serialize(req_sz, 0, 2, "echo", par_sz, "Hello", true);

runDecoderTest("== Test: Multiple RPCs in Buffer ==");

runDecoderConsumeTest("== Test: Mid-buffer consume ==", 5);

}

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

void setup() {
Serial.begin(115200);
while(!Serial);

delay(1000);
Serial.println("=== RPC Decoder Nested Tests ===");

Expand Down
11 changes: 11 additions & 0 deletions examples/dispatcher_example/dispatcher_example.ino
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/*
This file is part of the Arduino_RPClite library.

Copyright (c) 2025 Arduino SA

This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.

*/

#include <Arduino_RPClite.h>

int add(int x, int y) {
Expand Down
11 changes: 11 additions & 0 deletions examples/rpc_lite_client/rpc_lite_client.ino
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/*
This file is part of the Arduino_RPClite library.

Copyright (c) 2025 Arduino SA

This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.

*/

#include <Arduino_RPClite.h>

SerialTransport transport(Serial1);
Expand Down
11 changes: 11 additions & 0 deletions examples/rpc_lite_server/rpc_lite_server.ino
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/*
This file is part of the Arduino_RPClite library.

Copyright (c) 2025 Arduino SA

This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.

*/

#include <Arduino_RPClite.h>

SerialTransport transport(Serial1);
Expand Down
19 changes: 15 additions & 4 deletions examples/wrapper_example/wrapper_example.ino
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/*
This file is part of the Arduino_RPClite library.

Copyright (c) 2025 Arduino SA

This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.

*/

#include <Arduino_RPClite.h>

int add(int x, int y) {
Expand Down Expand Up @@ -55,9 +66,9 @@ void loop() {
out_packer.clear();

blink_before();
int out = wrapped_add(5, 3);
int out = (*wrapped_add)(5, 3);

bool unpack_ok = wrapped_add(unpacker, out_packer);
bool unpack_ok = (*wrapped_add)(unpacker, out_packer);

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

bool should_be_false = wrapped_divide(unpacker, out_packer);
bool should_be_false = (*wrapped_divide)(unpacker, out_packer);

if (!should_be_false){
Serial.println("RPC error call divide by zero ");
Expand All @@ -103,7 +114,7 @@ void loop() {
unpacker.clear();
unpacker.feed(packer.data(), packer.size());
out_packer.clear();
wrapped_hello(unpacker, out_packer);
(*wrapped_hello)(unpacker, out_packer);

for (size_t i=0; i<out_packer.size(); i++){
Serial.print(out_packer.data()[i], HEX);
Expand Down
8 changes: 8 additions & 0 deletions extras/examples/serial_client_example.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# This file is part of the Arduino_RPClite library.
#
# Copyright (c) 2025 Arduino SA
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

from serial_client import SerialClient

PORT = '/dev/ttySTM0'
Expand Down
8 changes: 8 additions & 0 deletions extras/examples/serial_server_example.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# This file is part of the Arduino_RPClite library.
#
# Copyright (c) 2025 Arduino SA
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

import random
from serial_server import SerialServer

Expand Down
8 changes: 8 additions & 0 deletions extras/integration_test/RPCClient_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
// This file is part of the Arduino_RPClite library.
//
// Copyright (c) 2025 Arduino SA

// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

package testsuite

import (
Expand Down
8 changes: 8 additions & 0 deletions extras/integration_test/RPCServer_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
// This file is part of the Arduino_RPClite library.
//
// Copyright (c) 2025 Arduino SA

// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

package testsuite

import (
Expand Down
11 changes: 11 additions & 0 deletions extras/integration_test/TestRPCClient/TestRPCClient.ino
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/*
This file is part of the Arduino_RPClite library.

Copyright (c) 2025 Arduino SA

This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.

*/

#include <Arduino_RPClite.h>

#ifdef ARDUINO_SAMD_ZERO
Expand Down
11 changes: 11 additions & 0 deletions extras/integration_test/TestRPCServer/TestRPCServer.ino
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/*
This file is part of the Arduino_RPClite library.

Copyright (c) 2025 Arduino SA

This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.

*/

#include <Arduino_RPClite.h>
#include "serial_ports.h"

Expand Down
8 changes: 8 additions & 0 deletions extras/integration_test/testsuite.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
// This file is part of the Arduino_RPClite library.
//
// Copyright (c) 2025 Arduino SA

// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

package testsuite

import (
Expand Down
8 changes: 8 additions & 0 deletions extras/serial_client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# This file is part of the Arduino_RPClite library.
#
# Copyright (c) 2025 Arduino SA
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

import serial
import time
import msgpack
Expand Down
8 changes: 8 additions & 0 deletions extras/serial_server.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# This file is part of the Arduino_RPClite library.
#
# Copyright (c) 2025 Arduino SA
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

import serial
import msgpack
import threading
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"maintainer": true
},
"version": "0.1.2",
"license": "MIT",
"license": "MPL2.0",
"frameworks": "arduino",
"platforms": "*",
"dependencies":
Expand Down
4 changes: 2 additions & 2 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name=Arduino_RPClite
version=0.1.2
author=Lucio Rossi (eigen-value)
maintainer=Lucio Rossi (eigen-value)
author=Arduino, Lucio Rossi (eigen-value)
maintainer=Arduino, Lucio Rossi (eigen-value)
sentence=A MessagePack RPC library for Arduino
paragraph=allows to create a client/server architecture using MessagePack as the serialization format. It follows the MessagePack-RPC protocol specification. It is designed to be lightweight and easy to use, making it suitable for embedded systems and IoT applications.
category=Communication
Expand Down
11 changes: 11 additions & 0 deletions src/Arduino_RPClite.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/*
This file is part of the Arduino_RPClite library.

Copyright (c) 2025 Arduino SA

This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.

*/

#ifndef ARDUINO_RPCLITE_H
#define ARDUINO_RPCLITE_H

Expand Down
11 changes: 11 additions & 0 deletions src/SerialTransport.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/*
This file is part of the Arduino_RPClite library.

Copyright (c) 2025 Arduino SA

This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.

*/

#ifndef SERIALTRANSPORT_H
#define SERIALTRANSPORT_H
#include "transport.h"
Expand Down
Loading