fix: correct postcard encoding for u8/i8 fields (was using varint/zigzag)
ROOT CAUSE: postcard encodes u8 and i8 as raw bytes, NOT varint/zigzag. The Python encoders used varint() for u8 and zigzag() for i8. For small values this was silently correct (varint(7) == raw byte 7), but for tx_power_dbm: zigzag(14) = 28, which the new validation correctly rejected as out of range (-9..22). This was a pre-existing bug masked by the absence of validation. Fix all RadioConfig field encoders in both donglora.py and meshcore_rx.py. Fix docs/PROTOCOL.md to correctly document i8 as raw byte, not zigzag. Restore full config validation.
This commit is contained in:
3 files changed
+22
-15
No files matched your search
+2
-1
@@ -26,8 +26,9 @@ Postcard is a compact binary format. The subset used by DongLoRa:
|
||||
| Type | Encoding |
|
||||
|------|----------|
|
||||
| `u8` | Raw byte |
|
||||
| `i8` | Raw byte (two's complement) |
|
||||
| `u16`, `u32` | Varint (LEB128: 7 data bits per byte, MSB = continuation) |
|
||||
| `i8`, `i16` | Zigzag then varint (`(n << 1) ^ (n >> bits-1)`) |
|
||||
| `i16`, `i32` | Zigzag then varint (`(n << 1) ^ (n >> bits-1)`) |
|
||||
| Enum variant | Varint of 0-based variant index, then variant fields |
|
||||
| `Option<T>` | `0x00` = None, `0x01` + T = Some |
|
||||
| `Vec<u8, N>` | Varint length, then raw bytes |
|
||||
|
||||
Reference in new issue
Block a user