I am using this library and the serial CAN module to talk to a race car dashboard that supports custom CAN in and out.
This works 95% of the time, but sometimes the data stream contains extra bytes (anywhere between 3 and 7) that don't make sense to me.
In theory we can just discard those extra bytes, and skip to the beginning of the next CAN message. In practice what happens is this library gets out of sync and starts sending back CAN messages which are offset in the byte stream.
example:
normal message:
0x0 0x0 0x0 0xA1 0x1 0x2 0x3 0x4 0x5 0x6 0x7 0x8
I receive the above in a loop, no problem. Then all of the sudden this arrives:
0xC1 0xA4 0x3 0x5
(this is an example, can be any random sequence and the number of bytes also varies)
followed by:
0x0 0x0 0x0 0xA1 0x1 0x2 0x3 0x4 0x5 0x6 0x7 0x8
What happens in the library. It builds the following CAN command:
and sends it back to the caller. Of course I can't do anything with that as I don't understand the command. From there on the entire CAN stream is offset 4 bytes and I never get a correct command again.
What I did to fix this is to check that when reading a sequence of bytes that the first 4 are 0x0 0x0 0x0 0xA1 and the last 2 are 0x7 0x8, but this of course only works because I know that the input data will always start with this and that the last 2 bytes are 2 fixed values. This is in no way a generic solution for the 'out of sync' problem.
Hi.
I am using this library and the serial CAN module to talk to a race car dashboard that supports custom CAN in and out.
This works 95% of the time, but sometimes the data stream contains extra bytes (anywhere between 3 and 7) that don't make sense to me. In theory we can just discard those extra bytes, and skip to the beginning of the next CAN message. In practice what happens is this library gets out of sync and starts sending back CAN messages which are offset in the byte stream.
example:
normal message:
I receive the above in a loop, no problem. Then all of the sudden this arrives:
(this is an example, can be any random sequence and the number of bytes also varies)
followed by:
What happens in the library. It builds the following CAN command:
and sends it back to the caller. Of course I can't do anything with that as I don't understand the command. From there on the entire CAN stream is offset 4 bytes and I never get a correct command again.
What I did to fix this is to check that when reading a sequence of bytes that the first 4 are
0x0 0x0 0x0 0xA1
and the last 2 are0x7 0x8
, but this of course only works because I know that the input data will always start with this and that the last 2 bytes are 2 fixed values. This is in no way a generic solution for the 'out of sync' problem.Any idea?