diff --git a/firmware/can_helper.cpp b/firmware/can_helper.cpp index 1647b8c7..ad783f0f 100644 --- a/firmware/can_helper.cpp +++ b/firmware/can_helper.cpp @@ -11,24 +11,26 @@ CanTxMessage::CanTxMessage(uint32_t eid, uint8_t dlc, bool isExtended) { memset(m_frame.data8, 0, sizeof(m_frame.data8)); } -static int txFailureCounter = 0; +static void onTxIssue() { + static int txFailureCounter = 0; + static Timer txFailureCounterReset; -static Timer txFailureCounterReset; - -bool isTxIssue() { + txFailureCounter++; if (txFailureCounterReset.hasElapsedSec(10)) { txFailureCounterReset.reset(); txFailureCounter = 0; } // 10 times 100ms timeout would take a second to enter error condition - return txFailureCounter > 10; + if (txFailureCounter > 10) { + SetFault(0, Fault::CanTxError); + } } CanTxMessage::~CanTxMessage() { // 100 ms timeout msg_t msg = canTransmitTimeout(&CAND1, CAN_ANY_MAILBOX, &m_frame, TIME_MS2I(100)); if (msg != MSG_OK) { - txFailureCounter++; + onTxIssue(); } } diff --git a/firmware/can_helper.h b/firmware/can_helper.h index 9f64773f..5ca38872 100644 --- a/firmware/can_helper.h +++ b/firmware/can_helper.h @@ -74,5 +74,3 @@ void transmitStruct(uint32_t eid) // see CanTxMessage::~CanTxMessage() populateFrame(frame.get()); } - -bool isTxIssue(); diff --git a/firmware/main.cpp b/firmware/main.cpp index bfb5a1ac..6430b455 100644 --- a/firmware/main.cpp +++ b/firmware/main.cpp @@ -14,7 +14,6 @@ #include "port.h" #include "tunerstudio.h" #include "indication.h" -#include "can_helper.h" #include "wideband_config.h" @@ -61,11 +60,7 @@ int main() { /* TODO: show EGT errors */ auto fault = GetCurrentFault(0); - if (isTxIssue()) { - // temporary solution: light up both LEDs in case of TX error - palSetPad(LED_BLUE_PORT, LED_BLUE_PIN); - palSetPad(LED_BLUE_PORT, LED_GREEN_PIN); - } else if (fault == Fault::None) + if (fault == Fault::None) { // blue is off palClearPad(LED_BLUE_PORT, LED_BLUE_PIN); diff --git a/for_rusefi/wideband_can.h b/for_rusefi/wideband_can.h index 01f79371..86c20c2f 100644 --- a/for_rusefi/wideband_can.h +++ b/for_rusefi/wideband_can.h @@ -40,6 +40,7 @@ enum class Fault : uint8_t SensorOverheat = 4, SensorUnderheat = 5, SensorNoHeatSupply = 6, + CanTxError = 7, }; struct StandardData