Files
pm3py/tests/test_hf.py
michael 35f16b7664 fix(hf): tune() must send START/MEASURE/STOP mode byte and parse uint16
CMD_MEASURE_ANTENNA_TUNING_HF requires a 1-byte mode arg (firmware rejects length!=1 with EINVARG) and returns the voltage as uint16, not uint32. tune() sent no arg (empty reply -> 0 mV) and parsed <I. Now sends mode 1/2/3 (START/MEASURE/STOP) and parses <H. Verified vs firmware appmain.c handler; C client reads the same ~15V on this firmware.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-04 22:38:23 -07:00

19 lines
820 B
Python

import asyncio
from unittest.mock import AsyncMock
from pm3py.core.protocol import Cmd
from pm3py.core.transport import PM3Response
from pm3py.core.hf import HFCommands
def test_hf_tune():
t = AsyncMock()
hf = HFCommands(t)
# MEASURE (mode 2) returns the voltage as a uint16 mV; 15485 mV = 0x3C7D
t.send_ng.return_value = PM3Response(cmd=Cmd.MEASURE_ANTENNA_TUNING_HF, status=0,
reason=0, ng=True, data=b"\x7d\x3c")
result = asyncio.get_event_loop().run_until_complete(hf.tune())
assert result["voltage_mV"] == 15485
assert result["voltage_V"] == 15.485
# Firmware requires the START(1)/MEASURE(2)/STOP(3) mode-byte sequence
modes = [call.args[1] for call in t.send_ng.call_args_list]
assert modes == [bytes([1]), bytes([2]), bytes([3])]