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

src: message: Fix: Checksum split payload_lenght and msg_id into two … #15

Merged
merged 1 commit into from
Apr 4, 2024

Conversation

RaulTrombin
Copy link
Member

Fix CRC calculus,
payload_lenght and msg_id should be splited into 2 different bytes for the sum.

Fixed issues for PIng1D msgs.

src/message.rs Outdated
Comment on lines 81 to 84
let (msb, lsb) = ((self.payload_length >> 8) as u8, self.payload_length as u8);
checksum += msb as u16 + lsb as u16;
let (msb, lsb) = ((self.message_id >> 8) as u8, self.message_id as u8);
checksum += msb as u16 + lsb as u16;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let (msb, lsb) = ((self.payload_length >> 8) as u8, self.payload_length as u8);
checksum += msb as u16 + lsb as u16;
let (msb, lsb) = ((self.message_id >> 8) as u8, self.message_id as u8);
checksum += msb as u16 + lsb as u16;
self.payload_length.to_le_bytes().for_each(|byte| checksum += byte);
self.message_id.to_le_bytes().for_each(|byte| checksum += byte);

note, needs to check if the correct would be to_le or to_be, it's just a pesdocode

Copy link
Member Author

@RaulTrombin RaulTrombin Apr 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about:

        for &byte in self.payload_length.to_le_bytes().iter() {
            checksum += byte as u16;
        }
        for &byte in self.message_id.to_le_bytes().iter() {
            checksum += byte as u16;
        }

@RaulTrombin
Copy link
Member Author

Seems fine.

ProtocolMessage { payload_length: 1, message_id: 1201, src_device_id: 1, dst_device_id: 0, payload: [1], checksum: 332 }
DeviceIdStruct { device_id: 1 }

@patrickelectric patrickelectric merged commit cfa4ffc into bluerobotics:master Apr 4, 2024
2 checks passed
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

Successfully merging this pull request may close these issues.

2 participants