Draft
Conversation
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
Picks up fix for swapped sim min/max on vdig and vdiv (#59).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
New
manual-simbinary 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
crossterm(withevent-streamfeature) for async raw terminal input, integrates with the existing tokio runtime.simulate), which is more useful for quick manual injection.--list-topicsflag lets you discover available topics without digging through config files.Test Cases
List available topics:
Prints all topics with units.
Run with the example keymap (requires Siren on localhost:1883):
Prints key mappings, then pressing
vpublishes a random voltage toBMS/Pack/Voltage.Custom broker:
Missing keymap shows clap error:
Checklist
Closes #292