Package master_discovery_fkie
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 __author__ = "Alexander Tiderko (Alexander.Tiderko@fkie.fraunhofer.de)"
36 __copyright__ = "Copyright (c) 2012 Alexander Tiderko, Fraunhofer FKIE"
37 __license__ = "BSD"
38 __version__ = "0.2"
39 __date__ = "2012-02-01"
40
41 import sys
42
43 import roslib; roslib.load_manifest('master_discovery_fkie')
44 import rospy
45
46 from master_monitor import MasterMonitor
47
48 MCAST_GROUP = "226.0.0.0"
49 MCAST_PORT = 11511
50
52 try:
53 masteruri = MasterMonitor._masteruri_from_ros()
54 rospy.loginfo("ROS Master URI: %s", masteruri)
55 from urlparse import urlparse
56 return urlparse(masteruri).port+(600 if zeroconf else 300)
57 except:
58 import traceback
59 print traceback.format_exc()
60 return 11911 if zeroconf else 11611
61
63 '''
64 Change the terminal name.
65 @param name: New name of the terminal
66 @type name: str
67 '''
68 sys.stdout.write("".join(["\x1b]2;",name,"\x07"]))
69
71 '''
72 Change the process name.
73 @param name: New process name
74 @type name: str
75 '''
76 try:
77 from ctypes import cdll, byref, create_string_buffer
78 libc = cdll.LoadLibrary('libc.so.6')
79 buff = create_string_buffer(len(name)+1)
80 buff.value = name
81 libc.prctl(15, byref(buff), 0, 0, 0)
82 except:
83 pass
84
85
87 '''
88 Creates and runs the ROS node using multicast messages for discovering
89 '''
90 import master_discovery
91 rospy.init_node("master_discovery", log_level=rospy.DEBUG)
92 setTerminalName(rospy.get_name())
93 setProcessName(rospy.get_name())
94 mcast_group = rospy.get_param('~mcast_group', MCAST_GROUP)
95 mcast_port = rospy.get_param('~mcast_port', MCAST_PORT)
96 rpc_port = rospy.get_param('~rpc_port', getDefaultRPCPort())
97 try:
98 discoverer = master_discovery.Discoverer(mcast_port, mcast_group, rpc_port)
99 discoverer.start()
100 rospy.spin()
101 except Exception as e:
102 rospy.logerr("Error while start master_discovery: %s", str(e))
103 import os, signal
104 os.kill(os.getpid(), signal.SIGKILL)
105 import time
106 time.sleep(10)
107
109 '''
110 Creates and runs the ROS node using zeroconf/avahi for discovering
111 '''
112 import zeroconf
113 rospy.init_node("zeroconf", log_level=rospy.DEBUG)
114 setTerminalName(rospy.get_name())
115 setProcessName(rospy.get_name())
116 rpc_port = rospy.get_param('~rpc_port', getDefaultRPCPort(True))
117 discoverer = zeroconf.Discoverer(rpc_port)
118 discoverer.start()
119 rospy.spin()
120