From 3e5617ef298e2702d10922133ed8406f1cde5fc9 Mon Sep 17 00:00:00 2001 From: Joaquin Krasuk Date: Thu, 9 Jan 2025 14:47:19 -0300 Subject: [PATCH] Change ACARS JSON output in the format ACARSHub is expecting --- iridiumtk/reassembler/sbd.py | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/iridiumtk/reassembler/sbd.py b/iridiumtk/reassembler/sbd.py index 3633be0..25edb38 100755 --- a/iridiumtk/reassembler/sbd.py +++ b/iridiumtk/reassembler/sbd.py @@ -469,11 +469,38 @@ def consume_l2(self, q): out['app'] = { 'name': 'iridium-toolkit', 'version': '0.0.2' } out['source'] = { 'transport': 'iridium', 'parser': 'libacars', 'version': libacars.version } - out['timestamp'] = q.timestamp - out['link_direction'] = 'uplink' if q.ul else 'downlink' if config.station: out['source']['station_id'] = config.station out['acars']=json.loads(o.json())['acars'] + out['acars']['timestamp'] = q.timestamp + out['acars']['link_direction'] = 'uplink' if q.ul else 'downlink' + out['acars']['errors'] = int(out["acars"]["err"] == 'true') + + for key in ('reg:tail', 'label', 'blk_id:block_id', 'msg_num_seq:message_number', 'ack', 'msg_text:text', 'more:block_end'): + old, _, new = key.partition(':') + if new == '': new = old + if old in out['acars'].keys(): + val = out['acars'][old] + if isinstance(val, bytes): + val = val.decode('ascii') + if old == 'label': + val = val.replace('_\u007f', '_d') + if old == 'ack': + val = val.replace('\u0015', '!') + if old == 'reg': + while len(val)>0 and val[0:1]=='.': + val = val[1:] + if old == 'more': + val = not val + out['acars'][new] = val + + out['freq'] = self.ofreq + out['level'] = self.olevel + if q.data[1] == 0x3: + out['header'] = q.data[1:9].hex() + else: + out['header'] = "" + print(json.dumps(out), file=outfile) return