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

Add converters to convert segments of bytes to strings in binary, oct, or hex representation #73

Closed ddasilva closed 12 months ago

ddasilva commented 1 year ago

This ticket is to support converts that turn segments of bytes into strings in binary, oct, or hex representation. This came out of conversations with @tloubrieu-jpl and @nischayn99 about something that they had in their legacy code for parsing CCSDS packets in Europa Clipper, that would be nice to have built in.

I think the most basic way this could be done would be as follows:

from ccsdspy import FixedLength, converters

pkt = FixedLength([
    PacketArray(
        name='some_bytes',
        data_type='uint',
        bit_length=8,
        array_shape=100,
    ),
])
pkt.add_converted_field(
    "some_bytes", 
    "some_bytes_as_string", 
    converters.StringifyBytes(format="oct")  # or "hex", "bin"
)
result = pkt.load('MyCCSDS.tlm')

print(result['some_bytes_as_string'])

Which would print an array of strings in oct format.

ddasilva commented 1 year ago

@tloubrieu-jpl Can you confirm the proposed implementation would fit your use case?

ddasilva commented 1 year ago

A merge request was opened for this, see #75

tloubrieu-jpl commented 1 year ago

Thanks @ddasilva , that will fit our need, sorry I missed your comment earlier. I am glad that you moved forward.