-
Notifications
You must be signed in to change notification settings - Fork 18
Description
Issue / request
- PLUART maintains a single static
_user_linebuffer for thread-safe access of serial line data from sensors. - If the client app does not service data in this buffer with a call to
readLinebefore another line comes from the sensor, the new line overwrites the buffer and data is lost. - Implement a thread-safe queue/buffer that can store multiple lines.
- Alert client if data if queue overflowed and has been overwritten/lost.
Background / why
The PLUART namespace (defined here) adds some very convenient wrappers to the DevKit's Payload UART interface, which is the data interface for many of the serial connections the DevKit supports (UART, RS232, RS485, RS422, SDI-12).
There are (2) thread-safe methods exposed for users to access Rx data from their apps - PLUART::readLine and PLUART::readByte.
readLine can be used when the attached device is generating frames of serial data with reserved delimiting characters (a common example is ASCII text data with <CR> and/or <LF> being the frame delimiter). This is a very common pattern for legacy marine sensors so this is a very convenient wrapper to have.
The issue is that most of these sensors will have some multi-line data or command responses, the the potential for overwriting with the existing implementation results hairy-edge brittleness and a poor developer experience - the line buffer works most of the time. Works often enough to make it non-obvious what exactly is going wrong, but fails more than often enough to make it something a developer can just ignore. It's also susceptible to small timing changes in the app causing things to break, which can result in pernicious Heisenbugs.
related PR from legacy private repo for reference: https://github.com/wavespotter/bristlemouth/pull/465