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

Parse Message Shift is Wrong! #4

Open
deejonur opened this issue Jan 12, 2021 · 0 comments
Open

Parse Message Shift is Wrong! #4

deejonur opened this issue Jan 12, 2021 · 0 comments

Comments

@deejonur
Copy link

uint32_t can_parse_msgid(uint8_t *buf)
{
uint32_t ret = 0;

if (buf[1] & 0x08) {  // Extended message ID
	ret = ((uint32_t)(buf[0]) << 21) | ((uint32_t)(buf[1] & 0xE0) << 12) |
		  (((uint32_t)(buf[1]) & 0x03) << 16) |
		  ((uint32_t)(buf[2]) << 8) |
		  (uint32_t)(buf[3]);
} else {
	ret = ((uint32_t)(buf[0]) << 3) | ((uint32_t)(buf[1]) >> 5);
}
return ret;

}

On the function above, "((uint32_t)((buf[1] & 0xE0) << 12" shift must be "13" instead of 12.

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

1 participant