Example #1
0
def test_time_type():
    """
    Tests the TimeType serialization and deserialization
    """
    TIME_SIZE = 11

    in_no_err_list = [
        (TimeBase["TB_NONE"].value, 1, 100, 999999),
        (TimeBase["TB_PROC_TIME"].value, 0xFF, 1234567, 2952),
        (TimeBase["TB_WORKSTATION_TIME"].value, 8, 1529430215, 12),
        (TimeBase["TB_SC_TIME"].value, 231, 1344230277, 123456),
        (TimeBase["TB_FPGA_TIME"].value, 78, 10395, 24556),
        (TimeBase["TB_DONT_CARE"].value, 0xB3, 12390819, 12356),
    ]

    in_err_list = [
        (10, 58, 15345, 0),
        (TimeBase["TB_NONE"].value, 1, 3, -1),
        (TimeBase["TB_WORKSTATION_TIME"].value, 1, 700000, 1234567),
    ]

    val = TimeType()
    size = val.getSize()
    assert size == TIME_SIZE

    for (t_base, t_context, secs, usecs) in in_no_err_list:
        ser_deser_time_test(t_base, t_context, secs, usecs)

    for (t_base, t_context, secs, usecs) in in_err_list:
        with pytest.raises(TypeRangeException):
            ser_deser_time_test(t_base, t_context, secs, usecs)
Example #2
0
    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)
Example #3
0
    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: Binary telemetry channel data to decode

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

        # Decode Ch ID here...
        id_obj = U32Type()
        id_obj.deserialize(data, ptr)
        ptr += id_obj.getSize()
        ch_id = id_obj.val

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

        if ch_id in self.__dict:
            # Retrieve the template instance for this channel
            ch_temp = self.__dict[ch_id]

            val_obj = self.decode_ch_val(data, ptr, ch_temp)

            return ChData(val_obj, ch_time, ch_temp)
        else:
            print("Channel decode error: id %d not in dictionary" % ch_id)
            return None