From 19283de3c004dc1b19bbbbc05d28ebee2e563c0e Mon Sep 17 00:00:00 2001 From: Raul Victor Trombin Date: Thu, 4 Apr 2024 14:18:09 -0300 Subject: [PATCH] src: message: Fix: Checksum split payload_lenght and msg_id into two bytes --- src/message.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/message.rs b/src/message.rs index 814c9962e..ccde7fe64 100644 --- a/src/message.rs +++ b/src/message.rs @@ -78,8 +78,14 @@ impl ProtocolMessage { let mut checksum: u16 = 0; checksum += HEADER[0] as u16; checksum += HEADER[1] as u16; - checksum += self.payload_length; - checksum += self.message_id; + self.payload_length + .to_le_bytes() + .iter() + .for_each(|byte| checksum += *byte as u16); + self.message_id + .to_le_bytes() + .iter() + .for_each(|byte| checksum += *byte as u16); checksum += self.src_device_id as u16; checksum += self.dst_device_id as u16; for &byte in &self.payload {