Something went wrong on our end
-
Bruce Flynn authoredBruce Flynn authored
prune_packets.py 904 B
#!/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