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:
- 0:06fc856e99ca
- Child:
- 1:098e75fd5ad2
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ros/subscriber.h Fri Aug 19 09:06:16 2011 +0000 @@ -0,0 +1,42 @@ +/* + * subscriber.h + * + * Created on: Aug 5, 2011 + * Author: astambler + */ + +#ifndef SUBSCRIBER_H_ +#define SUBSCRIBER_H_ + +#include "rosserial_ids.h" +#include "msg_receiver.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. + */ +template<typename MsgT> +class Subscriber: public MsgReceiver{ + public: + + typedef void(*CallbackT)(const MsgT&); + + Subscriber(const char * topic_name, CallbackT msgCB){ + topic_ = topic_name; + cb_= msgCB; + } + MsgT msg; + virtual void receive(unsigned char* data){ + msg.deserialize(data); + this->cb_(msg); + } + virtual const char * getMsgType(){return this->msg.getType();} + virtual int _getType(){return TOPIC_SUBSCRIBERS;} + private: + CallbackT cb_; +}; + +} +#endif /* SUBSCRIBER_H_ */