Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a command line interface #109

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Conversation

greglucas
Copy link
Collaborator

This adds a very basic command line interface and prints the header contents of a file to the terminal. I figured this would be easier to discuss as a prototype rather than opening an issue.

I've currently implemented this with just basic built-in argparse utilities, but I'm wondering if we should add some other dependencies to make the cli a little nicer? The two that have caught my eye are:

I don't keep up with all of the cli/formatting libraries, so if there are others I should look at let me know. These libraries don't have any other dependencies which is nice as well, so they would each only add their dependency and they are both lightweight and heavily used.

Example of the current output, which could definitely be spruced up and made to look nicer, but I wanted to just put this up quick as an example to get feedback on the approach.

Packet file: idex-many-files.bin
Number of packets: 46800
VERSION     | TYPE        | SEC_HDR_FLG | PKT_APID    | SEQ_FLGS    | SRC_SEQ_CTR | PKT_LEN     | 
           0|            0|            1|         1424|            3|            0|          297| 
           0|            0|            1|         1424|            3|            1|         4073| 
           0|            0|            1|         1424|            3|            2|         4073| 
           0|            0|            1|         1424|            3|            3|         2901| 
           0|            0|            1|         1424|            3|            4|         4073| 
...
           0|            0|            1|         1424|            3|           73|         4073| 
           0|            0|            1|         1424|            3|           74|         2901| 
           0|            0|            1|         1424|            3|           75|         1065| 
           0|            0|            1|         1424|            3|           76|         1065| 
           0|            0|            1|         1424|            3|           77|         1065|

Checklist

  • Changes are fully implemented without dangling issues or TODO items
  • Deprecated/superseded code is removed or marked with deprecation warning
  • Current dependencies have been properly specified and old dependencies removed
  • New code/functionality has accompanying tests and any old tests have been updated to match any new assumptions
  • The changelog.md has been updated

This refactors out the reading of a byte-stream into a separate
generator function that can yield raw CCSDSPackets with only
a header and the raw bytes. The definitions and parsing logic can
use this generator to yield packets and then parse whatever they
need to after the fact. This enables someone to use this generator
without a packet definition and to investigate what is in the packet
stream without needing to know more detailed information about
how individual packets are laid out internally.
…ts.py

This makes the packets.py the defacto generator and able to be called with
a definition file as input rather than needing to instantiate the generator
from the definition itself.
@greglucas greglucas requested a review from medley56 as a code owner October 16, 2024 20:54
@greglucas
Copy link
Collaborator Author

I decided to give click and rich a try and I liked the results, so I pushed those changes up. I personally think it adds a nice touch to the cli capability and it is way easier to expand than argparse/optparse IMO.

You can test it out locally with these commands (with color locally):

spp describe-packets tests/test_data/idex/sciData_2023_052_14_45_05 
          tests/test_data/idex/sciData_2023_052_14_45_05: 78 packets          
┏━━━━━━━━━┳━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━┓
┃ VERSION ┃ TYPE ┃ SEC_HDR_FLG ┃ PKT_APID ┃ SEQ_FLGS ┃ SRC_SEQ_CTR ┃ PKT_LEN ┃
┡━━━━━━━━━╇━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━┩
│ 0       │ 0    │ 1           │ 1424     │ 3        │ 0           │ 297     │
│ 0       │ 0    │ 1           │ 1424     │ 3        │ 1           │ 4073    │
│ 0       │ 0    │ 1           │ 1424     │ 3        │ 2           │ 4073    │
│ 0       │ 0    │ 1           │ 1424     │ 3        │ 3           │ 2901    │
│ 0       │ 0    │ 1           │ 1424     │ 3        │ 4           │ 4073    │
│ ...     │ ...  │ ...         │ ...      │ ...      │ ...         │ ...     │
│ 0       │ 0    │ 1           │ 1424     │ 3        │ 73          │ 4073    │
│ 0       │ 0    │ 1           │ 1424     │ 3        │ 74          │ 2901    │
│ 0       │ 0    │ 1           │ 1424     │ 3        │ 75          │ 1065    │
│ 0       │ 0    │ 1           │ 1424     │ 3        │ 76          │ 1065    │
│ 0       │ 0    │ 1           │ 1424     │ 3        │ 77          │ 1065    │
└─────────┴──────┴─────────────┴──────────┴──────────┴─────────────┴─────────┘
spp describe-xtce tests/test_data/idex/idex_combined_science_definition.xml                      
╭───────────────────────── XTCE Container Layout ──────────────────────────╮
│ CCSDSPacket                                                              │
│ └── CCSDSTelemetryPacket [<Comparison VERSION==0>, <Comparison TYPE==0>] │
│     ├── IDX_SCI0 [<Comparison PKT_APID==1424>]                           │
│     │   ├── Sci0TypeZero [<Comparison IDX__SCI0TYPE==1>]                 │
│     │   └── Sci0TypeNonZero [<Comparison IDX__SCI0TYPE>1>]               │
│     └── IDX_SCIFETCH [<Comparison PKT_APID==1425>]                       │
│         ├── SciFetchTypeZero [<Comparison IDX__SCIFETCHTYPE==1>]         │
│         └── SciFetchTypeNonZero [<Comparison IDX__SCIFETCHTYPE>1>]       │
╰──────────────────────────────────────────────────────────────────────────╯
spp parse tests/test_data/idex/sciData_2023_052_14_45_05 tests/test_data/idex/idex_combined_science_definition.xml --packet 0      
{
    'VERSION': 0,
    'TYPE': 0,
    'SEC_HDR_FLG': 1,
    'PKT_APID': 1424,
    'SEQ_FLGS': 3,
    'SRC_SEQ_CTR': 0,
    'PKT_LEN': 297,
    'SHCOARSE': 1266,
    'SHFINE': 19198,
    'IDX__SCI0AID': 56026,
    'IDX__SCI0TYPE': 1,
    'IDX__SCI0CONT': 127,
    'IDX__SCI0SPARE1': 0,
    'IDX__SCI0PACK': 'EN',
    'IDX__SCI0FRAG': 'DS',
    'IDX__SCI0COMP': 'DS',
    'IDX__SCI0EVTNUM': 0,
    'IDX__SCI0CAT': 32,
    'IDX__SCI0QUAL': 5,
    'IDX__SCI0FRAGOFF': 0,
    ... +87
}

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.

1 participant