From 1f8b0855983d454b0ad377138e356994df6a1044 Mon Sep 17 00:00:00 2001 From: Marcel Peterkau Date: Mon, 20 Feb 2023 09:18:14 +0100 Subject: [PATCH] small improvement of DTC-Handling for CAN --- Software/src/can.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Software/src/can.cpp b/Software/src/can.cpp index 512e468..ae8907f 100644 --- a/Software/src/can.cpp +++ b/Software/src/can.cpp @@ -23,6 +23,7 @@ uint32_t Process_CAN_WheelSpeed() can_frame canMsg; static uint32_t lastRecTimestamp = 0; uint16_t RearWheelSpeed_raw; + uint32_t milimeters_to_add = 0; if (CAN0.readMsgBuf(&canMsg.can_id, &canMsg.can_dlc, canMsg.data) == CAN_OK) { @@ -34,13 +35,14 @@ uint32_t Process_CAN_WheelSpeed() uint32_t timesincelast = millis() - lastRecTimestamp; lastRecTimestamp = millis(); - uint32_t milimeters_to_add = (RWP_millimeter_per_second * timesincelast) / 1000; - - return milimeters_to_add; + milimeters_to_add = (RWP_millimeter_per_second * timesincelast) / 1000; } - MaintainDTC(DTC_NO_CAN_SIGNAL, DTC_CRITICAL, (millis() > lastRecTimestamp + 10000 ? true : false)); + if (lastRecTimestamp != 0) + { + MaintainDTC(DTC_NO_CAN_SIGNAL, DTC_CRITICAL, (millis() > lastRecTimestamp + 10000 ? true : false)); + } - return 0; + return milimeters_to_add; } #endif \ No newline at end of file