velxio/test/multi_board_esp32/sketches/serial_passthrough/serial_passthrough.ino

37 lines
1.1 KiB
Arduino
Raw Normal View History

feat(multi-board): add wire-aware cross-board interconnect router Fixes the user-reported bug where two RPi Pico W boards wired GP0↔GP1 running SerialPassthrough don't communicate. Replaces the broken broadcast-style cross-board logic in addBoard (only routed AVR↔Pi3B, ignored wires entirely, no RP2040↔anything path) with a wire-aware Interconnect singleton. Architecture: digital pin transitions are the lowest-common-denominator abstraction. Each simulator's hardware peripherals (UART/I2C/SPI) and bit-banging libraries (SoftwareSerial, software I2C) decode the transitions naturally — propagate the pin and the protocols come for free. For cross-process boards (ESP32 backend QEMU, Pi3B QEMU) a byte-level shortcut is additionally enabled on hardware-UART pin pairs to handle high-baud links over WebSocket latency. Implementation: - New simulation/Interconnect.ts singleton subscribes to wire/board changes via the Zustand store. Handlers per tier: browser-sim → pinManager.onPinChange, ESP32 → Esp32Bridge.sendPinEvent, Pi3B → bridge.sendPinEvent. Re-entrancy guard via per-(board,pin) Set. - New utils/boardProtocols.ts classifies pins (uart-tx, i2c-sda, etc.) per board kind, used as optimization hint for the byte shortcut. - types/wire.ts: added signalType field, exports WireSignalType / WireColorMap (fixes a pre-existing TS import error in wireColors). - Deleted the bridgeMap/simulatorMap broadcast forEach blocks in addBoard. Initial board + future boards register with Interconnect via setInterconnectRuntime + store subscription. - PinManager.resetPinStates() helper for test isolation. Tests (16 new files, 96 tests, all passing): - Per-pair × per-protocol matrix: dual-arduino-digital, dual-pico-digital, arduino-pico-digital, triple-pico-digital-chain, dual-arduino-hw-uart, dual-arduino-software-serial, arduino-pico-mixed-uart, arduino-esp32-uart, dual-esp32-uart, pi3-pico-uart, arduino-pico-i2c, arduino-arduino-spi, interconnect-routing, dual-arduino-multi-protocol (UART+I2C+SPI+ digital + concurrent), dual-pico-multi-protocol (UART0+UART1 alt+ I2C0+I2C1+SPI0+digital + 3-Pico star topology) - Updated dual-pico-serial-passthrough to assert correct behaviour - Backend test/multi_board_esp32/test_dual_esp32_serial.py for two real QEMU instances (skip-graceful when lcgamboa lib absent) Verified: 1107/1107 tests pass, zero regressions, vite build OK. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-26 05:47:28 +07:00
// Bidirectional ESP32 ↔ ESP32 serial passthrough.
//
// Each ESP32's USB Serial talks to the host Python; Serial2 (UART2 on
// GPIO16=RX / GPIO17=TX) talks to the OTHER ESP32 via the wire that
// the Velxio Interconnect routes through the WebSocket bridge.
//
// Usage in the dual-ESP32 integration test:
// - Host writes "PING-A" to ESP32-A's USB Serial
// - ESP32-A forwards it to Serial2 (TX on GPIO17)
// - The frontend Interconnect bridges A.GPIO17 → B.GPIO16 over WS
// - ESP32-B reads it from Serial2 (RX on GPIO16)
// - ESP32-B prints the received line back on USB Serial
// - Host observes "PING-A" on ESP32-B's USB Serial output
//
// Compile (one-shot):
// arduino-cli compile --fqbn esp32:esp32:esp32 \
// --output-dir test/multi_board_esp32/out \
// test/multi_board_esp32/sketches/serial_passthrough
void setup() {
Serial.begin(115200);
Serial2.begin(9600, SERIAL_8N1, 16, 17);
delay(100);
Serial.println("READY");
}
void loop() {
if (Serial.available()) {
int c = Serial.read();
Serial2.write(c);
}
if (Serial2.available()) {
int c = Serial2.read();
Serial.write(c);
}
}