Skip to content

Byte-accurate UART reads: read_uart_bytes() and bytes on uart_records() - #16

Draft
ShahriarAhnaf wants to merge 1 commit into
mainfrom
agent/uart-bytes-e5f6
Draft

ShahriarAhnaf wants to merge 1 commit into
mainfrom
agent/uart-bytes-e5f6

Conversation

@ShahriarAhnaf

Copy link
Copy Markdown
Contributor

Summary

  • Depends on simantic-dev/simantic-core#353 (UartRecord.Bytes, Session.ReadUartBytes) — merge order matters, core first.
  • uart_records() dicts (both renode and rust backends) gain a "bytes" key alongside "text".
  • New Sim.read_uart_bytes(from_start=False) -> bytes, mirroring send_bytes()'s naming next to send().
  • docs/session-api.md's method table updated (was text-only).

Also two real fixes needed to drive a raw .repl (not .replx) through Sim(repl=...) in-process at all, not workarounds specific to one test:

  • _add_machine() only sets RenderPlatform when the file is a .replx template. A ready .repl was being routed through the engine's render step regardless, which copies it to a temp path and breaks any relative using line — SessionMachine's own doc comment already draws this distinction, the code just didn't honor it.
  • load() now registers a AssemblyResolve fallback that probes the engine directory for assemblies Renode loads dynamically outside Simantic.Core's own dependency graph (e.g. Microsoft.Dynamic/IronPython for a platform's PythonPeripheral). The sim apphost finds these via the framework-dependent host's own directory-probing fallback; pythonnet's manual coreclr host doesn't get that fallback, so a repl with a PythonPeripheral failed to start when hosted in-process without this.

Why

send_bytes() was already byte-accurate on the way in; there was no byte-accurate way to read back out, which blocks testing firmware with binary UART protocols (UBX, MAVLink) from Python.

Test plan

  • pytest tests/ (153 passed, 7 skipped; 2 pre-existing failures only when $SIMANTIC_SIM points at the released engine that predates core#353 — pass once pointed at a build containing that PR)
  • Ported sim-fixtures WARG ZeroPilot GPS test (simantic-dev/sim-fixtures#200) from the MCP harness to this in-process API, xfail removed, genuinely passing — see that PR.

Co-Authored-By: Claude Sonnet 5 noreply@anthropic.com

…ords()

simantic-core#352/#353 carries raw bytes on UartRecord (Session.Bytes)
alongside the existing Text field. This exposes that on the Python side:

- uart_records() dicts gain a "bytes" key (both the renode and rust
  backends), mirroring send_bytes()'s naming next to send().
- Sim.read_uart_bytes(from_start=False) -> bytes concatenates the raw
  UART bytes since the last read, for binary protocols (UBX, MAVLink)
  where read_uart()'s str would need an encoding round trip to recover
  the original bytes.

Also fixes two things needed to actually drive a raw (non-.replx) .repl
platform file through Sim(repl=...) in-process, both real gaps rather
than task-specific workarounds:

- _add_machine() now only asks the engine to render a platform when it
  is a .replx template; a ready .repl (SessionMachine's own doc comment
  already distinguishes the two) is loaded as-is, so relative `using`
  lines resolve against its own directory instead of a temp path the
  engine renders to.
- load() registers an AssemblyResolve fallback that probes the engine
  directory for assemblies Renode loads dynamically outside Simantic.Core's
  own dependency graph (e.g. a platform's PythonPeripheral needing
  Microsoft.Dynamic/IronPython). The `sim` apphost finds these via its
  own directory-probing fallback; pythonnet's manual coreclr host does
  not get that fallback, so without this a repl containing a
  PythonPeripheral fails to start when hosted in-process.

docs/session-api.md's method table updated accordingly.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant