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
ros/subscriber.h@0:06fc856e99ca, 2011-08-19 (annotated)
- Committer:
- nucho
- Date:
- Fri Aug 19 09:06:16 2011 +0000
- Revision:
- 0:06fc856e99ca
- Child:
- 1:098e75fd5ad2
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nucho | 0:06fc856e99ca | 1 | /* |
nucho | 0:06fc856e99ca | 2 | * subscriber.h |
nucho | 0:06fc856e99ca | 3 | * |
nucho | 0:06fc856e99ca | 4 | * Created on: Aug 5, 2011 |
nucho | 0:06fc856e99ca | 5 | * Author: astambler |
nucho | 0:06fc856e99ca | 6 | */ |
nucho | 0:06fc856e99ca | 7 | |
nucho | 0:06fc856e99ca | 8 | #ifndef SUBSCRIBER_H_ |
nucho | 0:06fc856e99ca | 9 | #define SUBSCRIBER_H_ |
nucho | 0:06fc856e99ca | 10 | |
nucho | 0:06fc856e99ca | 11 | #include "rosserial_ids.h" |
nucho | 0:06fc856e99ca | 12 | #include "msg_receiver.h" |
nucho | 0:06fc856e99ca | 13 | namespace ros{ |
nucho | 0:06fc856e99ca | 14 | |
nucho | 0:06fc856e99ca | 15 | /* ROS Subscriber |
nucho | 0:06fc856e99ca | 16 | * This class handles holding the msg so that |
nucho | 0:06fc856e99ca | 17 | * it is not continously reallocated. It is also used by the |
nucho | 0:06fc856e99ca | 18 | * node handle to keep track of callback functions and IDs. |
nucho | 0:06fc856e99ca | 19 | */ |
nucho | 0:06fc856e99ca | 20 | template<typename MsgT> |
nucho | 0:06fc856e99ca | 21 | class Subscriber: public MsgReceiver{ |
nucho | 0:06fc856e99ca | 22 | public: |
nucho | 0:06fc856e99ca | 23 | |
nucho | 0:06fc856e99ca | 24 | typedef void(*CallbackT)(const MsgT&); |
nucho | 0:06fc856e99ca | 25 | |
nucho | 0:06fc856e99ca | 26 | Subscriber(const char * topic_name, CallbackT msgCB){ |
nucho | 0:06fc856e99ca | 27 | topic_ = topic_name; |
nucho | 0:06fc856e99ca | 28 | cb_= msgCB; |
nucho | 0:06fc856e99ca | 29 | } |
nucho | 0:06fc856e99ca | 30 | MsgT msg; |
nucho | 0:06fc856e99ca | 31 | virtual void receive(unsigned char* data){ |
nucho | 0:06fc856e99ca | 32 | msg.deserialize(data); |
nucho | 0:06fc856e99ca | 33 | this->cb_(msg); |
nucho | 0:06fc856e99ca | 34 | } |
nucho | 0:06fc856e99ca | 35 | virtual const char * getMsgType(){return this->msg.getType();} |
nucho | 0:06fc856e99ca | 36 | virtual int _getType(){return TOPIC_SUBSCRIBERS;} |
nucho | 0:06fc856e99ca | 37 | private: |
nucho | 0:06fc856e99ca | 38 | CallbackT cb_; |
nucho | 0:06fc856e99ca | 39 | }; |
nucho | 0:06fc856e99ca | 40 | |
nucho | 0:06fc856e99ca | 41 | } |
nucho | 0:06fc856e99ca | 42 | #endif /* SUBSCRIBER_H_ */ |