def connect(self, argv): def property_callback(option, opt, option_value, parser): if option_value.count('=') != 1: raise wasanbon.InvalidUsageException() key, equals, value = option_value.partition('=') if not getattr(parser.values, option.dest): setattr(parser.values, option.dest, {}) if key in getattr(parser.values, option.dest): raise wasanbon.InvalidUsageException() getattr(parser.values, option.dest)[key] = value self.parser.add_option('-n', '--name', help='Name of connection. (Default: None)', type='string', default=None, dest='name') self.parser.add_option('-i', '--id', help='id of connection. (Default: "")', type='string', default='', dest='id') self.parser.add_option('-p', '--property', help='Properties of connection. Use A=B Format (Default:"")', type='string', dest='properties', action='callback', callback=property_callback) options, argv = self.parse_args(argv[:]) verbose = options.verbose_flag # This is default option if not getattr(options, 'properties'): setattr(options, 'properties', {}) from rtshell import path from rtshell.rtcon import connect_ports paths = [(arg, path.cmd_path_to_full_path(arg)) for arg in argv[3:]] try: connect_ports(paths, options, tree=None) sys.stdout.write('Success.\n') except: sys.stdout.write('Failed. Exception occurred.\n') return 0
def rtconnect(nameserver, tags, tree): for tag in tags: # check if/unless attribute in rtconnect tags exec_flag = True if tag.attributes.get(u'if'): val = tag.attributes.get(u'if').value arg = val.split(" ")[1].strip(")") # To "USE_WALKING" exec_flag = get_flag_from_argv(arg) if tag.attributes.get(u'unless'): val = tag.attributes.get(u'unless').value arg = val.split(" ")[1].strip(")") # To "USE_WALKING" exec_flag = not get_flag_from_argv(arg) if not exec_flag: continue source_path = nameserver + "/" + tag.attributes.get("from").value dest_path = nameserver + "/" + tag.attributes.get("to").value source_path = replace_arg_tag_by_env(source_path) dest_path = replace_arg_tag_by_env(dest_path) # print >>sys.stderr, "[rtmlaunch] Connecting from %s to %s"%(source_path,dest_path) source_full_path = path.cmd_path_to_full_path(source_path) dest_full_path = path.cmd_path_to_full_path(dest_path) if tag.attributes.get("subscription_type") != None: sub_type = tag.attributes.get("subscription_type").value sub_type = replace_arg_tag_by_env(sub_type) if not sub_type in ['flush', 'new', 'periodic']: print >> sys.stderr, sub_type + ' is not a subscription type' continue else: sub_type = 'flush' # this is default value if sub_type == 'new': push_policy = 'all' # wait for proess try: wait_component(source_full_path, tree) wait_component(dest_full_path, tree) if check_connect(source_full_path, dest_full_path, tree): continue except Exception, e: print >> sys.stderr, '\033[31m[rtmlaunch] [ERROR] Could not Connect (', source_full_path, ',', dest_full_path, '): ', e, '\033[0m' return 1 #print source_path, source_full_path, dest_path, dest_full_path; try: sub_type = str(sub_type) props = {'dataport.subscription_type': sub_type} if tag.attributes.get("push_policy") != None: push_policy = replace_arg_tag_by_env( str(tag.attributes.get("push_policy").value)) else: push_policy = 'all' if sub_type == 'new': props['dataport.publisher.push_policy'] = push_policy elif sub_type == 'periodic': props['dataport.publisher.push_policy'] = push_policy if tag.attributes.get("push_rate") != None: props['dataport.push_rate'] = replace_arg_tag_by_env( str(tag.attributes.get("push_rate").value)) else: props['dataport.push_rate'] = str('50.0') if tag.attributes.get("buffer_length") != None: props['dataport.buffer.length'] = replace_arg_tag_by_env( str(tag.attributes.get("buffer_length").value)) options = optparse.Values({ 'verbose': False, 'id': '', 'name': None, 'properties': props }) print >> sys.stderr, "[rtmlaunch] Connected from", source_path print >> sys.stderr, "[rtmlaunch] to", dest_path print >> sys.stderr, "[rtmlaunch] with", options try: rtcon.connect_ports(source_path, source_full_path, dest_path, dest_full_path, options, tree=tree) except Exception, e_1_1_0: # openrtm 1.1.0 try: rtcon.connect_ports([(source_path, source_full_path), (dest_path, dest_full_path)], options, tree=tree) except Exception, e_1_0_0: # openrtm 1.0.0 print >> sys.stderr, '\033[31m[rtmlaunch] {0} did not work on both OpenRTM 1.0.0 and 1.1.0'.format( os.path.basename(sys.argv[1])), '\033[0m' print >> sys.stderr, '\033[31m[rtmlaunch] OpenRTM 1.0.0 {0}'.format( e_1_0_0), '\033[0m' print >> sys.stderr, '\033[31m[rtmlaunch] OpenRTM 1.1.0 {0}'.format( e_1_1_0), '\033[0m' print >> sys.stderr, '\033[31m[rtmlaunch] This is very weird situation, Please check your network\033[0m' print >> sys.stderr, '\033[31m[rtmlaunch] configuration with `ifconfig` on both robot and client side. \033[0m' print >> sys.stderr, '\033[31m[rtmlaunch] Having multiple network interface sometimes causes problem, \033[0m' print >> sys.stderr, '\033[31m[rtmlaunch] please see FAQ site http://www.openrtm.org/OpenRTM-aist/html/FAQ2FE38388E383A9E38396E383ABE382B7E383A5E383BCE38386E382A3E383B3E382B0.html#f2bc375d\033[0m' print >> sys.stderr, '\033[31m[rtmlaunch] Issue related to this https://github.com/start-jsk/rtmros_hironx/issues/33\033[0m' print >> sys.stderr, '\033[31m[rtmlaunch] ~/.ros/log may contains usefully informations\033[0m'
def rtconnect(nameserver, tags, tree): for tag in tags: # check if/unless attribute in rtconnect tags exec_flag = True if tag.attributes.get(u'if'): val = tag.attributes.get(u'if').value arg = val.split(" ")[1].strip(")") # To "USE_WALKING" exec_flag = get_flag_from_argv(arg) if tag.attributes.get(u'unless'): val = tag.attributes.get(u'unless').value arg = val.split(" ")[1].strip(")") # To "USE_WALKING" exec_flag = not get_flag_from_argv(arg) if not exec_flag: continue source_path = nameserver+"/"+tag.attributes.get("from").value dest_path = nameserver+"/"+tag.attributes.get("to").value source_path = replace_arg_tag_by_env(source_path) dest_path = replace_arg_tag_by_env(dest_path) # print >>sys.stderr, "[rtmlaunch] Connecting from %s to %s"%(source_path,dest_path) source_full_path = path.cmd_path_to_full_path(source_path) dest_full_path = path.cmd_path_to_full_path(dest_path) if tag.attributes.get("subscription_type") != None: sub_type = tag.attributes.get("subscription_type").value if not sub_type in ['flush','new','periodic']: print >>sys.stderr, sub_type+' is not a subscription type' continue else: sub_type = 'flush' # this is default value if sub_type == 'new': push_policy = 'all' # wait for proess try: wait_component(source_full_path, tree) wait_component(dest_full_path, tree) if check_connect(source_full_path,dest_full_path, tree): continue except Exception, e: print >>sys.stderr, '\033[31m[rtmlaunch] [ERROR] Could not Connect (', source_full_path, ',', dest_full_path, '): ', e,'\033[0m' return 1 #print source_path, source_full_path, dest_path, dest_full_path; try: sub_type = str(sub_type) props = {'dataport.subscription_type': sub_type} if sub_type == 'new': props['dataport.publisher.push_policy'] = 'all' elif sub_type == 'periodic': props['dataport.publisher.push_policy'] = 'all' if tag.attributes.get("push_rate") != None: props['dataport.push_rate'] = str(tag.attributes.get("push_rate").value) else: props['dataport.push_rate'] = str('50.0') options = optparse.Values({'verbose': False, 'id': '', 'name': None, 'properties': props}) print >>sys.stderr, "[rtmlaunch] Connected from",source_path print >>sys.stderr, "[rtmlaunch] to",dest_path print >>sys.stderr, "[rtmlaunch] with",options try : rtcon.connect_ports(source_path, source_full_path, dest_path, dest_full_path, options, tree=tree) except Exception, e_1_1_0: # openrtm 1.1.0 try: rtcon.connect_ports([(source_path,source_full_path), (dest_path, dest_full_path)], options, tree=tree) except Exception, e_1_0_0: # openrtm 1.0.0 print >>sys.stderr, '\033[31m[rtmlaunch] {0} did not work on both OpenRTM 1.0.0 and 1.1.0'.format(os.path.basename(sys.argv[1])),'\033[0m' print >>sys.stderr, '\033[31m[rtmlaunch] OpenRTM 1.0.0 {0}'.format(e_1_0_0),'\033[0m' print >>sys.stderr, '\033[31m[rtmlaunch] OpenRTM 1.1.0 {0}'.format(e_1_1_0),'\033[0m' print >>sys.stderr, '\033[31m[rtmlaunch] This is very weird situation, Please check your network\033[0m' print >>sys.stderr, '\033[31m[rtmlaunch] configuration with `ifconfig` on both robot and client side. \033[0m' print >>sys.stderr, '\033[31m[rtmlaunch] Having multiple network interface sometimes causes problem, \033[0m' print >>sys.stderr, '\033[31m[rtmlaunch] please see FAQ site http://www.openrtm.org/OpenRTM-aist/html/FAQ2FE38388E383A9E38396E383ABE382B7E383A5E383BCE38386E382A3E383B3E382B0.html#f2bc375d\033[0m' print >>sys.stderr, '\033[31m[rtmlaunch] Issue related to this https://github.com/start-jsk/rtmros_hironx/issues/33\033[0m' print >>sys.stderr, '\033[31m[rtmlaunch] ~/.ros/log may contains usefully informations\033[0m'
def rtconnect(nameserver, tags): import re for tag in tags: # check if/unless attribute in rtconnect tags exec_flag = True if tag.attributes.get(u'if'): val = tag.attributes.get(u'if').value arg = val.split(" ")[1].strip(")") # To "USE_WALKING" exec_flag = get_flag_from_argv(arg) if tag.attributes.get(u'unless'): val = tag.attributes.get(u'unless').value arg = val.split(" ")[1].strip(")") # To "USE_WALKING" exec_flag = not get_flag_from_argv(arg) if not exec_flag: continue source_path = nameserver+"/"+tag.attributes.get("from").value dest_path = nameserver+"/"+tag.attributes.get("to").value source_path = re.sub("\$\(arg SIMULATOR_NAME\)",simulator,source_path); dest_path = re.sub("\$\(arg SIMULATOR_NAME\)",simulator,dest_path); # print >>sys.stderr, "[rtmlaunch] Connecting from %s to %s"%(source_path,dest_path) source_full_path = path.cmd_path_to_full_path(source_path) dest_full_path = path.cmd_path_to_full_path(dest_path) if tag.attributes.get("subscription_type") != None: sub_type = tag.attributes.get("subscription_type").value if not sub_type in ['flush','new','periodic']: print >>sys.stderr, sub_type+' is not a subscription type' continue else: sub_type = 'flush' # this is default value if sub_type == 'new': push_policy = 'all' # wait for proess try: wait_component(source_full_path) wait_component(dest_full_path) if check_connect(source_full_path,dest_full_path): continue except Exception, e: print >>sys.stderr, '\033[31m[rtmlaunch] [ERROR] Could not Connect (', source_full_path, ',', dest_full_path, '): ', e,'\033[0m' return 1 #print source_path, source_full_path, dest_path, dest_full_path; try: sub_type = str(sub_type) props = {'dataport.subscription_type': sub_type} if sub_type == 'new': props['dataport.publisher.push_policy'] = 'all' elif sub_type == 'periodic': props['dataport.publisher.push_policy'] = 'all' if tag.attributes.get("push_rate") != None: props['dataport.push_rate'] = str(tag.attributes.get("push_rate").value) else: props['dataport.push_rate'] = str('50.0') options = optparse.Values({'verbose': False, 'id': '', 'name': None, 'properties': props}) print >>sys.stderr, "[rtmlaunch] Connected from",source_path print >>sys.stderr, "[rtmlaunch] to",dest_path print >>sys.stderr, "[rtmlaunch] with",options try : rtcon.connect_ports(source_path, source_full_path, dest_path, dest_full_path, options, tree=None) except Exception, e: # openrtm 1.1.0 rtcon.connect_ports([(source_path,source_full_path), (dest_path, dest_full_path)], options, tree=None) except Exception, e: print >>sys.stderr, '\033[31m[rtmlaunch] {0}: {1}'.format(os.path.basename(sys.argv[1]), e),'\033[0m'