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@3:dff241b66f84, 2011-11-12 (annotated)
- Committer:
- nucho
- Date:
- Sat Nov 12 23:53:04 2011 +0000
- Revision:
- 3:dff241b66f84
- Parent:
- 1:098e75fd5ad2
This program supported the revision of 167 of rosserial.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nucho | 1:098e75fd5ad2 | 1 | /* |
nucho | 1:098e75fd5ad2 | 2 | * Software License Agreement (BSD License) |
nucho | 1:098e75fd5ad2 | 3 | * |
nucho | 1:098e75fd5ad2 | 4 | * Copyright (c) 2011, Willow Garage, Inc. |
nucho | 1:098e75fd5ad2 | 5 | * All rights reserved. |
nucho | 1:098e75fd5ad2 | 6 | * |
nucho | 1:098e75fd5ad2 | 7 | * Redistribution and use in source and binary forms, with or without |
nucho | 1:098e75fd5ad2 | 8 | * modification, are permitted provided that the following conditions |
nucho | 1:098e75fd5ad2 | 9 | * are met: |
nucho | 0:06fc856e99ca | 10 | * |
nucho | 1:098e75fd5ad2 | 11 | * * Redistributions of source code must retain the above copyright |
nucho | 1:098e75fd5ad2 | 12 | * notice, this list of conditions and the following disclaimer. |
nucho | 1:098e75fd5ad2 | 13 | * * Redistributions in binary form must reproduce the above |
nucho | 1:098e75fd5ad2 | 14 | * copyright notice, this list of conditions and the following |
nucho | 1:098e75fd5ad2 | 15 | * disclaimer in the documentation and/or other materials provided |
nucho | 1:098e75fd5ad2 | 16 | * with the distribution. |
nucho | 1:098e75fd5ad2 | 17 | * * Neither the name of Willow Garage, Inc. nor the names of its |
nucho | 1:098e75fd5ad2 | 18 | * contributors may be used to endorse or promote prducts derived |
nucho | 1:098e75fd5ad2 | 19 | * from this software without specific prior written permission. |
nucho | 1:098e75fd5ad2 | 20 | * |
nucho | 1:098e75fd5ad2 | 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
nucho | 1:098e75fd5ad2 | 22 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
nucho | 1:098e75fd5ad2 | 23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
nucho | 1:098e75fd5ad2 | 24 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
nucho | 1:098e75fd5ad2 | 25 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
nucho | 1:098e75fd5ad2 | 26 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
nucho | 1:098e75fd5ad2 | 27 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
nucho | 1:098e75fd5ad2 | 28 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
nucho | 1:098e75fd5ad2 | 29 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
nucho | 1:098e75fd5ad2 | 30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
nucho | 1:098e75fd5ad2 | 31 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
nucho | 1:098e75fd5ad2 | 32 | * POSSIBILITY OF SUCH DAMAGE. |
nucho | 0:06fc856e99ca | 33 | */ |
nucho | 0:06fc856e99ca | 34 | |
nucho | 1:098e75fd5ad2 | 35 | #ifndef ROS_SUBSCRIBER_H_ |
nucho | 1:098e75fd5ad2 | 36 | #define ROS_SUBSCRIBER_H_ |
nucho | 0:06fc856e99ca | 37 | |
nucho | 3:dff241b66f84 | 38 | #include "rosserial_msgs/TopicInfo.h" |
nucho | 1:098e75fd5ad2 | 39 | |
nucho | 1:098e75fd5ad2 | 40 | namespace ros { |
nucho | 0:06fc856e99ca | 41 | |
nucho | 3:dff241b66f84 | 42 | /* Base class for objects subscribers. */ |
nucho | 3:dff241b66f84 | 43 | class Subscriber_ |
nucho | 3:dff241b66f84 | 44 | { |
nucho | 3:dff241b66f84 | 45 | public: |
nucho | 3:dff241b66f84 | 46 | virtual void callback(unsigned char *data)=0; |
nucho | 3:dff241b66f84 | 47 | virtual int getEndpointType()=0; |
nucho | 3:dff241b66f84 | 48 | |
nucho | 3:dff241b66f84 | 49 | // id_ is set by NodeHandle when we advertise |
nucho | 3:dff241b66f84 | 50 | int16_t id_; |
nucho | 3:dff241b66f84 | 51 | |
nucho | 3:dff241b66f84 | 52 | virtual const char * getMsgType()=0; |
nucho | 3:dff241b66f84 | 53 | virtual const char * getMsgMD5()=0; |
nucho | 3:dff241b66f84 | 54 | const char * topic_; |
nucho | 3:dff241b66f84 | 55 | }; |
nucho | 3:dff241b66f84 | 56 | |
nucho | 3:dff241b66f84 | 57 | |
nucho | 3:dff241b66f84 | 58 | /* Actual subscriber, templated on message type. */ |
nucho | 1:098e75fd5ad2 | 59 | template<typename MsgT> |
nucho | 3:dff241b66f84 | 60 | class Subscriber: public Subscriber_{ |
nucho | 1:098e75fd5ad2 | 61 | public: |
nucho | 0:06fc856e99ca | 62 | typedef void(*CallbackT)(const MsgT&); |
nucho | 1:098e75fd5ad2 | 63 | MsgT msg; |
nucho | 0:06fc856e99ca | 64 | |
nucho | 3:dff241b66f84 | 65 | Subscriber(const char * topic_name, CallbackT cb, int endpoint=rosserial_msgs::TopicInfo::ID_SUBSCRIBER) : |
nucho | 3:dff241b66f84 | 66 | cb_(cb), |
nucho | 3:dff241b66f84 | 67 | endpoint_(endpoint) |
nucho | 3:dff241b66f84 | 68 | { |
nucho | 1:098e75fd5ad2 | 69 | topic_ = topic_name; |
nucho | 3:dff241b66f84 | 70 | }; |
nucho | 1:098e75fd5ad2 | 71 | |
nucho | 3:dff241b66f84 | 72 | virtual void callback(unsigned char* data){ |
nucho | 1:098e75fd5ad2 | 73 | msg.deserialize(data); |
nucho | 1:098e75fd5ad2 | 74 | this->cb_(msg); |
nucho | 0:06fc856e99ca | 75 | } |
nucho | 1:098e75fd5ad2 | 76 | |
nucho | 3:dff241b66f84 | 77 | virtual const char * getMsgType(){ return this->msg.getType(); } |
nucho | 3:dff241b66f84 | 78 | virtual const char * getMsgMD5(){ return this->msg.getMD5(); } |
nucho | 3:dff241b66f84 | 79 | virtual int getEndpointType(){ return endpoint_; } |
nucho | 1:098e75fd5ad2 | 80 | |
nucho | 1:098e75fd5ad2 | 81 | private: |
nucho | 1:098e75fd5ad2 | 82 | CallbackT cb_; |
nucho | 3:dff241b66f84 | 83 | int endpoint_; |
nucho | 1:098e75fd5ad2 | 84 | }; |
nucho | 0:06fc856e99ca | 85 | |
nucho | 0:06fc856e99ca | 86 | } |
nucho | 1:098e75fd5ad2 | 87 | |
nucho | 1:098e75fd5ad2 | 88 | #endif |