Skip to content
Snippets Groups Projects
Commit b4af1942 authored by Greg Quinn's avatar Greg Quinn
Browse files

Fix crgen problem handling packets w no stamp

parent 59b6afea
No related branches found
No related tags found
No related merge requests found
......@@ -177,17 +177,21 @@ def scan_packets(pds_file, prev_pds_file=None):
apid_map = {}
logger.info('scanning {}'.format(pds_file))
stream = jpss_packet_stream(open(pds_file, 'rb'))
first_pkt = stream.next()
for pkt in itertools.chain([first_pkt], stream):
first_pkt_time = None
last_pkt_time = None
for pkt in stream:
entry = apid_map.get(pkt.apid)
if not entry:
entry_from_prev_pds = prev_apid_map.get(pkt.apid)
apid_map[pkt.apid] = init_entry(pkt, entry_from_prev_pds)
else:
update_entry(entry, pkt)
last_pkt = pkt
return {'first_packet_time': datetime_to_ccsds(first_pkt.stamp),
'last_packet_time': datetime_to_ccsds(last_pkt.stamp),
if pkt.stamp:
if not first_pkt_time:
first_pkt_time = pkt.stamp
last_pkt_time = pkt.stamp
return {'first_packet_time': datetime_to_ccsds(first_pkt_time),
'last_packet_time': datetime_to_ccsds(last_pkt_time),
'apid_info': [apid_map[k] for k in sorted(apid_map)]}
def build_prev_apid_map(prev_pds_file):
......@@ -209,7 +213,10 @@ def scan_packets(pds_file, prev_pds_file=None):
def update_entry(entry, new_pkt):
prev_last_ssc = entry['last_packet_ssc']
prev_last_time = entry['last_packet_time']
entry['last_packet_time'] = datetime_to_ccsds(new_pkt.stamp)
if new_pkt.stamp:
if entry['first_packet_time'] == DaySegmentedTimecode():
entry['first_packet_time'] = datetime_to_ccsds(new_pkt.stamp)
entry['last_packet_time'] = datetime_to_ccsds(new_pkt.stamp)
entry['last_packet_ssc'] = new_pkt.seqid
entry['total_packets'] += 1
entry['total_bytes'] += new_pkt.size
......@@ -235,12 +242,12 @@ def datetime_to_ccsds(dt):
Handles input of None by returning epoch value of 1958-01-01.
"""
if dt is not None:
epoch = datetime(1958, 1, 1)
days = (dt - epoch).days
days = (dt - idps_epoch).days
micros = int((dt - datetime(dt.year, dt.month, dt.day)).total_seconds() * 1e6)
return DaySegmentedTimecode(days, micros // 1000, micros % 1000)
else:
return DaySegmentedTimecode()
idps_epoch = datetime(1958, 1, 1)
logger = logging.getLogger(__name__)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment