"""Tests for the ST25DV04K/16K/64K (ISO 15693 + I2C dynamic tag, RF side).""" import asyncio import struct import pytest from pm3py.sim.frame import RFFrame from pm3py.transponders.hf.iso15693.st.st25dv import ( ST25DV04K, ST25DV16K, ST25DV64K, REG_ENDA1, REG_RFA2SS, DYN_MB_CTRL, ) def run(coro): return asyncio.new_event_loop().run_until_complete(coro) def cmd(tag, payload: bytes): return run(tag.handle_frame(RFFrame.from_bytes(payload))) class TestIdentity: @pytest.mark.parametrize("cls,prefix,blocks", [ (ST25DV04K, b"\xE0\x02\x24", 128), (ST25DV16K, b"\xE0\x02\x26", 512), (ST25DV64K, b"\xE0\x02\x26", 2048), ]) def test_uid_and_blocks(self, cls, prefix, blocks): tag = cls() assert tag._uid[0:3] == prefix assert tag._num_blocks == blocks def test_04k_sysinfo_has_memsize(self): tag = ST25DV04K() run(tag.power_on()) r = cmd(tag, bytes([0x02, 0x2B])) assert r.data[1] == 0x0F assert r.data[-1] == 0x24 # IC ref assert r.data[-3] == 0x7F # 128 blocks - 1 def test_16k_sysinfo_omits_memsize(self): tag = ST25DV16K() run(tag.power_on()) r = cmd(tag, bytes([0x02, 0x2B])) assert r.data[1] == 0x0B # DSFID+AFI+ICref, no memsize assert r.data[-1] == 0x26 def test_ext_sysinfo_gives_memsize(self): tag = ST25DV64K() run(tag.power_on()) r = cmd(tag, bytes([0x02, 0x3B, 0x02, 0x0F])) assert struct.unpack_from("