1 from src.RAPacker import calc_sum, unpack_pkt, pack_pkt
5 assert calc_sum(0x12, ['0x00']) == (0, 0x2, 0xEC)
6 assert calc_sum(0x34, ['0x00']) == (0, 0x2, 0xCA)
7 assert calc_sum(0x00, ['0x00']) == (0, 0x02, 0xFE)
10 assert unpack_pkt(b'\x81\x00\x02\x00\x00\xFE\x03') == ['0x00']
11 assert unpack_pkt(b'\x81\x00\x02\x12\x00\xEC\x03') == ['0x00']
12 assert unpack_pkt(b'\x81\x00\x02\x13\x00\xEB\x03') == ['0x00']
14 def test_read_unpack():
15 assert unpack_pkt(b'\x81\x00\x04\x15\xAA\xBB\xCC\xB6\x03') == ['0xAA', '0xBB', '0xCC']
17 def test_pack_unpack():
18 assert unpack_pkt(pack_pkt(0x13, ['0x00','0x01','0x02'], ack=True)) == ['0x00', '0x01', '0x02']
19 assert unpack_pkt(pack_pkt(0x34, ['0x00'], ack=True)) == ['0x00']
20 assert unpack_pkt(pack_pkt(0x00, ['0x00'], ack=True)) == ['0x00']
21 assert unpack_pkt(pack_pkt(0x12, ['0x00'], ack=True)) == ['0x00']
23 def test_err_unpack():
24 with pytest.raises(ValueError, match=r".*0xC3.*") as excinfo:
25 unpack_pkt(b'\x81\x00\x02\x93\xC3\x38\x03')
26 assert str(excinfo.value) == 'MCU encountered error 0xC3'