mirror of
https://github.com/markqvist/Reticulum.git
synced 2024-11-22 13:40:19 +00:00
Improved RNode reconnection when serial device disappears
This commit is contained in:
parent
e738c9561a
commit
c604214bb9
@ -125,6 +125,8 @@ class RNodeInterface(Interface):
|
|||||||
self.stopbits = 1
|
self.stopbits = 1
|
||||||
self.timeout = 100
|
self.timeout = 100
|
||||||
self.online = False
|
self.online = False
|
||||||
|
self.detached = False
|
||||||
|
self.reconnecting= False
|
||||||
|
|
||||||
self.frequency = frequency
|
self.frequency = frequency
|
||||||
self.bandwidth = bandwidth
|
self.bandwidth = bandwidth
|
||||||
@ -210,6 +212,7 @@ class RNodeInterface(Interface):
|
|||||||
RNS.log("Could not open serial port for interface "+str(self), RNS.LOG_ERROR)
|
RNS.log("Could not open serial port for interface "+str(self), RNS.LOG_ERROR)
|
||||||
RNS.log("The contained exception was: "+str(e), RNS.LOG_ERROR)
|
RNS.log("The contained exception was: "+str(e), RNS.LOG_ERROR)
|
||||||
RNS.log("Reticulum will attempt to bring up this interface periodically", RNS.LOG_ERROR)
|
RNS.log("Reticulum will attempt to bring up this interface periodically", RNS.LOG_ERROR)
|
||||||
|
if not self.detached and not self.reconnecting:
|
||||||
thread = threading.Thread(target=self.reconnect_port)
|
thread = threading.Thread(target=self.reconnect_port)
|
||||||
thread.daemon = True
|
thread.daemon = True
|
||||||
thread.start()
|
thread.start()
|
||||||
@ -233,7 +236,15 @@ class RNodeInterface(Interface):
|
|||||||
|
|
||||||
|
|
||||||
def configure_device(self):
|
def configure_device(self):
|
||||||
|
self.r_frequency = None
|
||||||
|
self.r_bandwidth = None
|
||||||
|
self.r_txpower = None
|
||||||
|
self.r_sf = None
|
||||||
|
self.r_cr = None
|
||||||
|
self.r_state = None
|
||||||
|
self.r_lock = None
|
||||||
sleep(2.0)
|
sleep(2.0)
|
||||||
|
|
||||||
thread = threading.Thread(target=self.readLoop)
|
thread = threading.Thread(target=self.readLoop)
|
||||||
thread.daemon = True
|
thread.daemon = True
|
||||||
thread.start()
|
thread.start()
|
||||||
@ -242,7 +253,8 @@ class RNodeInterface(Interface):
|
|||||||
sleep(0.2)
|
sleep(0.2)
|
||||||
|
|
||||||
if not self.detected:
|
if not self.detected:
|
||||||
raise IOError("Could not detect device")
|
RNS.log("Could not detect device for "+str(self), RNS.LOG_ERROR)
|
||||||
|
self.serial.close()
|
||||||
else:
|
else:
|
||||||
if self.platform == KISS.PLATFORM_ESP32:
|
if self.platform == KISS.PLATFORM_ESP32:
|
||||||
self.display = True
|
self.display = True
|
||||||
@ -260,7 +272,6 @@ class RNodeInterface(Interface):
|
|||||||
RNS.log("Make sure that your hardware actually supports the parameters specified in the configuration", RNS.LOG_ERROR)
|
RNS.log("Make sure that your hardware actually supports the parameters specified in the configuration", RNS.LOG_ERROR)
|
||||||
RNS.log("Aborting RNode startup", RNS.LOG_ERROR)
|
RNS.log("Aborting RNode startup", RNS.LOG_ERROR)
|
||||||
self.serial.close()
|
self.serial.close()
|
||||||
raise IOError("RNode interface did not pass configuration validation")
|
|
||||||
|
|
||||||
|
|
||||||
def initRadio(self):
|
def initRadio(self):
|
||||||
@ -395,7 +406,7 @@ class RNodeInterface(Interface):
|
|||||||
|
|
||||||
|
|
||||||
def validateRadioState(self):
|
def validateRadioState(self):
|
||||||
RNS.log("Wating for radio configuration validation for "+str(self)+"...", RNS.LOG_VERBOSE)
|
RNS.log("Waiting for radio configuration validation for "+str(self)+"...", RNS.LOG_VERBOSE)
|
||||||
sleep(0.25);
|
sleep(0.25);
|
||||||
|
|
||||||
self.validcfg = True
|
self.validcfg = True
|
||||||
@ -668,11 +679,17 @@ class RNodeInterface(Interface):
|
|||||||
RNS.log("Reticulum will attempt to reconnect the interface periodically.", RNS.LOG_ERROR)
|
RNS.log("Reticulum will attempt to reconnect the interface periodically.", RNS.LOG_ERROR)
|
||||||
|
|
||||||
self.online = False
|
self.online = False
|
||||||
|
try:
|
||||||
self.serial.close()
|
self.serial.close()
|
||||||
|
except Exception as e:
|
||||||
|
pass
|
||||||
|
|
||||||
|
if not self.detached and not self.reconnecting:
|
||||||
self.reconnect_port()
|
self.reconnect_port()
|
||||||
|
|
||||||
def reconnect_port(self):
|
def reconnect_port(self):
|
||||||
while not self.online:
|
self.reconnecting = True
|
||||||
|
while not self.online and not self.detached:
|
||||||
try:
|
try:
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
RNS.log("Attempting to reconnect serial port "+str(self.port)+" for "+str(self)+"...", RNS.LOG_VERBOSE)
|
RNS.log("Attempting to reconnect serial port "+str(self.port)+" for "+str(self)+"...", RNS.LOG_VERBOSE)
|
||||||
@ -682,10 +699,12 @@ class RNodeInterface(Interface):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
RNS.log("Error while reconnecting port, the contained exception was: "+str(e), RNS.LOG_ERROR)
|
RNS.log("Error while reconnecting port, the contained exception was: "+str(e), RNS.LOG_ERROR)
|
||||||
|
|
||||||
|
self.reconnecting = False
|
||||||
if self.online:
|
if self.online:
|
||||||
RNS.log("Reconnected serial port for "+str(self))
|
RNS.log("Reconnected serial port for "+str(self))
|
||||||
|
|
||||||
def detach(self):
|
def detach(self):
|
||||||
|
self.detached = True
|
||||||
self.disable_external_framebuffer()
|
self.disable_external_framebuffer()
|
||||||
self.setRadioState(KISS.RADIO_STATE_OFF)
|
self.setRadioState(KISS.RADIO_STATE_OFF)
|
||||||
self.leave()
|
self.leave()
|
||||||
|
Loading…
Reference in New Issue
Block a user