Skip to content

Commit

Permalink
Prepare interface modularity
Browse files Browse the repository at this point in the history
  • Loading branch information
markqvist committed Nov 21, 2024
1 parent 760ab98 commit a762af0
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 31 deletions.
2 changes: 1 addition & 1 deletion RNS/Interfaces/AX25KISSInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def __init__(self, owner, configuration):

super().__init__()

c = configuration
c = Interface.get_config_obj(configuration)
name = c["name"]
preamble = int(c["preamble"]) if "preamble" in c else None
txtail = int(c["txtail"]) if "txtail" in c else None
Expand Down
2 changes: 1 addition & 1 deletion RNS/Interfaces/Android/KISSInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def __init__(self, owner, configuration):

super().__init__()

c = configuration
c = Interface.get_config_obj(configuration)
name = c["name"]
preamble = int(c["preamble"]) if "preamble" in c else None
txtail = int(c["txtail"]) if "txtail" in c else None
Expand Down
2 changes: 1 addition & 1 deletion RNS/Interfaces/Android/RNodeInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ def bluetooth_control(device_serial = None, port = None, enable_bluetooth = Fals


def __init__(self, owner, configuration):
c = configuration
c = Interface.get_config_obj(configuration)
name = c["name"]
allow_bluetooth = c["allow_bluetooth"]
target_device_name = c["target_device_name"]
Expand Down
2 changes: 1 addition & 1 deletion RNS/Interfaces/Android/SerialInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def __init__(self, owner, configuration):

super().__init__()

c = configuration
c = Interface.get_config_obj(configuration)
name = c["name"]
port = c["port"] if "port" in c else None
speed = int(c["speed"]) if "speed" in c else 9600
Expand Down
4 changes: 2 additions & 2 deletions RNS/Interfaces/AutoInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def interface_name_to_index(self, ifname):
return socket.if_nametoindex(ifname)

def __init__(self, owner, configuration):
c = configuration
c = Interface.get_config_obj(configuration)
name = c["name"]
group_id = c["group_id"] if "group_id" in c else None
discovery_scope = c["discovery_scope"] if "discovery_scope" in c else None
Expand All @@ -97,7 +97,7 @@ def __init__(self, owner, configuration):
data_port = int(c["data_port"]) if "data_port" in c else None
allowed_interfaces = c.as_list("devices") if "devices" in c else None
ignored_interfaces = c.as_list("ignored_devices") if "ignored_devices" in c else None
configured_bitrate = c["configured_bitrate"]
configured_bitrate = c["configured_bitrate"] if "configured_bitrate" in c else None

from RNS.vendor.ifaddr import niwrapper
super().__init__()
Expand Down
8 changes: 4 additions & 4 deletions RNS/Interfaces/I2PInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -834,14 +834,14 @@ class I2PInterface(Interface):
def __init__(self, owner, configuration):
super().__init__()

c = configuration
c = Interface.get_config_obj(configuration)
name = c["name"]
rns_storagepath = c["storagepath"]
peers = c.as_list("peers") if "peers" in c else None
connectable = c.as_bool("connectable") if "connectable" in c else False
ifac_size = c["ifac_size"]
ifac_netname = c["ifac_netname"]
ifac_netkey = c["ifac_netkey"]
ifac_size = c["ifac_size"] if "ifac_size" in c else None
ifac_netname = c["ifac_netname"] if "ifac_netname" in c else None
ifac_netkey = c["ifac_netkey"] if "ifac_netkey" in c else None

self.HW_MTU = 1064

Expand Down
14 changes: 13 additions & 1 deletion RNS/Interfaces/Interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import time
import threading
from collections import deque
from RNS.vendor.configobj import ConfigObj

class Interface:
IN = False
Expand Down Expand Up @@ -238,4 +239,15 @@ def process_announce_queue(self):
RNS.log("The announce queue for this interface has been cleared.", RNS.LOG_ERROR)

def detach(self):
pass
pass

@staticmethod
def get_config_obj(config_in):
if type(config_in) == ConfigObj:
return config_in
else:
try:
return ConfigObj(config_in)
except Exception as e:
RNS.log(f"Could not parse supplied configuration data. The contained exception was: {e}", RNS.LOG_ERROR)
raise SystemError("Invalid configuration data supplied")
2 changes: 1 addition & 1 deletion RNS/Interfaces/KISSInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def __init__(self, owner, configuration):

super().__init__()

c = configuration
c = Interface.get_config_obj(configuration)
name = c["name"]
preamble = int(c["preamble"]) if "preamble" in c else None
txtail = int(c["txtail"]) if "txtail" in c else None
Expand Down
2 changes: 1 addition & 1 deletion RNS/Interfaces/PipeInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class PipeInterface(Interface):
def __init__(self, owner, configuration):
super().__init__()

c = configuration
c = Interface.get_config_obj(configuration)
name = c["name"]
command = c["command"] if "command" in c else None
respawn_delay = c.as_float("respawn_delay") if "respawn_delay" in c else None
Expand Down
22 changes: 11 additions & 11 deletions RNS/Interfaces/RNodeInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,18 +132,18 @@ def __init__(self, owner, configuration):

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
c = Interface.get_config_obj(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
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
Expand Down
2 changes: 1 addition & 1 deletion RNS/Interfaces/RNodeMultiInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def __init__(self, owner, configuration):

super().__init__()

c = configuration
c = Interface.get_config_obj(configuration)
name = c["name"]

count = 0
Expand Down
2 changes: 1 addition & 1 deletion RNS/Interfaces/SerialInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def __init__(self, owner, configuration):

super().__init__()

c = configuration
c = Interface.get_config_obj(configuration)
name = c["name"]
port = c["port"] if "port" in c else None
speed = int(c["speed"]) if "speed" in c else 9600
Expand Down
8 changes: 4 additions & 4 deletions RNS/Interfaces/TCPInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ class TCPClientInterface(Interface):
def __init__(self, owner, configuration, connected_socket=None):
super().__init__()

c = configuration
c = Interface.get_config_obj(configuration)
name = c["name"]
target_ip = c["target_host"]
target_port = int(c["target_port"])
target_ip = c["target_host"] if "target_host" in c else None
target_port = int(c["target_port"]) if "target_port" in c else None
kiss_framing = False
if "kiss_framing" in c and c.as_bool("kiss_framing") == True:
kiss_framing = True
Expand Down Expand Up @@ -468,7 +468,7 @@ def get_address_for_host(name, bind_port):
def __init__(self, owner, configuration):
super().__init__()

c = configuration
c = Interface.get_config_obj(configuration)
name = c["name"]
device = c["device"] if "device" in c else None
port = int(c["port"]) if "port" in c else None
Expand Down
2 changes: 1 addition & 1 deletion RNS/Interfaces/UDPInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def get_broadcast_for_if(name):
def __init__(self, owner, configuration):
super().__init__()

c = configuration
c = Interface.get_config_obj(configuration)
name = c["name"]
device = c["device"] if "device" in c else None
port = int(c["port"]) if "port" in c else None
Expand Down

0 comments on commit a762af0

Please sign in to comment.