I’d like to set up a robust, bug free serial communication with a radar module, which can continously report data of an object, which meets the filtering parameters (e.g. object is within a specified range). The default report interval of the module is ~65ms, so the code should process data as fast as it can (however a simple speed report is not that long, so the RX buffer will not be filled so easily). The final code has to be validated with some measurements regarding the timing.
The main idea is to receive the speed data of the detected object, but with a safe approach. So if the report is not exactly the default report somehow (e.g starts with a timestamp, or magnitude is reported before the speed), get the right value anyway. I tried to write the code with this in mind, I added as much comment to explain what was my intention with certain instructions. I hope you get the idea. The module can save the parameters itself, unfortunately not all what is needed. The continous range report is switched on by default , but the switch off state cannot be saved. So to prepare for a reset situation, if range report starts (intended or unintended reset occured) this is used to set all the necessary parameters which were not saved permanently. Another good to have is the Blank Report, I chose comma ‘,’ for this purpose. If no object is detected, the module will continously report a comma with the above mentioned ~65ms. I’m intended to use this as a communication “watchdog” and reset the sensor module if comma is not received. This is not fully implemented yet.
I added the basic message types to the beginning of the code. The sketch works as expected based on the early tests (not field test though, so I can’t tell how accurately yet). The “online” parameter setting also, after I inject a reset, the needed parameters are set. As I said I’d like this to be as reliable as can, this is why I ask for help, to get rid of every possible bug in early phase.
Could you point out where the communincation can go wrong with this code?
Thanks in advance.
radarRxTx_wo_debug.ino (10.4 KB)