1
0
mirror of https://github.com/thooge/esp32-nmea2000-obp60.git synced 2025-12-14 22:43:07 +01:00

add bus off recovery

This commit is contained in:
andreas
2023-08-24 20:00:19 +02:00
parent 3be08a0c26
commit 41d8578681
3 changed files with 52 additions and 2 deletions

View File

@@ -110,7 +110,7 @@ GwLog logger(LOGLEVEL,NULL);
GwConfigHandler config(&logger);
#include "Nmea2kTwai.h"
tNMEA2000 &NMEA2000=*(new Nmea2kTwai(ESP32_CAN_TX_PIN,ESP32_CAN_RX_PIN,&logger));
Nmea2kTwai &NMEA2000=*(new Nmea2kTwai(ESP32_CAN_TX_PIN,ESP32_CAN_RX_PIN,&logger));
#ifdef GWBUTTON_PIN
bool fixedApPass=false;
@@ -821,6 +821,8 @@ void handleSendAndRead(bool handleRead){
TimeMonitor monitor(20,0.2);
unsigned long lastHeapReport=0;
unsigned long lastCanRecovery=0;
static const unsigned long CAN_RECOVERY_PERIOD=3000; //ms
void loop() {
monitor.reset();
GWSYNCHRONIZED(&mainLock);
@@ -839,6 +841,17 @@ void loop() {
logger.logDebug(GwLog::DEBUG,"Main loop %s",monitor.getLog().c_str());
}
}
if (now > (lastCanRecovery + CAN_RECOVERY_PERIOD)){
lastCanRecovery=now;
Nmea2kTwai::STATE canState=NMEA2000.getState();
if (canState != Nmea2kTwai::ST_RUNNING){
logger.logDebug(GwLog::DEBUG,"can state: %d",canState);
if (canState == Nmea2kTwai::ST_BUS_OFF){
bool rt=NMEA2000.startRecovery();
logger.logDebug(GwLog::LOG,"start can recovery - result %d",(int)rt);
}
}
}
monitor.setTime(3);
channels.allChannels([](GwChannel *c){
c->loop(true,false);