diff --git a/Software/src/can.cpp b/Software/src/can.cpp index 6e6ebe2..57d3db1 100644 --- a/Software/src/can.cpp +++ b/Software/src/can.cpp @@ -3,6 +3,7 @@ MCP_CAN CAN0(GPIO_CS_CAN); #ifdef CAN_DEBUG_MESSAGE +#define MAX_DEBUG_RETRIES 100 void sendCANDebugMessage(); #endif @@ -90,6 +91,7 @@ uint32_t Process_CAN_WheelSpeed() void sendCANDebugMessage() { #define MAX_DEBUG_MULTIPLEXER 6 + static uint16_t DebugSendFailTimeout = 0; static uint8_t debugMultiplexer = 0; byte data[8] = {debugMultiplexer, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; uint32_t millisValue = millis(); @@ -131,9 +133,20 @@ void sendCANDebugMessage() debugMultiplexer++; debugMultiplexer = debugMultiplexer > MAX_DEBUG_MULTIPLEXER ? 0 : debugMultiplexer; - byte sndStat = CAN0.sendMsgBuf(0x7FF, 0, 8, data); - if (sndStat != CAN_OK) - Debug_pushMessage("failed sending CAN-DbgMsg: %d\n", sndStat); + if (DebugSendFailTimeout < MAX_DEBUG_RETRIES) + { + byte sndStat = CAN0.sendMsgBuf(0x7FF, 0, 8, data); + if (sndStat != CAN_OK) + { + Debug_pushMessage("failed sending CAN-DbgMsg: %d, %d\n", sndStat, DebugSendFailTimeout); + DebugSendFailTimeout++; + } + } + else if (DebugSendFailTimeout == MAX_DEBUG_RETRIES) + { + Debug_pushMessage("disable CAN-DbgMsg due to timeout"); + DebugSendFailTimeout++; + } } #endif #endif \ No newline at end of file