Skip to content

Commit

Permalink
Internal interface config handling for RNodeInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
markqvist committed Nov 21, 2024
1 parent 8337a59 commit bf633bb
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 67 deletions.
38 changes: 37 additions & 1 deletion RNS/Interfaces/RNodeInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ def escape(data):

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

FREQ_MIN = 137000000
FREQ_MAX = 3000000000
Expand All @@ -117,7 +118,7 @@ class RNodeInterface(Interface):
BATTERY_STATE_CHARGING = 0x02
BATTERY_STATE_CHARGED = 0x03

def __init__(self, owner, name, port, frequency = None, bandwidth = None, txpower = None, sf = None, cr = None, flow_control = False, id_interval = None, id_callsign = None, st_alock = None, lt_alock = None, ble_addr = None, ble_name = None, force_ble=False):
def __init__(self, owner, configuration):
if RNS.vendor.platformutils.is_android():
raise SystemError("Invalid interface type. The Android-specific RNode interface must be used on Android")

Expand All @@ -131,6 +132,41 @@ def __init__(self, owner, name, port, frequency = None, bandwidth = None, txpowe

super().__init__()

c = configuration
name = c["name"]
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

force_ble = False
ble_name = None
ble_addr = None

port = c["port"] if "port" in c else None

if port == None:
raise ValueError("No port specified for RNode interface")

if port != None:
ble_uri_scheme = "ble://"
if port.lower().startswith(ble_uri_scheme):
force_ble = True
ble_string = port[len(ble_uri_scheme):]
port = None
if len(ble_string) == 0:
pass
elif len(ble_string.split(":")) == 6 and len(ble_string) == 17:
ble_addr = ble_string
else:
ble_name = ble_string

self.HW_MTU = 508

self.pyserial = serial
Expand Down
68 changes: 2 additions & 66 deletions RNS/Reticulum.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,72 +631,8 @@ def interface_post_init(interface):
interface_post_init(interface)

if c["type"] == "RNodeInterface":
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
spreadingfactor = int(c["spreadingfactor"]) if "spreadingfactor" in c else None
codingrate = 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

force_ble = False
ble_name = None
ble_addr = None

port = c["port"] if "port" in c else None

if port == None:
raise ValueError("No port specified for RNode interface")

if port != None:
ble_uri_scheme = "ble://"
if port.lower().startswith(ble_uri_scheme):
force_ble = True
ble_string = port[len(ble_uri_scheme):]
port = None
if len(ble_string) == 0:
pass
elif len(ble_string.split(":")) == 6 and len(ble_string) == 17:
ble_addr = ble_string
else:
ble_name = ble_string

interface = RNodeInterface.RNodeInterface(
RNS.Transport,
name,
port,
frequency = frequency,
bandwidth = bandwidth,
txpower = txpower,
sf = spreadingfactor,
cr = codingrate,
flow_control = flow_control,
id_interval = id_interval,
id_callsign = id_callsign,
st_alock = st_alock,
lt_alock = lt_alock,
ble_addr = ble_addr,
ble_name = ble_name,
force_ble = force_ble,
)

if "outgoing" in c and c.as_bool("outgoing") == False:
interface.OUT = False
else:
interface.OUT = True

interface.mode = interface_mode

interface.announce_cap = announce_cap
if configured_bitrate:
interface.bitrate = configured_bitrate
if ifac_size != None:
interface.ifac_size = ifac_size
else:
interface.ifac_size = 8
interface = RNodeInterface.RNodeInterface(RNS.Transport, interface_config)
interface_post_init(interface)

if c["type"] == "RNodeMultiInterface":
count = 0
Expand Down

0 comments on commit bf633bb

Please sign in to comment.