feat: adopt ELRS USB CRSF frame format, add skeleton modules

Switch CRC from CCITT (0x07) to DVB-S2 (0xD5) to match ELRS.
Adopt ELRS USB frame format: [addr][length][type][payload][crc].
Update frame type constants to match current ELRS protocol values.

New skeleton modules (stub implementations with TODO comments):
  - crsf_telemetry.h/.c: telemetry decoders (GPS, battery, link..)
  - crsf_stream.h/.c: incremental streaming frame reader
  - crsf_param.h/.c: parameter protocol (read/write/set_power)

Retained old frame format as *_legacy functions for backward
compatibility with existing telemetry tool and tests.

Add cel_serial_find_elrs_port() and cel_serial_open_probe()
stubs to serial module for port auto-detection and baud probing.
This commit is contained in:
2026-06-14 20:47:56 +02:00
parent c42ec407da
commit df3d399610
16 changed files with 919 additions and 156 deletions
+36 -29
View File
@@ -74,19 +74,22 @@ mock files are excluded. Requires GCC or Clang with gcov support, and
```
celrs/
crsf.h / crsf.c CRSF protocol: CRC8, frame parse/build
serial.h / serial.c Serial port abstraction (Win/POSIX)
logger.h / logger.c Level-filtering logger
log_write.h/.c stdout log sink
crsf.h / crsf.c CRSF protocol: CRC8/DVB-S2, frame build/parse
crsf_telemetry.h/.c Telemetry frame decoders (GPS, battery, link..)
crsf_stream.h/.c Incremental streaming frame reader
crsf_param.h/.c Parameter protocol (read/write/set_power)
serial.h / serial.c Serial port abstraction (Win/POSIX)
logger.h / logger.c Level-filtering logger
log_write.h/.c stdout log sink
tools/
telemetry.c Telemetry read tool
telemetry.c Telemetry read tool
tests/
test_crsf.c CRSF CRC, parse, build tests
test_serial.c Serial open/close/stub tests
test_logger.c Logger level-filtering tests
test_crsf.c CRSF CRC, parse, build tests
test_serial.c Serial open/close/stub tests
test_logger.c Logger level-filtering tests
deps/
FindUnity.cmake Fetches Unity v2.6.1 via ZIP
FindCMock.cmake Fetches CMock v2.6.0 via ZIP
FindUnity.cmake Fetches Unity v2.6.1 via ZIP
FindCMock.cmake Fetches CMock v2.6.0 via ZIP
```
## CRSF Protocol
@@ -94,22 +97,20 @@ deps/
CRSF (Crossfire Serial Protocol) is the serial protocol used by ELRS for
communication between ground station and TX/RX modules.
### Frame format
### Frame format (ELRS USB CRSF)
```
+------+------+------+------+-------+-------+
| 0xC8 | dest | src | type | size | ... | CRC |
+------+------+------+------+-------+-------+
1 byte 1B 1B 1B 1B N B 1 byte
+--------+----------+--------+----------+-----+
| addr | length | type | payload | CRC |
+--------+----------+--------+----------+-----+
1 byte 1 byte 1 byte N bytes 1B
```
- **Header:** Always `0xC8`
- **Destination:** Target device address
- **Source:** Sender device address
- **Type:** Frame type (heartbeat, RC channels, telemetry, etc.)
- **Size:** Payload length in bytes
- **Address:** Frame sync byte (`0xC8` for host, `0xEE` for module, etc.)
- **Length:** Total bytes after this field (type + payload + CRC)
- **Type:** Frame type (RC channels, telemetry, parameter, etc.)
- **Payload:** Frame-specific data
- **CRC:** CRC8-CCITT over dest+src+type+size+payload
- **CRC:** CRC8/DVB-S2 (poly `0xD5`) over type + payload
### Common device addresses
@@ -118,17 +119,23 @@ communication between ground station and TX/RX modules.
| 0x00 | FC Broadcast |
| 0x10 | Flight Controller |
| 0x80 | TBS Ground Station |
| 0xEA | Custom Module |
| 0xDD | RC Device |
| 0xEA | Custom Module (Radio) |
| 0xEE | ELRS TX Module |
| 0xEF | ELRS Lua (host script) |
### Common frame types
| Type | Name |
| ------ | --------------------------- |
| 0x01 | RC Channels Packed |
| 0x02 | Packet Link Telemetry |
| 0x03 | Heartbeat |
| 0x08 | Device Info |
| 0x09 | Parameter List |
| 0x17 | MSP Read |
| 0x18 | MSP Write |
| 0x02 | GPS |
| 0x08 | Battery |
| 0x0B | Heartbeat |
| 0x14 | Link Stats |
| 0x16 | RC Channels |
| 0x28 | Device Ping |
| 0x29 | Device Info |
| 0x2B | Parameter Entry |
| 0x2C | Parameter Read |
| 0x2D | Parameter Write |
| 0x2E | ELRS Status |