09-06-2021 08:31 AM - edited 09-06-2021 08:32 AM
@pooya_B wrote:
I need fast processing and I can not use the set of checks. I tried this way before and it slowed down data receiving a lot and there was a problem in processing my information.
You are talking over a serial port. Even at 115200 baud, you are only getting a byte every 868us. It doesn't take nearly this long to do a simple sum check. But I think you missed the point: You have to do some type of checks to make sure you got a proper frame or all of your data will be skewed.
@pooya_B wrote:
To start the message, I send two values in binary, the decimal is 65 and 122, and then two bytes of data related to my analog data. A fixed value of 112 is sent to separate the previous data value and two bytes of data for temperature, then another fixed value of 90 and two bytes of data are sent for time.
That's weird to have set bytes inside of your data, even to separate the types of data. I would propose moving the 112 and 90 to the end of the frame. This will make life easier on the receiver. It can read a single byte at a time until 0x41 (65) is read, then read another byte and verify it is 0x7A (112), then read the other 8 bytes, verifying the last two are 0x70 (112) and 0x5A (90). If the verification passes, then you can process the 6 bytes in the middle however you need to.
09-06-2021 11:03 AM
Can we assume that once we have a correct frame, all following frames will be aligned too?
Maybe what you should do is continuously read the data into a U8 array buffer, then take successive 10 element subsets, mask off the data using bitwise operations and compare with you packet pattern. Whenever a match is found, parse the data and send it to further processing, else continue. Once you have an aligned frame, you can guess the position of the next frame with high probability.
09-06-2021 11:10 AM
Hi
thank you very much, your solution was excellent and the information clutter was fixed.
09-06-2021 11:12 AM
Thank you very much for your help. My problem was solved.