Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extra bytes break library #4

Open
ir-fuel opened this issue Jan 27, 2020 · 1 comment
Open

Extra bytes break library #4

ir-fuel opened this issue Jan 27, 2020 · 1 comment

Comments

@ir-fuel
Copy link

ir-fuel commented Jan 27, 2020

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:

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:

0xC1 0xA4 0x3 0x5 0x0 0x0 0x0 0xA1 0x1 0x2 0x3 0x4

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.

Any idea?

@BrianDen
Copy link

I have the same problem here.. how did you write your code to check first 4 bytes?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants