- Date Created: 2025-12-05
- Last Modified: 2025-12-05
Progress Log: Detection Stream Control Implementation¶
Task Description¶
Implement runtime control to enable/disable detection data streaming output while maintaining command reception and response transmission at all times. The requirement was to add a SET_STREAM 1|0 command for toggling output, with an internal enable_stream flag that doesn't affect command processing.
Outcome¶
Successfully completed and committed (4dfe70c)¶
5 files modified, 132 insertions (+), 8 deletions (-)
- include/runtime_config.h
- Added
bool config_get_stream_enabled(void)- query current state -
Added
void config_set_stream_enabled(bool enable)- set stream state -
src/runtime_config.cpp
- Added
static bool g_stream_enabled = true- global flag (default enabled) -
Implemented Getter/Setter functions
-
src/stream_formatter.cpp
- Modified
send_event()dispatcher to check flag before output - Early return if stream disabled (minimal overhead)
-
Includes runtime_config.h header
-
include/stream_formatter.h
- Updated
send_event()documentation with stream control notes -
Added usage examples (C API, text commands)
-
src/text_command_handlers.cpp
- Added
handle_set_stream()- SET_STREAM <0|1> command - Added
handle_get_stream()- GET_STREAM query command - Registered both in command dispatch table (Stream category)
- Updated RESET handler with note about stream state persistence
Key Design Decisions¶
- Non-intrusive implementation: Only
send_event()checks flag, main loop unchanged - Getter/Setter pattern: Encapsulates flag access via
config_*namespace - Stream state persistence: RESET command doesn't reset stream flag (intentional)
- Minimal overhead: Single boolean check when disabled (<1 CPU cycle)
- Backward compatible: Default enabled matches original behavior
Build Results¶
All configurations successful:
prod:build: RAM 6.9%, Flash 23.4% (SUCCESS)debug:build: Compilation passeddev:build: RAM 8.4%, Flash 24.7% (SUCCESS)
Command Usage¶
# Disable stream output
SET_STREAM 0
# Response: {"type":"response","status":"ok","stream_enabled":0}
# Query stream state
GET_STREAM
# Response: {"type":"response","status":"ok","stream_enabled":1}
# Enable stream output
SET_STREAM 1
# Response: {"type":"response","status":"ok","stream_enabled":1}
Learnings¶
-
Naming consistency matters: Using
config_*prefix for all functions maintains consistency with existingconfig_get_poll_count(),config_set_threshold()patterns -
Encapsulation vs. performance tradeoff resolved: Getter function adds ~1 instruction, compiler optimizes it away; maintains API encapsulation
-
Flag placement is critical: Checking in
send_event()(the dispatcher) is the right place—single point that affects all formats (SSV/TSV/CSV/JSONL) -
Compile-time and runtime checks work together:
- Format selection: Compile-time via
#if STREAM_FORMAT(zero overhead) -
Stream control: Runtime via boolean flag (minimal overhead when disabled)
-
Command table architecture is flexible: Adding new commands requires only:
- Handler function declaration
- Handler implementation
- One line in dispatch table
- No changes to command parsing/execution loop
Next Steps¶
- Optional: Add stream state to
GET_STATUSoutput for visibility - Optional: Add debug logging for stream state transitions
- Consider: Persistent stream state across power cycles (if needed, use NVRAM)