wireless data reliability
I'm trying to think through the scenario of what happens when there isn't enough bandwidth between the transmitter on the OpenBCI board and the receiver dongle, whether that's because we have too much data to send, or the radio signal is too weak, or there's too much radio interference.
What was I saying? Ah, yes, sendChannelData does Serial0.write with the current data. That, I think, does not block until it's done transmitting, it just puts the data in the transmit buffer. And if we overflow the send buffer, which is maybe as little as 64 bytes, I think we're going to start silently dropping data. (I could be wrong! I have not found definitive documentation on this, it's just what I'm gleaning in my github dives.)
...wait a second, is this telling me that the RFD22301 chip we use on both the OpenBCI board and the receiver dongle is itself an arduino-programmable microcontroller? *mind blown*
Proposal 1: do Serial0.flush() at the end of sendChannelData or somewhere in our main loop. That'll prevent overrunning the transmit buffer.
But presumably all we know at this point is the data was sent. Do we know anything about whether the data was received? How does rfduino perform in less-than-ideal conditions? Is there a reliable protocol under there, like TCP, or is it more like a traditional serial port, where if you actually want to get data across in one piece you need an error-correcting protocol like xmodem? If it drops 20 bytes of one of our 32-byte messages, we're going to have a heck of a time recovering the session.
I have other questions, like how to detect when we need to back off and try a lower sample rate, or if a one-byte sequence counter is enough when that'll wrap over in a second, but I think that's too many thoughts for one evening.
Comments
Here's a couple other related data points that might provide some context.
If you look at the source file ob_eeg.cpp in the Brainbay Github, this contains the EEG device driver, data stream packet decoding logic for all the supported devices. These are for the most part, serial USB COM port based. And contain no provision for "TCP-like" high level error detection / retransmission. Or flow control for that matter. The port just runs at flat out full speed. A number of the drivers do support an incrementing packet counter. Which, if it is not increasing by '1' on each new packet, causes a user interface visible counter element to increment. Indicating a packet lost. That status area is at the bottom of the screen and looks like:
Status: [Session running. 250 Packets/sec (6 lost) ]
For OpenBCI, the 'lost' count is 99.99% of the time just stationary at some very small number. And only increments on rare occasions. So from this I'm concluding that our data link is pretty solid. :-)
William