def test_telemetry_predicates(self):
        temp1 = ChTemplate(1, "Test Channel 1", "Predicate_Tester", I32Type())
        temp2 = ChTemplate(2, "Test Channel 2", "Predicate_Tester",
                           StringType())
        update1 = ChData(I32Type(20), TimeType(), temp1)
        update2 = ChData(StringType("apple"), TimeType(), temp2)

        pred = predicates.telemetry_predicate()
        assert pred(
            update1
        ), "If no fields are specified a ChData object should return True"
        assert pred(
            update2
        ), "If no fields are specified a ChData object should return True"
        assert not pred(
            "diff object"
        ), "Anything that's not a ChData object should be False"
        assert not pred(
            5), "Anything that's not a ChData object should be False"
        self.check_str(pred)

        id_pred = predicates.equal_to(1)
        pred = predicates.telemetry_predicate(id_pred=id_pred)
        assert pred(update1), "This predicate on the ID 1 should return True"
        assert not pred(
            update2), "This predicate on the ID 2 should return False"
        self.check_str(pred)

        val_pred = predicates.equal_to("apple")
        pred = predicates.telemetry_predicate(value_pred=val_pred)
        assert not pred(
            update1), "This predicate on the value 20 should return False"
        assert pred(
            update2
        ), "This predicate on the value \"apple\" should return True"
        self.check_str(pred)

        time_pred = predicates.equal_to(0)
        pred = predicates.telemetry_predicate(time_pred=time_pred)
        assert pred(update1), "This predicate on the time 0 should return True"
        assert pred(update2), "This predicate on the time 0 should return True"
        self.check_str(pred)

        val_pred = predicates.within_range(10, 30)
        pred = predicates.telemetry_predicate(id_pred, val_pred, time_pred)
        assert pred(
            update1), "Specifying all fields should return True for update 1"
        assert not pred(
            update2), "Specifying all fields should return False for update 2"
        self.check_str(pred)
예제 #2
0
def test_pkt_encoder():
    """
    Tests the encoding of the packet encoder
    """
    config = ConfigManager()
    config.set("types", "msg_len", "U16")

    enc = PktEncoder()
    enc_config = PktEncoder(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 = b"\x00\x00\x00\x04"
    id_bin = b"\x00\x40"
    time_bin = b"\x00\x02\x00\x5b\x6b\x4c\xa5\x00\x01\xe2\x40"
    ch_bin = b"\x00\x00\x05\x4c\x8F\x05\xe5"
    long_len_bin = b"\x00\x00\x00\x18"
    short_len_bin = b"\x00\x18"

    reg_expected = long_len_bin + desc_bin + id_bin + time_bin + ch_bin
    config_expected = short_len_bin + desc_bin + id_bin + time_bin + ch_bin

    reg_output = enc.encode_api(pkt_obj)

    assert (reg_output == reg_expected
            ), "FAIL: expected regular output to be %s, but found %s" % (
                list(reg_expected),
                list(reg_output),
            )

    config_output = enc_config.encode_api(pkt_obj)

    assert (config_output == config_expected
            ), "FAIL: expected configured output to be %s, but found %s" % (
                list(config_expected),
                list(config_output),
            )
예제 #3
0
 def get_range(self, length):
     temp1 = ChTemplate(1, "Test Channel 1", "Chrono_Hist_Tester",
                        I32Type())
     chList = []
     ts0 = TimeType()
     for item in range(length):
         tsi = ts0 + time.time()
         chList.append(ChData(I32Type(item), tsi, temp1))
     return chList
예제 #4
0
    def construct_dicts(self, path):
        """
        Constructs and returns python dictionaries keyed on id and name

        This function should not be called directly, instead, use
        get_id_dict(path) and get_name_dict(path)

        Args:
            path: Path to the python module file dictionary to convert. This
                  should be a directory. If using a regular fprime deployment,
                  this should be a path to the events dictionary in your
                  generated folder:
                  ${GENERATED_FOLDER_LOCATION}/generated/${DEPLOYMENT}/channels

        Returns:
            A tuple with two channel dictionaries (python type dict):
            (id_dict, name_dict). The keys should be the channels' id and
            name fields respectively and the values should be ChTemplate
            objects.
        """
        # We do need it sometimes, so if we don't always set it to true, we will need to pass an arg
        module_dicts = self.read_dict(path, use_superpkg=True)

        id_dict = dict()
        name_dict = dict()

        for ch_dict in module_dicts:
            # Create a channel template object
            ch_temp = ChTemplate(
                ch_dict[self.ID_FIELD],
                ch_dict[self.NAME_FIELD],
                ch_dict[self.COMP_FIELD],
                ch_dict[self.TYPE_FIELD],
                ch_dict[self.FMT_STR_FIELD],
                ch_dict[self.DESC_FIELD],
                ch_dict[self.LOW_R_FIELD],
                ch_dict[self.LOW_O_FIELD],
                ch_dict[self.LOW_Y_FIELD],
                ch_dict[self.HIGH_Y_FIELD],
                ch_dict[self.HIGH_O_FIELD],
                ch_dict[self.HIGH_R_FIELD],
            )

            id_dict[ch_dict[self.ID_FIELD]] = ch_temp
            name_dict[ch_dict[self.NAME_FIELD]] = ch_temp

        return (id_dict, name_dict)
예제 #5
0
    def construct_dicts(self, path):
        """
        Constructs and returns python dictionaries keyed on id and name

        This function should not be called directly, instead, use
        get_id_dict(path) and get_name_dict(path)

        Args:
            path: Path to the xml dictionary file containing channel information

        Returns:
            A tuple with two channel dictionaries (python type dict):
            (id_idct, name_dict). The keys are the channels' id and name fields
            respectively and the values are ChTemplate objects
        """
        xml_tree = self.get_xml_tree(path)

        # Check if xml dict has channels section
        ch_section = self.get_xml_section(self.CH_SECT, xml_tree)
        if ch_section is None:
            raise exceptions.GseControllerParsingException(
                "Xml dict did not have a %s section" % self.CH_SECT
            )

        id_dict = dict()
        name_dict = dict()
        for ch in ch_section:
            ch_dict = ch.attrib

            # Assume the required fields are present (component, name, id,
            #  description, type). Check for all others
            ch_comp = ch_dict[self.COMP_TAG]
            ch_name = ch_dict[self.NAME_TAG]
            ch_id = int(ch_dict[self.ID_TAG], base=16)
            ch_type_obj = self.parse_type(ch_dict[self.TYPE_TAG], ch, xml_tree)

            ch_desc = None
            ch_fmt_str = None
            ch_low_red = None
            ch_low_orange = None
            ch_low_yellow = None
            ch_high_yellow = None
            ch_high_orange = None
            ch_high_red = None

            if self.DESC_TAG in ch_dict:
                ch_desc = ch_dict[self.DESC_TAG]

            if self.FMT_STR_TAG in ch_dict:
                ch_fmt_str = ch_dict[self.FMT_STR_TAG]

            # TODO we need to convert these into numbers, is this the best
            #  way to do it?
            if self.LOW_R_TAG in ch_dict:
                ch_low_red = float(ch_dict[self.LOW_R_TAG])

            if self.LOW_O_TAG in ch_dict:
                ch_low_orange = float(ch_dict[self.LOW_O_TAG])

            if self.LOW_Y_TAG in ch_dict:
                ch_low_yellow = float(ch_dict[self.LOW_Y_TAG])

            if self.HIGH_Y_TAG in ch_dict:
                ch_high_yellow = float(ch_dict[self.HIGH_Y_TAG])

            if self.HIGH_O_TAG in ch_dict:
                ch_high_orange = float(ch_dict[self.HIGH_O_TAG])

            if self.HIGH_R_TAG in ch_dict:
                ch_high_red = float(ch_dict[self.HIGH_R_TAG])

            ch_temp = ChTemplate(
                ch_id,
                ch_name,
                ch_comp,
                ch_type_obj,
                ch_fmt_str,
                ch_desc,
                ch_low_red,
                ch_low_orange,
                ch_low_yellow,
                ch_high_yellow,
                ch_high_orange,
                ch_high_red,
            )

            id_dict[ch_id] = ch_temp
            name_dict[ch_name] = ch_temp

        return (id_dict, name_dict)
예제 #6
0
def test_ch_encoder():
    """
    Tests the encoding of the channel encoder
    """
    config = ConfigManager()
    config.set("types", "msg_len", "U16")

    enc = ChEncoder()
    enc_config = ChEncoder(config)

    temp = ChTemplate(101, "test_ch", "test_comp", U32Type())

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

    ch_obj = ChData(U32Type(42), time_obj, temp)

    desc_bin = b"\x00\x00\x00\x01"
    id_bin = b"\x00\x00\x00\x65"
    time_bin = b"\x00\x02\x00\x5b\x6b\x4c\xa5\x00\x01\xe2\x40"
    val_bin = b"\x00\x00\x00\x2a"
    long_len_bin = b"\x00\x00\x00\x17"
    short_len_bin = b"\x00\x17"

    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

    reg_output = enc.encode_api(ch_obj)

    assert (reg_output == reg_expected
            ), "FAIL: expected regular output to be %s, but found %s" % (
                list(reg_expected),
                list(reg_output),
            )

    config_output = enc_config.encode_api(ch_obj)

    assert (config_output == config_expected
            ), "FAIL: expected configured output to be %s, but found %s" % (
                list(config_expected),
                list(config_output),
            )

    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 = b"\x00\x00\x00\x01"
    id_bin = b"\x00\x00\x00\x66"
    time_bin = b"\x00\x02\x00\x5b\x6b\x4c\xa4\x00\x01\xe2\x41"
    val_bin = b"\x00\x28"
    long_len_bin = b"\x00\x00\x00\x15"
    short_len_bin = b"\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

    reg_output = enc.encode_api(ch_obj)

    assert (reg_output == reg_expected
            ), "FAIL: expected regular output to be %s, but found %s" % (
                list(reg_expected),
                list(reg_output),
            )

    config_output = enc_config.encode_api(ch_obj)

    assert (config_output == config_expected
            ), "FAIL: expected configured output to be %s, but found %s" % (
                list(config_expected),
                list(config_output),
            )
예제 #7
0
        len_bin = self.len_obj.serialize()

        binary_data = (len_bin + desc_bin + id_bin + time_bin + val_bin)

        return binary_data


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

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

    temp = ChTemplate(101, "test_ch", "test_comp", U32Type())

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

    ch_obj = ChData(U32Type(42), time_obj, temp)

    desc_bin = "\x00\x00\x00\x01"
    id_bin = "\x00\x00\x00\x65"
    time_bin = "\x00\x02\x00\x5b\x6b\x4c\xa5\x00\x01\xe2\x40"
    val_bin = "\x00\x00\x00\x2a"
    long_len_bin = "\x00\x00\x00\x17"
    short_len_bin = "\x00\x17"

    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)
예제 #8
0
        len_bin = self.len_obj.serialize()

        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"