Ejemplo n.º 1
0
 def publish(self, msg_data):
     #rospy.loginfo('json_wrapper publish ' + str(msg_data['topic_name']))
     (msg, msg_cls) = self.decode_json_message(msg_data['msg_path'],
                                               msg_data)
     publisher = get_publisher(msg_data['topic_name'], msg_cls)
     publisher.publish(msg)
     return JSONWrapperResponse()
Ejemplo n.º 2
0
 def unsubscribe(self, msg_data):
     try:
         topic_name = msg_data['topic_name']
         subscriber = self.ros_subscriber[topic_name]
         subscriber.unregister()
         del self.ros_subscriber[topic_name]
     except:
         pass
     return JSONWrapperResponse()
Ejemplo n.º 3
0
 def service(self, request_data):
     # TODO: also include a status field in response
     srv_module = self.get_service_module(request_data['service_path'])
     module_name = request_data['service_path'].split('/')[-1]
     srv_cls = getattr(srv_module, module_name)
     req_cls = getattr(srv_module, module_name + 'Request')
     res_cls = getattr(srv_module, module_name + 'Response')
     # instantiate the message
     request = req_cls()
     self.assign_slots(request, request_data)
     # get a service handle
     srv = self.get_service(request_data['service_name'], srv_cls)
     # send it
     response = JSONWrapperResponse()
     try:
         srv_response = srv(request)
         response.json_data = self.read_slots(res_cls, srv_response)
     except:
         response.json_data = ''
     # return the json encoded response
     return response
Ejemplo n.º 4
0
 def publish(self, msg_data):
     (msg, msg_cls) = self.decode_json_message(msg_data['msg_path'],
                                               msg_data)
     publisher = self.get_publisher(msg_data['topic_name'], msg_cls)
     publisher.publish(msg)
     return JSONWrapperResponse()
Ejemplo n.º 5
0
 def subscribe(self, msg_data):
     # TODO: won't work at the moment when there are
     #       subscribers of the same topic
     msg_cls = self.get_msg_class(msg_data['msg_path'])
     self.get_subscriber(msg_data['topic_name'], msg_cls)
     return JSONWrapperResponse()
Ejemplo n.º 6
0
 def action(self, request_data):
     #rospy.loginfo('json_wrapper action')
     # TODO implement
     return JSONWrapperResponse()