예제 #1
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),
            )
예제 #2
0
def initialize_test_api(
    app_dictionary_path: str,
    log_path: str = None,
    server_ip: str = "127.0.0.1",
    server_port: int = 50050,
) -> IntegrationTestAPI:
    """
    Initializes an Integration Test API instance for use.

    Note that these MUST be manually disconnected when you're done using them,
    by calling "pipeline.disconnect()" and "api.teardown()", respectively.

    :param app_dictionary_path: A string path from the current working directory
        to the "<project name>AppDictionary.xml" file for the project you're
        using the API with
    :param log_path: A string path to where files should be logged, or "None" if
        you only want console output
    :param server_ip: The IP of the GDS server you want to connect to
    :param server_port: The port for the Test API on the GDS server
    """
    pipeline = StandardPipeline()
    pipeline.setup(ConfigManager(), app_dictionary_path, "/tmp")
    pipeline.connect(server_ip, server_port)

    # instantiate Test API (log_path of "None" will disable Test API logging)
    api = IntegrationTestAPI(pipeline, log_path)

    return (pipeline, api)
예제 #3
0
 def setup_class(cls):
     cls.pipeline = StandardPipeline()
     config = ConfigManager()
     filename = os.path.dirname(__file__)
     path = os.path.join(filename, "../../Top/RefTopologyAppDictionary.xml")
     cls.pipeline.setup(config, path)
     cls.pipeline.connect("127.0.0.1", 50050)
     logpath = os.path.join(filename, "./logs")
     cls.api = IntegrationTestAPI(cls.pipeline, logpath)
     cls.case_list = []  # TODO find a better way to do this.
예제 #4
0
 def setUpClass(cls):
     cls.pipeline = UTPipeline()
     config = ConfigManager()
     path = os.path.join(filename, "./UnitTestDictionary.xml")
     down_store = os.path.join(filename, "./")
     cls.pipeline.setup(config, path, down_store)
     log_path = os.path.join(filename, "./logs")
     cls.api = IntegrationTestAPI(cls.pipeline, log_path)
     cls.case_list = []  # TODO find a better way to do this.
     cls.threads = []
예제 #5
0
 def __init__(self, config=None):
     """
     Encoder class constructor
     :param config: (ConfigManager, default=None): Object with configuration data for the sizes of fields in the
                    binary data. If None passed, defaults are used.
     """
     super().__init__()
     if config is None:
         # Retrieve defaults for the configs
         config = ConfigManager()
     self.config = config
예제 #6
0
 def setup_class(cls):
     cls.pipeline = StandardPipeline()
     config = ConfigManager()
     filename = os.path.dirname(__file__)
     path = os.path.join(
         filename,
         "../../build-artifacts/raspberrypi/dict/RPITopologyAppDictionary.xml",
     )
     cls.pipeline.setup(config, path, "/tmp")
     cls.pipeline.connect("127.0.0.1", 50050)
     logpath = os.path.join(filename, "./logs")
     cls.api = IntegrationTestAPI(cls.pipeline, logpath)
     cls.case_list = []  # TODO find a better way to do this.
     cls.dictionary = path
    def __init__(self, parent, ch_dict, config=None):
        '''
        Constructor

        Args:
            ch_dict (dict() object with all ChTemplate objects as values):
                    Channel dictionary
            config (ConfigManager obj, default=None): ConfigManager with color
                   information. If None, defaults used
        '''

        wx.dataview.PyDataViewModel.__init__(self)

        if config==None:
            config = ConfigManager()

        self.config = config
        self.parent = parent

        # Colors in config object are Hex codes stored as strings.
        #  Convert the string to an int, and then convert to a wxPython Colour
        self.red = wx.Colour(int(self.config.get('colors', 'red'), 16))
        self.orange = wx.Colour(int(self.config.get('colors', 'orange'), 16))
        self.yellow = wx.Colour(int(self.config.get('colors', 'yellow'), 16))


        # All the possible ChData objects that we can possibly recieve
        self.data = []
        for c in ch_dict.values():
            self.data.append(ChData.get_empty_obj(c))

        # The ChData objects that we have recieved
        self.chs_seen = []

        # The current list of full_names that we want to filter for
        self.filter = []
        self.prev_filter = []

        # The PyDataViewModel derives from both DataViewModel and from
        # DataViewItemObjectMapper, which has methods that help associate
        # data view items with Python objects. Normally a dictionary is used
        # so any Python object can be used as data nodes. If the data nodes
        # are weak-referencable then the objmapper can use a
        # WeakValueDictionary instead.
        self.UseWeakRefs(True)
예제 #8
0
    def __init__(self, data, config=None):
        '''
        Constructor

        Args:
            data: TODO
            config (ConfigManager, default=None): object with all config info
                   for colors. If None, defaults used
        '''

        if config==None:
            config = ConfigManager()

        self.config = config

        # Colors in config object are Hex codes stored as strings.
        #  Convert the string to an int, and then convert to a wxPython Colour
        warn_lo_color_val = int(self.config.get('colors', 'warning_lo'), 16)
        warn_hi_color_val = int(self.config.get('colors', 'warning_hi'), 16)
        fatal_color_val = int(self.config.get('colors', 'fatal'), 16)
        command_color_val = int(self.config.get('colors', 'command'), 16)

        self.warn_lo_color = wx.Colour(warn_lo_color_val)
        self.warn_hi_color = wx.Colour(warn_hi_color_val)
        self.fatal_color = wx.Colour(fatal_color_val)
        self.command_color = wx.Colour(command_color_val)


        wx.dataview.PyDataViewModel.__init__(self)
        self.data = data

        self.data_filtered = list()

        self.current_filter = (None, None)

        # The PyDataViewModel derives from both DataViewModel and from
        # DataViewItemObjectMapper, which has methods that help associate
        # data view items with Python objects. Normally a dictionary is used
        # so any Python object can be used as data nodes. If the data nodes
        # are weak-referencable then the objmapper can use a
        # WeakValueDictionary instead.
        self.UseWeakRefs(True)
예제 #9
0
 def setup_class(cls):
     try:
         cls.pipeline = StandardPipeline()
         config = ConfigManager()
         filename = os.path.dirname(__file__)
         path = os.path.join(
             filename,
             "../../build-artifacts/{}/dict/RefTopologyAppDictionary.xml".
             format(platform.system()),
         )
         logpath = os.path.join(filename, "./logs")
         cls.pipeline.setup(config, path, "/tmp")
         cls.api = IntegrationTestAPI(cls.pipeline, logpath)
         cls.case_list = []  # TODO find a better way to do this.
         cls.dictionary = path
         cls.pipeline.connect("tcp://127.0.0.1:50050")
     except Exception as exc:
         print(f"[WARNING] Exception in setup: {exc}")
         cls.teardown_class()
         raise
예제 #10
0
파일: encoder.py 프로젝트: zchoffma/fprime
    def __init__(self, dest="FSW", config=None):
        '''
        Encoder class constructor

        Args:
            dest (string, "FSW" or "GUI", default="FSW"): Destination for binary
                  data produced by encoder.
            config (ConfigManager, default=None): Object with configuration data
                    for the sizes of fields in the binary data. If None passed,
                    defaults are used.

        Returns:
            An initialized encoder object.
        '''
        # List of senders to be notified of new data
        self.__senders = []

        if config == None:
            # Retrieve defaults for the configs
            config = ConfigManager()

        self.config = config

        self.dest = dest
예제 #11
0
def test_event_encoder():
    """
    Tests the encoding of the event encoder
    """
    config = ConfigManager()
    config.set("types", "msg_len", "U16")

    enc = EventEncoder()
    enc_config = EventEncoder(config)

    temp = EventTemplate(
        101,
        "test_ch",
        "test_comp",
        [("a1", "a1", U32Type()), ("a2", "a2", U32Type())],
        EventSeverity["DIAGNOSTIC"],
        "%d %d",
    )

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

    event_obj = EventData((U32Type(42), U32Type(10)), time_obj, temp)

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

    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

    reg_output = enc.encode_api(event_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(event_obj)

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

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

    reg_output = enc.encode_api(event_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(event_obj)

    assert (config_output == config_expected
            ), "FAIL: expected configured output to be %s, but found %s" % (
                list(config_expected),
                list(config_output),
            )
예제 #12
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),
            )
예제 #13
0
        time_bin = data.get_time().serialize()

        val_bin = data.get_val_obj().serialize()

        len_val = len(desc_bin) + len(id_bin) + len(time_bin) + len(val_bin)
        self.len_obj.val = len_val
        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"