def __multi_msg_dispatcher(self, data_dict): msg_id, msg_data = Util.get_msg_id_data_dict(data_dict) if msg_id is not None: module_name = self.msg_id_module_dict.get(msg_id) if isinstance(module_name, str): self.send_msg(msg_id, module_name, msg_data, msg_src=data_dict['msg_src'])
def show_box_show_tip(self, data_dict): msg_id, msg_data = Util.get_msg_id_data_dict(data_dict) if msg_id is not None: index, tip = Util.get_index_tip_msg_data(msg_data) if index is not None: pass pass
def __subscribe_msg(self, data_dict): """ subscribe msg_id with mode_name. :param data_dict: is a dict . include msg_id, mode_name Note: ## data_dict = { 'msg_id' : 'register_msg_id', 'msg_data' : { 'msg_id' : 'xxxxx_id', 'module_name' : 'xxxxxx' } } """ msg_id, msg_data = Util.get_msg_id_data_dict(data_dict) if msg_id is not None: msg_id = msg_data.get('msg_id') module_name = msg_data.get('module_name') if isinstance(msg_id, str) and isinstance(module_name, str): if msg_id == self.msg_id.inner_register_id: self.__logger.info('register_msg_id ready for service !') else: if msg_id in self.msg_id_module_dict: self.__logger.warning('msg_id : ' + str(msg_id) + ' register again! old module_ is ' + str(self.msg_id_module_dict[msg_id]) + ' new module is ' + str(module_name)) else: self.__logger.info('msg_id : ' + str(msg_id) + ' register to module :' + str(module_name)) self.msg_id_module_dict[msg_id] = module_name self.send_msg_id_manager_dispatcher(msg_id)
def mode_status_update(self, data_dict): self.logger.info(str(data_dict)) _, msg_data = Util.get_msg_id_data_dict(data_dict) if 'status' in msg_data and 'index' in msg_data: status = msg_data['status'] index = msg_data['index'] if isinstance(status, bool) and index in range(start_status_cnt): self.list_start_status[index][start_status] = status
def inner_msg_handler(self, data_dict): msg_id, msg_data = Util.get_msg_id_data_dict(data_dict) if msg_id is not None: callback = self.__subscriber_dict.get(msg_id) if callback is not None: callback(data_dict) else: if self.__default_callback is not None: self.__default_callback(data_dict)
def progress_notify_callback(self, data_dict): _, msg_data = Util.get_msg_id_data_dict(data_dict) self.logger.info('receive msg ' + str(data_dict)) if 'progress_percent' in msg_data: progress_percent = msg_data['progress_percent'] if isinstance(progress_percent, int): if progress_percent >= 100: self.progress_percent = 100 else: self.progress_percent = progress_percent
def position_notify_callback(self, data_dict): msg_id, msg_data = Util.get_msg_id_data_dict(data_dict) if 'x' in msg_data and 'y' in msg_data and 'z' in msg_data: self.position_x = int(msg_data['x']) self.position_y = int(msg_data['y']) self.position_z = int(msg_data['z']) else: self.logger.warning(str(data_dict) + ' data error !!!') pass
def interface_ros_send_msg_out(self, data_dict): _, msg_data = Util.get_msg_id_data_dict(data_dict) if msg_data is not None and isinstance(msg_data, dict): if self.ros_is_running: if self.ui_ros_topic_is_sub: # self.send_msg_ros(msg_data) self.msg_out_queue.put_nowait(msg_data) else: self.logger.info('/ui_ros_topic is not Subscriber') else: self.logger.info('ros_master is not run') return
def set_button_enable_callback(self, data_dict): """ { 'msg_id': 'base_frame_set_button_enable', 'msg_data':{ 'button_enable': False } } :param data_dict: :return: """ msg_id, msg_data = Util.get_msg_id_data_dict(data_dict) if msg_id is not None and isinstance(msg_data, dict): self.set_button_enable_msg_data_proc(msg_data)
def update_link_status_callback(self, data_dict): """ { 'msg_id' : 'mode_mt_update_link_status', 'msg_data': { 'link_ros': False, 'link_mcu': False } } :param data_dict: :return: """ msg_id, msg_data = Util.get_msg_id_data_dict(data_dict) if msg_id is not None and isinstance(msg_data, dict): self.update_link_status_proc(msg_data)
def __change_page_callback(self, data_dict): """ data_dict = { 'msg_id' : 'ui_manager_change_page', 'msg_data' : { 'page_mode',1 } } """ msg_id, msg_data = Util.get_msg_id_data_dict(data_dict) if msg_id is not None and isinstance(msg_data, dict): page_mode = msg_data.get('page_mode') if page_mode is not None and isinstance(page_mode, int): self.__logger.info('change mode ' + str(page_mode)) self.__change_page(page_mode)
def control_callback(self, data_dict): self.__logger.info(str(data_dict)) _, msg_data = Util.get_msg_id_data_dict(data_dict) if 'ros_start' in msg_data: if msg_data['ros_start']: if self.is_start: self.__logger.warning(' is starting please wait') else: self.__logger.info('start launch begin') Util.add_thread(target=self.start_launch_thread) else: if self.is_stop: self.__logger.warning(' is stopping please wait') else: self.__logger.info('stop launch begin') Util.add_thread(target=self.stop_launch_thread)
def set_odom_callback(self, data_dict): """ { 'msg_id' : 'cfg_server_set_odom', 'msg_data': { 'odom': 1.23 } } :param data_dict: :return: """ msg_id, msg_data = Util.get_msg_id_data_dict(data_dict) if msg_id is not None and isinstance(msg_data, dict): self.logger.info('set_odom :' + str(data_dict)) odom = msg_data['odom'] self.database.update_key_value('odom', str(odom))
def __show_box_callback(self, data_dict): """ data_dict = { 'msg_id' : 'ui_manager_show_box', 'msg_data' : { 'index' : 1 , 'tip' : 'this a tip for show box' } } """ msg_id, msg_data = Util.get_msg_id_data_dict(data_dict) if msg_id is not None: index, tip = Util.get_index_tip_msg_data(msg_data) if index is not None: self.__show_box(index, tip)
def show_map_callback(self, data_dict): msg_id, msg_data = Util.get_msg_id_data_dict(data_dict) if 'map_path' in msg_data and 'map_name' in msg_data: map_path = msg_data['map_path'] if os.path.isfile( map_path ) or map_path == ':/mode_map_select/mode_map_select/default.png': self.map_select_path = map_path if 'map_name' in msg_data: self.map_select_name = msg_data['map_name'] return else: self.logger.fatal(str(map_path) + ' select path is no existed') return self.logger.warning(str(data_dict) + ' data error !!!')
def update_button_status_callback(self, data_dict): """ { 'msg_id' : 'base_frame_update_button_status', 'msg_data': { 'page_mode': 1 } } :param data_dict: :return: """ msg_id, msg_data = Util.get_msg_id_data_dict(data_dict) if msg_id is not None and isinstance(msg_data, dict): self.logger.info('get_status :' + str(data_dict)) self.update_button_status_proc(msg_data)
def update_button_status_callback(self, data_dict): """ { 'msg_id' : 'mode_mt_update_button_status', 'msg_data': { 'brush_status': 'open', # close 'water_status': 'open', 'direction_status': 'forward' #back } } :param data_dict: :return: """ msg_id, msg_data = Util.get_msg_id_data_dict(data_dict) if msg_id is not None and isinstance(msg_data, dict): self.update_button_status_proc(msg_data)
def __robot_status_callback(self, data_dict): """ { 'msg_id': 'ui_manager_robot_status_notify', 'msg_data':{ 'robot_status': 'mt' } } :param data_dict: :return: """ # self.__logger.info('##########' + str(data_dict)) msg_id, msg_data = Util.get_msg_id_data_dict(data_dict) if msg_id is not None and isinstance(msg_data, dict): status = msg_data.get('robot_status') if status == 'mt' or status == 'at': self.robot_status = status
def info_notify_callback(self, data_dict): """ { 'msg_id': 'base_frame_info_notify', 'msg_data': { 'voltage_percent': 88, 'yewei2_percent': 88, 'Position_X': '0.3', 'Position_Y': '0.3' } } :param data_dict: :return: """ msg_id, msg_data = Util.get_msg_id_data_dict(data_dict) if msg_id is not None and isinstance(msg_data, dict): self.info_notify_msg_data_proc(msg_data)
def odom_notify_callback(self, data_dict): """ { 'msg_id' : 'base_frame_odom_notify', 'msg_data': { 'odom': '1.23' } } :param data_dict: :return: """ msg_id, msg_data = Util.get_msg_id_data_dict(data_dict) if msg_id is not None and isinstance(msg_data, dict): self.logger.info('get_odom :' + str(data_dict)) odom = msg_data['odom'] self.odom_count = float(odom) self.is_get_odom = True self.show_time()
def speed_notify_callback(self, data_dict): msg_id, msg_data = Util.get_msg_id_data_dict(data_dict) if 'speed' in msg_data: self.move_speed = msg_data['speed'] else: self.logger.warning(str(data_dict) + ' data error !!!')