From 5092a1fc916c16a2acbb5c5512a1b654ab382d99 Mon Sep 17 00:00:00 2001 From: Benjamin Koch <bbbsnowball@gmail.com> Date: Wed, 24 May 2023 00:27:40 +0200 Subject: [PATCH] only print CRC when it is wrong --- firmware/rust1/src/rs485.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/firmware/rust1/src/rs485.rs b/firmware/rust1/src/rs485.rs index 9c78b1e..314a006 100644 --- a/firmware/rust1/src/rs485.rs +++ b/firmware/rust1/src/rs485.rs @@ -534,13 +534,14 @@ impl RS485 { } if let ModbusFrameLength::Length(x) = rx_expected_bytes { if x == rx_received_bytes { - let received_crc = rx_char_prev as u16 | ((rx_char as u16) << 8); let calculated_crc = rxcrc.finalize(); - rxcrc = CRC.digest(); - info!("received_crc: {:04x}, calculated_crc: {:04x}", received_crc, calculated_crc); + rxcrc = CRC.digest(); // re-init to placate borrow checker + const CORRECT_CRC: u16 = 0; // because we include the CRC bytes in our calculation + if calculated_crc != CORRECT_CRC { + info!("CRC: {:04x} (should be zero)", calculated_crc); + } //FIXME In case of CRC mismatch, wait for gap/idle of >=1.5 chars. - const CORRECT_CRC: u16 = 0; // because we include the CRC bytes in our calculation const OUR_ADDRESS: u8 = 1; if rxbuf[0] == OUR_ADDRESS && calculated_crc == CORRECT_CRC { txbuf.clear(); -- GitLab