Conversation
…Restart() can be called by the CAN driver after it detects bus error and performs bus recovery and bus restart.
|
I have to study this, since I have on own library different solution, which I have not had time to publish. Which controller you use? |
|
The controller/driver choice shouldn't matter for the purposes of this PR. The model that I'm proposing should work for any controller/driver. I don't think that error detection and restart logic should belong inside the NMEA2000 library core, since you probably can't find a one-size-fits-all solution for every scenario. Let the NMEA2000_xxx driver, which inherits and extends the functions of your library, implement the best lifecycle plan for that unique controller. Anyway, I'm using ESP32 (on module ESP32-Pico-Mini-02-8n2r) ==> ISO1042 isolated CAN PHY. |
Fixes Restart() function so it triggers a full reset of the state. Now Restart() can be called (i.e. by the CAN driver after it detects bus error and performs bus recovery and bus restart) and the stack will properly reinitialize and restart the address claim.
This should not cause any harm to applications that don't make use of the Restart() function.
Usage example:
This is how my phatpaul/NMEA2000_esp32_autorestart driver class monitors the lower level driver and can restart the stack when necessary. With this I can unplug/replug the CAN bus and it will restart the address claim automatically.
--- title: NMEA2000_esp32xx Driver State Machine --- stateDiagram-v2 [*] --> STOPPED STOPPED --> RESTARTING: (autoRecoveryEnabled && timeout)<br/>twai_start()<br/>SendDummyFrame() STOPPED --> RUNNING: started by N2K stack RESTARTING --> RUNNING: tNMEA2000..Restart() RESTARTING --> STOPPED: (TxErr>0)<br/>reset timeout RUNNING --> RECOVERING: CAN bus error RUNNING --> STOPPED: (TxErr>=128)<br/>reset timeout RECOVERING --> STOPPED: (CAN bus recovered)<br/>reset timeout