I am writing some code to interface an STM32H7 with a BM64 Bluetooth module over UART.
The BM64 expects binary data in bytes; in general:
1. Start word (0xAA)
2-3. Payload length
4. Message ID
5-n. Payload
n+1. Checksum
My question is around best practice for message queuing, namely:
Custom iostream
, message vectors inside an interface class or other?
My understanding so far, please correct if wrong or add if something missed:
Custom
iostream
has the huge benefit of concise usage inline withcout
etc. Very usable and clean and most likely portable, at least in principle, to other devices on this project operating on other UART ports. The disadvantage is that it is relatively a lot of work to create a customstreambuf
and not sure what to use for "endl
" (can't use null or'\n'
as these may exist in the message, with it being binary.)Vectors seem a bit dirty to me and particularly for embedded stuff, the dynamic allocations could be stealing a lot of memory unless I ruthlessly spend cycles on
resize()
andreserve()
. However, a vector of messages (defined as either aclass
orstruct
) would be very quick and easy to do.Is there another solution? Note, I'd prefer not to use arrays, i.e. passing around buffer pointers and buffer lengths.
What would you suggest in this application?