def topic(visitor, topic, maping): try: i = maping[topic._qname] topic._publisher = i except KeyError: warning("The topic {} doesn't have any publisher.".format( topic._qname), topic._location) return topic, maping
def topic(visitor, topic, maping): try: i = maping[topic._qname] topic._publisher = i except KeyError: warning( "The topic {} doesn't have any publisher.".format( topic._qname), topic._location) return topic, maping
def node(visitor, node, _): for pub in node['PUBLISHES']: top = pub['TOPIC'] if top._qname in infos.publishers: warning( "Topic {} has multiple publishers." " -> Be cautious with the --ROS backend." "".format(top), top._location) infos.publishers[top._qname] = node._qname
def getIP(system): try: return system['IP']._val except AttributeError: if not (system._qname in warned_systems): warning( "No IP given, so SROS generation assumes IP 127.0.0.1 for system " + str(system._qname), system._location) warned_systems.add(system._qname) return '127.0.0.1'
def load_in_namespace(self, namespace, filepath): self.check_compat(filepath) n = self.root_node # reroot node n._namespace.father = namespace # add node to the root namespace try: #verify we are adding a new name namespace.lookup_node(n._qname) warning("Loading {} is shadowing a previous definition of {}" "".format(str(filepath), str(n._qname))) except: pass #everything is ok namespace.associate(n._qname, n)
def load_in_namespace(self, namespace, filepath): if not self.check_compat(filepath): error_noloc("Failed to load the object {}.".format(filepath)) n = self.root_node # reroot node n._namespace.father = namespace # add node to the root namespace try: #verify we are adding a new name namespace.lookup_node(n._qname) warning("Loading {} is shadowing a previous definition of {}" "".format(str(filepath), str(n._qname))) except: pass #everything is ok namespace.associate(n._qname, n) try: update_idents(self.root_node, namespace) except NonExistingIdent as e: error_noloc("Could not resolve the identifier {}.\n" "Check that you loaded its module first." "".format(e.ident))
def gennode(visitor, node, cpps): """ Nodes are not recursive for now """ d = {'in_struct' : '_in_t', 'out_struct' : '_out_t', 'in_flags_struct' : '_in_flags_t', 'out_flags_struct': '_out_flags_t', 'cxx_includes' : getincludes(node), 'period' : to_rate(node['PERIOD'])} #TODO: 5 correct when ros is fixed and allow a duration as rate constructor argument #Over publications and subscriptions pubsub_templates = ['msg_include'] for pt in pubsub_templates: d[pt] = '' #Over the publications pubmon_templates = ['pub_call', 'out_fill' , 'set_pub', 'out_flags_struct_def', 'out_struct_def', 'pub_flags_fill', 'set_counter', 'pub_report', 'report_fill'] pub_templates = ['pub_call', 'out_fill' , 'set_pub', 'out_flags_struct_def', 'out_struct_def', 'pub_flags_fill'] mon_templates = ['pub_report', 'report_fill' , 'set_pub', 'set_counter'] for pt in pubmon_templates: d[pt] = '' for pub in node['PUBLISHES']: d.update({'pubname' : pub._qname.name(), 'topic_name' : qn_topic(pub['TOPIC']._qname), 'actionname' : '_' + pub._qname.name() + '_pub', 'actionclass' : pub['PUBLISHER']['CXX']['CLASS']._val, 'topic_file' : pub['TOPIC']._ros_msgtype_header, 'topic_t' : pub['TOPIC']._ros_msgtype_name, 'initmsg' : '_init_' + pub._qname.name()}) d['init_msg_fill'] = ros_val_def(d['initmsg'], pub['TOPIC'], separators['init_msg_fill']) d['report_msg_fill'] = ros_val_def('_report', pub['TOPIC'], separators['report_msg_fill']) if pub['MONITOR'] is None: for f in pub_templates: app(d, f) else: if(pub['MONITOR']._val == 'true'): d.update({'times' : to_times(node['PERIOD'])}) for f in mon_templates: app(d, f) else: for f in pub_templates: app(d, f) for f in pubsub_templates: app(d, f) #Over the subscriptions sub_templates = ['in_fill', 'set_sub', 'in_struct_def', 'in_flags_struct_def', 'sub_flags_fill', 'gathered_flags'] for st in sub_templates: d[st] = '' d['gathered_flags'] = '0' for sub in node['SUBSCRIBES']: d.update({'subname' : sub._qname.name(), 'topic_name' : qn_topic(sub['TOPIC']._qname), 'actionname' : '_' + sub._qname.name() + '_sub', 'actionclass' : sub['SUBSCRIBER']['CXX']['CLASS']._val, 'topic_file' : sub['TOPIC']._ros_msgtype_header, 'topic_t' : sub['TOPIC']._ros_msgtype_name, 'initmsg' : '_init_' + sub._qname.name(), 'maxlatency' : to_ros_duration(sub['MAXLATENCY'])}) try: d['pubperiod'] = to_ros_duration(sub['TOPIC']._publisher['PERIOD']) except AttributeError: #no publisher warning("By lack of known publisher, subscription {} will " "compute timeout assuming the publisher period is 10s." "".format(str(sub._qname)), sub._location) d['pubperiod'] = "ros::Duration().fromNSec(10000000000)" d['init_msg_fill'] = ros_val_def(d['initmsg'], sub['TOPIC'], separators['init_msg_fill']) for f in sub_templates: app(d, f) for f in pubsub_templates: app(d, f) #generate the header file qname = node._qname #TODO: 4 namespace nodes... use the nodehandler? or the remaping args? d['name'] = qname.name() node_h_name = Path(qn_srcfile(node._qname, 'radl__', '.h')) node_h = templates['node_h'].format(**d) write_file(filepath(node_h_name), node_h) #generate the cpp file node_cpp_name = Path(qn_srcfile(node._qname, 'radl__', '.cpp')) node_cpp = templates['node_cpp'].format( node_h_name=node_h_name.name, rate=node['PERIOD']._val, node=node, **d) write_file(filepath(node_cpp_name), node_cpp) #register the cpp file cpps[qname] = node_cpp_name return (), cpps