Skip to content

Add parameter decoding CLI tool to F` GDS#285

Merged
thomas-bc merged 3 commits intonasa:develfrom
FireflySpace:param-decode
Mar 2, 2026
Merged

Add parameter decoding CLI tool to F` GDS#285
thomas-bc merged 3 commits intonasa:develfrom
FireflySpace:param-decode

Conversation

@Brian-Campuzano
Copy link
Contributor

Related Issue(s) nasa/fprime#4750
Has Unit Tests (y/n) Yes
Documentation Included (y/n) Yes (CLI help, docstrings)
Generative AI was used in this contribution (y/n) Yes

Change Description

Adds fprime-prm-decode CLI tool to decode binary parameter database (.dat) files into human-readable formats (JSON, text, CSV). This provides the inverse operation of fprime-prm-write.

Changes:

  • New fprime-prm-decode command-line tool
  • Supports three output formats:
    • JSON: Round-trip compatible with fprime-prm-write input format
    • Text: Human-readable format with component grouping, types, and IDs
    • CSV: Spreadsheet-compatible format with columns: Component, Parameter, Value, Type, ID
  • Comprehensive error handling for corrupt files, missing parameters, and deserialization failures
  • Format conversion logic to ensure decoded JSON matches encoder expectations for round-trip compatibility

Rationale

fprime-prm-write can encode parameter JSON to binary .dat files, but there's no way to decode them back. This makes it difficult to:

  • Inspect deployed parameter databases (only raw hex dumps available)
  • Verify encoded .dat files contain expected values
  • Debug parameter-related issues in production systems
  • Extract parameters from existing .dat files for modification

This tool completes the parameter workflow by enabling developers to inspect, verify, and debug parameter databases.

Testing/Review Recommendations

Unit Tests (14 tests, all passing):

  • Round-trip encode/decode verification
  • All output formats (JSON, text, CSV)
  • Error handling (invalid delimiter, unknown param ID, incomplete data)
  • Complex type conversion (arrays, structs, nested structures)
  • Empty file handling

Review Recommendation:

  • src/fprime_gds/common/tools/params.py: Review decode functions and main_decode() entry point
  • pyproject.toml: Review fprime-prm-decode CLI command registration
  • test/fprime_gds/common/tools/test_prm_decode.py: Review 14 new unit tests

Future Work

None planned.

AI Usage (see policy)

Claude (Sonnet 4.5) was used extensively in this contribution for:

  • Initial implementation: Generated decoder functions, format converters, and CLI interface
  • Test development: Created comprehensive unit test suite covering edge cases

All AI-generated code was reviewed, tested, and verified by myself. Round trip conversion of a parameter database was done manually using a flight like database.

Brian-Campuzano and others added 3 commits February 21, 2026 13:19
Implement a new CLI tool to decode binary parameter database (.dat) files
into human-readable formats (JSON, text, CSV). This provides the inverse
operation of fprime-prm-write, enabling inspection and debugging of
parameter files.

Features:
- Decode .dat files to JSON format (round-trip compatible with fprime-prm-write)
- Human-readable text output with type and ID information
- CSV output for spreadsheet compatibility
- Comprehensive error handling for invalid or corrupted files
- Full test coverage with 9 new tests

Changes:
- Add decode_dat_to_params() and formatter functions to params.py
- Add main_decode() CLI entry point
- Register fprime-prm-decode command in pyproject.toml
- Add comprehensive test suite in test_prm_decode.py

All 284 fprime-gds tests pass.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Collaborator

@thomas-bc thomas-bc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leveraging the global config singleton would help a lot with making these more portable. I wonder if you could prompt your AI to do that - it should be able to handle it fairly easily since other places in the repo are doing the same thing quite a lot.

As long as UTs pass, we should be fine.

But I'm also happy to take this in as is since the encode() variant doesn't currently do it.

offset += 1

# Read record size (4 bytes, big endian)
if offset + 4 > len(dat_bytes):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm seeing hardcoded widths and such. You should instead be using the loaded dictionary types. See my other comment on how to do that. Once you do have it, you should be able to do something like

from fprime_gds.common.utils.config_manager import ConfigManager

record_id_size = ConfigManager().get_type("FwDpIdType").getSize()

)
arg_parser.add_argument(
"--dictionary",
"-d",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With that argument, you can leverage the pre-existing Dictionaries class which can load all the dictionary types into a global config singleton, which will help processing without hardcoding type widths and such.

See

# If a dictionary is passed, load it into ConfigManager and add to args for convenient access
if args.dictionary:
args.dictionaries = Dictionaries.load_dictionaries_into_config(args.dictionary)

Copy link
Collaborator

@thomas-bc thomas-bc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good - let's merge this as is and I will capture a follow-up ticket to consolidate both scripts with Dictionary loading etc.

@thomas-bc thomas-bc merged commit c6cac11 into nasa:devel Mar 2, 2026
13 checks passed
@thomas-bc
Copy link
Collaborator

Follow up ticket: nasa/fprime#4792

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.

2 participants