Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello everybody,
I have finally found some time to work on adding TCP support for cannelloni (see also #20). This PR is a replacement of #38, and I would like to thank @simontegelid for their initial work!
With the extension of a decoder designed for streams, cannelloni can now support packet-oriented transports like TCP. Similar to the UDP protocol, the design is kept simple and straightforward. The protocol is binary and does not have any delimiters, and messages are sent one after the other. Since the CAN frame type provides enough information to know how many bytes need to be read, an additional data length code is not necessary.
The only addition to the protocol is a mandatory string that is sent upon connection establishment, which is currently set to
CANNELLONIv1
. This string allows instances to negotiate protocols, reject non-cannelloni peers (thinknmap
), and can be easily implemented on any hardware/software stack that is capable of communicating via TCP.The key difference between the UDP/SCTP packet-based protocol and the TCP implementation is that frames are sent out immediately without buffering or sorting. Enabling these options will have no effect, and it might be good to throw an error if the user attempts to do so. The memory footprint can be improved in the future by reducing the
FrameBuffer
to just a few frames for passing betweenCANThread
andTCPThread
and vice versa.In addition to adding TCP support, there has been some refactoring. For example, the main thread now has a pointer to
ConnectionThread
instead of anUDPThread
sinceTCPThread
does not inherit fromUDPThread
.I will leave this PR open for 10 days (until March 23, 2023) so that people have time to comment.
pinging @jreppnow as you might be interested in participating in the discussion 👀