Commit Graph
92 Commits
Author SHA1 Message Date
swaits 65c43cda23 feat: donglora-cobs workspace crate with 31 spec-compliance tests
Extract COBS encoder/decoder into a separate no_std workspace crate
(crates/donglora-cobs) with comprehensive tests against the Cheshire &
Baker 1999 IEEE/ACM specification and Wikipedia canonical vectors.

Tests cover: empty input, single/multiple zeros, block boundaries at
254/255 bytes, alternating patterns, the Ping regression case (tag 0x00),
round-trip verification, and error cases (truncation, unexpected zeros).

Replace inline cobs_decode() in usb/task.rs with the tested crate.
Replace external cobs dependency with workspace crate.
Fix encoder bug at 254-byte block boundary (spurious trailing code byte).
2026-03-29 21:33:08 -06:00
swaits ee71bb69d3 fix: add explicit SF=7 and CR=5 match arms in radio converters
to_sf() relied on the catch-all _ => _7 to handle SF=7, and to_cr()
relied on _ => _4_5 for CR=5. Both work by accident but are misleading
— a reader would think SF=7 and CR=5 are unhandled. Make them explicit.
2026-03-29 21:33:08 -06:00
swaits b2e8b1d366 fix: COBS decoder stripped trailing 0x00 data bytes (broke Ping command)
The cobs_decode() function had a bogus 'strip trailing zero' step that
removed the last byte if it was 0x00. The Ping command IS tag byte 0x00,
so its decoded payload was stripped to empty, causing from_bytes to return
None. The COBS standard algorithm doesn't produce spurious trailing zeros
— the post-processing was simply wrong.

Also fix read_frame to skip bare 0x00 sentinels on fresh USB connects.
2026-03-29 21:33:07 -06:00
swaits d22d2b92ac feat: show MAC address on splash screen
Splash/waiting screen now shows:
  Row 1: "DongLoRa" (bold)
  Row 2: "Board Name vX.Y.Z"
  Row 3: MAC address (XX:XX:XX:XX:XX:XX)
  Row 4: "Waiting for host..."

Each board reads its MAC at init:
- ESP32-S3: efuse MAC via esp_hal::efuse::Efuse::mac_address()
- nRF52840: FICR device address registers

BoardInfo struct bundles name/version/mac to keep dashboard() under
clippy's argument limit.
2026-03-29 21:33:07 -06:00
swaits 7dc79c1a24 fix: clippy-clean — rename to_bytes→write_to, fix Justfile clippy args 2026-03-29 20:42:59 -06:00
swaits fd360e0cfe docs: rewrite PROTOCOL.md for fixed-size LE encoding — no varint, no zigzag 2026-03-29 20:42:59 -06:00
swaits 7a947a1a05 refactor: update Python examples for fixed-size LE wire format
Remove all varint/zigzag encoding. Every field is now struct.pack/unpack
with fixed-size little-endian format strings. RadioConfig is a single
struct.pack('<IBBBHB', ...) call. Response decoding uses struct.unpack_from
with known offsets. No encoding helpers needed beyond struct.
2026-03-29 20:42:59 -06:00
swaits 1646564bc1 refactor: replace postcard/serde with fixed-size LE wire format
Drop postcard and serde dependencies entirely. All integers are now
fixed-width little-endian on the wire — no varints, no zigzag encoding.
A developer sending tx_power_dbm=14 sees 0x0E on the wire. No surprises.

- RadioConfig: 10 bytes fixed (freq:4 LE, bw:1, sf:1, cr:1, sync:2 LE, pwr:1)
- Commands/Responses: tag byte + fixed-size fields
- Vec<u8>: 2-byte LE length prefix + raw bytes
- Option<T>: 1-byte (0=None, 1=Some) + T
- COBS framing preserved (just byte-stuffing, no encoding tricks)
- Manual COBS decode replaces postcard's CobsAccumulator
- Removes ~15KB from firmware binary (no serde monomorphization)
2026-03-29 20:42:58 -06:00
swaits 584524dace docs: fix worked example, encoding table, and CHANGELOG for u8/i8 raw bytes and TX_POWER_MAX 2026-03-29 20:42:58 -06:00
swaits ebe9197d04 feat: per-board TX power range, TX_POWER_MAX sentinel (-128)
- Each board exports TX_POWER_RANGE constant (min, max dBm)
- RadioConfig::validate() uses the board's range, not hardcoded limits
- TX_POWER_MAX sentinel (-128 on the wire) means "use board's maximum"
  — resolved to the actual max before storing config
- GetConfig returns the resolved actual power, not the sentinel
- Default configs in examples use TX_POWER_MAX
- Protocol docs updated
2026-03-29 20:42:58 -06:00
swaits 0b4eb04591 fix: correct postcard encoding for u8/i8 fields (was using varint/zigzag)
ROOT CAUSE: postcard encodes u8 and i8 as raw bytes, NOT varint/zigzag.
The Python encoders used varint() for u8 and zigzag() for i8. For small
values this was silently correct (varint(7) == raw byte 7), but for
tx_power_dbm: zigzag(14) = 28, which the new validation correctly
rejected as out of range (-9..22). This was a pre-existing bug masked
by the absence of validation.

Fix all RadioConfig field encoders in both donglora.py and meshcore_rx.py.
Fix docs/PROTOCOL.md to correctly document i8 as raw byte, not zigzag.
Restore full config validation.
2026-03-29 20:42:58 -06:00
swaits a0d9b3b4f0 docs: README rewrite for publication 2026-03-29 20:42:58 -06:00
swaits 8a5d8c419e refactor: relocate MeshCore tools to examples/meshcore/
MeshCore is a protocol implementation ON TOP of DongLoRa, not part of the
dongle itself. Moving it to examples/ makes the separation clear while
keeping it accessible as a real-world usage example.
2026-03-29 20:42:58 -06:00
swaits 8790ebfd7b feat: example scripts (simple_rx, simple_tx, ping_pong) with shared donglora.py helper 2026-03-29 20:42:58 -06:00
swaits f56ddf196a docs: complete USB protocol specification (docs/PROTOCOL.md) 2026-03-29 20:42:57 -06:00
swaits 9d6ae7db6a docs: CHANGELOG.md and CONTRIBUTING.md 2026-03-29 20:42:57 -06:00
swaits 3a03778e47 chore: LICENSE (MIT), Cargo.toml metadata, gitignore firmware, display cleanup
- Add MIT LICENSE file (Stephen Waits <steve@waits.net>)
- Add Cargo.toml: authors, license, description, repository, readme, keywords
- Gitignore /firmware (built binaries don't belong in VCS)
- Display task: use DisplayState::new() for reset, handle watch/brightness errors
2026-03-29 20:42:57 -06:00
swaits a60c18a8bf fix: eliminate panics, validate config, handle all errors in radio/USB tasks
Radio task:
- Remove all .unwrap() — start_rx/rx_once now take &RadioConfig directly
- Validate RadioConfig on SetConfig and Transmit (freq, SF, CR, power)
- Notify host when RX restart fails (was silently going Idle)
- Clamp payload length with warning instead of silent truncation
- Extract modulation_params() helper, eliminating 3x duplication
- Name all magic numbers (PREAMBLE_LEN, CRC_ON, etc.)
- Add comprehensive module documentation

USB task:
- Log serialization and write failures instead of silently dropping
- Break chunk loop on write error
- Add compile-time buffer size assertion

Protocol:
- Add RadioConfig::validate() with SX1262 hardware limits
- Document all field ranges
2026-03-29 20:42:57 -06:00
swaits ece7cbc8ab refactor: make CodingRate a plain u8 denominator (5-8) on the wire
CodingRate was an enum with repr(u8) values that didn't match postcard's
wire encoding (variant index). Instead of papering over the mismatch,
make cr a plain u8 in RadioConfig. Host sends the denominator directly:
5 for CR 4/5, 6 for CR 4/6, etc. No lookup tables, no index confusion.

Remove CodingRate enum, cr_denom() helper, and the Bandwidth import that
was only needed for cr_denom. ErrorCode repr values also fixed to 0-based.
2026-03-29 20:42:57 -06:00
swaits 920dd7cef8 fix: reject payload_ver > 0 as non-MeshCore (only v0 is implemented) 2026-03-29 20:42:57 -06:00
swaits 3451ceb652 feat: MeshCore decoder, Watchman, test corpus, sparkline TX indicators
Firmware:
- fix(protocol): SNR type i8→i16 to match lora_phy PacketStatus
- fix(display): combine splash + waiting into one screen
- fix(display): move TX power to row 0 right-justified
- feat(display): sparkline distinguishes TX from RX — TX bars are dotted
  (alternating pixel rows), RX bars are solid. TX-only slots show a short
  marker. TX takes precedence over RX in the same time slot.

Host tool (tools/meshcore_rx.py):
- feat: full MeshCore packet decoder with colored ANSI output
- feat: GRP_TXT decryption using 276 channels from channels.csv
- feat: Watchman loop/collision reporter to #watchman
- feat: ADVERT-informed node registry with 12h TTL persistence
- feat: transport code fallback for older MeshCore firmware
- fix: robust error handling for long-running operation
- fix: collision detection uses evidence-based reasoning from advert cache

Channel directory (tools/channels.csv): 276 channels

Test corpus (corpus/): JSON Schema, 28 hand-crafted vectors, Hypothesis generator
2026-03-29 20:42:56 -06:00
swaits eab42e9ad8 fix: invert only RX/TX letters, not surrounding spaces in display 2026-03-29 20:42:56 -06:00
swaitsandClaude Opus 4.6 a569e09b42 fix: reliable USB disconnect/reconnect display handling
- Poll DTR every 250ms via select3 timer arm (read_packet blocks
  forever after host closes port, so DTR check must not depend on it)
- DTR drop → send DisplayCommand::Reset (blocking send, not try_send)
- DTR rise → send DisplayCommand::On
- Display task: disconnected flag ignores StatusWatch while set,
  preventing stale radio status from overriding the idle screen
- On reconnect, display grabs current RadioStatus from watch and
  renders dashboard immediately (no waiting for next radio event)
- Simplified clippy to use _cargo helper

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 20:42:56 -06:00
swaitsandClaude Opus 4.6 4e7e6d2167 feat: USB OTG CDC-ACM with custom VID:PID, disconnect UX
Switch all ESP32-S3 boards from UsbSerialJtag to USB OTG CDC-ACM via
embassy-usb. The USB device stack is now shared code — boards only
provide the platform-specific embassy-usb Driver.

- Custom VID:PID 1209:5741 (open-source VID, "WA" PID)
- CDC-ACM class with proper device enumeration
- COBS+postcard protocol over CDC-ACM packet read/write
- Concurrent USB device loop + protocol loop via join()
- On disconnect: sends DisplayCommand::Reset to show "Waiting for host..."
- Justfile: espflash no longer uses --monitor (OTG steals PHY)
- Test script updated to detect by new VID:PID

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 20:42:56 -06:00
swaitsandClaude Opus 4.6 78b0c25040 chore: note custom USB VID:PID 1209:5741 for future OTG implementation
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 20:42:56 -06:00
swaitsandClaude Opus 4.6 e8744e17da fix: CR encoding bug, display overflow, auto-reconnect script
- Fix CodingRate encoding: postcard uses 0-based variant index, not
  repr(u8) value. CR 4/5 is variant 0, not 1.
- Shorten RSSI/SNR display line to fit 21-char width
- Python script auto-detects DongLoRa by USB VID:PID (303a:1001),
  reconnects on device reset/disconnect, no more crash on RST

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 20:42:56 -06:00
swaitsandClaude Opus 4.6 102ce417ff fix: ack SetConfig/StartRx/StopRx, improve display layout
Protocol:
- SetConfig, StartRx, StopRx now send Response::Ok on success
  (host was timing out waiting for acks that never came)

Display:
- Full frequency precision: 910.525MHz not 910.5MHz
- Full bandwidth labels: 62.5kHz not 62k
- RSSI/SNR row shows units (dBm, dB)
- Separator line moved down 3px to give RSSI/SNR breathing room
- Sparkline is now time-based: each bar = 1 second, scrolls left,
  showing ~1 minute of RSSI history. Empty slots = no packets.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 20:42:56 -06:00
swaitsandClaude Opus 4.6 024b03c7ad feat: implement LoRa radio operations (TX, RX, config)
Wire up the lora-phy driver in radio_task:
- SetConfig stores radio parameters
- StartRx enters continuous receive mode via lora-phy
- rx_once waits for a packet, reports RSSI/SNR/payload to host
- StopRx returns to standby
- Transmit sends a payload with the configured (or overridden) params
- Concurrent RX: select between incoming packets and host commands
- Automatic RX restart after receiving a packet or completing TX
- Error handling: radio errors are reported to host, RX fallback to idle

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 20:42:55 -06:00
swaitsandClaude Opus 4.6 b6fd85495a feat: implement USB serial with COBS-framed postcard protocol
Wire up UsbSerialJtag on ESP32-S3 boards for host communication:
- Read COBS-framed postcard commands from host via serial
- Route DisplayOn/Off to display task, everything else to radio
- Serialize responses back to host as COBS frames
- Use postcard::CobsAccumulator for chunked deserialization
- Concurrent read/write via embassy select

RAK nRF52840 USB (embassy-usb CDC-ACM) is still a stub — different
init path, will be implemented separately.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 20:42:55 -06:00
swaitsandClaude Opus 4.6 f1df675363 refactor: rename project to DongLoRa
Rebrand from lora-dongle to DongLoRa (portmanteau of dongle + LoRa).
Lowercase donglora in Cargo package name, firmware filenames, and code.
Splash screen shows "DongLoRa" in 9x15 bold.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 20:42:55 -06:00
swaitsandClaude Opus 4.6 7d20e3ef97 fix: resolve ESP32-S3 runtime crash, match official esp-hal examples
Root causes found and fixed:
- USB OTG init stole the PHY from USB-Serial-JTAG (the only USB on V4)
- executor-thread feature conflicted with esp-hal-embassy's executor
- Linker flags needed -Wl, prefix for GCC-to-LD passthrough
- Missing exception-handler feature on esp-backtrace
- Missing alloc in build-std
- Missing LTO and codegen-units=1 in release profile
- Vext on V4 is active LOW (datasheet correct, Arduino lib was wrong)

Now matches the official esp-hal v0.22.0 examples exactly.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 20:42:55 -06:00
swaitsandClaude Opus 4.6 b90739d2a2 fix: use espflash for ESP32, add prereq checks with install instructions
- flash command uses espflash for Xtensa boards, probe-rs for ARM
  (ESP32-S3 has a USB-serial bootloader, not a debug probe)
- Pre-flight checks before flash: missing tools get a clear error with
  the exact install command instead of a cryptic failure
- Pre-flight check for esp toolchain before build/clippy too

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 20:42:55 -06:00
swaitsandClaude Opus 4.6 da37f6aa8a fix: resolve ESP32-S3 linker errors, all boards produce firmware
Three fixes:
- Add .cargo/config.toml with -Tlinkall.x for xtensa target (resolves
  ROM functions, interrupt handlers, memory layout)
- Add integrated-timers feature to embassy-executor for ESP32 boards
  (resolves _embassy_time_schedule_wake)
- Add `use esp_println as _` to pull in defmt global_logger (was being
  stripped as dead code because nothing referenced the crate)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 20:42:55 -06:00
swaitsandClaude Opus 4.6 7bf4041357 docs: add README with board support matrix
Three tiers: supported now, next up (popular/straightforward), and
future (niche/contributions welcome). Board names follow MeshCore
flasher conventions.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 20:42:55 -06:00
swaitsandClaude Opus 4.6 78827155b5 fix: source espup env for linker, add build-all, fix Ctrl+C handling
- Source ~/export-esp.sh in Justfile for xtensa builds (provides GCC)
- Add build-all target for producing firmware
- Trap SIGINT in build-all/check-all so Ctrl+C stops immediately
- Add .cargo/config.toml to .gitignore (may be generated)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 20:42:54 -06:00
swaitsandClaude Opus 4.6 c37b63fa18 refactor: rename rak_4631 to rak_wisblock_4631, add proper display names
Board naming now follows MeshCore conventions:
- rak_4631 → rak_wisblock_4631 (feature, file, Justfile, splash screen)
- Display splash shows human-readable names: "RAK WisBlock 4631",
  "Heltec v3", "Heltec v4"

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 20:42:54 -06:00
swaitsandClaude Opus 4.6 110172ded7 feat: add Heltec V4, wire up V3/V4 peripherals, restructure entry point
- Add heltec_v4 board: ESP32-S3R2, SX1262, SSD1315 display, native USB,
  Vext on GPIO36 (active HIGH)
- Wire up heltec_v3 with real esp-hal peripherals (was a stub)
- V3 and V4 share radio/I2C pins, differ in Vext pin/polarity and
  display reset
- Restructure main.rs: cfg_if selects embassy_executor::main (Cortex-M)
  vs esp_hal_embassy::main (Xtensa) per board
- Display detection via SSD1306 init in display_task — boards always
  provide I2C bus, task exits gracefully if no display responds

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 20:42:54 -06:00
swaitsandClaude Opus 4.6 8649b2ec46 fix: get Heltec V3 (ESP32-S3) building with esp toolchain
Use nightly cargo + esp rustc (RUSTC override) + -Zbuild-std=core for
Xtensa targets. This avoids the esp cargo's inability to parse modern
crate manifests (edition 2024) while still using esp's LLVM with full
Xtensa support.

Pin proc-macro-crate to 3.2.0 to avoid transitive deps requiring
rustc 1.85+.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 20:42:54 -06:00
swaitsandClaude Opus 4.6 3102fc747a feat: add display UI with splash screen, dashboard, and RSSI sparkline
Implement full SSD1306 OLED display support:
- Splash screen on boot (1.5s) with project name, version, board
- Dashboard showing radio state, config, counters, RSSI/SNR
- RSSI history sparkline (64-sample ring buffer, 2px-wide bars)
- DisplayOn/DisplayOff host commands routed via dedicated channel
- Pure render functions against generic DrawTarget (no hardware coupling)
- Display on/off control bypasses radio task entirely

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 20:42:54 -06:00
swaits 7064110293 feat: restore Heltec V3, add firmware output, support all common boards
Reverts the removal of heltec_v3 — it's a major board. Xtensa builds
use the esp toolchain (+esp via espup); check-all gracefully skips
boards whose toolchain isn't installed.

Build artifacts now land in firmware/ with readable names like
lora-dongle-rak_4631-release.elf instead of being buried in target/.

DESIGN.md updated with "support all common boards" principle (#10)
and corrected toolchain policy (#11).
2026-03-29 20:42:54 -06:00
swaits 0e9315280b refactor: drop Heltec V3, enforce standard toolchain, remove dead code
Heltec V3 (ESP32-S3) requires the espup Xtensa toolchain fork, which
violates the standard-toolchain-only principle. Removed until upstream
Rust supports Xtensa targets via stock rustup.

Also removes all #[allow(dead_code)] band-aids — unused items are
deleted rather than suppressed. DESIGN.md updated with standard
toolchain principle (#10) and peripheral model (input/telemetry slots).
2026-03-26 15:29:58 -06:00
swaits c30f480c34 feat: initial lora-dongle firmware scaffold
Transparent LoRa-over-USB dongle firmware supporting Heltec V3 (ESP32-S3)
and RAK 4631 (nRF52840) boards. Actor-model architecture with typed
channels between USB, radio, and display tasks.

- Protocol: Command/Response enums with COBS+postcard framing design
- Board abstraction: auto-discovered via build.rs Jinja2 codegen
- Radio task: SX1262 state machine (Idle → Receiving ↔ Transmitting)
- Display task: optional SSD1306 dashboard via StatusWatch
- RAK 4631: fully wired SPI/USB/I2C peripherals, clippy-clean
- Heltec V3: structure in place, awaits espup Xtensa toolchain
2026-03-26 15:16:42 -06:00