|
4 | 4 | the map raster; the device reports them as base64-encoded blobs in separate data |
5 | 5 | points (``dpRestrictedZoneUp`` 55, ``dpVirtualWallUp`` 57, ``dpZonedUp`` 59). |
6 | 6 |
|
7 | | -The blob format was reverse-engineered from a live ss07 (confirmed against 7 |
8 | | -real no-go zones): |
| 7 | +The restricted-zone / zoned blob format (DP 55 and DP 59) was reverse-engineered |
| 8 | +from a live ss07 (confirmed against 7 real no-go zones): |
9 | 9 |
|
10 | 10 | [version: u8][count: u8] then ``count`` fixed-size records, each: |
11 | 11 | [type: u8][vertex_count: u8] then vertex_count (x, y) int16-BE pairs, |
12 | 12 | zero-padded to the record size. |
13 | 13 |
|
| 14 | +Use :func:`parse_zone_blob` for those. Virtual walls (DP 57) use a *different* |
| 15 | +frame -- a bare ``[count]`` and 8-byte ``(y, x)`` records, no version/type/pad -- |
| 16 | +so they have their own :func:`parse_virtual_wall_blob`; feeding DP 57 to |
| 17 | +:func:`parse_zone_blob` mis-frames it (the leading byte is read as a version and |
| 18 | +the next, a coordinate, as a record count). Provenance and the byte-level |
| 19 | +breakdown are in PR #850's review thread. |
| 20 | +
|
14 | 21 | Coordinates are in the device's world units (the same space as the cleaning |
15 | 22 | path), so a :class:`~roborock.map.b01_grid_layers.GridCalibration` maps them to |
16 | 23 | map pixels. ``type`` distinguishes the restriction kind (2 = no-mop, 3 = door |
@@ -83,12 +90,61 @@ def parse_zone_blob(data: bytes | str | None) -> list[Q10Zone]: |
83 | 90 | return zones |
84 | 91 |
|
85 | 92 |
|
| 93 | +_WALL_RECORD_SIZE = 8 # two int16-BE endpoints, stored (y, x) on the wire |
| 94 | + |
| 95 | + |
| 96 | +def parse_virtual_wall_blob(data: bytes | str | None) -> list[Q10Zone]: |
| 97 | + """Decode a Q10 virtual-wall overlay blob (``dpVirtualWallUp`` 57). |
| 98 | +
|
| 99 | + Virtual walls use a *different* frame from the restricted-zone DPs handled by |
| 100 | + :func:`parse_zone_blob`: a single ``[count: u8]`` byte (no version, no |
| 101 | + per-record type/pad) followed by ``count`` 8-byte records, each two |
| 102 | + ``(y, x)`` int16-BE endpoints -- note the swapped axis order. |
| 103 | +
|
| 104 | + Each wall is returned as a :class:`Q10Zone` of type |
| 105 | + :data:`ZONE_TYPE_VIRTUAL_WALL` with its two endpoints as ``(x, y)`` vertices |
| 106 | + (axes un-swapped to match the restricted-zone order), so callers can place |
| 107 | + them onto the map through the same |
| 108 | + :class:`~roborock.map.b01_grid_layers.GridCalibration`. |
| 109 | +
|
| 110 | + Accepts raw bytes or the base64 string straight from the data point. Returns |
| 111 | + ``[]`` for empty/absent/unparsable blobs (the device sends a single ``0x00`` |
| 112 | + byte -- base64 ``AA==`` -- when there are none). |
| 113 | + """ |
| 114 | + raw = _as_bytes(data) |
| 115 | + if len(raw) < 1: |
| 116 | + return [] |
| 117 | + count = raw[0] |
| 118 | + if count <= 0: |
| 119 | + return [] |
| 120 | + |
| 121 | + body = raw[1:] |
| 122 | + walls: list[Q10Zone] = [] |
| 123 | + for index in range(count): |
| 124 | + record = body[index * _WALL_RECORD_SIZE : (index + 1) * _WALL_RECORD_SIZE] |
| 125 | + if len(record) < _WALL_RECORD_SIZE: |
| 126 | + break # truncated trailing record; stop rather than misread |
| 127 | + vertices = [ |
| 128 | + ( |
| 129 | + # records are (y, x) on the wire; swap to (x, y) for the caller |
| 130 | + int.from_bytes(record[2 + p * 4 : 4 + p * 4], "big", signed=True), |
| 131 | + int.from_bytes(record[p * 4 : 2 + p * 4], "big", signed=True), |
| 132 | + ) |
| 133 | + for p in range(2) |
| 134 | + ] |
| 135 | + walls.append(Q10Zone(type=ZONE_TYPE_VIRTUAL_WALL, vertices=vertices)) |
| 136 | + return walls |
| 137 | + |
| 138 | + |
86 | 139 | # Observed ``type`` values, confirmed against an ss07 Q10 (firmware 03.11.24) and |
87 | 140 | # cross-checked with the ioBroker roborock adapter: 2 = no-mop, 3 = door |
88 | | -# threshold, 1 = virtual wall. Any other value (including 0) is a no-go zone. |
89 | | -# In practice virtual walls arrive on a separate DP (VIRTUAL_WALL_UP 57), so this |
90 | | -# restricted-zone DP normally only carries 0 / 2 / 3. The raw value is also kept |
91 | | -# on ``Q10Zone.type`` for callers that recognise it. |
| 141 | +# threshold. Any other value (including 0) is a no-go zone. The raw value is also |
| 142 | +# kept on ``Q10Zone.type`` for callers that recognise it. |
| 143 | +# |
| 144 | +# Virtual walls arrive on a separate DP (VIRTUAL_WALL_UP 57) with their own frame |
| 145 | +# (see :func:`parse_virtual_wall_blob`), so this restricted-zone DP only carries |
| 146 | +# 0 / 2 / 3 -- never a 1. ``ZONE_TYPE_VIRTUAL_WALL`` is kept here only to tag the |
| 147 | +# walls that :func:`parse_virtual_wall_blob` produces. |
92 | 148 | # |
93 | 149 | # Corrected from an earlier reading that treated type 3 as no-mop -- 3 is the |
94 | 150 | # door-threshold rectangle; the no-mop area reads back as type 2. Reported and |
|
0 commit comments