21 pub = {
"op":
"publish",
"topic": topic,
"msg": obj}
24 def subscribe(self, topic, callback, throttle_rate=-1):
26 sub = {
"op":
"subscribe",
"topic": topic}
28 sub[
'throttle_rate'] = throttle_rate
33 keys_for_deletion = []
34 for key, values
in self.
callbacks.iteritems():
40 keys_for_deletion.append(key)
42 for key
in keys_for_deletion:
47 unsub = {
"op":
"unsubscribe",
"topic": topic}
52 call = {
"op":
"call_service",
"id": id,
"service": serviceName}
66 while self.
resp ==
None:
83 return ''.join(random.SystemRandom().choice(string.ascii_letters + string.digits)
for _
in range(chars))
105 obj = json.loads(message)
108 if obj.has_key(
'op'):
110 if option ==
"publish":
118 print "exception on callback", callback,
"from", topic
119 traceback.print_exc()
121 elif option ==
"service_response":
122 if obj.has_key(
"id"):
124 values = obj[
"values"]
130 print "exception on callback ID:", id
131 traceback.print_exc()
136 print "Recieved unknown option - it was: ", option
140 print "exception in onMessageReceived" 141 print "message", message
142 traceback.print_exc()
148 self.
ws = websocket.WebSocketApp(
158 print "### ROS bridge connected ###" 163 print "Error: not connected, could not send message" 166 self.
ws.send(message)
170 print "Error: %s" % error
174 print "### ROS bridge closed ###" 177 self.
ws.run_forever()
def unhook(self, callback)
def onMessageReceived(self, message)
def addServiceCallback(self, id, callback)
def subscribe(self, topic, callback, throttle_rate=-1)
def registerCallback(self, callback)
def addCallback(self, topic, callback)
def on_message(self, ws, message)
def sendString(self, message)
def generate_id(self, chars=16)
def __init__(self, host, port)
def unsubscribe(self, topic)
def __init__(self, host, port)
def publish(self, topic, obj)
def on_error(self, ws, error)
def callService(self, serviceName, callback=None, msg=None)