コード例 #1
0
def parse_test_data(class_name: Type[KaitaiStruct],
                    glob_string: str,
                    pretty_print: bool = True) -> Optional[KaitaiStruct]:
    """
    :param class_name: type of struct to expect
    :param glob_string: glob for test files
    :param pretty_print: if set to false, will dump vars instead
    :return KaitaiStruct last tested file
    """
    from glob import glob

    testfile = None
    print("parseTestData: path: %s" % glob_string)
    for testfile in sorted(glob(glob_string)):
        print("----------")
        print("parseTestData: testfile: %s" % testfile)
        instance = class_name.from_file(testfile)
        if pretty_print:
            from hytera_homebrew_bridge.tests.prettyprint import prettyprint

            prettyprint(instance)
        else:
            print(vars(instance))

    return testfile
コード例 #2
0
        print("use as %s <hexstring>" % sys.argv[0])
        exit(0)

    packet = IpSiteConnectProtocol.from_bytes(bytes.fromhex(sys.argv[1]))
    print(
        "source id: \t%s\ntarget id: \t%s\ncall type: \t%s\ntimeslot: \t%s\npacket_type: \t%s\nslot_type: \t%s\n\n"
        % (
            packet.source_radio_id,
            packet.destination_radio_id,
            IpSiteConnectProtocol.CallTypes(packet.call_type),
            packet.Timeslots(packet.timeslot_raw),
            packet.packet_type,
            packet.slot_type,
        ))

    prettyprint(packet)

    original = bytearray(packet.ipsc_payload)
    # swap bytes
    original[0::2], original[1::2] = original[1::2], original[0::2]

    print(hexlify(original))

    if (packet.slot_type
            == IpSiteConnectProtocol.SlotTypes.slot_type_voice_lc_header
            or packet.slot_type
            == IpSiteConnectProtocol.SlotTypes.slot_type_terminator_with_lc):
        lc = voice_head_term(bytes(original))
        print(lc)
        print("LC: OPT-{} SRC-{} DST-{}, SLOT TYPE: CC-{} DTYPE-{}".format(
            ahex(lc["LC"][0:3]),