2525import struct
2626from dataclasses import dataclass , field , replace
2727
28+ from vacuum_map_parser_base .config .drawable import Drawable
29+
2830from roborock .data .b01_q10 .b01_q10_containers import Q10RoborockPoint
2931from roborock .data .code_mappings import RoborockEnum
3032from roborock .data .containers import RoborockBase
@@ -209,6 +211,30 @@ def from_payload(cls, payload: bytes) -> "Q10MapPacketKind | None":
209211 return None if kind is cls .unknown else kind
210212
211213
214+ @dataclass
215+ class Q10Point (RoborockBase ):
216+ """A point in the Q10 firmware's dock-relative trace coordinate space."""
217+
218+ x : int
219+ y : int
220+
221+ def to_roborock (self ) -> Q10RoborockPoint :
222+ """Convert this trace point to common Roborock coordinates."""
223+ return Q10RoborockPoint .from_trace (self .x , self .y )
224+
225+
226+ @dataclass
227+ class Q10Obstacle (RoborockBase ):
228+ """A position-only obstacle in the map package's coordinate frame.
229+
230+ Fifty raw units equal one grid pixel. These coordinates use the map header
231+ origin and carry no validated obstacle type, confidence, or photo identifier.
232+ """
233+
234+ x : int
235+ y : int
236+
237+
212238@dataclass
213239class Q10MapPacket :
214240 """Decoded contents of a Q10 current or archived map packet."""
@@ -228,6 +254,11 @@ class Q10MapPacket:
228254 the same (top-down) pixel space as :attr:`grid`, where a non-zero cell is
229255 carpet (the value is the carpet kind). ``None`` if the packet carried none."""
230256
257+ obstacles : list [Q10Obstacle ] = field (default_factory = list )
258+ """Obstacle positions embedded after the carpet mask (50 raw units/pixel)."""
259+ skip_cleaning_points : list [Q10Point ] = field (default_factory = list )
260+ """Skip-clean markers in their distinct firmware coordinate frame."""
261+
231262 @property
232263 def layers (self ) -> GridLayers :
233264 """Split the occupancy grid into separable grid-pixel layers."""
@@ -236,18 +267,6 @@ def layers(self) -> GridLayers:
236267 return decompose_grid (self .width , self .height , self .grid , rooms , classify_q10_cell , flip = False )
237268
238269
239- @dataclass
240- class Q10Point (RoborockBase ):
241- """A point in the Q10 firmware's dock-relative trace coordinate space."""
242-
243- x : int
244- y : int
245-
246- def to_roborock (self ) -> Q10RoborockPoint :
247- """Convert this trace point to common Roborock coordinates."""
248- return Q10RoborockPoint .from_trace (self .x , self .y )
249-
250-
251270@dataclass
252271class Q10TracePacket :
253272 """Decoded contents of a Q10 ``02 01`` cleaning-path packet.
@@ -335,12 +354,11 @@ class Q10CleanRecordDetail:
335354_TRACE_POINT_COUNT_OFFSET = 8
336355_TRACE_HEADING_OFFSET = 10
337356
338- _HISTORICAL_TRACE_HEADER_LENGTH = 14
339- _HISTORICAL_TRACE_PREFIX_LENGTH = 1
357+ _HISTORICAL_TRACE_HEADER_LENGTH = 13
340358_HISTORICAL_TRACE_VERSION = 1
341- _HISTORICAL_TRACE_POINT_COUNT_OFFSET = 6
342- _HISTORICAL_TRACE_HEADING_OFFSET = 10
343- _HISTORICAL_TRACE_RESERVED_OFFSET = 12
359+ _HISTORICAL_TRACE_POINT_COUNT_OFFSET = 5
360+ _HISTORICAL_TRACE_HEADING_OFFSET = 9
361+ _HISTORICAL_TRACE_RESERVED_OFFSET = 11
344362
345363# Some cleans still prepend a single near-origin sentinel as the first real
346364# point (e.g. ~(5, 76) / (-3, 0) when the path proper starts near (-1700, -800));
@@ -572,6 +590,17 @@ def _parse_map_layout(payload: bytes) -> tuple[Q10MapPacket, bytes, int | None]:
572590 tail = payload [layout_end :]
573591 erase_zones = _parse_erase_zones (tail )
574592 carpet_mask , carpet_end = _parse_carpet_block (tail , width , height )
593+ obstacles : list [Q10Obstacle ] = []
594+ skip_cleaning_points : list [Q10Point ] = []
595+ trace_offset = None
596+ if carpet_end is not None :
597+ obstacle_coords , obstacle_end = _parse_counted_points (tail , carpet_end )
598+ if obstacle_end is not None :
599+ skip_coords , skip_end = _parse_counted_points (tail , obstacle_end )
600+ if skip_end is not None :
601+ obstacles = [Q10Obstacle (x , y ) for x , y in obstacle_coords ]
602+ skip_cleaning_points = [Q10Point (x , y ) for x , y in skip_coords ]
603+ trace_offset = skip_end
575604 header_calibration = _parse_header_calibration (payload )
576605 packet = Q10MapPacket (
577606 kind = kind ,
@@ -583,8 +612,10 @@ def _parse_map_layout(payload: bytes) -> tuple[Q10MapPacket, bytes, int | None]:
583612 erase_zones = erase_zones ,
584613 header_calibration = header_calibration ,
585614 carpet_mask = carpet_mask ,
615+ obstacles = obstacles ,
616+ skip_cleaning_points = skip_cleaning_points ,
586617 )
587- return packet , tail , carpet_end
618+ return packet , tail , trace_offset
588619
589620
590621def _parse_header_calibration (payload : bytes ) -> Q10HeaderCalibration | None :
@@ -699,6 +730,16 @@ def _parse_carpet_block(tail: bytes, width: int, height: int) -> tuple[bytes | N
699730 return mask , block_end
700731
701732
733+ def _parse_counted_points (tail : bytes , offset : int ) -> tuple [list [tuple [int , int ]], int | None ]:
734+ """Decode a complete u8-counted signed-BE coordinate table atomically."""
735+ if offset >= len (tail ):
736+ return [], None
737+ end = offset + 1 + tail [offset ] * 4
738+ if end > len (tail ):
739+ return [], None
740+ return list (struct .iter_unpack (">hh" , memoryview (tail )[offset + 1 : end ])), end
741+
742+
702743def _parse_clean_record_trace (
703744 tail : bytes ,
704745 offset : int ,
@@ -707,20 +748,17 @@ def _parse_clean_record_trace(
707748
708749 The header and declared point count were validated against a physical ss07
709750 clean-record response and its point bytes match captured prefixes of the
710- corresponding live trace exactly. One observed zero byte precedes the path;
711- its meaning is unknown, so a non-zero value makes the entire section opaque.
712- Any unsupported version, non-zero reserved word, or truncated point table is
751+ corresponding live trace exactly. The obstacle and skip-clean tables precede
752+ the one-byte path version. Any unsupported version, non-zero reserved word,
753+ or truncated point table is
713754 likewise left completely opaque. Bytes after the declared points are
714755 deliberately not consumed: the observed 12-byte suffix appears structured,
715756 but there is not enough controlled evidence to name or decode it safely.
716757 """
717- if offset >= len (tail ) or tail [offset ] != 0 :
718- return None
719- offset += _HISTORICAL_TRACE_PREFIX_LENGTH
720758 header_end = offset + _HISTORICAL_TRACE_HEADER_LENGTH
721759 if header_end > len (tail ):
722760 return None
723- version = int . from_bytes ( tail [offset : offset + 2 ], "big" )
761+ version = tail [offset ]
724762 reserved = int .from_bytes (
725763 tail [offset + _HISTORICAL_TRACE_RESERVED_OFFSET : offset + _HISTORICAL_TRACE_RESERVED_OFFSET + 2 ],
726764 "big" ,
@@ -766,3 +804,5 @@ class B01Q10MapParserConfig:
766804
767805 map_scale : int = 4
768806 """Scale factor for the rendered map image."""
807+ drawables : list [Drawable ] | None = None
808+ """Enabled overlays, or ``None`` for the Q10 defaults."""
0 commit comments