Skip to content

fix(simulator): restore host serial port bridge in WASM simulator#7284

Open
raphaelcoeffic wants to merge 2 commits intomainfrom
fix-7283
Open

fix(simulator): restore host serial port bridge in WASM simulator#7284
raphaelcoeffic wants to merge 2 commits intomainfrom
fix-7283

Conversation

@raphaelcoeffic
Copy link
Copy Markdown
Member

@raphaelcoeffic raphaelcoeffic commented Apr 11, 2026

Summary

Fixes #7283.

PR #6435 ported the simulator plug-ins to WASM but did not bridge the aux serial ports across the WASM boundary, leaving AUX1/AUX2 backed by a no-op driver. Lua serialWrite() / serialRead() and any other firmware code touching the aux serials was silently dropped.

This PR re-establishes the bridge across the WASM boundary; the existing Companion-side machinery (HostSerialConnector, SimulatorInterface aux serial signals, SimulatorMainWindow wiring) was already in place and is reused as-is.

WASM API additions

New imports (firmware → host):

  • simuAuxSerialStart(port_nr, baudrate, encoding)
  • simuAuxSerialStop(port_nr)
  • simuAuxSerialSetBaudrate(port_nr, baudrate)
  • simuAuxSerialSendBuffer(port_nr, data, len)

New export (host → firmware):

  • simuAuxSerialReceive(port_nr, data, len)

Test plan

  • WASM module (tx16s) and Companion build clean
  • End-to-end TX: Lua serialWrite("hello\n")socat PTY pair → host terminal sees the bytes
  • End-to-end RX: printf 'line\n' > /dev/ttysXXX → Lua serialRead() → tool script displays the line
  • Real USB-serial dongle (not done — verified with socat virtual PTY pair)

PR #6435 ported the simulator plug-ins to WASM but did not bridge the
aux serial ports across the WASM boundary, leaving AUX1/AUX2 backed by
a no-op driver. Lua serialWrite() and any other code touching the aux
serials was silently dropped, breaking host serial integration in
Companion's simulator (#7283).

Add a host bridge driver in simulib.cpp that forwards TX through new
WASM imports (simuAuxSerialStart/Stop/SetBaudrate/SendBuffer) and serves
RX from per-port mutex-protected queues, populated by a new
simuAuxSerialReceive export. On the Companion side, register native
callbacks that re-emit the existing SimulatorInterface aux serial
signals so HostSerialConnector (already wired up in
SimulatorMainWindow) drives the real host port, and implement
WasmSimulatorInterface::receiveAuxSerialData() to push host bytes back
into the firmware.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@wimalopaan
Copy link
Copy Markdown
Contributor

Tested with real USB/serial adapter (and using a rx-as-tx) on 921KB.
Looks very good to me!

The host_drv bridge added in the previous commit calls four WASM
imports (simuAuxSerialStart/Stop/SetBaudrate/SendBuffer).  On WASM
targets WASM_IMPORT resolves them via import_name attributes, but on
native builds (gtests-radio, SDL simu) the macro is a no-op, leaving
the declarations as plain externs with no definitions and breaking
link of every target with AUX_SERIAL enabled.

Provide no-op stubs for the four functions in simulib.cpp, guarded by
!__wasm__, so native builds link cleanly.  The WASM simulator path is
untouched and Companion continues to resolve the symbols through WAMR.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@raphaelcoeffic raphaelcoeffic added the bug/regression ↩️ A new version of EdgeTX broke something label Apr 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug/regression ↩️ A new version of EdgeTX broke something

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Simulaor (WASM): host serial ports aren't working anymore

2 participants