Dear Julia Community!
I am currently working on a university project where data is streamed to a Raspberry Pi 4 and needs to be processed in a soft real-time environment. The projects goal is to provide infrastructure for the development of data processing algorithms. These algorithms also need to run in soft real-time on the Raspberry Pi.
The data stream is characterized as following
- 3 channels of 3-byte (24-bit) ADC samples
- The channels are recorded simultaneously and continuously at a rate of 50 kHz using a STM32H7 microcontroller
- Data is transferred to the Raspberry Pi using the USB VCP in batches of 50 samples of all channels, which equals to 3 channels * 3 bytes * 50 samples = 450 bytes of data per transaction. On the Raspberry Pi side, the data is extracted in the
extract_data
function of my code
Which results in a data rate of 3 channels * 3 bytes * 50 kHz = 450 kBytes per second (+ some overhead)
The code of the main file is here:
Data synchronization problem
The data stream is initiated by sending a start command to the STM32 microcontroller. To prevent data loss, all the functions are compiled before starting the data stream, which works fine. I also try to empty the serial receive buffer before starting the data stream.
function fcm_flush(port)
sp_flush(port, SP_BUF_BOTH)
end
This does not work and data is misaligned. Even after multiple restarts, the problem persists. However, it does not appear to be a problem when trying the same in an equivalent Python script. The problem also disappears if i first access the data stream using the Python script, then stop the stream and then using the Julia Script.
General advice
Is there some more elegant way of designing the extract_data
function? At the moment, it just iterates over the data and, using bit-manipulation, extracts the data for each channel from the stream. It does work, with the justifiable premise of aligned data, but I feel like there must be a more julian way of doing the job.
It would also be very nice to be able to compile the whole program and run it as an executable. Is the package compiler suitable for this?
I am currently using version 1.6.4
Thanks a lot for reading, any thoughts on this are appreciated!