def send_control_message(self, message): self.scheme.write_one_message(message, self.control_connection) resp = self.read_one_control_message() if resp: return resp else: # timed out waiting for response -> list error as invalid message m = Message() m.valid = False m.error = "Timeout"
def get_veh_flash(self, names_list): m = Message({ 'msgtype': b'VEH', 'mode': READ_FLASH, 'configurations': names_list }) return self.send_control_message(m)
def set_veh_flash(self, configurations): m = Message({ 'msgtype': b'VEH', 'mode': WRITE_FLASH, 'configurations': configurations }) return self.send_control_message(m)
def get_cfg(self, names_list): m = Message({ 'msgtype': b'CFG', 'mode': READ_RAM, 'configurations': names_list }) return self.send_control_message(m)
def set_cfg(self, configurations): m = Message({ 'msgtype': b'CFG', 'mode': WRITE_RAM, 'configurations': configurations }) return self.send_control_message(m)
def read_one_message(self, connection): # UDPConnection doesn't have a read_until, it reads entire lines. So need different handling here # TODO - moving read_one_message into connection class might be more tidy. then it needs to know start/end codes if type(connection) is UDPConnection: data = connection.readall( ) #TODO does it need a read until end char function? else: before = connection.read_until(READABLE_START) #TODO can handle partial start on whatever came before start code data = connection.read_until(READABLE_END) if not data: return None #print("receiving: "+data.decode()) if data[:len(READABLE_START )] == READABLE_START: #chop off start code if present data = data[len(READABLE_START):] if data[-len(READABLE_END ):] == READABLE_END: #chop off end code if present data = data[:-len(READABLE_END)] else: pass #TODO if no end code, could handle partial read or give an error if data: message = Message() self.set_fields_general(message, data) return message
def send_odometer(self, speed): m = Message({'msgtype': b'ODO', 'speed': speed}) return self.send_control_no_wait(m)
def send_reset(self, code): m = Message({'msgtype': b'RST', 'code': code}) return self.send_control_no_wait(m) # after reset it may not respond
def echo(self, contents): m = Message({'msgtype': b'ECH', 'contents': contents}) return self.send_control_message(m)
def ping(self): m = Message({'msgtype': b'PNG'}) return self.send_control_message(m)
def get_status(self): m = Message({'msgtype': b'STA'}) return self.send_control_message(m)
def get_pid(self): m = Message({'msgtype': b'PID'}) return self.send_control_message(m)
def get_serial(self): m = Message({'msgtype': b'SER'}) return self.send_control_message(m)
def get_version(self): m = Message({'msgtype': b'VER'}) return self.send_control_message(m)