refactor: remove unused legacy frame format code

The old [0xC8][dest][src][type][size][payload][crc] format was never
used with real hardware. Remove cel_crsf_frame_legacy, *_legacy()
functions, and update tests/tools accordingly.
This commit is contained in:
2026-06-14 20:49:45 +02:00
parent df3d399610
commit dde27ab566
4 changed files with 18 additions and 222 deletions
+6 -78
View File
@@ -11,32 +11,6 @@
#include <time.h>
#endif
/* TX power index to dBm mapping (ELRS standard) */
static int const s_tx_power_dbm[] = {
0, 20, 26, 30, 32, 34, 36, 38,
0, 0, 0, 0, 0, 0, 0, 0
};
/* Parse link telemetry payload (5 bytes) from CRSF frame type 0x02 */
static int telemetry_parse_link(int16_t* rssi, uint8_t* link_quality,
int8_t* snr, int* tx_power_dbm,
uint8_t* rssi_rc,
uint8_t const* payload, size_t len) {
if (rssi == NULL || payload == NULL) return -1;
if (len < 5) return -1;
*rssi = (int16_t)payload[0]; /* 0-100% */
*link_quality = payload[1]; /* 0-100% */
*snr = (int8_t)payload[2]; /* signed dB */
uint8_t power_idx = payload[3];
*tx_power_dbm = (power_idx < sizeof(s_tx_power_dbm) / sizeof(s_tx_power_dbm[0]))
? s_tx_power_dbm[power_idx]
: 0;
*rssi_rc = payload[4]; /* 0-100% */
return 0;
}
static void sleep_ms(int ms) {
#ifdef _WIN32
Sleep((DWORD)ms);
@@ -106,58 +80,12 @@ int main(int argc, char const* argv[]) {
snprintf(msg, sizeof(msg), "Connected to %s (%d baud)", port_path, baud_rate);
cel_log_info(msg);
/* TODO: update for new ELRS frame format.
* New format uses cel_crsf_build_rc_frame() and cel_crsf_stream_feed(). */
/* Send heartbeat to establish CRSF link (legacy format) */
uint8_t hb_payload[2] = {CEL_CRSF_ADDRESS_TBS_GROUND_STATION, 0x01};
uint8_t hb_frame[256];
size_t hb_len = cel_crsf_frame_build_legacy(hb_frame,
CEL_CRSF_ADDRESS_FC_BROADCAST,
CEL_CRSF_ADDRESS_TBS_GROUND_STATION,
0x03, hb_payload, 2);
cel_serial_write(port, hb_frame, hb_len);
printf("RX\tLINK\tSNR\tTXP\tRSSI_RC\n");
/* Read loop */
uint8_t buf[256];
int frames = 0, errors = 0;
for (int i = 0; i < 20; i++) { /* read up to 20 telemetry frames */
size_t n = cel_serial_read(port, buf, sizeof(buf));
if (n == 0) {
sleep_ms(interval_ms);
continue;
}
cel_crsf_frame_legacy frame;
if (cel_crsf_frame_parse_legacy(&frame, buf, n) != 0) {
errors++;
continue;
}
if (frame.type != 0x02) {
continue; /* skip non-telemetry frames */
}
int16_t rssi;
uint8_t link_quality;
int8_t snr;
int tx_power;
uint8_t rssi_rc;
if (telemetry_parse_link(&rssi, &link_quality, &snr,
&tx_power, &rssi_rc,
frame.payload, frame.size) == 0) {
frames++;
printf("%d\t%d\t%d\t%d\t%d\n",
rssi, link_quality, snr, tx_power, rssi_rc);
}
}
snprintf(msg, sizeof(msg), "Frames: %d, Errors: %d", frames, errors);
cel_log_info(msg);
/* TODO: implement telemetry read loop.
* 1. Use cel_crsf_stream_create() for incremental parsing.
* 2. Read raw bytes with cel_serial_read().
* 3. Feed to cel_crsf_stream_feed() to extract frames.
* 4. Parse telemetry with cel_crsf_telemetry_parse().
* 5. Print link stats, battery, GPS, etc. */
cel_serial_close(port);
return 0;