Files
celrs/celrs/crsf_stream.c
T
portersky df3d399610 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.
2026-06-14 20:47:56 +02:00

59 lines
1.8 KiB
C

#include "celrs/crsf_stream.h"
#include <stdlib.h>
#include <string.h>
/* Valid CRSF address bytes (frame sync bytes) */
static uint8_t const s_valid_addrs[] = {
0x00, 0xC8, 0xC4, 0xEC, 0xEE, 0xEA, 0xEF
};
static int is_valid_addr(uint8_t addr) {
for (size_t i = 0; i < sizeof(s_valid_addrs); i++) {
if (s_valid_addrs[i] == addr) return 1;
}
return 0;
}
struct cel_crsf_stream {
uint8_t buf[260]; /* internal buffer (max frame = 2 + 255 + 1 = 258) */
size_t buf_len;
};
cel_crsf_stream* cel_crsf_stream_create(void) {
/* TODO: allocate and zero-initialize the stream struct. */
return NULL;
}
void cel_crsf_stream_destroy(cel_crsf_stream* stream) {
/* TODO: free the stream struct. */
(void)stream;
}
int cel_crsf_stream_feed(cel_crsf_stream* stream, uint8_t const* data,
size_t len, cel_crsf_frame* out,
size_t out_capacity) {
/* TODO: append data to internal buffer, scan for complete frames.
* Algorithm:
* 1. Copy incoming bytes into internal buffer.
* 2. While buffer has >= 4 bytes:
* a. If buf[0] is not a valid address byte, pop(0) and continue.
* b. Read length = buf[1].
* c. Total frame = 2 + length.
* d. If buffer < total, break (need more data).
* e. Parse frame from buf[0..total-1].
* f. On success (CRC valid), copy into out[] and advance buffer.
* g. On failure (CRC invalid), discard frame and continue.
* 3. Return number of valid frames parsed, or -1 on error. */
(void)stream;
(void)data;
(void)len;
(void)out;
(void)out_capacity;
return 0;
}
void cel_crsf_stream_reset(cel_crsf_stream* stream) {
/* TODO: zero buf_len to discard any partial frame. */
(void)stream;
}