2026 sim: drive the Unity simulation with the real remote over the radio
Dongle (app):
- bridge mode: stands in for the robot's radio (ch 96 / 250k / HXPD1,
auto-ack, dynamic payloads, ack payloads). Received packets go to the PC
as A5-framed 'R' frames; the PC's 'A' frames become the ack payload of
the next packet, like robot/Comms.cpp; dropped after ~0.5 s without a
refresh. 'S' status once a second.
- USART RX through circular DMA into a ring buffer, overrun stall
disabled, error flags cleared: a burst (e.g. SignalRGB probing the port)
used to deafen the app until a replug.
- RX test mode ('x') accepts protocol v4's dynamic-length packets.
- safeboot_flash.py --knock: keeps knocking across a replug to catch
safeboot's cold-boot window when the app doesn't answer.
Unity:
- SimRemote sources: Keyboard, or the real remote via the dongle
(DongleLink.cs: kernel32 serial, auto-finds the CH340, all port I/O on
one background thread). Packets go into the firmware byte for byte, the
robot's telemetry goes back on the ack, so the remote's display shows
the sim. Tested end to end with the real remote.
- Dropped the USB joystick and robot-serial-harness inputs and the old
Serial/Serial2/Serial3/HandleHoystick scripts (and their components in
Main.unity): no USB links to remote or robot any more.
- Test panel: dongle status; no sideways scroll bar.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6b3b2629cd
commit
2b4750f8f4
24 files changed
+682
-710
No files matched your search
@@ -2,12 +2,14 @@
|
||||
No BOOT0 wire, no ST-Link, no ROM bootloader. Writes only the app region
|
||||
(pages 4-15); safeboot itself is never touched.
|
||||
|
||||
usage: safeboot_flash.py app.bin [--port COM16]
|
||||
usage: safeboot_flash.py app.bin [--port COM16] [--knock]
|
||||
|
||||
How it enters flash mode:
|
||||
1) if the app is running, 'b' makes it soft-reset into safeboot flash mode;
|
||||
2) otherwise (dead/absent app) replug the dongle and this spams 'S' to catch
|
||||
safeboot's cold-boot knock window.
|
||||
--knock skips 1) and keeps knocking for 2 minutes, reopening the port as it
|
||||
comes and goes: start it, then replug. Use it when the app doesn't answer.
|
||||
"""
|
||||
import sys, time, serial
|
||||
|
||||
@@ -54,6 +56,36 @@ def enter_flash(s):
|
||||
return False
|
||||
|
||||
|
||||
def knock_until_caught(port, timeout=120.0):
|
||||
"""--knock: for an app that doesn't answer 'b' (dead or deaf). Keeps the
|
||||
port open and spams 'S' for up to `timeout` s, reopening whenever the port
|
||||
vanishes, so replugging the dongle at any moment lands in safeboot's 1.5 s
|
||||
cold-boot knock window. Returns the open port in flash mode, or None."""
|
||||
t = time.time()
|
||||
s = None
|
||||
while time.time() - t < timeout:
|
||||
try:
|
||||
if s is None:
|
||||
s = serial.Serial(port, 115200, timeout=0.02)
|
||||
s.write(b"S")
|
||||
r = s.read(16)
|
||||
if b"K" in r or b"SB1" in r or b"SBR" in r:
|
||||
time.sleep(0.1); s.reset_input_buffer(); s.timeout = 0.3
|
||||
s.write(b"V"); time.sleep(0.1)
|
||||
if b"SBV" in s.read(16):
|
||||
return s
|
||||
s.timeout = 0.02
|
||||
except (serial.SerialException, OSError):
|
||||
try:
|
||||
if s is not None:
|
||||
s.close()
|
||||
except Exception:
|
||||
pass
|
||||
s = None
|
||||
time.sleep(0.02)
|
||||
return None
|
||||
|
||||
|
||||
def expect(s, ch, what):
|
||||
r = s.read(1)
|
||||
if r != ch:
|
||||
@@ -68,11 +100,18 @@ def main():
|
||||
data += b"\xFF"
|
||||
print("app %s: %d bytes -> 0x%08X" % (args[0], len(data), APP_BASE))
|
||||
|
||||
s = open_port(port)
|
||||
print("entering safeboot flash mode...")
|
||||
if not enter_flash(s):
|
||||
print("could not enter flash mode (app not running? replug and retry)")
|
||||
return 1
|
||||
if "--knock" in sys.argv:
|
||||
print("knock mode: replug the dongle now (waiting up to 2 min)...")
|
||||
s = knock_until_caught(port)
|
||||
if s is None:
|
||||
print("no knock window caught")
|
||||
return 1
|
||||
else:
|
||||
s = open_port(port)
|
||||
print("entering safeboot flash mode...")
|
||||
if not enter_flash(s):
|
||||
print("could not enter flash mode (app not running? replug and retry with --knock)")
|
||||
return 1
|
||||
s.reset_input_buffer()
|
||||
s.write(b"V"); time.sleep(0.1)
|
||||
print("safeboot:", s.read(16).decode("ascii", "replace").strip())
|
||||
|
||||
Reference in new issue
Block a user