I have one more question which I forgot to mention on first post. there is 3 serial port and getser1() and getser2() also receives data on serial port 1 and 2 of mega.
sure, not so uncommon. but the code you posted waited for 5 bytes, so it looks like your processing differently on different interfaces
so as you're code does, it scans for the start char(s), resetting the char index when it doesn't see it, then read the data length when the char index == 1 and then read up to the data length when char index > 2
very often, the checksum appended to a msg, is not necessarily the actual checksum, but a value that causes the calculated checksum to become zero which is easily recognized
We added the delay when thereis checksum error. Our device send missed data sometimes and we need to check data is ok or not. we just wrote 10s but we will decrease it to 0.5seconds.
i just thought that can i appent calculate function to getser1() or getser2() function. Speed change is not very important but gyro data is important.
If somebody should help checking how it can be done with the highest possible reliability
you have to explain in much more detail what is happening
and how things depend on each other
and post how do the messages look like
As far as I have understood it
you are receiving five bytes on Serial
these five bytes are a digits (0..9) with a decimal-point
example 123.8
is this example correct? or does the byte-sequence look different?
Only in case you have received a valid SpeedGPS-value
the data rushing in from Serial1 / Serial2 shall be processed
if there is no valid SpeedGPS-value drop the data from the Serial1-receive-bufferal2-receive-buffer
and wait for a valid SpeedGPS-value.
is this a correct description?
If this description is not correct. Post a correct discription in this grade of details
Also it would help to see how the byte-sequence looks like
and that you describe what in the bytesequence is always the same value which bytes can be different.
Another question:
at what time-intervals does the data come in on Serial?
at what time-intervals does the data come in on Serial1?
at what time-intervals does the data come in on Serial2?
You wrote
You are receiving three different "data" Which "data" = coming from which serial interface do you mean?
and which "data" is meant in your sentence
This "data" must be something different because if no data is received there is nothing that could be processed.
My conclusion the "old-data" is something different than "new data"
You should specifiy each kind of "data" in such a specific way that there is absolutely no room left for speculation.