Files
led-controller/main/bridge.h
T
jimmyandClaude Opus 5.5 4ab0c7c6d7 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>
2026-11-24 21:45:25 +13:00

66 lines
4.0 KiB
C

#pragma once
// Bridges: carry the controller's ESP-NOW frames to hosts that stand in for the radio. Several can run at
// once; every frame goes to all of them, and frames from any of them count as received (a frame heard by
// two boards arrives once). The list is settings "bridges" (or "bridge", one address, before that list):
// "host:port" UDP, e.g. led-simulator (bridge_sim.py), or a network bridge board.
// Down: dst_mac(6) + packet. Up: src_mac(6) + packet.
// "/dev/ttyACM1" serial, the USB ESP-NOW bridge board in bridge/ (linux target only), or "serial:/dev/...".
// "usb:aabbccddeeff" a USB board by its MAC, wherever its port is (linux). A board added by port becomes this
// once it answers; the list is saved again then (bridge_set_renamed_cb).
// "dmx:<id>" a DMX bridge (bridge_dmx.h, linux only): the "dmx_bridge" record id's fixtures, each a
// led-driver of its own, sent as Art-Net, sACN or USB-DMX at 40 Hz.
// "browser" the rig page at /sim/: the simulated drivers run in the browser and get the frames over the
// page's WebSocket (sim_rig.c). Always running on esp32p4, whatever the list says.
// "c6" the ESP32-P4-Nano's own C6 radio (bridge_hosted.h, esp32p4 only). Always running on
// that target, whatever the list says: the P4 has no ESP-NOW of its own.
// While one runs, nothing goes out over the air.
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "esp_err.h"
typedef void (*bridge_rx_cb_t)(const uint8_t *src_mac, const uint8_t *data, int len);
// Microphone audio from a board that has one: 16 kHz mono samples, BRIDGE_AUDIO_SAMPLES at a time
typedef void (*bridge_audio_cb_t)(const int16_t *pcm, size_t n);
#define BRIDGE_DEFAULT_PORT 8766
#define BRIDGE_MAX_LINKS 8
#define BRIDGE_ADDR_MAX 80
#define BRIDGE_BROWSER "browser"
// Make the running set of bridges addrs[0..n-1] (see above). Bridges not in the list are closed, new ones
// opened, and frames received from any of them go to cb. Returns the first error, if any; the bridges that
// could open stay up.
esp_err_t bridge_set_all(const char addrs[][BRIDGE_ADDR_MAX], size_t n, bridge_rx_cb_t cb);
// Called when a bridge's address changed by itself (a USB board became "usb:<mac>"): save the list
void bridge_set_renamed_cb(void (*cb)(void));
bool bridge_active(void);
// A frame the rig page's drivers sent: src_mac(6) + packet (sim_rig.c). Dropped unless "browser" runs.
void bridge_browser_rx(const uint8_t *frame, int len);
// The driver with this MAC was heard on the browser bridge since start: a simulated driver of the rig page
bool bridge_mac_is_browser(const uint8_t mac[6]);
// The driver with this MAC is a fixture of a running DMX bridge; that bridge's address ("dmx:<id>") in addr
bool bridge_mac_is_dmx(const uint8_t mac[6], char *addr, size_t n);
// The "browser" bridge is running
bool bridge_has_browser(void);
// Send to every running bridge
esp_err_t bridge_send(const uint8_t *dst_mac, const void *data, size_t len);
// The running bridges' addresses, in order; returns how many (at most max)
size_t bridge_list(char addrs[][BRIDGE_ADDR_MAX], size_t max);
// JSON array describing each running bridge: {addr, kind, ...}; returns its length
size_t bridge_status_json(char *out, size_t n);
// Serial ports a board may be on, as a JSON array of paths ("[]" off linux); returns its length
size_t bridge_ports_json(char *out, size_t n);
// Microphone audio from whichever board is recording (any bridge type)
void bridge_set_audio_cb(bridge_audio_cb_t cb);
// A running board has a microphone (USB or network)
bool bridge_has_mic(void);
// Start (true) or stop (false) the microphone on the board that has one. Network boards are asked every
// half second while they record, so a stop from the host is never needed for safety.
esp_err_t bridge_mic(bool on);
// Set the radio channel of the serial board at addr (linux). ESP_ERR_NOT_FOUND if no such board is running.
esp_err_t bridge_board_set_channel(const char *addr, uint8_t channel);