Skip to content

Commit

Permalink
Merge branch 'cpp_api'
Browse files Browse the repository at this point in the history
  • Loading branch information
lexus2k committed Feb 19, 2024
2 parents 9fa1389 + 54a18d3 commit 14ba930
Show file tree
Hide file tree
Showing 76 changed files with 3,345 additions and 536 deletions.
113 changes: 67 additions & 46 deletions .hash_db
Original file line number Diff line number Diff line change
@@ -1,84 +1,105 @@
./setup.py:8775ca7225d845ad1118efe5ac753337
./src/TinyProtocolFd.cpp:acf146d0a76f3cda95429dce729092fc
./setup.py:6a65fb06d718c8ed6ffd5e1e2ce7e337
./src/TinyProtocolFd.cpp:dc52761597f73e0581db6510d7923cf6
./src/TinyLightProtocol.h:a684b685ec5ba4641ee10d24caf0f8cb
./src/TinyProtocolFd.h:1e1d12b2171d29c4a54c809575da28d4
./src/TinyProtocolFd.h:6db1007de88e2fc2dfc2bf18c55ddf4c
./src/TinyLightProtocol.cpp:edacf9b017dece5234deb2c95c5c3e7d
./src/TinyPacket.h:b56b28b96ea3fcbe92caabc451dc2a46
./src/TinyProtocolHdlc.cpp:faae0c5dafec91d17e36cdb1e79cc8fd
./src/TinyPacket.h:916d0bd1221d3ec2ddfc5ac70a26b344
./src/TinyProtocolHdlc.cpp:49d00baaa1c26434215aa1cf6c6d75d2
./src/TinyProtocolHdlc.h:3603d51944e3fbc4e054a303db241a6a
./src/TinyProtocol.h:809be13c3866e0079f241bdf89515905
./src/TinyProtocol.h:56877f0a2681b3393daab59460a46a97
./src/proto/crc/tiny_crc.h:ec366c5c7751a822b2c4931e40150a84
./src/proto/crc/tiny_crc.c:73d4dca2d3805a8127b1a710599bce9e
./src/proto/hdlc/low_level/hdlc.c:e9cef2ceddf62003be442e545606fef7
./src/proto/hdlc/low_level/hdlc.h:46b3f839d54ccd1e74f1ee6a03e416ec
./src/proto/hdlc/low_level/hdlc_int.h:b0de584cb91f54e076205819482211f7
./src/proto/hdlc/high_level/hdlc.c:e05cb9f1d665e05c1d6049d6d21098fb
./src/proto/hdlc/high_level/hdlc.h:45f2819c6fc7ca87a9973d85755da7af
./src/proto/fd/tiny_fd_frames.c:4beb7ca7ede2a9d2b95f640eb55b61f8
./src/proto/fd/tiny_fd_int.h:60c9ca86201de0f701c8f08ac6e64607
./src/proto/fd/tiny_fd_frames_int.h:d5fd2ddec29cd8fcfcacb65a1efe7b00
./src/proto/fd/tiny_fd.c:869e50962199beddb7f6d5a6ad1328b8
./src/proto/fd/tiny_fd.h:72ae1056ac69df1cff98a985299856e2
./src/proto/light/tiny_light.c:415fd59073e4387b1983b7b7b0a14533
./src/proto/light/tiny_light.h:47c725e8f06bee91be92af93ed0a1407
./src/proto/hdlc/low_level/hdlc.c:f9d0a64ccf41c0b8a2c2bbeb622652ab
./src/proto/hdlc/low_level/hdlc.h:e06a1a5c44259759b4260c7b29bfe303
./src/proto/hdlc/low_level/hdlc_int.h:af5576216218e1d9f55395312d8cf3b1
./src/proto/hdlc/high_level/hdlc.c:65870a83fbb238e91ec1dfeb0d54439e
./src/proto/hdlc/high_level/hdlc.h:4be46b73f8b2dbbdf2fa737f00fa1b77
./src/proto/fd/tiny_fd_frames.c:ea1ec41497b45cf62371bd8e6062f284
./src/proto/fd/tiny_fd_int.h:f6c7329485870ac86a9043f5d2d468fc
./src/proto/fd/tiny_fd_frames_int.h:4153dc1d7f31da43095514c8694c18ec
./src/proto/fd/tiny_fd.c:6c50c6ad70b658d2d317f3a19f9d9bcb
./src/proto/fd/tiny_fd.h:7148a2d7e8f1dfe3121c181534599525
./src/proto/light/tiny_light.c:c7bbb1ce83bd7f09e2b0a1b372485ef7
./src/proto/light/tiny_light.h:61e2d702ae9490e451cde3cdd36d25ce
./src/hal/tiny_debug.h:ec3baec310bcef743d2e16957253ca6f
./src/hal/tiny_list.c:db940e41cce84752164648cb9e1613df
./src/hal/tiny_types.h:0bc8dd83fcb5fa5b02a96a58288382e5
./src/hal/tiny_serial.h:9506b27b1b4db5651406f0afe262266b
./src/hal/tiny_types.h:5bb6f783238245be50cd4e444544889b
./src/hal/tiny_serial.h:0399afef7fd429e9461d9bbeed009c95
./src/hal/tiny_list.h:69b562367054b805e7e27581e427e5bd
./src/hal/tiny_types.c:77dbfa4d58a4359eac564af2feeee3dc
./src/hal/tiny_serial.c:379a35795a230e2502a67c709aab04b5
./src/hal/tiny_types.c:1e1a12815d82d93d27d38f5650b97353
./src/hal/tiny_serial.c:3a33d156aff044633cff04a900601cd5
./src/hal/arduino/arduino_hal.inl:168da39110fe026168904a881538af6c
./src/hal/arduino/arduino_hal.h:06465d36d34bd55179707e956210544c
./src/hal/linux/linux_hal.h:f22f0625726652e842866bb0ad352411
./src/hal/linux/linux_hal.h:63c1b74aaedcfa7e5e89098068e99443
./src/hal/linux/linux_serial.inl:0354da90c95ae791f0c6e64c5eac63f7
./src/hal/linux/linux_serial.h:9f2594db69e4a98891fe780395c9ae62
./src/hal/linux/linux_hal.inl:bfbae9584d3320f3b822370a439269bb
./src/hal/esp32/esp32_hal.h:6113e4e5411c75eea3c794bc28861702
./src/hal/linux/linux_hal.inl:cd6a48e6c95b23c9ec0d68181923622f
./src/hal/esp32/esp32_hal.h:bc3b84848393530797c47a31712cbb4b
./src/hal/esp32/esp32_hal.inl:b9bd509161524eee58743875995d62bd
./src/hal/avr/avr_hal.h:f0faa8c545a6f4259c7eb2980d275bba
./src/hal/avr/avr_hal.inl:dd4e0d37312349c1dc35fdcdff8786c0
./src/hal/no_platform/noplatform_serial.h:9f2594db69e4a98891fe780395c9ae62
./src/hal/no_platform/no_platform_hal.h:ac36d0f88f70ce88ca3f5cdd5731ab29
./src/hal/no_platform/no_platform_hal.inl:459112564afc8e2b271975c39ea83ae2
./src/hal/mingw32/mingw32_hal.h:fb6697f9d2e7d9248aa4913defe35f95
./src/hal/mingw32/mingw32_hal.h:ed7464e4405cd7c0148339cf8469f3ea
./src/hal/mingw32/mingw32_hal.inl:e19ec5e42f167f89ee0fff4a6ca77218
./src/hal/win32/win32_hal.inl:4478824cd82891dd9f87aa5118fa8545
./src/hal/win32/win32_serial.inl:a455c67d103c5eab8c27b6f2cd77a983
./src/hal/win32/win32_serial.h:3b28603bd650706c7aea0caccc069b4d
./src/hal/win32/win32_hal.h:2a71b3291935017689ae7585fda36f33
./src/hal/win32/win32_hal.h:2fd3b03be2a6a501f8cdb00bae97a3f3
./src/hal/single_core/hal_single_core.inl:c652ec6f2c6f4755d48fd0f389fa3603
./unittest/packet_tests.cpp:f605740365a18b398e61fed987d892f4
./unittest/hdlc_tests.cpp:f04c965a8dfd9b493a44fee4ec22b6c6
./unittest/hdlc_tests.cpp:f17e0ab45d0ec2555be553111f891036
./unittest/hal_tests.cpp:bcafc594a1d14046d0589b03d79cdeba
./unittest/main.cpp:a5d2d3bcfd2c084575144432699615af
./unittest/light_tests.cpp:11956897536d066270a83ba431c1926e
./unittest/fd_tests.cpp:ccd8151cc8fc22791d5cc6743a370612
./unittest/light_tests.cpp:d19aaeef4014babe927be441bc744a3d
./unittest/fd_tests.cpp:2effb9109059715ef4c254a5db482233
./unittest/helpers/fake_wire.cpp:278850827a1f550db720ab0daa3a06d4
./unittest/helpers/tiny_fd_helper.cpp:ff095f96fd1afc77f3c3607ffbc4a3cc
./unittest/helpers/fake_wire.h:78cbaed09db450c9ebf260fc45362334
./unittest/helpers/fake_connection.cpp:2279cd42f10b50e81739813783224b8d
./unittest/helpers/fake_endpoint.cpp:e8706b5310db12dca55f28e0a50320bb
./unittest/helpers/tiny_fd_helper.cpp:198b6e1ffe917aaef39e4caea1ef0458
./unittest/helpers/fake_wire.h:d4376c88bb2900aafe14887085a27607
./unittest/helpers/fake_connection.cpp:df9ccb0a0019a9e93f3f4cbd513ab0e3
./unittest/helpers/fake_endpoint.cpp:bf2a8d7d026c9c545f459c7a37712338
./unittest/helpers/tiny_base_helper.cpp:edf076d2e466029c6613bfe02d3d2272
./unittest/helpers/semaphore_helper.h:aac4cd56d3f6b4ea76328152d7c13f65
./unittest/helpers/fake_endpoint.h:2229b37293da9ad97af75086f2756b09
./unittest/helpers/tiny_hdlc_helper.cpp:805d67c197d8035b9a9643a99e24b21e
./unittest/helpers/tiny_hdlc_helper.h:fdb9e14e35d3a0dcd789ea8a23966f46
./unittest/helpers/fake_connection.h:c913aae2ed0196d70057d7bd1587b3bc
./unittest/helpers/fake_endpoint.h:61184617911efd05a026e5d169fd8ac6
./unittest/helpers/tiny_hdlc_helper.cpp:29dea22e1b598538475e3675de3587be
./unittest/helpers/tiny_hdlc_helper.h:88f4ea73a648a7e1a24d6acc944f5b48
./unittest/helpers/fake_connection.h:702a3253c031ab4e5612d08c4b0c4b1d
./unittest/helpers/tiny_base_helper.h:40ef1492748b45514e0798794536f644
./unittest/helpers/tiny_light_helper.cpp:2e001bd885b7b71db6d45a66c7d63f54
./unittest/helpers/tiny_fd_helper.h:52ffc9c680dbf6f7a887ff4b5e780a48
./unittest/helpers/tiny_fd_helper.h:f171aaef68243291c867acafd04648b6
./unittest/helpers/tiny_light_helper.h:e6324b2e96a6cbe1a09c5634639c70ba
./python/hdlc_ll.h:888d0725f810e5aaf68475d29c4f9533
./python/fd.h:fdd07995e6ef9db40e2b1f10d3840d8f
./python/main.cpp:34255ea2532f9ef38d208e59c83a6634
./python/hdlc_ll.cpp:d79004d6397cc677448c6b7a2f71f082
./python/fd.cpp:38b67d7a49dea267fffbe9d71a88cd42
./python/main.cpp:76a3d87011ad890b2fb1f0a33ad074a0
./python/hdlc_ll.cpp:727b6a7f052efd60325a0a9885f3923b
./python/fd.cpp:78ddabbd9edcb38a850b02c98b7281ed
./python/__init__.py:6960c69f1d180109c61003badb83dc6b
./python/options/__init__.py:bd9232ea6932e44b412796fe57a835c3
./python/wrappers/__init__.py:d4882c0a8b1d2cd9b93c0ebb4d00f8c8
./tools/hal_template_functions/platform_hal.c:65b3641a1d6a998aa6758892bbe4b18b
./src/hal/tiny_types_cpp.cpp:67981a27bacb015ed3aac52023444706
./src/hal/cpp/cpp_hal.h:f35701b7333807fc1c3f591b55112c57
./src/hal/cpp/cpp_hal.inl:a214dca4b7ba191f4708163b36bbe4c0
./unittest/fd_multidrop_tests.cpp:c92b46501ad2da42ebb0bcec588e6375
./src/tinyproto.h:0cb81312452718c98861e4d97c657b42
./src/TinyProtocol.cpp:f54ac0c67f7cb9e26b17e0dc53096810
./src/interface/TinySerial.h:3913e5134de45d9f5839fd8022c7acb3
./src/interface/TinySerial.cpp:af0ab33ca149ee544376d8d493c1694a
./src/link/TinyLinkLayer.h:78a7f59e9c0924a846f3689d91c6e6c8
./src/link/TinyHdlcLinkLayer.h:48d8fa2929714628d1d3a6fed49db4df
./src/link/TinySerialFdLink.h:6f43bf69afda07153295f5ac086e9bb8
./src/link/TinyLinkLayer.cpp:fac80ae5781b043285f7b5c58ed75841
./src/link/TinySerialHdlcLink.cpp:a4dd427178817266fb7c4835e15cb3e3
./src/link/TinyHdlcLinkLayer.cpp:3f83291eab7d00a782c1f9e12b6e6af8
./src/link/TinyFdLinkLayer.cpp:b17559e42aca68c3eaa349778727fcef
./src/link/TinySerialFdLink.cpp:a3645d25a8a9276e24115aad3efec1f2
./src/link/TinySerialLinkLayer.cpp:87f5c8102c0cac6163843df8232cdd29
./src/link/TinyFdLinkLayer.h:8bddd88e8b1ecad4633cb113c8c36281
./src/link/TinySerialLinkLayer.h:e5d33a746fa0630ea6d1aa816b5f8fd0
./src/link/TinySerialHdlcLink.h:bf0b5e032b859f72cc3a4a03e96e138c
./src/hal/tiny_serial_cpp.cpp:3fdefe16cf76a59d364a16d595f2bd7e
./src/hal/arduino/arduino_serial.inl:7bdd66771fae6fcba2fcb11c53f642aa
./src/hal/arduino/arduino_serial.h:d1029eb03354a63b4248513a13da5f6b
./src/hal/esp32/esp32_serial.inl:8dee400fd7c298b269e18f9fba973506
./src/hal/esp32/esp32_serial.h:c619f28e5762a1da3ac797a6205607c7
./src/hal/no_platform/noplatform_serial.inl:e33eb4ae4554074cd400c8b98852d023
./python/py_serial.cpp:4da3de2dbc6b2b72582c06c9f7bbdcda
./python/py_serial.h:68e016b996aea104b0bf8a908df96db6
./python/helpers/__init__.py:9df0084a1c0b1cadec43caaf0b21cc20
4 changes: 2 additions & 2 deletions .travis/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ create_terminals
./bld/tiny_loopback -p /tmp/sideB -t fd -r -w 7 &
sleep 0.5
# Run tests on sideA for 15 seconds
# Use window 4 for now, need to solve overload connection issues
./bld/tiny_loopback -p /tmp/sideA -t fd -g -r -w 4
# We don't want to limit loopback side, so test can miss some frames
./bld/tiny_loopback -p /tmp/sideA -t fd -g -r -w 7
if [ $? -ne 0 ]; then
close_terminals_and_exit 1
fi
Expand Down
11 changes: 11 additions & 0 deletions Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ CPPFLAGS += -I./src

CFLAGS += -std=gnu99
CPPFLAGS += -Os -Wall -Werror -ffunction-sections -fdata-sections $(EXTRA_CPPFLAGS)
# Uncomment for performance profiling
# CPPFLAGS += -pg
CXXFLAGS += -std=c++11

ifneq ($(LOG_LEVEL),)
Expand Down Expand Up @@ -74,9 +76,18 @@ OBJ_LIB += \
src/hal/tiny_types.o \
src/hal/tiny_types_cpp.o \
src/hal/tiny_serial.o \
src/hal/tiny_serial_cpp.o \
src/TinyProtocolHdlc.o \
src/TinyProtocolFd.o \
src/TinyLightProtocol.o \
src/TinyProtocol.o \
src/link/TinyLinkLayer.o \
src/link/TinyFdLinkLayer.o \
src/link/TinyHdlcLinkLayer.o \
src/link/TinySerialLinkLayer.o \
src/link/TinySerialFdLink.o \
src/link/TinySerialHdlcLink.o \
src/interface/TinySerial.o \

prep:
ifdef CONFIG_FOR_WINDOWS_BUILD
Expand Down
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,26 @@ Main features:

### What if my platform is not yet supported?

That's not a problem. Just implement abstraction layer for your platform (timing and mutex functions).
That's not a problem. Just implement abstraction layer for your platform (timing and mutex functions). Please
go through the steps below:

* add TINY_CUSTOM_PLATFORM define to your compilation flags.
* Implement HAL functions and call `tiny_hal_init()` to pass your platform functions to the library
* add CONFIG_TINYHAL_THREAD_SUPPORT define to your compilation flags if your platform supports standard c++ thread library

Refer to `tiny_hal_init()` function. To understand HAL implementation refer to
[Linux](https://github.com/lexus2k/tinyproto/blob/master/src/hal/linux/linux_hal.inl) and
[ESP32](https://github.com/lexus2k/tinyproto/blob/master/src/hal/esp32/esp32_hal.inl) examples in
[HAL abstraction layer](https://github.com/lexus2k/tinyproto/tree/master/src/hal).
Do not forget to add TINY_CUSTOM_PLATFORM define to your compilation flags. You may use template code
[platform_hal.c](tools/hal_template_functions/platform_hal.c)
You may use template code [platform_hal.c](tools/hal_template_functions/platform_hal.c)

## Easy to use

### Cpp

Usage of light Tiny Protocol in C++ can look like this:
```.cpp
#include "TinyProtocol.h"
#include "tinyproto.h"

tinyproto::Light proto;
tinyproto::Packet<256> packet;
Expand All @@ -104,7 +109,7 @@ void loop() {

Example of using full duplex Tiny Protocol in C++ is a little bit bigger, but it is still simple:
```.cpp
#include "TinyProtocol.h"
#include "tinyproto.h"

tinyproto::Fd<FD_MIN_BUF_SIZE(64,4)> proto;

Expand Down
2 changes: 2 additions & 0 deletions component.mk
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ COMPONENT_SRCDIRS := ./src \
./src/proto/fd \
./src/proto/light \
./src/proto/crc \
./src/link \
./src/interface \

CPPFLAGS += \
-DTINY_LOG_LEVEL_DEFAULT=0 \
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* This example sends back every buffer received over UART.
*
* !README!
* The sketch is developed to perform UART tests between Arduino
* and PC.
* 1. Burn this program to Arduino
* 2. Compile tiny_loopback tool (see tools folder) for your system
* 3. Connect Arduino TX and RX lines to your PC com port
* 4. Run tiny_loopback on the PC (use correct port name on your system)
* 5. tiny_loopback will print the test speed results
*
* Also, this example demonstrates how to pass data between 2 systems
* By default the sketch and tiny_loopback works as 115200 speed.
*/
#include <TinyProtocol.h>

// By default SerialFdProto class allows sending and receiving
// messages upto 32 bytes, we will use Serial0
tinyproto::SerialFdProto proto(Serial);

void onRead(tinyproto::Proto &proto, tinyproto::IPacket &packet)
{
// process received packet here
// send it back
proto.send(packet, 0);
}

void setup()
{
/* Run at 115200 */
proto.getLink().setSpeed( 115200 );
/* Lets use 8-bit checksum, available on all platforms */
proto.getLink().setCrc( HDLC_CRC_8 ); //enableCheckSum();
/* Set callback for incoming packets */
proto.setRxCallback( onRead );
/* Start */
proto.begin();
}

void loop()
{
proto.read(0);
}
46 changes: 46 additions & 0 deletions examples/arduino_generic/new_api/fd_loopback/fd_loopback.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* This example sends back every buffer received over UART.
*
* !README!
* The sketch is developed to perform UART tests between Arduino
* and PC.
* 1. Burn this program to Arduino
* 2. Compile tiny_loopback tool (see tools folder) for your system
* 3. Connect Arduino TX and RX lines to your PC com port
* 4. Run tiny_loopback on the PC (use correct port name on your system)
* 5. tiny_loopback will print the test speed results
*
* Also, this example demonstrates how to pass data between 2 systems
* By default the sketch and tiny_loopback works as 115200 speed.
*/
#include <TinyProtocol.h>

// By default SerialFdProto class allows sending and receiving
// messages upto 32 bytes, we will use Serial0

tinyproto::SerialFdProto proto(Serial);
tinyproto::StaticPacket<32> poolPacket;

void setup()
{
/* Run at 115200 */
proto.getLink().setSpeed( 115200 );
/* Lets use 8-bit checksum, available on all platforms */
proto.getLink().setCrc( HDLC_CRC_8 ); //enableCheckSum();
/* Register global packet buffer in the pool */
proto.addRxPool( poolPacket );
/* Start */
proto.begin();
}

void loop()
{
IPacket * packet = proto.read(0)
if (packet)
{
// process received packet
// Send it back
proto.send(*packet, 100);
proto.release(packet);
}
}
39 changes: 39 additions & 0 deletions examples/arduino_zero_m0/new_api/fd_loopback/fd_loopback.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* This example sends back every buffer received over UART.
*
* !README!
* The sketch is developed to perform UART tests between Arduino
* and PC.
* 1. Burn this program to Arduino
* 2. Compile tiny_loopback tool (see tools folder) for your system
* 3. Connect Arduino TX and RX lines to your PC com port
* 4. Run tiny_loopback on the PC (use correct port name on your system)
* 5. tiny_loopback will print the test speed results
*
* Also, this example demonstrates how to pass data between 2 systems
* By default the sketch and tiny_loopback works as 115200 speed.
*/
#include <TinyProtocol.h>

// By default SerialFdProto class allows sending and receiving
// messages upto 32 bytes, we will use Serial0
tinyproto::SerialFdProto proto(SerialUSB);

void setup()
{
/* Run at 115200 */
proto.getLink().setSpeed( 115200 );
/* Lets use 8-bit checksum, available on all platforms */
proto.getLink().setCrc( HDLC_CRC_8 ); //enableCheckSum();
/* Start */
proto.begin();
}

void loop()
{
tinyproto::StaticPacket<32> packet;
if ( proto.read(packet, 0) )
{
// process received packet
}
}
Loading

0 comments on commit 14ba930

Please sign in to comment.