34 __author__ =
"astambler@willowgarage.com (Adam Stambler)" 39 from rosserial_python
import SerialClient
60 self.
lock = threading.Lock()
67 while( ( len(self.
rxdata) < size )
and (
not rospy.is_shutdown()) ):
82 print "Sending ", [d
for d
in data]
83 self.xbee.send(
'tx', frame_id=
'0', options=
"\x01", dest_addr=self.
id,data=data)
96 if __name__==
'__main__':
97 print "RosSerial Xbee Network" 98 rospy.init_node(
'xbee_network')
99 sys.argv= rospy.myargv(argv=sys.argv)
104 if len(sys.argv) <3 :
106 This program connects to rosserial xbee nodes. The program must be called 109 ./xbee_network.py <xbee_serial_port> ID1 [ ID2 ID3 ....] 113 xbee_port = sys.argv[1]
114 network_ids = [ struct.pack(
'>h', int(id) )
for id
in sys.argv[2:] ]
116 print "Contacting Xbees : " , network_ids
120 ser = serial.Serial(xbee_port, 57600, timeout=0.01)
126 xbee = XBee(ser, escaped=
True)
128 for xid
in network_ids:
131 clients[xid] = SerialClient(client_ports[xid])
133 threads = [ threading.Thread(target=c.run)
for c
in clients.values()]
139 while not rospy.is_shutdown():
141 msg = xbee.wait_read_frame()
143 print "Received " , msg
145 if msg[
'id'] ==
'rx':
146 src = msg[
'source_addr']
147 data = msg[
'rf_data']
149 client_ports[src].putData(data)
150 except KeyError
as e:
151 print "Rcv ID corrupted" 152 except KeyboardInterrupt:
156 print "Quiting the Sensor Network"
def __init__(self, id, xbee)