Channel 11 defaults, ESP-NOW driver config and rig/desktop updates
Moves the controller, bridge and led-driver default ESP-NOW channel to 11 and updates the led-driver and led-tool submodule pointers. Includes the rest of the working tree: web UI, desktop and sim-controller changes, API and bridge code, graphify output, and the .gitea and fixture-driver folders. Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
35207a868a
commit
edf35e9c71
280 files changed
+24043
-1756
No files matched your search
+155
-5
@@ -29,7 +29,9 @@ typedef struct {
|
||||
} tx_frame_t;
|
||||
|
||||
struct bridge_serial {
|
||||
char dev[80];
|
||||
char dev[80]; // the port; empty while a board known by MAC has not been found yet
|
||||
bool by_mac; // follow the board by its MAC: when its port goes away, find it on another
|
||||
uint8_t want_mac[6];
|
||||
bool used; // a slot holds a board (closed boards keep their slot and tasks)
|
||||
bool active; // the link task keeps the port open while this is set
|
||||
bridge_rx_cb_t cb;
|
||||
@@ -59,7 +61,7 @@ static uint32_t get_u32(const uint8_t *p)
|
||||
|
||||
static bool open_port(bridge_serial_t *b)
|
||||
{
|
||||
int fd = open(b->dev, O_RDWR | O_NOCTTY);
|
||||
int fd = open(b->dev, O_RDWR | O_NOCTTY | O_CLOEXEC); // processes the controller starts must not keep the board open
|
||||
if (fd < 0) {
|
||||
return false;
|
||||
}
|
||||
@@ -176,6 +178,92 @@ static void handle_frame(bridge_serial_t *b, const uint8_t *msg, size_t len)
|
||||
}
|
||||
}
|
||||
|
||||
// Is a board on this port in use by a board slot other than skip?
|
||||
static bool port_taken(const char *path, const bridge_serial_t *skip)
|
||||
{
|
||||
for (int i = 0; i < MAX_BOARDS; i++) {
|
||||
const bridge_serial_t *o = &s_boards[i];
|
||||
if (o != skip && o->used && o->fd >= 0 && strcmp(o->dev, path) == 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Open path for a moment and ask the board for its INFO. True with its MAC if one answers.
|
||||
static bool probe_mac(const char *path, uint8_t mac[6])
|
||||
{
|
||||
int fd = open(path, O_RDWR | O_NOCTTY | O_NONBLOCK | O_CLOEXEC);
|
||||
if (fd < 0) {
|
||||
return false;
|
||||
}
|
||||
struct termios t;
|
||||
if (tcgetattr(fd, &t) == 0) {
|
||||
cfmakeraw(&t);
|
||||
cfsetispeed(&t, B921600);
|
||||
cfsetospeed(&t, B921600);
|
||||
t.c_cflag |= CLOCAL | CREAD;
|
||||
tcsetattr(fd, TCSANOW, &t);
|
||||
}
|
||||
tcflush(fd, TCIOFLUSH);
|
||||
uint8_t hello[BRIDGE_ENC_MAX];
|
||||
size_t hn = bridge_encode(hello, sizeof(hello), BRIDGE_MSG_HELLO, NULL, 0);
|
||||
bridge_decoder_t dec;
|
||||
memset(&dec, 0, sizeof(dec));
|
||||
bool found = false;
|
||||
for (int tick = 0; tick < 75 && !found; tick++) { // 1.5 s, HELLO every 0.5 s
|
||||
if (tick % 25 == 0 && hn) {
|
||||
ssize_t w = write(fd, hello, hn);
|
||||
(void)w;
|
||||
}
|
||||
uint8_t buf[128];
|
||||
ssize_t n = read(fd, buf, sizeof(buf));
|
||||
for (ssize_t i = 0; i < n && !found; i++) {
|
||||
if (bridge_decode_feed(&dec, buf[i]) && dec.frame_len >= 8 && dec.buf[0] == BRIDGE_MSG_INFO &&
|
||||
dec.buf[1] == BRIDGE_PROTO_VERSION) {
|
||||
memcpy(mac, dec.buf + 2, 6);
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
vTaskDelay(pdMS_TO_TICKS(20));
|
||||
}
|
||||
}
|
||||
close(fd);
|
||||
return found;
|
||||
}
|
||||
|
||||
// A board followed by MAC lost its port: look for it on the other serial ports. Sets b->dev when found.
|
||||
static bool find_board(bridge_serial_t *b)
|
||||
{
|
||||
static const char *const pats[] = { "/dev/ttyACM*", "/dev/ttyUSB*", "/dev/led-bridge" };
|
||||
glob_t g;
|
||||
memset(&g, 0, sizeof(g));
|
||||
for (size_t i = 0; i < sizeof(pats) / sizeof(pats[0]); i++) {
|
||||
glob(pats[i], i ? GLOB_APPEND : 0, NULL, &g);
|
||||
}
|
||||
bool found = false;
|
||||
for (size_t i = 0; i < g.gl_pathc && !found; i++) {
|
||||
const char *path = g.gl_pathv[i];
|
||||
uint8_t mac[6];
|
||||
if (strlen(path) >= sizeof(b->dev) || port_taken(path, b)) {
|
||||
continue;
|
||||
}
|
||||
if (probe_mac(path, mac) && memcmp(mac, b->want_mac, 6) == 0) {
|
||||
if (strcmp(b->dev, path) != 0) {
|
||||
ESP_LOGW(TAG, "bridge board %02x:%02x:%02x:%02x:%02x:%02x is now on %s", mac[0], mac[1], mac[2], mac[3],
|
||||
mac[4], mac[5], path);
|
||||
}
|
||||
xSemaphoreTake(b->lock, portMAX_DELAY);
|
||||
snprintf(b->dev, sizeof(b->dev), "%s", path);
|
||||
xSemaphoreGive(b->lock);
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
globfree(&g);
|
||||
return found;
|
||||
}
|
||||
|
||||
static void link_task(void *arg)
|
||||
{
|
||||
bridge_serial_t *b = arg;
|
||||
@@ -185,6 +273,15 @@ static void link_task(void *arg)
|
||||
memset(&dec, 0, sizeof(dec));
|
||||
for (;;) {
|
||||
if (b->fd < 0) {
|
||||
if (b->by_mac && b->active && !find_board(b)) {
|
||||
if (!b->warned) {
|
||||
ESP_LOGW(TAG, "waiting for the bridge board %02x:%02x:%02x:%02x:%02x:%02x", b->want_mac[0],
|
||||
b->want_mac[1], b->want_mac[2], b->want_mac[3], b->want_mac[4], b->want_mac[5]);
|
||||
b->warned = true;
|
||||
}
|
||||
vTaskDelay(pdMS_TO_TICKS(2000));
|
||||
continue;
|
||||
}
|
||||
xSemaphoreTake(b->lock, portMAX_DELAY);
|
||||
bool ok = b->active && open_port(b);
|
||||
if (ok) {
|
||||
@@ -233,14 +330,45 @@ static void link_task(void *arg)
|
||||
}
|
||||
}
|
||||
|
||||
// "usb:aabbccddeeff" (colons allowed): a board known by its MAC
|
||||
static bool parse_usb_mac(const char *s, uint8_t mac[6])
|
||||
{
|
||||
if (strncmp(s, "usb:", 4) != 0) {
|
||||
return false;
|
||||
}
|
||||
int n = 0;
|
||||
for (const char *c = s + 4; *c && n < 12; c++) {
|
||||
if (*c == ':') {
|
||||
continue;
|
||||
}
|
||||
int v = (*c >= '0' && *c <= '9') ? *c - '0' : (*c >= 'a' && *c <= 'f') ? *c - 'a' + 10
|
||||
: (*c >= 'A' && *c <= 'F') ? *c - 'A' + 10 : -1;
|
||||
if (v < 0) {
|
||||
return false;
|
||||
}
|
||||
mac[n / 2] = (uint8_t)((n % 2 ? mac[n / 2] << 4 : 0) | v);
|
||||
n++;
|
||||
}
|
||||
return n == 12;
|
||||
}
|
||||
|
||||
bridge_serial_t *bridge_serial_open(const char *dev, bridge_rx_cb_t cb)
|
||||
{
|
||||
if (!dev || !dev[0] || strlen(dev) >= sizeof(((bridge_serial_t *)0)->dev)) {
|
||||
return NULL;
|
||||
}
|
||||
uint8_t want[6];
|
||||
bool by_mac = parse_usb_mac(dev, want);
|
||||
if (strncmp(dev, "usb:", 4) == 0 && !by_mac) {
|
||||
return NULL;
|
||||
}
|
||||
bridge_serial_t *b = NULL;
|
||||
for (int i = 0; i < MAX_BOARDS; i++) {
|
||||
if (s_boards[i].used && strcmp(s_boards[i].dev, dev) == 0) {
|
||||
if (!s_boards[i].used) {
|
||||
continue;
|
||||
}
|
||||
if (by_mac ? (s_boards[i].by_mac && memcmp(s_boards[i].want_mac, want, 6) == 0)
|
||||
: strcmp(s_boards[i].dev, dev) == 0) {
|
||||
b = &s_boards[i];
|
||||
break;
|
||||
}
|
||||
@@ -255,7 +383,12 @@ bridge_serial_t *bridge_serial_open(const char *dev, bridge_rx_cb_t cb)
|
||||
return NULL;
|
||||
}
|
||||
memset(b, 0, sizeof(*b));
|
||||
snprintf(b->dev, sizeof(b->dev), "%s", dev);
|
||||
if (by_mac) {
|
||||
b->by_mac = true;
|
||||
memcpy(b->want_mac, want, 6);
|
||||
} else {
|
||||
snprintf(b->dev, sizeof(b->dev), "%s", dev);
|
||||
}
|
||||
b->fd = -1;
|
||||
b->lock = xSemaphoreCreateMutex();
|
||||
b->txq = xQueueCreate(TX_QUEUE_LEN, sizeof(tx_frame_t));
|
||||
@@ -270,7 +403,7 @@ bridge_serial_t *bridge_serial_open(const char *dev, bridge_rx_cb_t cb)
|
||||
b->cb = cb;
|
||||
b->active = true;
|
||||
xSemaphoreGive(b->lock);
|
||||
ESP_LOGW(TAG, "ESP-NOW frames go to the bridge board on %s, not the radio", dev);
|
||||
ESP_LOGW(TAG, "ESP-NOW frames go to the bridge board %s, not the radio", dev);
|
||||
return b;
|
||||
}
|
||||
|
||||
@@ -290,6 +423,23 @@ void bridge_serial_close(bridge_serial_t *b)
|
||||
xSemaphoreGive(b->lock);
|
||||
}
|
||||
|
||||
bool bridge_serial_mac(bridge_serial_t *b, uint8_t mac[6])
|
||||
{
|
||||
if (!b || !b->have_info) {
|
||||
return false;
|
||||
}
|
||||
memcpy(mac, b->mac, 6);
|
||||
return true;
|
||||
}
|
||||
|
||||
void bridge_serial_follow_mac(bridge_serial_t *b)
|
||||
{
|
||||
if (b && b->have_info) {
|
||||
memcpy(b->want_mac, b->mac, 6);
|
||||
b->by_mac = true;
|
||||
}
|
||||
}
|
||||
|
||||
esp_err_t bridge_serial_send(bridge_serial_t *b, const uint8_t *dst_mac, const void *data, size_t len)
|
||||
{
|
||||
if (!b || !b->active) {
|
||||
|
||||
Reference in new issue
Block a user