feat(ble_log_console): add BUF_UTIL internal frame decoding

Add BUF_UTIL=5 to InternalSource, BufUtilPool enum, BufUtilResult
TypedDict, BufUtilEntry dataclass, and name resolution helpers.
Add decode branch in internal_decoder with pool/index extraction
from the packed lbm_id field. Tests cover valid decode, pool/index
extraction, and truncated payload handling.
This commit is contained in:
Zhou Xiao
2026-04-07 13:12:52 +08:00
parent 184f5d2392
commit 79155a609a
3 changed files with 118 additions and 2 deletions
@@ -69,6 +69,38 @@ class TestUnknown:
assert result is None
class TestBufUtil:
def test_decode_buf_util(self) -> None:
# lbm_id=0x01 (pool=0, index=1), trans_cnt=4, inflight_peak=3
sub = b'\x01\x04\x03'
payload = _make_internal_payload(os_ts=7777, int_src=5, sub_payload=sub)
result = decode_internal_frame(payload)
assert result is not None
assert result['int_src'] == InternalSource.BUF_UTIL
assert result['lbm_id'] == 0x01
assert result['pool'] == 0
assert result['index'] == 1
assert result['trans_cnt'] == 4
assert result['inflight_peak'] == 3
assert result['os_ts_ms'] == 7777
def test_buf_util_pool_index_extraction(self) -> None:
# lbm_id=0x21 -> pool=2 (LL), index=1 (ll_hci)
sub = b'\x21\x04\x02'
payload = _make_internal_payload(os_ts=0, int_src=5, sub_payload=sub)
result = decode_internal_frame(payload)
assert result is not None
assert result['pool'] == 2
assert result['index'] == 1
def test_buf_util_too_short(self) -> None:
# Only 2 bytes of sub_payload (need 3 after int_src_code)
sub = b'\x00\x04'
payload = _make_internal_payload(os_ts=0, int_src=5, sub_payload=sub)
result = decode_internal_frame(payload)
assert result is None
class TestMalformed:
def test_too_short_payload(self) -> None:
result = decode_internal_frame(b'\x00\x00\x00')