Added better teardown handling on RNodeInterfaces

This commit is contained in:
Mark Qvist 2022-10-30 23:13:44 +01:00
parent 34cdd4bf0f
commit 40cd961eab
2 changed files with 10 additions and 0 deletions

View File

@ -56,6 +56,8 @@ class KISS():
CMD_FB_EXT = 0x41 CMD_FB_EXT = 0x41
CMD_FB_READ = 0x42 CMD_FB_READ = 0x42
CMD_FB_WRITE = 0x43 CMD_FB_WRITE = 0x43
CMD_FB_READL = 0x44
CMD_BT_CTRL = 0x45
CMD_PLATFORM = 0x48 CMD_PLATFORM = 0x48
CMD_MCU = 0x49 CMD_MCU = 0x49
CMD_FW_VERSION = 0x50 CMD_FW_VERSION = 0x50

View File

@ -44,6 +44,7 @@ class KISS():
CMD_RADIO_STATE = 0x06 CMD_RADIO_STATE = 0x06
CMD_RADIO_LOCK = 0x07 CMD_RADIO_LOCK = 0x07
CMD_DETECT = 0x08 CMD_DETECT = 0x08
CMD_LEAVE = 0x0A
CMD_READY = 0x0F CMD_READY = 0x0F
CMD_STAT_RX = 0x21 CMD_STAT_RX = 0x21
CMD_STAT_TX = 0x22 CMD_STAT_TX = 0x22
@ -276,6 +277,12 @@ class RNodeInterface(Interface):
if written != len(kiss_command): if written != len(kiss_command):
raise IOError("An IO error occurred while detecting hardware for "+self(str)) raise IOError("An IO error occurred while detecting hardware for "+self(str))
def leave(self):
kiss_command = bytes([KISS.FEND, KISS.CMD_LEAVE, 0xFF, KISS.FEND])
written = self.serial.write(kiss_command)
if written != len(kiss_command):
raise IOError("An IO error occurred while sending host left command to device")
def enable_external_framebuffer(self): def enable_external_framebuffer(self):
if self.display != None: if self.display != None:
kiss_command = bytes([KISS.FEND, KISS.CMD_FB_EXT, 0x01, KISS.FEND]) kiss_command = bytes([KISS.FEND, KISS.CMD_FB_EXT, 0x01, KISS.FEND])
@ -681,6 +688,7 @@ class RNodeInterface(Interface):
def detach(self): def detach(self):
self.disable_external_framebuffer() self.disable_external_framebuffer()
self.setRadioState(KISS.RADIO_STATE_OFF) self.setRadioState(KISS.RADIO_STATE_OFF)
self.leave()
def __str__(self): def __str__(self):
return "RNodeInterface["+str(self.name)+"]" return "RNodeInterface["+str(self.name)+"]"