P4-Nano: controller port with the C6 as ESP-NOW radio, and the simulator
The controller now builds for the Waveshare ESP32-P4-Nano only (plus the linux sim and the desktop); the S3 stays for the USB/network bridge in bridge/. - radio-c6/: C6 firmware, esp-hosted plus ESP-NOW over peer data. The P4 loads it from the slave_fw partition when the C6 runs another version (c6_update.c) - bridge_hosted.c: the C6 as the always-on "c6" bridge, and the P4 as a network bridge on UDP 8766 for the desktop - Ethernet on the P4's EMAC, ES8311 mic; default address 192.168.50.20. The W5500, INMP441 and direct ESP-NOW code is gone - The simulated rig at /sim/ is built into the board image, with an always-on "browser" bridge. Its frames go through a queue so a slow page cannot hold up the radio, and frames for simulated bars are not sent over the C6. Receiver buffers are on the heap; a bar's flash file is only written when it changes - HTTP server: more handlers, sockets and stack for the rig - docs/P4_NANO.md, README and Makefile updated; graphify output Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ba8e160aee
commit
4ab0c7c6d7
101 files changed
+3284
-971
No files matched your search
+64
-19
@@ -12,6 +12,9 @@
|
||||
#include "lwip/sockets.h"
|
||||
#include "sdkconfig.h"
|
||||
#include "bridge_proto.h"
|
||||
#if CONFIG_IDF_TARGET_ESP32P4
|
||||
#include "bridge_hosted.h"
|
||||
#endif
|
||||
#if CONFIG_IDF_TARGET_LINUX
|
||||
#include "bridge_dmx.h"
|
||||
#include "bridge_serial.h"
|
||||
@@ -26,8 +29,9 @@ static const char *TAG = "bridge";
|
||||
typedef struct {
|
||||
bool used;
|
||||
bool serial; // a USB board (bridge_serial), else UDP
|
||||
bool browser; // the rig page of the host build (sim_rig.c), over its WebSocket
|
||||
bool browser; // the rig page (sim_rig.c), over its WebSocket
|
||||
bool dmx; // a DMX bridge "dmx:<id>" (bridge_dmx.c): its fixtures are drivers of their own
|
||||
bool c6; // the ESP32-P4-Nano's own C6 radio (bridge_hosted.c), always there on that target
|
||||
bridge_dmx_t *dmx_b;
|
||||
char addr[BRIDGE_ADDR_MAX]; // as the settings store it
|
||||
bridge_serial_t *board; // serial: the board (linux)
|
||||
@@ -78,11 +82,21 @@ static bool is_dmx_addr(const char *addr)
|
||||
return strncmp(addr, "dmx:", 4) == 0;
|
||||
}
|
||||
|
||||
#if CONFIG_IDF_TARGET_LINUX
|
||||
static bool is_c6_addr(const char *addr)
|
||||
{
|
||||
return strcmp(addr, "c6") == 0;
|
||||
}
|
||||
|
||||
// The rig page's link (sim-controller/components/sim/sim_rig.c): dst_mac(6) + packet to the page, if it is open
|
||||
bool sim_rig_tx(const uint8_t *frame, size_t len);
|
||||
bool sim_rig_page_open(void);
|
||||
#endif
|
||||
|
||||
// The MACs the rig gives its bars (MAC_PREFIX in sim_rig.c): no real board has one
|
||||
static bool is_sim_mac(const uint8_t *mac)
|
||||
{
|
||||
static const uint8_t PREFIX[3] = { 0x02, 0x51, 0x4D };
|
||||
return memcmp(mac, PREFIX, sizeof(PREFIX)) == 0;
|
||||
}
|
||||
|
||||
static int64_t now_ms(void)
|
||||
{
|
||||
@@ -301,7 +315,19 @@ static esp_err_t activate(const char *addr)
|
||||
link_t *l = &s_links[slot];
|
||||
l->browser = false;
|
||||
l->dmx = false;
|
||||
if (is_dmx_addr(addr)) {
|
||||
l->c6 = false;
|
||||
if (is_c6_addr(addr)) {
|
||||
#if CONFIG_IDF_TARGET_ESP32P4
|
||||
bridge_hosted_set_rx(deliver);
|
||||
l->c6 = true;
|
||||
l->serial = false;
|
||||
l->sock = -1;
|
||||
l->ctl = -1;
|
||||
ESP_LOGI(TAG, "ESP-NOW frames go to the C6 radio");
|
||||
#else
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
#endif
|
||||
} else if (is_dmx_addr(addr)) {
|
||||
#if CONFIG_IDF_TARGET_LINUX
|
||||
if (!addr[4]) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
@@ -319,15 +345,11 @@ static esp_err_t activate(const char *addr)
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
#endif
|
||||
} else if (is_browser_addr(addr)) {
|
||||
#if CONFIG_IDF_TARGET_LINUX
|
||||
l->browser = true;
|
||||
l->serial = false;
|
||||
l->sock = -1;
|
||||
l->ctl = -1;
|
||||
ESP_LOGW(TAG, "ESP-NOW frames go to the rig page (/sim/), not the radio");
|
||||
#else
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
#endif
|
||||
ESP_LOGI(TAG, "ESP-NOW frames go to the rig page (/sim/)");
|
||||
} else if (is_serial_addr(addr)) {
|
||||
#if CONFIG_IDF_TARGET_LINUX
|
||||
const char *dev = strncmp(addr, "serial:", 7) == 0 ? addr + 7 : addr; // "usb:<mac>" goes as it is
|
||||
@@ -399,6 +421,7 @@ static void deactivate(int i)
|
||||
if (s_mic_slot == i) {
|
||||
s_mic_slot = -1;
|
||||
}
|
||||
l->c6 = false;
|
||||
l->used = false;
|
||||
}
|
||||
|
||||
@@ -421,11 +444,24 @@ esp_err_t bridge_set_all(const char addrs[][BRIDGE_ADDR_MAX], size_t n, bridge_r
|
||||
}
|
||||
xSemaphoreTake(s_lock, portMAX_DELAY);
|
||||
s_cb = cb;
|
||||
#if CONFIG_IDF_TARGET_ESP32P4
|
||||
// The board's own radio is always one of them, whatever the saved list says
|
||||
if (find_link(BRIDGE_HOSTED_ADDR) < 0) {
|
||||
activate(BRIDGE_HOSTED_ADDR);
|
||||
}
|
||||
// So is the rig page (/sim/), which only gets frames while it is open
|
||||
if (find_link(BRIDGE_BROWSER) < 0) {
|
||||
activate(BRIDGE_BROWSER);
|
||||
}
|
||||
#endif
|
||||
for (int i = 0; i < BRIDGE_MAX_LINKS; i++) {
|
||||
if (!s_links[i].used) {
|
||||
continue;
|
||||
}
|
||||
bool wanted = false;
|
||||
bool wanted = s_links[i].c6;
|
||||
#if CONFIG_IDF_TARGET_ESP32P4
|
||||
wanted = wanted || s_links[i].browser;
|
||||
#endif
|
||||
for (size_t j = 0; j < n; j++) {
|
||||
wanted = wanted || strcmp(s_links[i].addr, addrs[j]) == 0;
|
||||
}
|
||||
@@ -494,17 +530,22 @@ esp_err_t bridge_send(const uint8_t *dst_mac, const void *data, size_t len)
|
||||
continue;
|
||||
}
|
||||
any = true;
|
||||
if (l->dmx) {
|
||||
if (l->c6) {
|
||||
#if CONFIG_IDF_TARGET_ESP32P4
|
||||
// A simulated bar is not on the air: no airtime for frames nothing will acknowledge
|
||||
if (!is_sim_mac(dst_mac) && bridge_hosted_send(dst_mac, data, len) == ESP_OK) {
|
||||
l->tx++;
|
||||
}
|
||||
#endif
|
||||
} else if (l->dmx) {
|
||||
#if CONFIG_IDF_TARGET_LINUX
|
||||
bridge_dmx_send(l->dmx_b, dst_mac, data, len);
|
||||
l->tx++;
|
||||
#endif
|
||||
} else if (l->browser) {
|
||||
#if CONFIG_IDF_TARGET_LINUX
|
||||
if (sim_rig_tx(buf, 6 + len)) { // no page open: the frame is lost, as on air
|
||||
l->tx++;
|
||||
}
|
||||
#endif
|
||||
} else if (l->serial) {
|
||||
#if CONFIG_IDF_TARGET_LINUX
|
||||
bridge_serial_send(l->board, dst_mac, data, len); // a closed port loses the frame, as on air
|
||||
@@ -533,19 +574,21 @@ size_t bridge_status_json(char *out, size_t n)
|
||||
continue;
|
||||
}
|
||||
char body[400];
|
||||
if (l->dmx) {
|
||||
if (l->c6) {
|
||||
#if CONFIG_IDF_TARGET_ESP32P4
|
||||
bridge_hosted_status(body, sizeof(body));
|
||||
#else
|
||||
snprintf(body, sizeof(body), "{}");
|
||||
#endif
|
||||
} else if (l->dmx) {
|
||||
#if CONFIG_IDF_TARGET_LINUX
|
||||
bridge_dmx_status(l->dmx_b, body, sizeof(body));
|
||||
#else
|
||||
snprintf(body, sizeof(body), "{}");
|
||||
#endif
|
||||
} else if (l->browser) {
|
||||
#if CONFIG_IDF_TARGET_LINUX
|
||||
snprintf(body, sizeof(body), "{\"page\":%s,\"tx\":%lu,\"rx\":%lu}",
|
||||
sim_rig_page_open() ? "true" : "false", (unsigned long)l->tx, (unsigned long)l->rx);
|
||||
#else
|
||||
snprintf(body, sizeof(body), "{}");
|
||||
#endif
|
||||
} else if (l->serial) {
|
||||
#if CONFIG_IDF_TARGET_LINUX
|
||||
bridge_serial_status(l->board, body, sizeof(body));
|
||||
@@ -565,7 +608,7 @@ size_t bridge_status_json(char *out, size_t n)
|
||||
(unsigned long)l->tx, (unsigned long)l->rx, (unsigned long)l->audio);
|
||||
}
|
||||
int w = snprintf(out + used, n - used, "%s{\"addr\":\"%s\",\"kind\":\"%s\",\"status\":%s}",
|
||||
first ? "" : ",", l->addr, l->dmx ? "dmx" : l->browser ? "browser" : (l->serial ? "serial" : "udp"), body);
|
||||
first ? "" : ",", l->addr, l->c6 ? "c6" : l->dmx ? "dmx" : l->browser ? "browser" : (l->serial ? "serial" : "udp"), body);
|
||||
if (w < 0 || (size_t)w >= n - used) {
|
||||
break;
|
||||
}
|
||||
@@ -600,6 +643,8 @@ esp_err_t bridge_board_set_channel(const char *addr, uint8_t channel)
|
||||
esp_err_t err = (i >= 0 && s_links[i].serial) ? bridge_serial_set_channel(s_links[i].board, channel) : ESP_ERR_NOT_FOUND;
|
||||
xSemaphoreGive(s_lock);
|
||||
return err;
|
||||
#elif CONFIG_IDF_TARGET_ESP32P4
|
||||
return is_c6_addr(addr) ? bridge_hosted_set_channel(channel) : ESP_ERR_NOT_FOUND;
|
||||
#else
|
||||
(void)addr;
|
||||
(void)channel;
|
||||
|
||||
Reference in new issue
Block a user