#!/usr/bin/env python3

import sys

GDL90_FLAGBYTE = 0x7E
GDL90_EVERY_N = 1000

data = open(sys.argv[1], "rb").read()
n = 0
c = 0

while c < len(data):
    if data[c] == GDL90_FLAGBYTE and data[c + 1] == int(sys.argv[2], 16):
        i = 1
        msg = bytearray((GDL90_FLAGBYTE,))

        while data[c + i] != GDL90_FLAGBYTE:
            msg.append(data[c + i])

            c += 1

        msg.append(GDL90_FLAGBYTE)

        if not n % GDL90_EVERY_N:
            fmt = "{ %d, \"" % len(msg)
            fmt += ("\\x%02X" * len(msg)) % tuple(msg)
            fmt += "\" },"

            print(fmt)

        n += 1

    c += 1
