![](/media/cache/profiles/94aef38441efa3380a3bed3faf1f9d5d.50x50_q85.jpg)
This program is porting rosserial_arduino for mbed http://www.ros.org/wiki/rosserial_arduino This program supported the revision of 169 of rosserial. This program contains an example.
Dependencies: rosserial_mbed_lib mbed Servo
Diff: ros/subscriber.h
- Revision:
- 3:dff241b66f84
- Parent:
- 1:098e75fd5ad2
--- a/ros/subscriber.h Sun Oct 16 09:33:53 2011 +0000 +++ b/ros/subscriber.h Sat Nov 12 23:53:04 2011 +0000 @@ -35,37 +35,52 @@ #ifndef ROS_SUBSCRIBER_H_ #define ROS_SUBSCRIBER_H_ -#include "rosserial_ids.h" -#include "msg_receiver.h" +#include "rosserial_msgs/TopicInfo.h" namespace ros { - /* ROS Subscriber - * This class handles holding the msg so that - * it is not continously reallocated. It is also used by the - * node handle to keep track of callback functions and IDs. - */ + /* Base class for objects subscribers. */ + class Subscriber_ + { + public: + virtual void callback(unsigned char *data)=0; + virtual int getEndpointType()=0; + + // id_ is set by NodeHandle when we advertise + int16_t id_; + + virtual const char * getMsgType()=0; + virtual const char * getMsgMD5()=0; + const char * topic_; + }; + + + /* Actual subscriber, templated on message type. */ template<typename MsgT> - class Subscriber: public MsgReceiver{ + class Subscriber: public Subscriber_{ public: typedef void(*CallbackT)(const MsgT&); MsgT msg; - Subscriber(const char * topic_name, CallbackT msgCB){ + Subscriber(const char * topic_name, CallbackT cb, int endpoint=rosserial_msgs::TopicInfo::ID_SUBSCRIBER) : + cb_(cb), + endpoint_(endpoint) + { topic_ = topic_name; - cb_= msgCB; - } + }; - virtual void receive(unsigned char* data){ + virtual void callback(unsigned char* data){ msg.deserialize(data); this->cb_(msg); } - virtual const char * getMsgType(){return this->msg.getType();} - virtual int _getType(){return TOPIC_SUBSCRIBERS;} + virtual const char * getMsgType(){ return this->msg.getType(); } + virtual const char * getMsgMD5(){ return this->msg.getMD5(); } + virtual int getEndpointType(){ return endpoint_; } private: CallbackT cb_; + int endpoint_; }; }