Prepare interface modularity for Android-specific interfaces

This commit is contained in:
Mark Qvist 2024-11-21 13:51:34 +01:00
parent 7b43ff0cef
commit 760ab981d0
3 changed files with 52 additions and 8 deletions

View File

@ -52,6 +52,7 @@ class KISS():
class KISSInterface(Interface): class KISSInterface(Interface):
MAX_CHUNK = 32768 MAX_CHUNK = 32768
BITRATE_GUESS = 1200 BITRATE_GUESS = 1200
DEFAULT_IFAC_SIZE = 8
owner = None owner = None
port = None port = None
@ -61,7 +62,7 @@ class KISSInterface(Interface):
stopbits = None stopbits = None
serial = None serial = None
def __init__(self, owner, name, port, speed, databits, parity, stopbits, preamble, txtail, persistence, slottime, flow_control, beacon_interval, beacon_data): def __init__(self, owner, configuration):
import importlib import importlib
if RNS.vendor.platformutils.is_android(): if RNS.vendor.platformutils.is_android():
self.on_android = True self.on_android = True
@ -83,6 +84,21 @@ class KISSInterface(Interface):
raise SystemError("Android-specific interface was used on non-Android OS") raise SystemError("Android-specific interface was used on non-Android OS")
super().__init__() super().__init__()
c = configuration
name = c["name"]
preamble = int(c["preamble"]) if "preamble" in c else None
txtail = int(c["txtail"]) if "txtail" in c else None
persistence = int(c["persistence"]) if "persistence" in c else None
slottime = int(c["slottime"]) if "slottime" in c else None
flow_control = c.as_bool("flow_control") if "flow_control" in c else False
port = c["port"] if "port" in c else None
speed = int(c["speed"]) if "speed" in c else 9600
databits = int(c["databits"]) if "databits" in c else 8
parity = c["parity"] if "parity" in c else "N"
stopbits = int(c["stopbits"]) if "stopbits" in c else 1
beacon_interval = int(c["beacon_interval"]) if "beacon_interval" in c else None
beacon_data = c["beacon_data"] if "beacon_data" in c else None
self.HW_MTU = 564 self.HW_MTU = 564

View File

@ -238,6 +238,7 @@ class AndroidBluetoothManager():
class RNodeInterface(Interface): class RNodeInterface(Interface):
MAX_CHUNK = 32768 MAX_CHUNK = 32768
DEFAULT_IFAC_SIZE = 8
FREQ_MIN = 137000000 FREQ_MIN = 137000000
FREQ_MAX = 1020000000 FREQ_MAX = 1020000000
@ -341,12 +342,27 @@ class RNodeInterface(Interface):
serial.close() serial.close()
def __init__( def __init__(self, owner, configuration):
self, owner, name, port, frequency = None, bandwidth = None, txpower = None, c = configuration
sf = None, cr = None, flow_control = False, id_interval = None, name = c["name"]
allow_bluetooth = False, target_device_name = None, allow_bluetooth = c["allow_bluetooth"]
target_device_address = None, id_callsign = None, st_alock = None, lt_alock = None, target_device_name = c["target_device_name"]
ble_addr = None, ble_name = None, force_ble=False): target_device_address = c["target_device_address"]
ble_name = c["ble_name"]
ble_addr = c["ble_addr"]
force_ble = c["force_ble"]
frequency = int(c["frequency"]) if "frequency" in c else None
bandwidth = int(c["bandwidth"]) if "bandwidth" in c else None
txpower = int(c["txpower"]) if "txpower" in c else None
sf = int(c["spreadingfactor"]) if "spreadingfactor" in c else None
cr = int(c["codingrate"]) if "codingrate" in c else None
flow_control = c.as_bool("flow_control") if "flow_control" in c else False
id_interval = int(c["id_interval"]) if "id_interval" in c else None
id_callsign = c["id_callsign"] if "id_callsign" in c else None
st_alock = float(c["airtime_limit_short"]) if "airtime_limit_short" in c else None
lt_alock = float(c["airtime_limit_long"]) if "airtime_limit_long" in c else None
port = c["port"] if "port" in c else None
import importlib import importlib
if RNS.vendor.platformutils.is_android(): if RNS.vendor.platformutils.is_android():
self.on_android = True self.on_android = True

View File

@ -42,6 +42,7 @@ class HDLC():
class SerialInterface(Interface): class SerialInterface(Interface):
MAX_CHUNK = 32768 MAX_CHUNK = 32768
DEFAULT_IFAC_SIZE = 8
owner = None owner = None
port = None port = None
@ -51,7 +52,7 @@ class SerialInterface(Interface):
stopbits = None stopbits = None
serial = None serial = None
def __init__(self, owner, name, port, speed, databits, parity, stopbits): def __init__(self, owner, configuration):
import importlib import importlib
if RNS.vendor.platformutils.is_android(): if RNS.vendor.platformutils.is_android():
self.on_android = True self.on_android = True
@ -74,6 +75,17 @@ class SerialInterface(Interface):
super().__init__() super().__init__()
c = configuration
name = c["name"]
port = c["port"] if "port" in c else None
speed = int(c["speed"]) if "speed" in c else 9600
databits = int(c["databits"]) if "databits" in c else 8
parity = c["parity"] if "parity" in c else "N"
stopbits = int(c["stopbits"]) if "stopbits" in c else 1
if port == None:
raise ValueError("No port specified for serial interface")
self.HW_MTU = 564 self.HW_MTU = 564
self.pyserial = serial self.pyserial = serial