From 0a4dd64434089a5721da878e22b90c67e572c6bc Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Sat, 22 Jan 2022 21:36:49 +0100 Subject: [PATCH] Improved support for ESP32-based RNodes --- RNS/Interfaces/RNodeInterface.py | 26 +++++++++++++++++--------- RNS/Reticulum.py | 2 -- RNS/__init__.py | 5 +++++ 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/RNS/Interfaces/RNodeInterface.py b/RNS/Interfaces/RNodeInterface.py index 7e009d7..5f0663c 100644 --- a/RNS/Interfaces/RNodeInterface.py +++ b/RNS/Interfaces/RNodeInterface.py @@ -223,7 +223,7 @@ class RNodeInterface(Interface): 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) self.serial.close() - raise IOError("RNode interface did not pass validation") + raise IOError("RNode interface did not pass configuration validation") def initRadio(self): @@ -245,7 +245,7 @@ class RNodeInterface(Interface): written = self.serial.write(kiss_command) if written != len(kiss_command): raise IOError("An IO error occurred while restarting device") - sleep(2); + sleep(2.25); def setFrequency(self): c1 = self.frequency >> 24 @@ -293,13 +293,14 @@ class RNodeInterface(Interface): raise IOError("An IO error occurred while configuring coding rate for "+self(str)) def setRadioState(self, state): + self.state = state kiss_command = bytes([KISS.FEND])+bytes([KISS.CMD_RADIO_STATE])+bytes([state])+bytes([KISS.FEND]) written = self.serial.write(kiss_command) if written != len(kiss_command): raise IOError("An IO error occurred while configuring radio state for "+self(str)) def validateRadioState(self): - RNS.log("Validating radio configuration for "+str(self)+"...", RNS.LOG_VERBOSE) + RNS.log("Wating for radio configuration validation for "+str(self)+"...", RNS.LOG_VERBOSE) sleep(0.25); if (self.frequency != self.r_frequency): RNS.log("Frequency mismatch", RNS.LOG_ERROR) @@ -313,6 +314,9 @@ class RNodeInterface(Interface): if (self.sf != self.r_sf): RNS.log("Spreading factor mismatch", RNS.LOG_ERROR) self.validcfg = False + if (self.state != self.r_state): + RNS.log("Radio state mismatch", RNS.LOG_ERROR) + self.validcfg = False if (self.validcfg): return True @@ -453,10 +457,11 @@ class RNodeInterface(Interface): self.updateBitrate() elif (command == KISS.CMD_RADIO_STATE): self.r_state = byte - # if self.r_state: - # RNS.log(str(self)+" Radio reporting state is online ("+RNS.hexrep([self.r_state])+")", RNS.LOG_DEBUG) - # else: - # RNS.log(str(self)+" Radio reporting state is offline ("+RNS.hexrep([self.r_state])+")", RNS.LOG_DEBUG) + if self.r_state: + pass + #RNS.log(str(self)+" Radio reporting state is online", RNS.LOG_DEBUG) + else: + RNS.log(str(self)+" Radio reporting state is offline", RNS.LOG_DEBUG) elif (command == KISS.CMD_RADIO_LOCK): self.r_lock = byte @@ -501,10 +506,13 @@ class RNodeInterface(Interface): elif (command == KISS.CMD_ERROR): if (byte == KISS.ERROR_INITRADIO): RNS.log(str(self)+" hardware initialisation error (code "+RNS.hexrep(byte)+")", RNS.LOG_ERROR) + raise IOError("Radio initialisation failure") elif (byte == KISS.ERROR_INITRADIO): RNS.log(str(self)+" hardware TX error (code "+RNS.hexrep(byte)+")", RNS.LOG_ERROR) + raise IOError("Hardware transmit failure") else: RNS.log(str(self)+" hardware error (code "+RNS.hexrep(byte)+")", RNS.LOG_ERROR) + raise IOError("Unknown hardware failure") elif (command == KISS.CMD_RESET): if (byte == 0xF8): if self.platform == KISS.PLATFORM_ESP32: @@ -540,7 +548,7 @@ class RNodeInterface(Interface): self.online = False RNS.log("A serial port error occurred, the contained exception was: "+str(e), RNS.LOG_ERROR) RNS.log("The interface "+str(self)+" experienced an unrecoverable error and is now offline.", RNS.LOG_ERROR) - + if RNS.Reticulum.panic_on_interface_error: RNS.panic() @@ -564,5 +572,5 @@ class RNodeInterface(Interface): RNS.log("Reconnected serial port for "+str(self)) def __str__(self): - return "RNodeInterface["+self.name+"]" + return "RNodeInterface["+str(self.name)+"]" diff --git a/RNS/Reticulum.py b/RNS/Reticulum.py index 7f6d72e..5f1cbde 100755 --- a/RNS/Reticulum.py +++ b/RNS/Reticulum.py @@ -541,8 +541,6 @@ class Reticulum: except Exception as e: RNS.log("The interface \""+name+"\" could not be created. Check your configuration file for errors!", RNS.LOG_ERROR) RNS.log("The contained exception was: "+str(e), RNS.LOG_ERROR) - # TODO: Remove - raise e RNS.panic() else: RNS.log("The interface name \""+name+"\" was already used. Check your configuration file for errors!", RNS.LOG_ERROR) diff --git a/RNS/__init__.py b/RNS/__init__.py index 33084da..40eeaf3 100755 --- a/RNS/__init__.py +++ b/RNS/__init__.py @@ -109,6 +109,11 @@ def rand(): return result def hexrep(data, delimit=True): + try: + iter(data) + except TypeError: + data = [data] + delimiter = ":" if not delimit: delimiter = ""