45 lines
1.1 KiB
Python
45 lines
1.1 KiB
Python
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
from app.mqtt.parsers.nmea import parse_nmea_sentences
|
|
|
|
|
|
def summarize_rtcm_types(payload: bytes) -> dict[int, int]:
|
|
counts: dict[int, int] = {}
|
|
i = 0
|
|
|
|
while i + 6 <= len(payload):
|
|
if payload[i] != 0xD3:
|
|
i += 1
|
|
continue
|
|
|
|
length = ((payload[i + 1] & 0x03) << 8) | payload[i + 2]
|
|
frame_end = i + 3 + length + 3
|
|
if frame_end > len(payload):
|
|
break
|
|
|
|
message_type = ((payload[i + 3] << 4) | (payload[i + 4] >> 4)) & 0x0FFF
|
|
counts[message_type] = counts.get(message_type, 0) + 1
|
|
i = frame_end
|
|
|
|
return counts
|
|
|
|
|
|
def parse_mixed_payload(payload: bytes) -> list[dict[str, Any]]:
|
|
events = parse_nmea_sentences(payload)
|
|
|
|
rtcm_types = summarize_rtcm_types(payload)
|
|
if rtcm_types:
|
|
events.append(
|
|
{
|
|
"event_type": "rtcm_summary",
|
|
"payload": {
|
|
"rtcm_message_count": sum(rtcm_types.values()),
|
|
"rtcm_types": rtcm_types,
|
|
},
|
|
}
|
|
)
|
|
|
|
return events
|