telemetry ok

This commit is contained in:
Florent de Lamotte
2025-05-15 12:27:13 +02:00
parent 9ecc98bdc0
commit 6bf788ad82
2 changed files with 18 additions and 5 deletions

View File

@@ -41,7 +41,8 @@ async def main():
# Wait for status response # Wait for status response
telemetry_event = await mc.wait_for_event(EventType.TELEMETRY_RESPONSE, timeout=args.timeout) telemetry_event = await mc.wait_for_event(EventType.TELEMETRY_RESPONSE, timeout=args.timeout)
print(telemetry_event) print(telemetry_event.payload["lpp"])
else: else:
print("Login failed or timed out") print("Login failed or timed out")

View File

@@ -1,7 +1,8 @@
import sys import sys
import logging import logging
import asyncio import asyncio
from cayennelpp import LppFrame import json
from cayennelpp import LppFrame, LppData, LppUtil
from typing import Any, Optional, Dict from typing import Any, Optional, Dict
from .events import Event, EventType, EventDispatcher from .events import Event, EventType, EventDispatcher
from .packets import PacketType from .packets import PacketType
@@ -380,12 +381,23 @@ class MessageReader:
res = {} res = {}
res["pubkey_pre"] = data[2:8].hex() res["pubkey_pre"] = data[2:8].hex()
buf = data[8:-8] buf = data[8:]
res["data"] = buf.hex() res["data"] = buf.hex()
res["lpp"] = LppFrame().from_bytes(buf)
"""Parse a given byte string and return as a LppFrame object."""
i = 0
data = []
while i < len(buf) and buf[i] != 0:
lppdata = LppData.from_bytes(buf[i:])
data.append(lppdata)
i = i + len(lppdata)
lpp = json.loads(json.dumps(LppFrame(data), default=LppUtil.json_encode_type_str))
res["lpp"] = lpp
attributes = { attributes = {
"data" : res["data"], "raw" : buf.hex(),
} }
await self.dispatcher.dispatch(Event(EventType.TELEMETRY_RESPONSE, res, attributes)) await self.dispatcher.dispatch(Event(EventType.TELEMETRY_RESPONSE, res, attributes))