Added UV-K1 support

This commit is contained in:
Mark Qvist 2026-11-28 22:30:05 +01:00
parent 606a16911d
commit 20bd15cdf6
No known key found for this signature in database

View file

@ -169,7 +169,7 @@ class KISSInterface(Interface):
except Exception as e: RNS.log(f"Could not close port for {self} at detach: {e}", RNS.LOG_ERROR)
def open_port(self):
RNS.log("Opening serial port "+self.port+"...")
RNS.log("Opening serial port "+self.port+"...", RNS.LOG_DEBUG)
# Get device parameters
from usb4a import usb
device = usb.get_usb_device(self.port)
@ -185,6 +185,12 @@ class KISSInterface(Interface):
from usbserial4a.cdcacmserial4a import CdcAcmSerial
proxy = CdcAcmSerial
if vid == 0x36B7:
# Force CDC driver for UV-K1 radios
RNS.log(str(self)+" using CDC driver for "+RNS.hexrep(vid)+":"+RNS.hexrep(pid), RNS.LOG_DEBUG)
from usbserial4a.cdcacmserial4a import CdcAcmSerial
proxy = CdcAcmSerial
self.serial = proxy(
self.port,
baudrate = self.speed,
@ -214,6 +220,12 @@ class KISSInterface(Interface):
self.serial.DEFAULT_READ_BUFFER_SIZE = 64
self.serial.USB_READ_TIMEOUT_MILLIS = 12
self.serial.timeout = 0.1
elif vid == 0x36B7:
# Hardware parameters for UV-K1 radios
self.serial.DEFAULT_READ_BUFFER_SIZE = 64
self.serial.DEFAULT_WRITE_BUFFER_SIZE = 64
self.serial.USB_READ_TIMEOUT_MILLIS = 12
self.serial.timeout = 0.1
else:
# Default values
self.serial.DEFAULT_READ_BUFFER_SIZE = 1 * 1024
@ -319,7 +331,20 @@ class KISSInterface(Interface):
data = data.replace(bytes([0xc0]), bytes([0xdb])+bytes([0xdc]))
frame = bytes([KISS.FEND])+bytes([0x00])+data+bytes([KISS.FEND])
written = self.serial.write(frame)
try: written = self.serial.write(frame)
except Exception as e:
self.online = False
RNS.log(f"A serial port write error occurred, the contained exception was: {e}", RNS.LOG_ERROR)
RNS.log(f"The interface {self} experienced an unrecoverable error and is now offline.", RNS.LOG_ERROR)
if RNS.Reticulum.panic_on_interface_error: RNS.panic()
RNS.log("Reticulum will attempt to reconnect the interface periodically.", RNS.LOG_ERROR)
self.online = False
try: self.serial.close()
except Exception as e: RNS.log(f"Could not close port for {self}", RNS.LOG_ERROR)
if not self.detached and not self.reconnecting: self.reconnect_port()
return
self.txb += datalen
if data == self.beacon_d:
@ -419,10 +444,7 @@ class KISSInterface(Interface):
self.online = False
RNS.log("A serial port error occurred, the contained exception was: "+str(e), RNS.LOG_ERROR)
RNS.log("The interface "+str(self)+" experienced an unrecoverable error and is now offline.", RNS.LOG_ERROR)
if RNS.Reticulum.panic_on_interface_error:
RNS.panic()
if RNS.Reticulum.panic_on_interface_error: RNS.panic()
RNS.log("Reticulum will attempt to reconnect the interface periodically.", RNS.LOG_ERROR)
self.online = False
@ -431,11 +453,12 @@ class KISSInterface(Interface):
if not self.detached and not self.reconnecting: self.reconnect_port()
def reconnect_port(self):
if self.reconnecting: return
self.reconnecting = True
while not self.online:
try:
time.sleep(5)
RNS.log("Attempting to reconnect serial port "+str(self.port)+" for "+str(self)+"...", RNS.LOG_VERBOSE)
RNS.log("Attempting to reconnect serial port "+str(self.port)+" for "+str(self)+"...", RNS.LOG_DEBUG)
self.open_port()
if self.serial.is_open: self.configure_device()
except Exception as e: RNS.log("Error while reconnecting port, the contained exception was: "+str(e), RNS.LOG_ERROR)