dde27ab566
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.
93 lines
2.6 KiB
C
93 lines
2.6 KiB
C
#include "celrs/crsf.h"
|
|
#include "celrs/serial.h"
|
|
#include "celrs/logger.h"
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#ifdef _WIN32
|
|
#include <windows.h>
|
|
#else
|
|
#include <time.h>
|
|
#endif
|
|
|
|
static void sleep_ms(int ms) {
|
|
#ifdef _WIN32
|
|
Sleep((DWORD)ms);
|
|
#else
|
|
struct timespec ts = {.tv_sec = ms / 1000, .tv_nsec = (ms % 1000) * 1000000L};
|
|
nanosleep(&ts, NULL);
|
|
#endif
|
|
}
|
|
|
|
static void print_usage(char const* prog) {
|
|
printf("Usage: %s --port <serial_port> [--baudrate <rate>] [interval_ms]\n", prog);
|
|
printf(" %s --list\n", prog);
|
|
printf(" --port <serial_port> : COM3 (Windows) or /dev/ttyUSB0 (Linux)\n");
|
|
printf(" --baudrate <rate> : baud rate (default 400000)\n");
|
|
printf(" interval_ms : poll interval in ms (default 200)\n");
|
|
printf(" --list : list available serial ports and exit\n");
|
|
}
|
|
|
|
static int list_ports(void) {
|
|
char** ports = NULL;
|
|
int count = cel_serial_list_ports(&ports, 0);
|
|
if (count < 0) {
|
|
cel_log_err("Failed to list serial ports");
|
|
return 1;
|
|
}
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
printf("%s\n", ports[i]);
|
|
}
|
|
|
|
cel_serial_free_ports(ports, count);
|
|
return 0;
|
|
}
|
|
|
|
int main(int argc, char const* argv[]) {
|
|
char const* port_path = NULL;
|
|
int baud_rate = 400000;
|
|
int interval_ms = 200;
|
|
|
|
for (int i = 1; i < argc; i++) {
|
|
if (strcmp(argv[i], "--list") == 0) {
|
|
return list_ports();
|
|
} else if (strcmp(argv[i], "--port") == 0 && i + 1 < argc) {
|
|
port_path = argv[++i];
|
|
} else if (strcmp(argv[i], "--baudrate") == 0 && i + 1 < argc) {
|
|
baud_rate = atoi(argv[++i]);
|
|
if (baud_rate <= 0) baud_rate = 400000;
|
|
} else {
|
|
interval_ms = atoi(argv[i]);
|
|
if (interval_ms <= 0) interval_ms = 200;
|
|
}
|
|
}
|
|
|
|
if (port_path == NULL) {
|
|
print_usage(argv[0]);
|
|
return 1;
|
|
}
|
|
|
|
/* Open serial port */
|
|
cel_serial_port* port = cel_serial_open(port_path, baud_rate);
|
|
if (port == NULL) {
|
|
cel_log_err("Failed to open serial port");
|
|
return 1;
|
|
}
|
|
|
|
char msg[256];
|
|
snprintf(msg, sizeof(msg), "Connected to %s (%d baud)", port_path, baud_rate);
|
|
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;
|
|
}
|