Skip to content

Commit

Permalink
Prepare interface modularity for Android-specific interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
markqvist committed Nov 21, 2024
1 parent 7b43ff0 commit 760ab98
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 8 deletions.
18 changes: 17 additions & 1 deletion RNS/Interfaces/Android/KISSInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def escape(data):
class KISSInterface(Interface):
MAX_CHUNK = 32768
BITRATE_GUESS = 1200
DEFAULT_IFAC_SIZE = 8

owner = None
port = None
Expand All @@ -61,7 +62,7 @@ class KISSInterface(Interface):
stopbits = 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
if RNS.vendor.platformutils.is_android():
self.on_android = True
Expand All @@ -83,6 +84,21 @@ def __init__(self, owner, name, port, speed, databits, parity, stopbits, preambl
raise SystemError("Android-specific interface was used on non-Android OS")

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

Expand Down
28 changes: 22 additions & 6 deletions RNS/Interfaces/Android/RNodeInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ def write(self, data):

class RNodeInterface(Interface):
MAX_CHUNK = 32768
DEFAULT_IFAC_SIZE = 8

FREQ_MIN = 137000000
FREQ_MAX = 1020000000
Expand Down Expand Up @@ -341,12 +342,27 @@ def bluetooth_control(device_serial = None, port = None, enable_bluetooth = Fals
serial.close()


def __init__(
self, owner, name, port, frequency = None, bandwidth = None, txpower = None,
sf = None, cr = None, flow_control = False, id_interval = None,
allow_bluetooth = False, target_device_name = None,
target_device_address = None, id_callsign = None, st_alock = None, lt_alock = None,
ble_addr = None, ble_name = None, force_ble=False):
def __init__(self, owner, configuration):
c = configuration
name = c["name"]
allow_bluetooth = c["allow_bluetooth"]
target_device_name = c["target_device_name"]
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
if RNS.vendor.platformutils.is_android():
self.on_android = True
Expand Down
14 changes: 13 additions & 1 deletion RNS/Interfaces/Android/SerialInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def escape(data):

class SerialInterface(Interface):
MAX_CHUNK = 32768
DEFAULT_IFAC_SIZE = 8

owner = None
port = None
Expand All @@ -51,7 +52,7 @@ class SerialInterface(Interface):
stopbits = None
serial = None

def __init__(self, owner, name, port, speed, databits, parity, stopbits):
def __init__(self, owner, configuration):
import importlib
if RNS.vendor.platformutils.is_android():
self.on_android = True
Expand All @@ -74,6 +75,17 @@ def __init__(self, owner, name, port, speed, databits, parity, stopbits):

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.pyserial = serial
Expand Down

0 comments on commit 760ab98

Please sign in to comment.