Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007 import roslib
00008 roslib.load_manifest('rocon_gateway')
00009 import rospy
00010 import re
00011 from gateway_msgs.msg import Rule, RemoteRule
00012 import utils
00013
00014
00015
00016
00017
00018
00019 def setup_ros_parameters():
00020 '''
00021 Returns the gateway parameters from the ros param server.
00022 Most of these should be fairly self explanatory.
00023 '''
00024 param = {}
00025
00026
00027 param['hub_uri'] = rospy.get_param('~hub_uri', '')
00028 param['hub_whitelist'] = rospy.get_param('~hub_whitelist', [])
00029 param['hub_blacklist'] = rospy.get_param('~hub_blacklist', [])
00030
00031
00032 param['name'] = rospy.get_param('~name', 'gateway')
00033 param['watch_loop_period'] = rospy.get_param('~watch_loop_period', 10)
00034
00035
00036 param['default_blacklist'] = rospy.get_param('~default_blacklist', [])
00037
00038
00039 param['firewall'] = rospy.get_param('~firewall', True)
00040
00041
00042 param['advertise_all'] = rospy.get_param('~advertise_all', [])
00043
00044
00045 param['default_advertisements'] = rospy.get_param('~default_advertisements', [])
00046 param['default_flips'] = rospy.get_param('~default_flips', [])
00047 param['default_pulls'] = rospy.get_param('~default_pulls', [])
00048
00049 return param
00050
00051
00052 def generate_rules(param):
00053 '''
00054 Converts a param of the suitable type (see default_blacklist.yaml)
00055 into a dictionary of Rule types.
00056
00057 @return all rules as gateway_msgs.msg.Rule objects in our usual keyed dictionary format
00058 @rtype type keyed dictionary of Rule lists
00059 '''
00060 rules = utils.createEmptyConnectionTypeDictionary()
00061 for value in param:
00062 rule = Rule()
00063 rule.name = value['name']
00064
00065 pattern = re.compile("None", re.IGNORECASE)
00066 if pattern.match(value['node']):
00067 rule.node = ''
00068 else:
00069 rule.node = value['node']
00070 rule.type = value['type']
00071 rules[rule.type].append(rule)
00072 return rules
00073
00074
00075 def generate_remote_rules(param):
00076 '''
00077 Converts a param of the suitable type (default_flips, default_pulls) into
00078 a list of RemoteRule objects and a list of target gateways for flip_all/pull_all.
00079
00080 @param yaml object
00081 @type complicated
00082
00083 @return list of remote rules
00084 @return RemoteRule[]
00085 '''
00086 remote_rules = []
00087 all_targets = []
00088 pattern = re.compile("None", re.IGNORECASE)
00089 for remote_rule in param:
00090 if 'rule' in remote_rule:
00091
00092 node = None if pattern.match(remote_rule['rule']['node']) else remote_rule['rule']['node']
00093 remote_rules.append(RemoteRule(remote_rule['gateway'],
00094 Rule(remote_rule['rule']['type'],
00095 remote_rule['rule']['name'],
00096 node
00097 )
00098 )
00099 )
00100 else:
00101 all_targets.append(remote_rule['gateway'])
00102 return remote_rules, all_targets