Added support for RNode interfaces on Android

This commit is contained in:
Mark Qvist 2022-10-11 14:06:42 +02:00
parent 1141a3034d
commit 372bedcd85
2 changed files with 52 additions and 22 deletions

View File

@ -102,12 +102,21 @@ class RNodeInterface(Interface):
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): 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):
import importlib import importlib
if importlib.util.find_spec('serial') != None: if not RNS.vendor.platformutils.is_android():
import serial if importlib.util.find_spec('serial') != None:
import serial
self.parity = serial.PARITY_NONE
else:
RNS.log("Using the RNode interface requires a serial communication module to be installed.", RNS.LOG_CRITICAL)
RNS.log("You can install one with the command: python3 -m pip install pyserial", RNS.LOG_CRITICAL)
RNS.panic()
else: else:
RNS.log("Using the RNode interface requires a serial communication module to be installed.", RNS.LOG_CRITICAL) if importlib.util.find_spec('usbserial4a') != None:
RNS.log("You can install one with the command: python3 -m pip install pyserial", RNS.LOG_CRITICAL) from usbserial4a import serial4a as serial
RNS.panic() self.parity = "N"
else:
RNS.log("Could not load USB serial module for Android, RNode interface cannot be created.", RNS.LOG_CRITICAL)
RNS.panic()
self.rxb = 0 self.rxb = 0
self.txb = 0 self.txb = 0
@ -121,7 +130,6 @@ class RNodeInterface(Interface):
self.port = port self.port = port
self.speed = 115200 self.speed = 115200
self.databits = 8 self.databits = 8
self.parity = serial.PARITY_NONE
self.stopbits = 1 self.stopbits = 1
self.timeout = 100 self.timeout = 100
self.online = False self.online = False
@ -214,20 +222,34 @@ class RNodeInterface(Interface):
def open_port(self): def open_port(self):
RNS.log("Opening serial port "+self.port+"...") RNS.log("Opening serial port "+self.port+"...")
self.serial = self.pyserial.Serial( if not RNS.vendor.platformutils.is_android():
port = self.port, self.serial = self.pyserial.Serial(
baudrate = self.speed, port = self.port,
bytesize = self.databits, baudrate = self.speed,
parity = self.parity, bytesize = self.databits,
stopbits = self.stopbits, parity = self.parity,
xonxoff = False, stopbits = self.stopbits,
rtscts = False, xonxoff = False,
timeout = 0, rtscts = False,
inter_byte_timeout = None, timeout = 0,
write_timeout = None, inter_byte_timeout = None,
dsrdtr = False, write_timeout = None,
) dsrdtr = False,
)
else:
self.serial = self.pyserial.get_serial_port(
self.port,
baudrate = self.speed,
bytesize = self.databits,
parity = self.parity,
stopbits = self.stopbits,
xonxoff = False,
rtscts = False,
timeout = 0,
inter_byte_timeout = None,
write_timeout = None,
dsrdtr = False,
)
def configure_device(self): def configure_device(self):
sleep(2.0) sleep(2.0)
@ -236,7 +258,10 @@ class RNodeInterface(Interface):
thread.start() thread.start()
self.detect() self.detect()
sleep(0.1) if not RNS.vendor.platformutils.is_android():
sleep(0.1)
else:
sleep(0.25)
if not self.detected: if not self.detected:
raise IOError("Could not detect device") raise IOError("Could not detect device")
@ -350,7 +375,11 @@ class RNodeInterface(Interface):
def validateRadioState(self): def validateRadioState(self):
RNS.log("Wating for radio configuration validation for "+str(self)+"...", RNS.LOG_VERBOSE) RNS.log("Wating for radio configuration validation for "+str(self)+"...", RNS.LOG_VERBOSE)
sleep(0.25); if not RNS.vendor.platformutils.is_android():
sleep(0.25);
else:
sleep(1.00);
if (self.frequency != self.r_frequency): if (self.frequency != self.r_frequency):
RNS.log("Frequency mismatch", RNS.LOG_ERROR) RNS.log("Frequency mismatch", RNS.LOG_ERROR)
self.validcfg = False self.validcfg = False

View File

@ -29,6 +29,7 @@ if get_platform() == "android":
from .Interfaces import TCPInterface from .Interfaces import TCPInterface
from .Interfaces import UDPInterface from .Interfaces import UDPInterface
from .Interfaces import I2PInterface from .Interfaces import I2PInterface
from .Interfaces import RNodeInterface
else: else:
from .Interfaces import * from .Interfaces import *