From deffcae4199ffc72e07378dc420ce4dc1ea5f37a Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Wed, 27 Jun 2018 10:15:39 +0200 Subject: [PATCH] RNode interface updates --- RNS/Interfaces/RNodeInterface.py | 32 ++++++++++++++++++++++++++------ RNS/Link.py | 3 +-- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/RNS/Interfaces/RNodeInterface.py b/RNS/Interfaces/RNodeInterface.py index 5481be5..0c56cf7 100644 --- a/RNS/Interfaces/RNodeInterface.py +++ b/RNS/Interfaces/RNodeInterface.py @@ -20,22 +20,30 @@ class KISS(): CMD_BANDWIDTH = chr(0x02) CMD_TXPOWER = chr(0x03) CMD_SF = chr(0x04) - CMD_RADIO_STATE = chr(0x05) - CMD_RADIO_LOCK = chr(0x06) + CMD_CR = chr(0x05) + CMD_RADIO_STATE = chr(0x06) + CMD_RADIO_LOCK = chr(0x07) + CMD_DETECT = chr(0x08) CMD_READY = chr(0x0F) CMD_STAT_RX = chr(0x21) CMD_STAT_TX = chr(0x22) CMD_STAT_RSSI = chr(0x23) CMD_BLINK = chr(0x30) CMD_RANDOM = chr(0x40) + CMD_FW_VERSION = chr(0x50) + CMD_ROM_READ = chr(0x51) + + DETECT_REQ = chr(0x73) + DETECT_RESP = chr(0x46) RADIO_STATE_OFF = chr(0x00) RADIO_STATE_ON = chr(0x01) RADIO_STATE_ASK = chr(0xFF) - CMD_ERROR = chr(0x90) - ERROR_INITRADIO = chr(0x01) - ERROR_TXFAILED = chr(0x02) + CMD_ERROR = chr(0x90) + ERROR_INITRADIO = chr(0x01) + ERROR_TXFAILED = chr(0x02) + ERROR_EEPROM_LOCKED = chr(0x03) @staticmethod def escape(data): @@ -74,7 +82,7 @@ class RNodeInterface(Interface): self.bandwidth = bandwidth self.txpower = txpower self.sf = sf - self.cr = 5 # Coding rate is hard-coded in firmware for now + self.cr = 5 self.state = KISS.RADIO_STATE_OFF self.bitrate = 0 @@ -82,6 +90,7 @@ class RNodeInterface(Interface): self.r_bandwidth = None self.r_txpower = None self.r_sf = None + self.r_cr = None self.r_state = None self.r_lock = None self.r_stat_rx = None @@ -200,6 +209,13 @@ class RNodeInterface(Interface): if written != len(kiss_command): raise IOError("An IO error occurred while configuring spreading factor for "+self(str)) + def setCodingRate(self): + cr = chr(self.cr) + kiss_command = KISS.FEND+KISS.CMD_CR+cr+KISS.FEND + written = self.serial.write(kiss_command) + if written != len(kiss_command): + raise IOError("An IO error occurred while configuring coding rate for "+self(str)) + def setRadioState(self, state): kiss_command = KISS.FEND+KISS.CMD_RADIO_STATE+state+KISS.FEND written = self.serial.write(kiss_command) @@ -342,6 +358,10 @@ class RNodeInterface(Interface): self.r_sf = ord(byte) RNS.log(str(self)+" Radio reporting spreading factor is "+str(self.r_sf), RNS.LOG_DEBUG) self.updateBitrate() + elif (command == KISS.CMD_CR): + self.r_cr = ord(byte) + RNS.log(str(self)+" Radio reporting coding rate is "+str(self.r_cr), RNS.LOG_DEBUG) + self.updateBitrate() elif (command == KISS.CMD_RADIO_STATE): self.r_state = ord(byte) elif (command == KISS.CMD_RADIO_LOCK): diff --git a/RNS/Link.py b/RNS/Link.py index dc868b3..94d4c28 100644 --- a/RNS/Link.py +++ b/RNS/Link.py @@ -191,8 +191,6 @@ class Link: RNS.log("Link "+str(self)+" established with "+str(self.destination)+", RTT is "+str(self.rtt), RNS.LOG_VERBOSE) rtt_data = umsgpack.packb(self.rtt) rtt_packet = RNS.Packet(self, rtt_data, context=RNS.Packet.LRRTT) - # TODO: remove - RNS.log("Sending RTT packet", RNS.LOG_EXTREME) rtt_packet.send() self.status = Link.ACTIVE @@ -437,6 +435,7 @@ class Link: return plaintext except Exception as e: RNS.log("Decryption failed on link "+str(self)+". The contained exception was: "+str(e), RNS.LOG_ERROR) + traceback.print_exc() def sign(self, message): return self.prv.sign(message, ec.ECDSA(hashes.SHA256()))