mirror of
https://github.com/thooge/esp32-nmea2000-obp60.git
synced 2025-12-13 05:53:06 +01:00
count timeouts to detect offline state
This commit is contained in:
@@ -20,9 +20,13 @@ bool Nmea2kTwai::CANSendFrame(unsigned long id, unsigned char len, const unsigne
|
||||
memcpy(message.data,buf,len);
|
||||
esp_err_t rt=twai_transmit(&message,0);
|
||||
if (rt != ESP_OK){
|
||||
logDebug(LOG_DEBUG,"twai transmit for %ld failed: %x",LOGID(id),(int)rt);
|
||||
if (rt == ESP_ERR_TIMEOUT){
|
||||
txTimeouts++;
|
||||
}
|
||||
logDebug(LOG_MSG,"twai transmit for %ld failed: %x",LOGID(id),(int)rt);
|
||||
return false;
|
||||
}
|
||||
txTimeouts=0;
|
||||
logDebug(LOG_MSG,"twai transmit id %ld, len %d",LOGID(id),(int)len);
|
||||
return true;
|
||||
}
|
||||
@@ -106,6 +110,10 @@ Nmea2kTwai::Status Nmea2kTwai::getStatus(){
|
||||
rt.tx_failed=state.tx_failed_count;
|
||||
rt.rx_missed=state.rx_missed_count;
|
||||
rt.rx_overrun=state.rx_overrun_count;
|
||||
rt.tx_timeouts=txTimeouts;
|
||||
if (rt.tx_timeouts > 256 && rt.state == ST_RUNNING){
|
||||
rt.state=ST_OFFLINE;
|
||||
}
|
||||
return rt;
|
||||
}
|
||||
|
||||
@@ -125,6 +133,7 @@ const char * Nmea2kTwai::stateStr(const Nmea2kTwai::STATE &st){
|
||||
case ST_RECOVERING: return "RECOVERING";
|
||||
case ST_RUNNING: return "RUNNING";
|
||||
case ST_STOPPED: return "STOPPED";
|
||||
case ST_OFFLINE: return "OFFLINE";
|
||||
}
|
||||
return "ERROR";
|
||||
}
|
||||
@@ -11,6 +11,7 @@ class Nmea2kTwai : public tNMEA2000{
|
||||
ST_RUNNING,
|
||||
ST_BUS_OFF,
|
||||
ST_RECOVERING,
|
||||
ST_OFFLINE,
|
||||
ST_ERROR
|
||||
} STATE;
|
||||
typedef struct{
|
||||
@@ -20,6 +21,7 @@ class Nmea2kTwai : public tNMEA2000{
|
||||
uint32_t tx_failed=0;
|
||||
uint32_t rx_missed=0;
|
||||
uint32_t rx_overrun=0;
|
||||
uint32_t tx_timeouts=0;
|
||||
STATE state=ST_ERROR;
|
||||
} Status;
|
||||
Status getStatus();
|
||||
@@ -47,6 +49,7 @@ class Nmea2kTwai : public tNMEA2000{
|
||||
void initDriver();
|
||||
gpio_num_t TxPin;
|
||||
gpio_num_t RxPin;
|
||||
uint32_t txTimeouts=0;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user