Skip to content

#292 - interactive MQTT manual-sim tool#293

Draft
bracyw wants to merge 10 commits intoDevelopfrom
292-interactive-mqtt-injection-tool
Draft

#292 - interactive MQTT manual-sim tool#293
bracyw wants to merge 10 commits intoDevelopfrom
292-interactive-mqtt-injection-tool

Conversation

@bracyw
Copy link
Copy Markdown
Collaborator

@bracyw bracyw commented Mar 29, 2026

Changes

New manual-sim binary for interactive MQTT injection -- press mapped keys to publish randomized sensor values to specific topics. Useful for manual testing without needing the full simulator or CLI MQTT clients.

Notes

  • Uses crossterm (with event-stream feature) for async raw terminal input, integrates with the existing tokio runtime.
  • Randomizes values across the full min/max range per keypress (not incremental like simulate), which is more useful for quick manual injection.
  • --list-topics flag lets you discover available topics without digging through config files.
  • RAII guard ensures terminal raw mode is always cleaned up, even on panic.

Test Cases

  • List available topics:

    cargo run --bin manual-sim -- --list-topics
    

    Prints all topics with units.

  • Run with the example keymap (requires Siren on localhost:1883):

    cargo run --bin manual-sim -- --key-map manual_sim_keymap.example.json
    

    Prints key mappings, then pressing v publishes a random voltage to BMS/Pack/Voltage.

  • Custom broker:

    cargo run --bin manual-sim -- --key-map manual_sim_keymap.example.json -u 10.0.0.5:1883
    
  • Missing keymap shows clap error:

    cargo run --bin manual-sim
    

Checklist

  • No merge conflicts
  • All checks passing
  • Remove any non-applicable sections of this template
  • Assign the PR to yourself
  • Request reviewers & ping on Slack
  • PR is linked to the ticket

Closes #292

bracyw added 3 commits March 29, 2026 18:44
New standalone binary (src/bin/inject) that maps keyboard keys to MQTT
topics and publishes a random value within each topic's defined min/max
range on keypress. Reuses SimComponent config from simulate.rs.

Features:
- Key-to-topic mapping via JSON file (--key-map)
- --list-topics to discover available topics
- Siren host override via --siren-host-url or CALYPSO_SIREN_HOST_URL
- Clean shutdown on Ctrl+C

Also cfg-gates imd_poll module to target_os=linux so the library crate
compiles on non-Linux platforms (simulate, inject, nerdbc, etc).
- Clamp values after rounding in randomize_component to prevent
  inc_min/round pushing values past min/max bounds
- Add RawModeGuard (RAII) so terminal restores on panic
- Extract publish_injection helper to reduce nesting in main loop
- Remove dead tracing import (no subscriber configured)
- Deduplicate stdout flush calls
Rename bin from inject to manual-sim for clarity.

Review fixes:
- Fix parse_key_map byte-length check to use char count (Unicode correctness)
- Add error feedback on protobuf serialization failure
- Log MQTT connection errors in poll_stub instead of silently swallowing
- Use clap required_unless_present for key_map argument
- Couple RawModeGuard with enable_raw_mode via constructor
- Log terminal event errors before exiting
- Simplify parse_key_map validation with destructure pattern
- Use idiomatic choose() for Discrete random selection
- Move values_str allocation into success branch
- Replace infallible if-let with direct indexing
- Remove SystemTime import, use UNIX_EPOCH.elapsed() consistently
@bracyw bracyw changed the title #292 - interactive MQTT injection tool #292 - interactive MQTT manual-sim tool Mar 31, 2026
@bracyw bracyw self-assigned this Mar 31, 2026
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.

Interactive MQTT Injection Tool for Calypso

1 participant