better display for bus off condition
This commit is contained in:
parent
28431bfdcf
commit
b7a7dad290
|
@ -157,6 +157,7 @@ Nmea2kTwai::Status Nmea2kTwai::logStatus(){
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Nmea2kTwai::startRecovery(){
|
bool Nmea2kTwai::startRecovery(){
|
||||||
|
lastRecoveryStart=millis();
|
||||||
esp_err_t rt=twai_driver_uninstall();
|
esp_err_t rt=twai_driver_uninstall();
|
||||||
if (rt != ESP_OK){
|
if (rt != ESP_OK){
|
||||||
logDebug(LOG_ERR,"twai: deinit for recovery failed with %x",(int)rt);
|
logDebug(LOG_ERR,"twai: deinit for recovery failed with %x",(int)rt);
|
||||||
|
|
|
@ -25,6 +25,7 @@ class Nmea2kTwai : public tNMEA2000{
|
||||||
STATE state=ST_ERROR;
|
STATE state=ST_ERROR;
|
||||||
} Status;
|
} Status;
|
||||||
Status getStatus();
|
Status getStatus();
|
||||||
|
unsigned long getLastRecoveryStart(){return lastRecoveryStart;}
|
||||||
void loop();
|
void loop();
|
||||||
static const char * stateStr(const STATE &st);
|
static const char * stateStr(const STATE &st);
|
||||||
virtual bool CANOpen();
|
virtual bool CANOpen();
|
||||||
|
@ -54,6 +55,7 @@ class Nmea2kTwai : public tNMEA2000{
|
||||||
gpio_num_t RxPin;
|
gpio_num_t RxPin;
|
||||||
uint32_t txTimeouts=0;
|
uint32_t txTimeouts=0;
|
||||||
GwIntervalRunner timers;
|
GwIntervalRunner timers;
|
||||||
|
unsigned long lastRecoveryStart=0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
15
src/main.cpp
15
src/main.cpp
|
@ -112,6 +112,7 @@ GwConfigHandler config(&logger);
|
||||||
|
|
||||||
#include "Nmea2kTwai.h"
|
#include "Nmea2kTwai.h"
|
||||||
static const unsigned long CAN_RECOVERY_PERIOD=3000; //ms
|
static const unsigned long CAN_RECOVERY_PERIOD=3000; //ms
|
||||||
|
static const unsigned long NMEA2000_HEARTBEAT_INTERVAL=5000;
|
||||||
class Nmea2kTwaiLog : public Nmea2kTwai{
|
class Nmea2kTwaiLog : public Nmea2kTwai{
|
||||||
private:
|
private:
|
||||||
GwLog* logger;
|
GwLog* logger;
|
||||||
|
@ -388,7 +389,17 @@ protected:
|
||||||
status["fwtype"]= firmwareType;
|
status["fwtype"]= firmwareType;
|
||||||
status["heap"]=(long)xPortGetFreeHeapSize();
|
status["heap"]=(long)xPortGetFreeHeapSize();
|
||||||
Nmea2kTwai::Status n2kState=NMEA2000.getStatus();
|
Nmea2kTwai::Status n2kState=NMEA2000.getStatus();
|
||||||
status["n2kstate"]=NMEA2000.stateStr(n2kState.state);
|
Nmea2kTwai::STATE driverState=n2kState.state;
|
||||||
|
if (driverState == Nmea2kTwai::ST_RUNNING){
|
||||||
|
unsigned long lastRec=NMEA2000.getLastRecoveryStart();
|
||||||
|
if (lastRec > 0 && (lastRec+NMEA2000_HEARTBEAT_INTERVAL*2) > millis()){
|
||||||
|
//we still report bus off at least for 2 heartbeat intervals
|
||||||
|
//this avoids always reporting BUS_OFF-RUNNING-BUS_OFF if the bus off condition
|
||||||
|
//remains
|
||||||
|
driverState=Nmea2kTwai::ST_BUS_OFF;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
status["n2kstate"]=NMEA2000.stateStr(driverState);
|
||||||
status["n2knode"]=NodeAddress;
|
status["n2knode"]=NodeAddress;
|
||||||
//nmea0183Converter->toJson(status);
|
//nmea0183Converter->toJson(status);
|
||||||
countNMEA2KIn.toJson(status);
|
countNMEA2KIn.toJson(status);
|
||||||
|
@ -802,7 +813,7 @@ void setup() {
|
||||||
logger.flush();
|
logger.flush();
|
||||||
NMEA2000.SetMode(tNMEA2000::N2km_ListenAndNode, NodeAddress);
|
NMEA2000.SetMode(tNMEA2000::N2km_ListenAndNode, NodeAddress);
|
||||||
NMEA2000.SetForwardOwnMessages(false);
|
NMEA2000.SetForwardOwnMessages(false);
|
||||||
NMEA2000.SetHeartbeatInterval(5000);
|
NMEA2000.SetHeartbeatInterval(NMEA2000_HEARTBEAT_INTERVAL);
|
||||||
if (sendOutN2k){
|
if (sendOutN2k){
|
||||||
// Set the information for other bus devices, which messages we support
|
// Set the information for other bus devices, which messages we support
|
||||||
unsigned long *pgns=toN2KConverter->handledPgns();
|
unsigned long *pgns=toN2KConverter->handledPgns();
|
||||||
|
|
Loading…
Reference in New Issue