Improved RNode bluetooth hotplug

This commit is contained in:
Mark Qvist 2022-12-20 16:02:25 +01:00
parent 990cfb024a
commit c3b9172233

View File

@ -1578,83 +1578,81 @@ class SidebandCore():
# TODO: Add more intelligent selection here # TODO: Add more intelligent selection here
target_device = self.owner_app.usb_devices[0] target_device = self.owner_app.usb_devices[0]
if target_device or self.config["hw_rnode_bluetooth"]: # if target_device or self.config["hw_rnode_bluetooth"]:
if target_device != None: if target_device != None:
target_port = target_device["port"] target_port = target_device["port"]
else: else:
target_port = None target_port = None
bt_device_name = None
rnode_allow_bluetooth = False
if self.getpersistent("permissions.bluetooth"):
if self.config["hw_rnode_bluetooth"]:
RNS.log("Allowing RNode bluetooth", RNS.LOG_DEBUG)
rnode_allow_bluetooth = True
if self.config["hw_rnode_bt_device"] != None:
bt_device_name = self.config["hw_rnode_bt_device"]
bt_device_name = None
rnode_allow_bluetooth = False
if self.getpersistent("permissions.bluetooth"):
if self.config["hw_rnode_bluetooth"]:
RNS.log("Allowing RNode bluetooth", RNS.LOG_DEBUG)
rnode_allow_bluetooth = True
if self.config["hw_rnode_bt_device"] != None:
bt_device_name = self.config["hw_rnode_bt_device"]
else:
RNS.log("Disallowing RNode bluetooth since config is disabled", RNS.LOG_DEBUG)
rnode_allow_bluetooth = False
else: else:
RNS.log("Disallowing RNode bluetooth due to missing permission", RNS.LOG_DEBUG) RNS.log("Disallowing RNode bluetooth since config is disabled", RNS.LOG_DEBUG)
rnode_allow_bluetooth = False rnode_allow_bluetooth = False
else:
RNS.log("Disallowing RNode bluetooth due to missing permission", RNS.LOG_DEBUG)
rnode_allow_bluetooth = False
if self.config["connect_rnode_ifac_netname"] == "":
ifac_netname = None
else:
ifac_netname = self.config["connect_rnode_ifac_netname"]
if self.config["connect_rnode_ifac_passphrase"] == "":
ifac_netkey = None
else:
ifac_netkey = self.config["connect_rnode_ifac_passphrase"]
if self.config["connect_rnode_ifac_netname"] == "": rnodeinterface = RNS.Interfaces.Android.RNodeInterface.RNodeInterface(
ifac_netname = None RNS.Transport,
else: "RNodeInterface",
ifac_netname = self.config["connect_rnode_ifac_netname"] target_port,
frequency = self.config["hw_rnode_frequency"],
bandwidth = self.config["hw_rnode_bandwidth"],
txpower = self.config["hw_rnode_tx_power"],
sf = self.config["hw_rnode_spreading_factor"],
cr = self.config["hw_rnode_coding_rate"],
flow_control = None,
id_interval = self.config["hw_rnode_beaconinterval"],
id_callsign = self.config["hw_rnode_beacondata"],
allow_bluetooth = rnode_allow_bluetooth,
target_device_name = bt_device_name,
)
if self.config["connect_rnode_ifac_passphrase"] == "": rnodeinterface.OUT = True
ifac_netkey = None
else:
ifac_netkey = self.config["connect_rnode_ifac_passphrase"]
rnodeinterface = RNS.Interfaces.Android.RNodeInterface.RNodeInterface( if RNS.Reticulum.transport_enabled():
RNS.Transport, if_mode = Interface.Interface.MODE_FULL
"RNodeInterface", if self.config["connect_ifmode_rnode"] == "gateway":
target_port, if_mode = Interface.Interface.MODE_GATEWAY
frequency = self.config["hw_rnode_frequency"], elif self.config["connect_ifmode_rnode"] == "access point":
bandwidth = self.config["hw_rnode_bandwidth"], if_mode = Interface.Interface.MODE_ACCESS_POINT
txpower = self.config["hw_rnode_tx_power"], elif self.config["connect_ifmode_rnode"] == "roaming":
sf = self.config["hw_rnode_spreading_factor"], if_mode = Interface.Interface.MODE_ROAMING
cr = self.config["hw_rnode_coding_rate"], elif self.config["connect_ifmode_rnode"] == "boundary":
flow_control = None, if_mode = Interface.Interface.MODE_BOUNDARY
id_interval = self.config["hw_rnode_beaconinterval"], else:
id_callsign = self.config["hw_rnode_beacondata"], if_mode = None
allow_bluetooth = rnode_allow_bluetooth,
target_device_name = bt_device_name, self.reticulum._add_interface(rnodeinterface, mode = if_mode, ifac_netname = ifac_netname, ifac_netkey = ifac_netkey)
) self.interface_rnode = rnodeinterface
rnodeinterface.OUT = True if rnodeinterface != None:
if len(rnodeinterface.hw_errors) > 0:
self.setpersistent("startup.errors.rnode", rnodeinterface.hw_errors[0])
if RNS.Reticulum.transport_enabled(): if self.interface_rnode.online:
if_mode = Interface.Interface.MODE_FULL self.interface_rnode.display_image(sideband_fb_data)
if self.config["connect_ifmode_rnode"] == "gateway": self.interface_rnode.enable_external_framebuffer()
if_mode = Interface.Interface.MODE_GATEWAY else:
elif self.config["connect_ifmode_rnode"] == "access point": self.interface_rnode.last_imagedata = sideband_fb_data
if_mode = Interface.Interface.MODE_ACCESS_POINT
elif self.config["connect_ifmode_rnode"] == "roaming":
if_mode = Interface.Interface.MODE_ROAMING
elif self.config["connect_ifmode_rnode"] == "boundary":
if_mode = Interface.Interface.MODE_BOUNDARY
else:
if_mode = None
self.reticulum._add_interface(rnodeinterface, mode = if_mode, ifac_netname = ifac_netname, ifac_netkey = ifac_netkey)
self.interface_rnode = rnodeinterface
if rnodeinterface != None:
if len(rnodeinterface.hw_errors) > 0:
self.setpersistent("startup.errors.rnode", rnodeinterface.hw_errors[0])
if self.interface_rnode.online:
self.interface_rnode.display_image(sideband_fb_data)
self.interface_rnode.enable_external_framebuffer()
else:
self.interface_rnode.last_imagedata = sideband_fb_data
except Exception as e: except Exception as e:
RNS.log("Error while adding RNode Interface. The contained exception was: "+str(e)) RNS.log("Error while adding RNode Interface. The contained exception was: "+str(e))