Closed sidcha closed 2 years ago
I faced this problem in the beginning! "Would it make sense to have a while loop there instead, and drop all leading bytes until the SOM byte is found?" this is how I get the message in esp32! because you have to read whatever it's available from the uart buffer , I drop everything till I reach ff 53 and store it in a buffer according to the size that is provided by the higher function!
Would it make sense to have a while loop there instead, and drop all leading bytes until the SOM byte is found?
Certainly. I just never had to face this situation before. Do you know why the CP flooding the RX buffer with FFs? It has to actively pull the line low to do this (so its no accident).
(or 0xfe at 115200)
Even if we workaround the issue above, this is problematic. This current packet will be fine, but the next one would be dropped.
The mercury panel is not flooding the line. It sends two 0xFF frames. It is expected (and many other PD's) that your packet detection logic looks for the SOM to start a packet. You should not be looking for 0xFF 0x53.
It sends two 0xFF frames. It is expected (and many other PD's) that your packet detection logic looks for the SOM to start a packet.
@rsgmodelworks, I agreed on the look for FF 53 for start of packet part. I do see a lot more than 2 0xFF in the 115200 capture sample. And there is also the tailing 0xFE which tells me something is amiss.
Based on assessment, to correctly deal with this situation, a bit of rework is needed around how we manage the RX buffers altogether (it needs to become a circular buffer).
It would also mean we can get rid of memmove that we do after we are done processing the bytes which should speed things up quite a bit. :)
Now LibOSDP will discard any number of leading mark bytes (and any other junk till it finds the SOM). It also extracts exactly one packet from the RX buffer so the tailing fe should be discarded as junk before processing the next packet.
This should resolve this ticket; feel free to reopen if it doesn't work.
Cross posting issue reported by email: