Zephyr Shell Integration
Relevant source files
The following files were used as context for generating this wiki page:
Zephyr Shell Integration in ComChan provides specialized support for interacting with and parsing data from the Zephyr RTOS shell and logging subsystem. This feature enables the tool to differentiate between interactive shell commands, structured log outputs, and raw sensor data, ensuring that plotting and monitoring remain accurate even when telemetry is interleaved with system logs.
The integration includes specific logic to strip Zephyr-specific log headers (such as level indicators like <inf> or <err>) and handles the echoing behavior of the Zephyr shell to prevent duplicate data from appearing in the monitor or plotter. Sources: CHANGELOG.md:129, CHANGELOG.md:195, src/parser.rs:163-174
Configuration and Initialization
The Zephyr shell mode is activated via a dedicated configuration flag. When enabled, the application adjusts its serial communication and parsing strategies to accommodate Zephyr's interactive nature.
Configuration Parameters
The following configuration options directly impact Zephyr integration:
| Option | Type | Description |
|---|---|---|
zephyr | bool | Enables Zephyr Shell mode, activating specific log stripping and echo suppression. |
reset_delay_ms | u64 | Time to wait after opening the port before sending initial Zephyr commands (default 1000ms). |
baud | u32 | Standard baud rate, typically configured to match the Zephyr target (default 9600). |
Sources: src/config.rs:88, src/config.rs:109, src/config.rs:198
Initialization Flow
During the startup of "Normal Mode" (Monitor), the system performs a reset sequence if the Zephyr flag is active. This includes sending a carriage return (\r) to trigger the shell prompt and handling initial metadata headers.
Sources: src/monitor.rs:252-277
Data Processing Architecture
The integration relies on a multi-stage parsing pipeline that cleans incoming strings before they reach the telemetry engine or the TUI.
Log Header Stripping
The strip_zephyr_headers function is a specialized preprocessor. It identifies standard Zephyr log levels and removes the metadata, preserving only the actual payload for the plotter.
fn strip_zephyr_headers(line: &str) -> &str {
let is_zephyr_log = line.contains("<inf>")
|| line.contains("<err>")
|| line.contains("<wrn>")
|| line.contains("<dbg>");
if is_zephyr_log && let Some(gt_pos) = line.find('>') {
return line[gt_pos + 1..].trim_start();
}
line
}
Sources: src/parser.rs:163-174
Telemetry Parsing Pipeline
When data arrives, it follows a specific flow to ensure that Zephyr-specific formatting does not interfere with numeric extraction.
Sources: src/parser.rs:114-124, src/parser.rs:163-174
Monitor Mode Integration
In monitor.rs, the integration handles the interactive aspects of the Zephyr shell.
Echo Suppression and Line Accumulation
The monitor tracks the last_sent command. If Zephyr mode is enabled, it compares incoming data against the last_sent buffer to suppress the local echo commonly generated by the Zephyr shell. This prevents the TUI from displaying the user's own typed command as an incoming RX message. Sources: src/monitor.rs:260-272
Interactive Shell Flow
- Input: User types a command in the TUI.
- Transmission: The command is appended with
\rand sent to the target. - Echo Handling: The incoming echo from the Zephyr shell is detected and discarded.
- Response Parsing: The subsequent output from the command is processed for both display and plotting.
Sources: src/monitor.rs:484-518
Plotting from Zephyr Logs
The plotter supports real-time visualization of data embedded within Zephyr logs. The parse_sensor_data function uses rfind on delimiters (like : or =) to safely handle lines like dht22_logger: Temperature: 25.0, where the first segment is the Zephyr module name and the second is the telemetry data. Sources: src/parser.rs:271-274
Supported Format Example
| Raw Zephyr Log | Processed Telemetry |
|---|---|
<inf> app: Temp: 22.5 | Temp = 22.5 |
<dbg> sensor_hub: Humidity=60 | Humidity = 60.0 |
Sources: src/parser.rs:163-174, src/parser.rs:271-274
Summary
Zephyr Shell Integration makes ComChan a powerful tool for Zephyr RTOS development by providing a clean interface that manages the complexities of shell echos and multi-level logging. By stripping metadata early in the parsing pipeline, the tool ensures that the Serial Plotter receives clean numeric data even when the target device is providing verbose system diagnostics. Sources: src/monitor.rs:270, src/parser.rs:163