diff --git a/scripts/prune_packets.py b/scripts/prune_packets.py new file mode 100755 index 0000000000000000000000000000000000000000..1c62196000bee95e0c01e148c60c3de54734dfe5 --- /dev/null +++ b/scripts/prune_packets.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python +""" +Prune all the non-header data out of a PDS file. Usefull for geenerating test +data for CCSDS tools. +""" +import ctypes as c +import argparse + +from edosl0util import stream + +parser = argparse.ArgumentParser(description=__doc__) +parser.add_argument('pdsfile') +parser.add_argument('outfile') + +args = parser.parse_args() + + +def pack_hdr_bytes(hdr): + return c.string_at(c.byref(hdr), c.sizeof(hdr)) + + +with open(args.outfile, 'wb') as fptr: + idx = 0 + for pkt in stream.PacketStream(open(args.pdsfile)): + h1 = pkt._primary_header + h2 = pkt._secondary_header + if h2: + h1.data_length_minus1 = c.sizeof(h2) - 1 + fptr.write(h1) + if pkt.stamp: + h2.packet_count = 0 + fptr.write(h2) + else: + h1.data_length_minus1 = 0 + fptr.write(h1) + fptr.write('x') + + idx += 1