diff --git a/README.md b/README.md index 25c3420..ef7b9c5 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ sudo apt-get install build-essential cmake libboost-all-dev libprotoc-dev protob This was tested with Ubuntu 12.04.5 LTS (Precise Pangolin) and 14.04.1 LTS (Trusty Tahr). + ## Compiling To compile, use: @@ -41,6 +42,7 @@ lib/libroah_rsbb_msgs.a lib/libprotobuf_comm.a ``` + ## Using roah_rsbb.h This C++ header file provides a small decorator on top of @@ -50,3 +52,12 @@ provide a pooling interface for the last messages of the allowed types received on each channel as well as a specific signal for each one. Be careful with synchronization, the callbacks will be called from different threads. + + +## Using ros_roah_rsbb.h + +The classes `RosPublicChannel` and `RosPrivateChannel` provide +a way to use `PublicChannel` and `PrivateChannel` with error output +done by ROS. Include this file only if your project uses ROS. +If your project uses some other framework, you can use this file +as a base to adapt to your framework. diff --git a/include/ros_roah_rsbb.h b/include/ros_roah_rsbb.h new file mode 100644 index 0000000..a1f6cdf --- /dev/null +++ b/include/ros_roah_rsbb.h @@ -0,0 +1,108 @@ +/* + * Copyright 2014 Instituto de Sistemas e Robotica, Instituto Superior Tecnico + * + * This file is part of RoAH RSBB Comm. + * + * RoAH RSBB Comm is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * RoAH RSBB Comm is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with RoAH RSBB Comm. If not, see . + */ + +#ifndef __ROS_ROAH_RSBB_H__ +#define __ROS_ROAH_RSBB_H__ + +#include + +#include +#include + +#include "roah_rsbb.h" + + + +namespace roah_rsbb +{ + class RosErrorHandler + { + public: + RosErrorHandler (std::string const& name, + protobuf_comm::ProtobufBroadcastPeer& channel) : + name_ (name) + { + channel.signal_recv_error().connect (boost::bind (&RosErrorHandler::recv_error, this, _1, _2)); + channel.signal_send_error().connect (boost::bind (&RosErrorHandler::send_error, this, _1)); + } + + void + unknown_msg (boost::asio::ip::udp::endpoint& endpoint, + uint16_t comp_id, + uint16_t msg_type, + std::shared_ptr msg) + { + ROS_ERROR_STREAM ("On channel " << name_ + << ": Unknown message from " << endpoint.address().to_string() + << ":" << endpoint.port() + << ", COMP_ID " << comp_id + << ", MSG_TYPE " << msg_type + << ", of type " << typeid (*msg).name()); + } + + private: + std::string name_; + + void + recv_error (boost::asio::ip::udp::endpoint& endpoint, + std::string msg) + { + ROS_ERROR_STREAM ("On channel " << name_ + << ": Receive error from " << endpoint.address().to_string() + << ":" << endpoint.port() + << ": " << msg); + } + + void + send_error (std::string msg) + { + ROS_ERROR_STREAM ("On channel " << name_ + << ": Send error: " << msg); + } + }; + + typedef PublicChannel RosPublicChannel; + typedef PrivateChannel RosPrivateChannel; +} + + + +template inline void +param_direct (std::string const& name, + T const& def_value, + T& var) +{ + if (! ros::param::getCached (name, var)) { + var = def_value; + ros::param::set (name, var); + } +} + + + +template inline T +param_direct (std::string const& name, + T const& def_value) +{ + T tmp; + param_direct (name, def_value, tmp); + return tmp; +} + +#endif