lexus2k / tinyproto

Tiny Software Protocol for communication over UART, SPI, etc
GNU General Public License v3.0
236 stars 51 forks source link

TinyProtocolStream - encapsulate tinyproto into Arduino Stream for ease of use #24

Open embedded-creations opened 3 years ago

embedded-creations commented 3 years ago

I need a reliable Serial connection between two Arduinos, and found your project. I created an Arduino Stream class that inherits from IFd and it's getting close to reliable at high throughput as tested through a loopback test running between two Teensy 4.1s.

https://github.com/embedded-creations/tinyproto/tree/stream

Take a look at this example to see how simple it is to use (just a few lines reference tinyproto in the sketch, and the API is nearly identical to a Stream object like Serial which makes it easy for a new user):

https://github.com/embedded-creations/tinyproto/blob/stream/examples/arduino_generic/TinyProtocolStreamTest/TinyProtocolStreamTest.ino

Some questions:

lexus2k commented 2 years ago

Hi Louis,

I'm sorry for the late reply, was too busy. Thank you for the interest to the library. I'm really appreciate your help. Of course, you did the great job. Answering to you questions,

Would you like to include FdStream in the library once it's finished?

Yes, it is the good idea to integrate your changes to tinyproto library. However, we need to be very careful, since the tinyproto library is used not only in Arduino environment.

It's difficult to see the status of the library, have you thought about how to improve the API in this regard? I added a getStatus() method to access tiny_fd_get_status(), but beyond that I'd like to know if I lost any data so I can reset the protocol running on top of tinyproto.

Absolutely agree with you, I have idea to capture the protocol statistics, and to make it available via some API for a applications.

Have you run any loopback tests that validate data? I didn't see any in the repo and found packets were getting dropped unless I left a couple of I slots free when running at high throughput. This may go overlooked if you're just counting packets received and not validating.

The library does not have any stress tests for now, but it have numerous checks for each commit. With every commit, the CircleCI subsystem runs 1) throughput tests via virtual sockets. You can find those in the .travis/run_tests.sh shell script. 2) unit tests, which check only packets loss.

But both these checks must be as quick as possible (CircleCI has limit of 10 minutes for the operation). And yes, the it is good idea to implement stress tests in some script and run them manually from time to time.

Do you have any Teensy devices? I'm using the Teensy 4 as it has multiple hardware serial ports, and I can enable multiple USB serial ports so I can get the tinyproto debug output on one, and sketch data on another. I had to make some HAL tweaks to get this to work, which I can contribute if it helps you.

No, I don't have that one. I have ESP32, which allows to implement similar setup. But it is not the problem, I can order Teensy boards from Aliexpress (it will take some time before the boards will be delivered). All I need to know is description of your setup, maybe some picture of how the boards are inter-connected.

embedded-creations commented 2 years ago

Glad to hear you're interested in integrating this new feature into tinyproto. Although there is still work to be done (listed in the "TODOs" section in the README on my fork), it's currently functional enough to test and to discuss how to integrate it. Please let me know your thoughts when you've taken a look.

If you don't have a Teensy it's not necessary to get one, I just think it's convenient for debugging as it has multiple USB and hardware serial ports, and compiling and programming is very fast. I used a Teensy 4.1 for my testing, but a Teensy 4.0 should work just as well. A Teensy 3.2/3.5/3.6 probably would work well if it's easier to source. They're manufactured in the US and their list of worldwide distributors is available here:

https://www.pjrc.com/store/

I also have multiple ESP32s, but so far have only tested tinyproto on a single ESP32 connected to a Teensy 4.1. I don't think pictures are necessary, I just have three wires for GND/TX/RX connected between the two boards.