CCSDSPy / ccsdspy

I/O interface and utilities for CCSDS binary spacecraft data in Python. Library used in flight missions at NASA, NOAA, and SWRI
https://ccsdspy.org
BSD 3-Clause "New" or "Revised" License
74 stars 18 forks source link

Support arrays whose length is determined by another field #58

Closed ddasilva closed 1 year ago

ddasilva commented 1 year ago

This feature request comes from wanting to support a type of data I have been told some instruments generate, but currently isn't supported.

This change would update VariableLength class to support variable length fields where the length is determined by another field in the packet. For example, you could have fields data1_len which sets the length of the data array, and then data2_len which follows it and sets the length of the data2 array.

An example is below:



   import ccsdspy
   from ccsdspy import PacketField, PacketArray

    pkt = ccsdspy.VariableLength([
         PacketField(
              name='SHCOARSE',
              data_type='uint',
              bit_length=32
         ),
         PacketField(
              name='data_len',
              data_type='uint',
              bit_length=8,
         ),  
         PacketArray(
              name="data",
              data_type="uint",
              bit_length=16,
              array_shape="data_len",  # links data to data_len
         ),
         PacketField(
              name="checksum",
              data_type="uint",
              bit_length=16
         ),
    ])