def test_get_msg_text(self): d = get_test_path() msg_d = os.path.join(d, 'msg') test_message_package = 'test_rosmaster' rospack = rospkg.RosPack() msg_raw_d = os.path.join(rospack.get_path(test_message_package), 'msg') for t in ['RosmsgA', 'RosmsgB']: with open(os.path.join(msg_d, '%s.msg'%t), 'r') as f: text = f.read() with open(os.path.join(msg_raw_d, '%s.msg'%t), 'r') as f: text_raw = f.read() type_ = test_message_package+'/'+t self.assertEquals(text, rosmsg.get_msg_text(type_, raw=False)) self.assertEquals(text_raw, rosmsg.get_msg_text(type_, raw=True)) # test recursive types t = 'RosmsgC' with open(os.path.join(d, '%s_raw.txt'%t), 'r') as f: text = f.read() with open(os.path.join(msg_raw_d, '%s.msg'%t), 'r') as f: text_raw = f.read() type_ = test_message_package+'/'+t self.assertEquals(text, rosmsg.get_msg_text(type_, raw=False)) self.assertEquals(text_raw, rosmsg.get_msg_text(type_, raw=True))
def test_get_msg_text(self): d = get_test_path() msg_d = os.path.join(d, 'msg') test_message_package = 'diagnostic_msgs' rospack = rospkg.RosPack() msg_raw_d = os.path.join(rospack.get_path(test_message_package), 'msg') t = 'KeyValue' with open(os.path.join(msg_d, '%s.msg'%t), 'r') as f: text = f.read() with open(os.path.join(msg_raw_d, '%s.msg'%t), 'r') as f: text_raw = f.read() type_ = test_message_package+'/'+t self.assertEquals(text, rosmsg.get_msg_text(type_, raw=False)) self.assertEquals(text_raw, rosmsg.get_msg_text(type_, raw=True)) # test recursive types t = 'DiagnosticStatus' with open(os.path.join(d, '%s_raw.txt'%t), 'r') as f: text = f.read() with open(os.path.join(msg_raw_d, '%s.msg'%t), 'r') as f: text_raw = f.read() type_ = test_message_package+'/'+t self.assertEquals(text, rosmsg.get_msg_text(type_, raw=False)) self.assertEquals(text_raw, rosmsg.get_msg_text(type_, raw=True))
def show(*args): # TODO: provide plugin? if not args: raise ValueError("show requires an argument") arg = args[0] if hasattr(arg, '_show'): return arg._show() # duck-type check for generated services elif isinstance(arg, type) and hasattr(arg, '_request_class') and hasattr(arg, '_response_class'): print rosmsg.get_srv_text(arg._type) # duck-type check for generated messages elif isinstance(arg, type) and hasattr(arg, '_slot_types'): print rosmsg.get_msg_text(arg._type) else: raise ValueError("unknown show arg: %s: %s"%(type(arg), arg))
def _rightclick_menu(self, event): menu = QMenu() text_action = QAction(self.tr('View Text'), menu) menu.addAction(text_action) raw_action = QAction(self.tr('View Raw'), menu) menu.addAction(raw_action) action = menu.exec_(event.globalPos()) if action == raw_action or action == text_action: selected = self.messages_tree.selectedIndexes() selected_type = selected[1].data() if selected_type[-2:] == '[]': selected_type = selected_type[:-2] browsetext = None try: if self._mode == rosmsg.MODE_MSG: browsetext = rosmsg.get_msg_text(selected_type, action == raw_action) elif self._mode == rosmsg.MODE_SRV: browsetext = rosmsg.get_srv_text(selected_type, action == raw_action) else: raise except rosmsg.ROSMsgException, e: QMessageBox.warning( self, self.tr('Warning'), self. tr('The selected item component does not have text to view.' )) if browsetext is not None: self._browsers.append(TextBrowseDialog(browsetext)) self._browsers[-1].show()
def _get_topic_data_map(self, topic_data_map, topic_nm): result = False if (topic_nm in topic_data_map): result = True self.topic_items = topic_data_map[topic_nm] else: try: topic_type_info = rostopic.get_topic_type(topic_nm) if (topic_type_info[0] is not None): topic_msg = rosmsg.get_msg_text(topic_type_info[0]) self.topic_items = self._parse_topic_items( self.topic, topic_msg) topic_data_map[topic_nm] = { "topic_msg": topic_type_info[0], "items": self.topic_items } result = True except NameError as ne: rospy.logerr("topic info get failed. %s", self.topic) print(ne) return result
def __str__(self): if self._type_name is None: self._init_type() if self._type_name is None: return self._ns else: return rosmsg.get_msg_text(self._type_name)
def __str__(self): # re-initialize if self._type is None and self._type_name is not None: self._init_action() if self._type is not None: return rosmsg.get_msg_text(self._goal._type) else: return self._ns
def getColumnValidationClasses(self): msg = self.MsgClass() spec = rosmsg.get_msg_text(msg._type) spec = spec.split('\n') spec.remove("") spec, _ = self._parseMsg(spec) spec = self._translateSpecToCassandra(spec) return spec
def test_get_msg_text(self): d = get_test_path() msg_d = os.path.join(d, 'msg') for t in ['RosmsgA', 'RosmsgB']: with open(os.path.join(msg_d, '%s.msg'%t), 'r') as f: text = f.read() type_ = 'test_ros/'+t self.assertEquals(text, rosmsg.get_msg_text(type_, raw=False)) self.assertEquals(text, rosmsg.get_msg_text(type_, raw=True)) # test recursive types t = 'RosmsgC' with open(os.path.join(msg_d, '%s.msg'%t), 'r') as f: text = f.read() type_ = 'test_ros/'+t self.assertEquals(text, rosmsg.get_msg_text(type_, raw=True)) self.assertEquals("""std_msgs/String s1 string data std_msgs/String s2 string data""", rosmsg.get_msg_text(type_, raw=False).strip())
def _rightclick_menu(self, event): """ :type event: QEvent """ # QTreeview.selectedIndexes() returns 0 when no node is selected. # This can happen when after booting no left-click has been made yet # (ie. looks like right-click doesn't count). These lines are the # workaround for that problem. selected = self._messages_tree.selectedIndexes() if len(selected) == 0: return menu = QMenu() text_action = QAction(self.tr('View Text'), menu) menu.addAction(text_action) raw_action = QAction(self.tr('View Raw'), menu) menu.addAction(raw_action) remove_action = QAction(self.tr('Remove message'), menu) menu.addAction(remove_action) action = menu.exec_(event.globalPos()) if action == raw_action or action == text_action: rospy.logdebug('_rightclick_menu selected={}'.format(selected)) selected_type = selected[1].data() if selected_type[-2:] == '[]': selected_type = selected_type[:-2] browsetext = None try: if (self._mode == rosmsg.MODE_MSG or self._mode == rosaction.MODE_ACTION): browsetext = rosmsg.get_msg_text(selected_type, action == raw_action) elif self._mode == rosmsg.MODE_SRV: browsetext = rosmsg.get_srv_text(selected_type, action == raw_action) else: raise except rosmsg.ROSMsgException as e: QMessageBox.warning( self, self.tr('Warning'), self.tr('The selected item component ' + 'does not have text to view.')) if browsetext is not None: self._browsers.append( TextBrowseDialog(browsetext, self._rospack)) self._browsers[-1].show() if action == remove_action: self._messages_tree.model().removeRow(selected[0].row())
def _rightclick_menu(self, event): """ :type event: QEvent """ # QTreeview.selectedIndexes() returns 0 when no node is selected. # This can happen when after booting no left-click has been made yet # (ie. looks like right-click doesn't count). These lines are the # workaround for that problem. selected = self._messages_tree.selectedIndexes() if len(selected) == 0: return menu = QMenu() text_action = QAction(self.tr('View Text'), menu) menu.addAction(text_action) raw_action = QAction(self.tr('View Raw'), menu) menu.addAction(raw_action) remove_action = QAction(self.tr('Remove message'), menu) menu.addAction(remove_action) action = menu.exec_(event.globalPos()) if action == raw_action or action == text_action: rospy.logdebug('_rightclick_menu selected={}'.format(selected)) selected_type = selected[1].data() if selected_type[-2:] == '[]': selected_type = selected_type[:-2] browsetext = None try: if (self._mode == rosmsg.MODE_MSG or self._mode == rosaction.MODE_ACTION): browsetext = rosmsg.get_msg_text(selected_type, action == raw_action) elif self._mode == rosmsg.MODE_SRV: browsetext = rosmsg.get_srv_text(selected_type, action == raw_action) else: raise except rosmsg.ROSMsgException as e: QMessageBox.warning(self, self.tr('Warning'), self.tr('The selected item component ' + 'does not have text to view.')) if browsetext is not None: self._browsers.append(TextBrowseDialog(browsetext, self._rospack)) self._browsers[-1].show() if action == remove_action: self._messages_tree.model().removeRow(selected[0].row())
print(ex) exit(-1) selected_topics_list = [topics[i] for i in topic_selections] # used later to know how far you have been message_count = sum(bag.get_message_count(topics[i]) for i in topic_selections) if use_saved: data_selections = saved_input["data_selections"] else: data_selections = [] for topic_selection in topic_selections: print( f"{COLORS.BOLD}{COLORS.OKGREEN}Available Fields from {COLORS.OKBLUE}{topics[topic_selection]}{COLORS.ENDC}" ) print(rosmsg.get_msg_text(types[topic_selection])) single_topic_data_selection = input( "Specify which fields you want seperated with spaces. " "You can also use a semantic like \"orientation.x\" to access internal fields." "Header stamp and seq are included automatically.\n") data_selections.append(single_topic_data_selection.split()) def recursive_getattr(obj, field_list): if len(field_list) == 1: return getattr(obj, field_list[0]) else: return recursive_getattr(getattr(obj, field_list[0]), field_list[1:]) frames = []
def get_msg_fields(msg_name, rospack=None): lines = rosmsg.get_msg_text(msg_name, False, rospack).splitlines() return get_fields(lines)
def __init__(self, msg_name, rospack=None): # parse msg definition lines = rosmsg.get_msg_text(msg_name, False, rospack).splitlines() self.typespec = TypeSpec(msg_name) msg = Fields(lines) self.fields = msg.fields
import os import rosmsg import rospkg import genmsg """ This module retrieves ROS MsgSpecs by message type. This is the only way I know of to get the types of message constants. rosmsg.get_msg_text() *almost* does this, but converts the MsgSpec to text. These library functions are based on its implementation. """ def get_msg_search_path(): """ Get ROS search path for messages """ # see rosmsg.get_msg_text for reference rospack = rospkg.RosPack() search_path = {} for p in rospack.list(): package_paths = rosmsg._get_package_paths(p, rospack) search_path[p] = [os.path.join(d, 'msg') for d in package_paths] return search_path def get_msg_spec(msg_type_name): """ Get ROS MsgSpec for given message type """ # see rosmsg.get_msg_text for reference context = genmsg.MsgContext.create_default() search_path = get_msg_search_path() return genmsg.msg_loader.load_msg_by_type(context, msg_type_name, search_path)
def get_msg_info(self): """ @output: The structure defined in file .msg of the actual message. """ return rosmsg.get_msg_text(self._message)