def make_packet(command: CommandType, data: str): return Packet(address=0, command=command, seq=0, timestamp=None, data=data, is_user_interface_resp=True)
def test_encode_decode1(self): pkt = Packet( address=0x00, seq=0x00, command=CommandType.USER_INTERFACE, data='A1234E', timestamp=None, ) self.assertEqual(pkt.length, 6) self.assertEqual(pkt.encode(), '8300660A1234E49')
def test_encode_cecode2(self): pkt = Packet( address=0x00, seq=0x00, command=CommandType.USER_INTERFACE, data='000100', timestamp=datetime.datetime( year=2018, month=5, day=10, hour=15, minute=32, second=55), ) self.assertEqual(pkt.length, 3) self.assertEqual(pkt.encode(), '87000360000100180510153255E3')