def print(self): _print("Data: ", DEBUG) _print("\tPreamble=" + hex(self.preamble), DEBUG) _print("\tData Flags=" + hex(self.data_flags), DEBUG) _print("\tPacket Number=" + str(self.packet_number), DEBUG) _print_bytes("\tArgs=", self.args, DEBUG) _print("\tMotion=" + str(self.motion), DEBUG)
def set(self, _bytes): #calculate length of remaining bytes length = len(_bytes) length_hex = length.to_bytes(1, byteorder='little') #build self.bytes = SERIAL_PREAMBLE + length_hex + _bytes + SERIAL_TRAILER _print_bytes("Serial Packet: ", self.bytes, DEBUG)
def write(self, data): _print_bytes("Write: ", data, DEBUG) return self._serial.write(data)
def read_bytes(self, num_bytes): read = self._serial.read(num_bytes) _print_bytes("Read: ", read, DEBUG) return read
def read_until(self, bytes): read = self._serial.read_until(bytes, None) _print_bytes("Read: ", read, DEBUG) return read
def receive(self): serial_packet = SerialPacket() serial_packet.receive() self.bytes = serial_packet.get_notif() _print_bytes("Recieved Notif: ", self.bytes, DEBUG)
def send(self): _print_bytes("Sent Notif: ", self.bytes, DEBUG) serial_packet = SerialPacket() serial_packet.set(self.bytes) serial_packet.send()
def print(self): _print("Response: ", APP) _print("\tPreamble=" + hex(self.preamble), APP) _print("\tOpcode=" + hex(self.opcode), APP) _print("\tLength=" + str(self.length), APP) _print_bytes("\tArgs=", self.args, APP)