def test_tag_inventory(): transport = MockTransport(bytearray.fromhex(RESP_TAGS_1)) command = ReaderCommand(G2_TAG_INVENTORY) runner = CommandRunner(transport) frame = G2InventoryResponseFrame(runner.run(command)) assert frame.result_status == 3 assert frame.resp_cmd == 0x01 assert frame.reader_addr == 0 assert frame.num_tags == 1 tag = next(frame.get_tag()) assert tag.epc == bytearray.fromhex('000000000000000000000313') assert tag.rssi is None assert tag.antenna_num == 1
def test_reader_info_frame(): transport = MockTransport(bytearray.fromhex(RESP_READER_INFO)) get_reader_info = ReaderCommand(CF_GET_READER_INFO) runner = CommandRunner(transport) reader_info = ReaderInfoFrame(runner.run(get_reader_info)) assert reader_info.result_status == 0 assert reader_info.resp_cmd == 0x21 assert reader_info.reader_addr == 0 assert reader_info.data == bytearray.fromhex('00160c034e001e0a01000000') assert reader_info.firmware_version == bytearray([0, 22]) # 0x4E = 0b 01 00 1110 Max # 0x00 = 0b0 Min assert reader_info.frequency_band == ReaderFrequencyBand.EU assert reader_info.get_max_frequency() == 865.1 + 0.2 * 14 assert reader_info.get_min_frequency() == 865.1
def test_multiple_tags(): transport = MockTransport(bytearray.fromhex(RESP_MULTIPLE_TAGS)) command = ReaderCommand(G2_TAG_INVENTORY) runner = CommandRunner(transport) response = G2InventoryResponse(runner.run(command)) frame_generator = response.get_frame() frame = next(frame_generator) assert frame.result_status == 3 assert frame.resp_cmd == 0x01 assert frame.reader_addr == 0 assert frame.num_tags == 2 tag_generator = frame.get_tag() tag1 = next(tag_generator) assert tag1.epc == bytearray.fromhex('000000000000000000000313') assert tag1.rssi is None assert tag1.antenna_num == 1 tag2 = next(tag_generator) assert tag2.epc == bytearray.fromhex('000000000000000000000314') assert tag2.rssi is None assert tag2.antenna_num == 1
def test_reader_frame_bad_checksum(): transport = MockTransport(bytearray.fromhex(RESP_TAGS_BAD_CHECKSUM)) get_reader_info = ReaderCommand(G2_TAG_INVENTORY) runner = CommandRunner(transport) with pytest.raises(ValueError): assert ReaderResponseFrame(runner.run(get_reader_info))