This document outlines proposed refactorings for the fsdr-cli codebase based on an initial analysis. The goals are to reduce boilerplate, improve type safety, and centralize common logic.
Current command parsing is split between the pest grammar in cmd_line.pest and manual logic in src/csdr_cmd/mod.rs and src/csdr_cmd/any_cmd.rs.
pestidentifies top-level commands and their parameters.AnyCmd::parsemanually matches on rules and callsbuild_*methods.build_*methods manually extract parameters frompestpairs.
- Move more parameter extraction logic into
pestif possible, or use a more declarative approach. - Consider using a trait or a macro for command building to avoid the large match block in
AnyCmd::parse. - Unify the handling of CSDR commands and iqengine commands where patterns overlap.
Each BlockConverter manually extracts parameters and sets up the FutureSDR block.
parameter_as_f64is called repeatedly.- Type mapping (e.g.,
"ccc"->Complex32) is done via string matching in each converter. - Window type matching is duplicated across multiple filter converters.
- Core Principle: All refactorings must preserve GNU Radio Companion (GRC) compatibility. Block IDs, parameter names, and enumerations (like
byte,float64, orwindow.WIN_HAMMING) must strictly follow GRC standards. - Create a
ConverterContexthelper to streamline parameter extraction with better error handling:let decim = ctx.get_param_as_usize("decim")?; let window = ctx.get_window("win")?;
- Use an
ItemTypeenum to handle"ccc","ff", etc., and centralize the mapping to Rust types. - Move shared window and tap generation logic into a common module (e.g.,
src/grc/converter/filter_util.rs).
The codebase makes significant use of expect(), unwrap(), and todo!().
- Replaced
expect()withcontext()andbail!()from theanyhowcrate. - Updated
GrcItemTypeto useTryFromfor safe error propagation. - Eliminated common
todo!()occurrences in converters with clear error messages. - Implemented more robust validation in
iqengineplugin modules.
GrcBuilder manages the intermediate state when parsing CSDR commands.
- Simplify the block linking logic.
- Ensure that metadata (like sample rate) is consistently propagated throughout the builder.
- Improve the
ensure_sink()logic to handle cases where a sink is already present or explicitly defined.
- Consider moving some of the manual conversion logic from
src/csdr_cmd/agc_cmd.rsinto the corresponding converter insrc/grc/converter/. - Ensure a clean separation between the GRC-focused conversion and the CLI command parsing.