I am developing an application that reads data from DAQ, which transmits its data via Bluetooth. The packet sizes can vary, as well as the sampling frequency (1 Hz - 512 Hz), and I can scroll and read data from the device using the buffer.
My question is: how to properly process data when there is such a variable in packet size and sample rate? How to determine the size of the buffer?
Currently, I just open the socket by opening the input stream and then using the while loop (while the socket is open == true) to read from the stream and process the data (simple decoding, not an outside task).
As an example, the packet has 23 bytes, and my sampling rate is very low at the moment at a frequency of 1 Hz. I have a 256 byte buffer, which means that it does not fit a complete packet at the end of the buffer, and I wrote code to move it to the next buffer. After reading the data, capture one packet from the buffer, decode and save it, perform the following, etc.
How should I be streaming and managing data correctly? In the end, Iโll catch something in the area of โโ44 packets at 512 Hz, right on the Bluetooth data transfer limit, and I want to be able to process it as efficiently as possible and display errors when the packet is dropped in the process, etc.
TL DR: how to properly transmit data using buffers and / or interrupts.
source share