Skip to content
Snippets Groups Projects
info.py 1.14 KiB
import io
import logging
from edosl0util.cli import util
from edosl0util import stream

LOG = logging


def main():
    parser = util.default_parser()
    parser.add_argument('-a', '--aqua', action='store_true')
    parser.add_argument('filepath')
    args = parser.parse_args()
    util.configure_logging(args)

    num_packets = 0
    if not args.aqua:
        packets = stream.jpss_packet_stream(io.open(args.filepath, 'rb'))
    else:
        packets = stream.aqua_packet_stream(io.open(args.filepath, 'rb'))
    while True:
        try:
            packets.next()
            num_packets += 1
        except stream.PacketTooShort as err:
            LOG.warn("corrupt packet stream after %d packets: %s",
                     num_packets, err)
            break
        except StopIteration:
            break
    total = 0
    first, last, info = packets.info()
    LOG.info("First: %s", first)
    LOG.info("Last: %s", last)
    for apid, dat in info.items():
        total += dat['count']
        LOG.info("%d: count=%d missing=%d", apid, dat['count'], dat['num_missing'])
    LOG.info("{} total packets".format(total))


if __name__ == '__main__':
    main()