''' SRAS Serial Communication Tools Thomas Ales | Feb 2026 Version 1 ''' from threading import Thread from queue import Queue import serial import struct import time class SerialSnooper(Thread): def __init__(self, _port, _spd): super().__init__() self.serial_connection = None self.serial_port = _port self.serial_speed = _spd self.am_listening = False self.rx_msg_queue = Queue() def run(self): ''' run() - Starts up the serial listener, checks if the port was opened successfully, and if so begins listening for APT messages. ''' self.serial_connection = serial.Serial(port=self.serial_port, baudrate=self.serial_speed, rtscts=True, timeout=0.05) if self.serial_connection.is_open is True: # Send disconnect to stop any ongoing auto-updates from # a previous session for addr in [0x11, 0x21, 0x22]: disconnect_msg = struct.pack(' 0: self.serial_connection.read(self.serial_connection.in_waiting) self.am_listening = True _rxbuf = bytearray() while self.am_listening is True: try: # Read whatever is available (or wait up to timeout) _chunk = self.serial_connection.read( max(1, self.serial_connection.in_waiting)) if _chunk: _rxbuf.extend(_chunk) # Process complete messages from the buffer while len(_rxbuf) >= 6: # Check if this is a long message (bit 7 of byte 4) if _rxbuf[4] & 0x80: _msglen = struct.unpack("