def decode_api(self, data):
        '''
        Decodes the given data and returns the result.

        This function allows for non-registered code to call the same decoding
        code as is used to parse data passed to the data_callback function.

        Args:
            data: (bytearray) Binary packetized telemetry data to decode

        Returns:
            Parsed version of the input data in the form of a PktData object
            or None if the data is not decodable
        '''
        ptr = 0

        # Decode Pkt ID here...
        id_obj = U16Type()
        id_obj.deserialize(data, ptr)
        ptr += id_obj.getSize()
        pkt_id = id_obj.val

        # Decode time...
        pkt_time = TimeType()
        pkt_time.deserialize(data, ptr)
        ptr += pkt_time.getSize()

        if pkt_id not in self.__dict:
            # Don't crash if can't find pkt. Just notify and keep going
            print("Packet decode error: id %d not in dictionary. Time=%s" %
                  (pkt_id, pkt_time.to_readable()))
            print("Full pkt = \n")
            for i in data:
                print("0x%02x" % ord(i))

            return None

        # Retrieve the template instance for this channel
        pkt_temp = self.__dict[pkt_id]

        ch_temps = pkt_temp.get_ch_list()

        ch_data_objs = []
        for ch_temp in ch_temps:
            val_obj = self.decode_ch_val(data, ptr, ch_temp)
            ptr += val_obj.getSize()
            ch_data_objs.append(ChData(val_obj, pkt_time, ch_temp))

        return PktData(ch_data_objs, pkt_time, pkt_temp)
Beispiel #2
0
        print("FAIL: expected regular output to be %s, but found %s" %
              (list(reg_expected), list(reg_output)))
        sys.exit(-1)
    else:
        print("PASSED test 1")

    config_output = enc_config.encode_api(ch_obj)

    if (config_output != config_expected):
        print("FAIL: expected configured output to be %s, but found %s" %
              (list(config_expected), list(config_output)))
        sys.exit(-1)
    else:
        print("PASSED test 2")

    temp = ChTemplate(102, "test_ch2", "test_comp2", U16Type())

    time_obj = TimeType(2, 0, 1533758628, 123457)

    ch_obj = ChData(U16Type(40), time_obj, temp)

    desc_bin = "\x00\x00\x00\x01"
    id_bin = "\x00\x00\x00\x66"
    time_bin = "\x00\x02\x00\x5b\x6b\x4c\xa4\x00\x01\xe2\x41"
    val_bin = "\x00\x28"
    long_len_bin = "\x00\x00\x00\x15"
    short_len_bin = "\x00\x15"

    reg_expected = (long_len_bin + desc_bin + id_bin + time_bin + val_bin)
    config_expected = (short_len_bin + desc_bin + id_bin + time_bin + val_bin)
Beispiel #3
0
              (list(reg_expected), list(reg_output)))
        sys.exit(-1)
    else:
        print("PASSED test 1")

    config_output = enc_config.encode_api(event_obj)

    if (config_output != config_expected):
        print("FAIL: expected configured output to be %s, but found %s" %
              (list(config_expected), list(config_output)))
        sys.exit(-1)
    else:
        print("PASSED test 2")

    temp = EventTemplate(102, "test_ch2", "test_comp2",
                         [("a1", "a1", U8Type()), ("a2", "a2", U16Type())],
                         EventSeverity["DIAGNOSTIC"], "%d %d")

    time_obj = TimeType(2, 0, 1533758628, 123457)

    event_obj = EventData((U8Type(128), U16Type(40)), time_obj, temp)

    desc_bin = "\x00\x00\x00\x02"
    id_bin = "\x00\x00\x00\x66"
    time_bin = "\x00\x02\x00\x5b\x6b\x4c\xa4\x00\x01\xe2\x41"
    arg_bin = "\x80\x00\x28"
    long_len_bin = "\x00\x00\x00\x16"
    short_len_bin = "\x00\x16"

    reg_expected = (long_len_bin + desc_bin + id_bin + time_bin + arg_bin)
    config_expected = (short_len_bin + desc_bin + id_bin + time_bin + arg_bin)
Beispiel #4
0
        binary_data = (len_bin + desc_bin + id_bin + time_bin + ch_bin)

        return binary_data


if __name__ == "__main__":
    # Unit Tests
    config = ConfigManager()
    config.set('types', 'msg_len', 'U16')

    enc = PktEncoder()
    enc_config = PktEncoder("GUI", config)

    ch_temp_1 = ChTemplate(101, "test_ch", "test_comp", U32Type())
    ch_temp_2 = ChTemplate(102, "test_ch2", "test_comp2", U8Type())
    ch_temp_3 = ChTemplate(103, "test_ch3", "test_comp3", U16Type())

    pkt_temp = PktTemplate(64, "test_pkt", [ch_temp_1, ch_temp_2, ch_temp_3])

    time_obj = TimeType(2, 0, 1533758629, 123456)

    ch_obj_1 = ChData(U32Type(1356), time_obj, ch_temp_1)
    ch_obj_2 = ChData(U8Type(143), time_obj, ch_temp_2)
    ch_obj_3 = ChData(U16Type(1509), time_obj, ch_temp_3)

    pkt_obj = PktData([ch_obj_1, ch_obj_2, ch_obj_3], time_obj, pkt_temp)

    desc_bin = "\x00\x00\x00\x04"
    id_bin = "\x00\x40"
    time_bin = "\x00\x02\x00\x5b\x6b\x4c\xa5\x00\x01\xe2\x40"
    ch_bin = "\x00\x00\x05\x4c\x8F\x05\xe5"