Esempio n. 1
0
    def CreateFrame(self, index):
        frame = None
        title = "Mech-II" + "  v" + const.VERSION_MAJOR + '.' + const.VERSION_MINOR

        if index == 0:
            frame = SplashViewer(UpdateFrame=self.UpdateFrame,
                                 parent=None,
                                 title=title,
                                 name="Splash Frame",
                                 style=wx.DEFAULT_FRAME_STYLE,
                                 size=(1920, 1080))

        elif index == 1:
            devices_info = DevicesInfo()
            devices_info = devices_info.get_devices_name()
            focus_device = list(devices_info.keys())[0]
            focus_node = devices_info[focus_device][0]

            frame = MechIIViewer(devices_info=devices_info,
                                 focus_device=focus_device,
                                 focus_node=focus_node,
                                 UpdateFrame=self.UpdateFrame,
                                 parent=None,
                                 title=title,
                                 name="Mech-II Frame",
                                 style=wx.DEFAULT_FRAME_STYLE,
                                 size=(1920, 1080))

        return frame
Esempio n. 2
0
    def OnNodeShow(self, evt):
        """
        切换Node的事件触发
        :param evt:
        :return:
        """
        self.__logger.info("Switch Node = {} --> {}".format(
            self.__focus_node, evt.name))
        # print("focus_uuid = ", self.__focus_uuid)

        #
        if self.__focus_node != evt.name:
            if self.DeleteAllItems() is not True:
                self.__logger.error("error in DeleteAllItems")
            else:
                self.__logger.debug("ok in DeleteAllItems")

            devices_info = DevicesInfo()
            # print(devices_info.get_uuid())
            for uuid in devices_info.get_uuid():
                if uuid[-4:] == evt.name[-4:]:
                    # print("match evt.name and uuid", uuid[-4:], evt.name[-4:])
                    # print("modules list = ", self._monitor_modules[uuid])
                    # print("monitor_modules = ", self._monitor_modules)
                    # print("monitor modules list = ", self._monitor_modules_list)
                    self.__logger.debug("monitor modules list = {}".format(
                        self._monitor_modules_list))
                    # print("monitor modules log = ", self._monitor_modules_log)
                    # print("monitor modules max state = ", self._monitor_modules_max_state)

                    self.__focus_node = evt.name
                    self.__focus_uuid = uuid

                    # 显示当前节点必须监控的模块
                    for name in self._monitor_modules_list[self.__focus_uuid]:
                        log = self._monitor_modules_list[
                            self.__focus_uuid][name]["log"]
                        item = (name, log)
                        index = self.AddItem(item)

                        # self._monitor_modules_list[self.__focus_uuid][name] = {}
                        # self._monitor_modules_list[self.__focus_uuid][name]["index"] = index
                        # self._monitor_modules_list[self.__focus_uuid][name]["log"] = log
                        # self._monitor_modules_list[self.__focus_uuid][name]["state"] = "none"

                        status = self._monitor_modules_list[
                            self.__focus_uuid][name]["state"]
                        self.UpdateItemStatus(name, status)
                        """
                        if state == 'warning':
                            self.UpdateItemBackground(name, 'yellow')
                        elif state == 'error':
                            self.UpdateItemBackground(name, 'red')
                        elif state == 'info':
                            self.UpdateItemBackground(name, 'green')
                        """
                        """
Esempio n. 3
0
    def parse_body_system_info(self, body):
        body_dic = json.loads(body.decode("utf-8"))
        system_info = body_dic['system']
        system_info['uuid'] = ""
        for char in bytesTobcd(
                self.vendor_id.to_bytes(1, byteorder='little', signed=False) +
                self.product_id.to_bytes(1, byteorder='little', signed=False) +
                self.serial_id):
            system_info['uuid'] += char
        system_info['ip'] = self.__ip

        self.__system_info.update(system_info)
        # print("system info = ", self.__system_info)

        wx.CallAfter(pub.sendMessage,
                     self.__pub_system_info_msg_name,
                     info=self.__system_info)

        devices_info = DevicesInfo()
        if devices_info.get_uuid_from_ip(self.__ip) is None:
            devices_info.set_uuid(self.__ip, system_info['uuid'])
Esempio n. 4
0
    def parse_body_heart_beat(self):
        # print("parse_body_heart_beat::++++++++++++++++++++")

        devices_info = DevicesInfo()
        if self.__uuid is "":
            self.__uuid = '%02X' % self.vendor_id
            self.__uuid += '%02X' % self.product_id
            self.__uuid += bytesToHexString(self.serial_id)
            # print("uuid = ", self.__uuid)

            devices_info.set_uuid(self.__ip, self.__uuid)
            # print(devices_info.devices_ready())

            if self.__device_logger is None:
                log_dir = "log/" + self.__uuid
                # print("log dir = ", log_dir)
                self.__device_logger = db_file(log_dir)

            if devices_info.devices_ready():
                # print(" send msg device_node_ready!!!")
                wx.CallAfter(pub.sendMessage, self.__pub_device_ready_msg_name)

        wx.CallAfter(pub.sendMessage, 'heart_beat_event', mode=True)
Esempio n. 5
0
    def __init__(self, *args, **kwargs):
        super(ModuleList, self).__init__(*args, **kwargs)

        # 初始化日志类
        self.__logger = SingleLogger()

        # 创建数据库管理类
        self.__sql = db_sql()

        # 当前Module Tab显示的列名
        self.AddColumns()

        # 初始化私有变量
        self._monitor_modules_list = {
        }  # 对应每个设备(uuid), 记录这个设备的每个module的名字和位置的对应关系
        # self._monitor_modules_log = {}              # 对应每个设备(uuid), 记录这个设备的每个module的名字和日志的对应关系
        # self._monitor_modules_max_state = {}        # 对应每个设备(uuid), 记录这个设备的每个module的名字和状态的对应关系

        # 默认的焦点设备,节点和设备的uuid
        devices_info = DevicesInfo()
        devices = devices_info.get_devices_name()
        self.__logger.debug("all devices list = {}".format(devices))

        #
        self.__focus_device = list(devices.keys())[0]
        self.__focus_node = devices[self.__focus_device][0]
        self.__focus_uuid = devices_info.get_uuid()[0]

        # 初始化每个设备,必须监控的模块
        for uuid in devices_info.get_uuid():
            # 当前Module Tab监控的模块
            self._monitor_modules_list[uuid] = {
            }  # {name : index} --> 记录每个module的名字和位置的对应关系
            # self._monitor_modules_max_state[uuid] = {}      # {name : state} --> 记录每个module的名字和最差状态的对应关系
            # self._monitor_modules_log[uuid] = {}            # {name : log} --> 记录每个module的名字和日志的对应关系

            # self.__focus_uuid = uuid

            # 显示当前节点必须监控的模块
            for module in devices_info.get_module_monitor_name_from_uuid(uuid):
                item = (module, '')
                index = self.AddItem(item)

                self._monitor_modules_list[self.__focus_uuid][module] = {}
                self._monitor_modules_list[
                    self.__focus_uuid][module]["index"] = index
                self._monitor_modules_list[
                    self.__focus_uuid][module]["log"] = ''
                self._monitor_modules_list[
                    self.__focus_uuid][module]["state"] = "none"

                self.__sql.create_table(uuid=uuid, name=module)

        # 订阅消息 (module信息传输触发事件消息)
        self.__pub_module_info_msg_name = 'module_info_event'
        pub.subscribe(self.OnReceiveModuleEvent,
                      self.__pub_module_info_msg_name)

        # 绑定公共事件处理
        self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected)
        self.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.OnItemDeselected)
        self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnItemDoubleClicked)
        self.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK, self.OnItemRightClicked)

        # 绑定自定义事件处理
        self.Bind(EVT_NODE, self.OnNodeShow)
Esempio n. 6
0
        # bin = build_event_info_bin(module_protocol)
        print(type(bin))
        #bin = random_function()
        print(bin)
        conn.send(bin)
        time.sleep(5)

        bin = build_heart_beat_bin(module_protocol)
        conn.send(bin)
        time.sleep(0.02)

        bin = build_system_info_bin(module_protocol, start_time)
        conn.send(bin)
        time.sleep(1)


if __name__ == '__main__':
    # 改变当前工作目录到上一级目录
    os.chdir("../")

    devices_info = DevicesInfo()
    devices_info.set_uuid("127.0.0.1", "2001313233223637")
    devices_info.set_uuid("192.168.1.101", "1234567890121111")

    client = socket.socket()  # 默认是AF_INET、SOCK_STREAM
    client.connect(("localhost", 9999))

    simu_node_client(client)

    client.close()
Esempio n. 7
0
            self.__flag.wait()              # 为True时立即返回, 为False时阻塞直到内部的标识位为True后返回

        server.shutdown()
        server.server_close()


if __name__ == '__main__':
    # 改变当前工作目录到上一级目录
    os.chdir("../")

    # devices_info = {'#1': ['#1-TC397-2222', '#1-H3-3333'], '#2': ['#2-TC397-4444', '#2-H3-5555'], '#3': ['#3-TC397-6666', '#3-H3-7777']}
    # devices_info = {'#1': ['TC397-2222', 'H3-3333'], '#2': ['TC397-4444', 'H3-5555'], '#3': ['TC397-5555', 'H3-6666']}
    # devices_info = {'1111': ['2222', '3333'], '1112': ['4444', '5555']}
    # devices_info = {'1111': ['2222', '3333']}

    devices_info = DevicesInfo()
    devices_info.set_uuid("127.0.0.1", "2001313233223637")
    # devices_info.set_uuid("192.168.1.101", "2001353137626261")
    devices_info.set_uuid("192.168.1.101", "2001333836373665")

    # print("++++++++++++++++++++")
    # print(devices_info.devices_ready())
    # print(devices_info.get_devices_name())
    # print(devices_info.get_uuid())
    # print("--------------------")
    devices_info = devices_info.get_devices_name()
    focus_device = list(devices_info.keys())[0]
    focus_node = devices_info[focus_device][0]
    print("focus_device = ", focus_device)
    print("focus_node = ", focus_node)