count timeouts to detect offline state
This commit is contained in:
parent
9fd25ab6a8
commit
f5e48fcab3
|
@ -20,9 +20,13 @@ bool Nmea2kTwai::CANSendFrame(unsigned long id, unsigned char len, const unsigne
|
||||||
memcpy(message.data,buf,len);
|
memcpy(message.data,buf,len);
|
||||||
esp_err_t rt=twai_transmit(&message,0);
|
esp_err_t rt=twai_transmit(&message,0);
|
||||||
if (rt != ESP_OK){
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
txTimeouts=0;
|
||||||
logDebug(LOG_MSG,"twai transmit id %ld, len %d",LOGID(id),(int)len);
|
logDebug(LOG_MSG,"twai transmit id %ld, len %d",LOGID(id),(int)len);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -106,6 +110,10 @@ Nmea2kTwai::Status Nmea2kTwai::getStatus(){
|
||||||
rt.tx_failed=state.tx_failed_count;
|
rt.tx_failed=state.tx_failed_count;
|
||||||
rt.rx_missed=state.rx_missed_count;
|
rt.rx_missed=state.rx_missed_count;
|
||||||
rt.rx_overrun=state.rx_overrun_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;
|
return rt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,6 +133,7 @@ const char * Nmea2kTwai::stateStr(const Nmea2kTwai::STATE &st){
|
||||||
case ST_RECOVERING: return "RECOVERING";
|
case ST_RECOVERING: return "RECOVERING";
|
||||||
case ST_RUNNING: return "RUNNING";
|
case ST_RUNNING: return "RUNNING";
|
||||||
case ST_STOPPED: return "STOPPED";
|
case ST_STOPPED: return "STOPPED";
|
||||||
|
case ST_OFFLINE: return "OFFLINE";
|
||||||
}
|
}
|
||||||
return "ERROR";
|
return "ERROR";
|
||||||
}
|
}
|
|
@ -11,6 +11,7 @@ class Nmea2kTwai : public tNMEA2000{
|
||||||
ST_RUNNING,
|
ST_RUNNING,
|
||||||
ST_BUS_OFF,
|
ST_BUS_OFF,
|
||||||
ST_RECOVERING,
|
ST_RECOVERING,
|
||||||
|
ST_OFFLINE,
|
||||||
ST_ERROR
|
ST_ERROR
|
||||||
} STATE;
|
} STATE;
|
||||||
typedef struct{
|
typedef struct{
|
||||||
|
@ -20,6 +21,7 @@ class Nmea2kTwai : public tNMEA2000{
|
||||||
uint32_t tx_failed=0;
|
uint32_t tx_failed=0;
|
||||||
uint32_t rx_missed=0;
|
uint32_t rx_missed=0;
|
||||||
uint32_t rx_overrun=0;
|
uint32_t rx_overrun=0;
|
||||||
|
uint32_t tx_timeouts=0;
|
||||||
STATE state=ST_ERROR;
|
STATE state=ST_ERROR;
|
||||||
} Status;
|
} Status;
|
||||||
Status getStatus();
|
Status getStatus();
|
||||||
|
@ -47,6 +49,7 @@ class Nmea2kTwai : public tNMEA2000{
|
||||||
void initDriver();
|
void initDriver();
|
||||||
gpio_num_t TxPin;
|
gpio_num_t TxPin;
|
||||||
gpio_num_t RxPin;
|
gpio_num_t RxPin;
|
||||||
|
uint32_t txTimeouts=0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -861,11 +861,13 @@ void loop() {
|
||||||
if (now > (lastCanRecovery + CAN_RECOVERY_PERIOD)){
|
if (now > (lastCanRecovery + CAN_RECOVERY_PERIOD)){
|
||||||
lastCanRecovery=now;
|
lastCanRecovery=now;
|
||||||
Nmea2kTwai::Status canState=NMEA2000.getStatus();
|
Nmea2kTwai::Status canState=NMEA2000.getStatus();
|
||||||
logger.logDebug(GwLog::DEBUG,"can state %s, rxerr %d, txerr %d, txfail %d, rxmiss %d, rxoverrun %d",
|
logger.logDebug(GwLog::DEBUG,
|
||||||
|
"can state %s, rxerr %d, txerr %d, txfail %d, txtimeout %d, rxmiss %d, rxoverrun %d",
|
||||||
NMEA2000.stateStr(canState.state),
|
NMEA2000.stateStr(canState.state),
|
||||||
canState.rx_errors,
|
canState.rx_errors,
|
||||||
canState.tx_errors,
|
canState.tx_errors,
|
||||||
canState.tx_failed,
|
canState.tx_failed,
|
||||||
|
canState.tx_timeouts,
|
||||||
canState.rx_missed,
|
canState.rx_missed,
|
||||||
canState.rx_overrun);
|
canState.rx_overrun);
|
||||||
if (canState.state != Nmea2kTwai::ST_RUNNING){
|
if (canState.state != Nmea2kTwai::ST_RUNNING){
|
||||||
|
|
Loading…
Reference in New Issue