Streaming via UART

386 views
Skip to first unread message

Jason Phillips

unread,
Oct 2, 2020, 3:41:21 PM10/2/20
to nanopb
Hello,

I am pretty new to protobuffers and NanoPB. I have the examples up and running on a single chip. Now I am trying to find the best way to transition this to a multi-chip system by transferring the serialized stream over something like UART or SPI.

I have read through the documentation and searched the group but haven't found or at least fully understood the correct way to do this. 

The main problem I am running into is I will be transferring a byte at a time and the receiver will not know the length of the message as it comes in due to many optional fields. So I don't have a full buffer at many points and the decode then fails. 

I have been trying to figure out if I need to implement something in the input stream or implement callbacks. I'm not really sure what each would look like. I would like to link the UART read/write functions directly to the input/output streams for NanoPB if possible. 

Traditionally I would write a circular buffer and wrap a custom protocol with start and stop bytes (with internal matching bytes being escaped) so I know I have a complete message. As far as I can tell there is no way for me to detect when a full protobuffer message has been transmitted.

Any help is greatly appreciated! I am sure I am just missing something simple here. 

denra...@gmail.com

unread,
Oct 3, 2020, 1:03:08 AM10/3/20
to nanopb
You want to do delimited encoding and decoding, see PB_ENCODE_DELIMITED and PB_DECODE_DELIMITED at https://jpa.kapsi.fi/nanopb/docs/reference.html.
It starts by sending a varint encoded payload size. The receiver can start by decoding the varint to see if it has received the entire message. It's possible that pb_decode_ex handles this for you, I haven't dug that deep into the implementation.

 /Marco

Jason Phillips

unread,
Oct 5, 2020, 7:24:00 AM10/5/20
to nanopb
Marco,

Thank you, I will dig in and learn more about the delimited encoding. I appreciate the guidance!

Sincerely,
Jason

Reply all
Reply to author
Forward
0 new messages