From 4c3a874b2131860064f42b0fee2978177460ac4a Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Sun, 3 May 2020 23:06:53 +0200 Subject: [PATCH] Fixed Python2 remnant in interfaces --- RNS/Interfaces/AX25KISSInterface.py | 10 ++++++++-- RNS/Interfaces/KISSInterface.py | 8 +++++++- RNS/Interfaces/RNodeInterface.py | 2 +- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/RNS/Interfaces/AX25KISSInterface.py b/RNS/Interfaces/AX25KISSInterface.py index ca13a96..916f798 100644 --- a/RNS/Interfaces/AX25KISSInterface.py +++ b/RNS/Interfaces/AX25KISSInterface.py @@ -23,6 +23,12 @@ class KISS(): CMD_READY = 0x0F CMD_RETURN = 0xFF + @staticmethod + def escape(data): + data = data.replace(bytes([0xdb]), bytes([0xdb])+bytes([0xdd])) + data = data.replace(bytes([0xc0]), bytes([0xdb])+bytes([0xdc])) + return data + class AX25(): PID_NOLAYER3 = 0xF0 CTRL_UI = 0x03 @@ -245,7 +251,7 @@ class AX25KISSInterface(Interface): in_frame = False escape = False command = KISS.CMD_UNKNOWN - data_buffer = "" + data_buffer = b"" last_read_ms = int(time.time()*1000) while self.serial.is_open: @@ -284,7 +290,7 @@ class AX25KISSInterface(Interface): else: time_since_last = int(time.time()*1000) - last_read_ms if len(data_buffer) > 0 and time_since_last > self.timeout: - data_buffer = "" + data_buffer = b"" in_frame = False command = KISS.CMD_UNKNOWN escape = False diff --git a/RNS/Interfaces/KISSInterface.py b/RNS/Interfaces/KISSInterface.py index e2fef24..d80cb1b 100644 --- a/RNS/Interfaces/KISSInterface.py +++ b/RNS/Interfaces/KISSInterface.py @@ -23,6 +23,12 @@ class KISS(): CMD_READY = 0x0F CMD_RETURN = 0xFF + @staticmethod + def escape(data): + data = data.replace(bytes([0xdb]), bytes([0xdb])+bytes([0xdd])) + data = data.replace(bytes([0xc0]), bytes([0xdb])+bytes([0xdc])) + return data + class KISSInterface(Interface): MAX_CHUNK = 32768 @@ -236,7 +242,7 @@ class KISSInterface(Interface): else: time_since_last = int(time.time()*1000) - last_read_ms if len(data_buffer) > 0 and time_since_last > self.timeout: - data_buffer = "" + data_buffer = b"" in_frame = False command = KISS.CMD_UNKNOWN escape = False diff --git a/RNS/Interfaces/RNodeInterface.py b/RNS/Interfaces/RNodeInterface.py index 76dc82b..7a68056 100644 --- a/RNS/Interfaces/RNodeInterface.py +++ b/RNS/Interfaces/RNodeInterface.py @@ -429,7 +429,7 @@ class RNodeInterface(Interface): time_since_last = int(time.time()*1000) - last_read_ms if len(data_buffer) > 0 and time_since_last > self.timeout: RNS.log(str(self)+" serial read timeout", RNS.LOG_DEBUG) - data_buffer = "" + data_buffer = b"" in_frame = False command = KISS.CMD_UNKNOWN escape = False