59 #ifndef CALLBACK_HANDLERS_HPP 60 #define CALLBACK_HANDLERS_HPP 63 #define MIN_NMEA_SIZE 9 // Minimum size of an NMEA message in bytes (e.g. proprietary "$PSSN,HRP") 67 #define MAX_NMEA_SIZE 89 // Maximum size of an NMEA message in bytes 71 #include <boost/foreach.hpp> 73 #include <boost/function.hpp> 78 #include <boost/thread.hpp> 82 #include <boost/thread/condition.hpp> 83 #include <boost/tokenizer.hpp> 86 #include <boost/algorithm/string/join.hpp> 88 #include <boost/date_time/posix_time/posix_time.hpp> 91 #include <boost/asio.hpp> 93 #include <boost/bind.hpp> 94 #include <boost/format.hpp> 95 #include <boost/asio/serial_port.hpp> 96 #include <boost/thread/mutex.hpp> 148 virtual void handle(
RxMessage& rx_message, std::string message_key) = 0;
150 bool Wait(
const boost::posix_time::time_duration& timeout)
152 boost::mutex::scoped_lock lock(
mutex_);
165 template <
typename T>
170 virtual const T&
Get() {
return message_; }
174 boost::mutex::scoped_lock lock(
mutex_);
177 if (!rx_message.
read<T>(message_, message_key))
179 std::ostringstream ss;
180 ss <<
"Read unsuccessful: Rx decoder error for message with ID (empty field if non-determinable)" <<
181 rx_message.
messageID() <<
". Reason unknown.";
182 throw std::runtime_error(ss.str());
183 ROS_INFO(
"%s", ss.str().c_str());
186 }
catch (std::runtime_error& e)
188 std::ostringstream ss;
189 ss <<
"Read unsuccessful: Rx decoder error for message with ID " <<
190 rx_message.
messageID() <<
".\n" << e.what();
191 throw std::runtime_error(ss.str());
192 ROS_INFO(
"%s", ss.str().c_str());
213 typedef std::multimap<std::string, boost::shared_ptr<AbstractCallbackHandler>>
CallbackMap;
227 template <
typename T>
228 CallbackMap
insert(std::string message_key)
230 boost::mutex::scoped_lock lock(callback_mutex_);
233 callbackmap_.insert(std::make_pair(message_key, boost::shared_ptr<AbstractCallbackHandler>(handler)));
234 CallbackMap::key_type key = message_key;
235 ROS_DEBUG(
"Key %s successfully inserted into multimap: %s", message_key.c_str(),
236 ((
unsigned int) callbackmap_.count(key)) ?
"true" :
"false");
251 void readCallback(
const uint8_t* data, std::size_t& size);
std::map< std::string, uint32_t > GPSFixMap
Shorthand for the map responsible for matching ROS message identifiers relevant for GPSFix to a uint3...
bool g_poscovgeodetic_has_arrived_navsatfix
For NavSatFix: Whether the PosCovGeodetic block of the current epoch has arrived or not...
bool g_publish_navsatfix
Whether or not to publish the sensor_msgs::NavSatFix message.
std::map< std::string, uint32_t > PoseWithCovarianceStampedMap
bool g_publish_gpst
Whether or not to publish the sensor_msgs::TimeReference message with GPST.
bool g_poscovgeodetic_has_arrived_gpsfix
For GPSFix: Whether the PosCovGeodetic block of the current epoch has arrived or not.
bool g_poscovgeodetic_has_arrived_pose
For PoseWithCovarianceStamped: Whether the PosCovGeodetic block of the current epoch has arrived or n...
static DiagnosticArrayMap diagnosticarray_map
std::map< std::string, uint32_t > DiagnosticArrayMap
bool g_channelstatus_has_arrived_gpsfix
For GPSFix: Whether the ChannelStatus block of the current epoch has arrived or not.
boost::condition_variable condition_
CallbackMap insert(std::string message_key)
Adds a pair to the multimap "callbackmap_", with the message_key being the key.
static GPSFixMap gpsfix_map
bool Wait(const boost::posix_time::time_duration &timeout)
bool g_dop_has_arrived_gpsfix
For GPSFix: Whether the DOP block of the current epoch has arrived or not.
std::multimap< std::string, boost::shared_ptr< AbstractCallbackHandler > > CallbackMap
Key is std::string and represents the ROS message key, value is boost::shared_ptr<CallbackHandler> ...
boost::mutex g_response_mutex
Mutex to control changes of global variable "g_response_received".
Abstract class representing a generic callback handler, includes high-level functionality such as wai...
bool g_qualityind_has_arrived_diagnostics
For DiagnosticArray: Whether the QualityInd block of the current epoch has arrived or not...
Defines a class that reads messages handed over from the circular buffer.
Can search buffer for messages, read/parse them, and so on.
bool g_atteuler_has_arrived_gpsfix
For GPSFix: Whether the AttEuler block of the current epoch has arrived or not.
Represents ensemble of (to be constructed) ROS messages, to be handled at once by this class...
bool g_atteuler_has_arrived_pose
For PoseWithCovarianceStamped: Whether the AttEuler block of the current epoch has arrived or not...
static std::string do_pose_
bool g_response_received
Determines whether a command reply was received from the Rx.
uint32_t g_cd_count
Since after SSSSSSSSSSS we need to wait for second connection descriptor, we have to count the connec...
virtual void handle(RxMessage &rx_message, std::string message_key)=0
static std::string do_navsatfix_
boost::mutex g_cd_mutex
Mutex to control changes of global variable "g_cd_received".
void handle(RxMessage &rx_message, std::string message_key)
bool g_publish_pose
Whether or not to publish the geometry_msgs::PoseWithCovarianceStamped message.
std::string g_rx_tcp_port
Rx TCP port, e.g. IP10 or IP11, to which ROSaic is connected to.
bool g_pvtgeodetic_has_arrived_pose
For PoseWithCovarianceStamped: Whether the PVTGeodetic block of the current epoch has arrived or not...
bool g_cd_received
Determines whether the connection descriptor was received from the Rx.
bool g_attcoveuler_has_arrived_pose
For PoseWithCovarianceStamped: Whether the AttCovEuler block of the current epoch has arrived or not...
std::map< std::string, uint32_t > NavSatFixMap
Shorthand for the map responsible for matching ROS message identifiers relevant for NavSatFix to a ui...
static NavSatFixMap navsatfix_map
boost::condition_variable g_cd_condition
Condition variable complementing "g_cd_mutex".
bool g_receiverstatus_has_arrived_diagnostics
For DiagnosticArray: Whether the ReceiverStatus block of the current epoch has arrived or not...
boost::condition_variable g_response_condition
Condition variable complementing "g_response_mutex".
bool g_measepoch_has_arrived_gpsfix
For GPSFix: Whether the MeasEpoch block of the current epoch has arrived or not.
static boost::mutex callback_mutex_
bool g_publish_gpsfix
Whether or not to publish the gps_common::GPSFix message.
bool g_pvtgeodetic_has_arrived_gpsfix
For GPSFix: Whether the PVTGeodetic block of the current epoch has arrived or not.
bool read(typename boost::call_traits< T >::reference message, std::string message_key, bool search=false)
Performs the CRC check (if SBF) and populates ROS message "message" with the necessary content...
bool g_attcoveuler_has_arrived_gpsfix
For GPSFix: Whether the AttCovEuler block of the current epoch has arrived or not.
bool g_publish_diagnostics
Whether or not to publish the diagnostic_msgs::DiagnosticArray message.
static std::string do_gpsfix_
bool g_pvtgeodetic_has_arrived_navsatfix
For NavSatFix: Whether the PVTGeodetic block of the current epoch has arrived or not.
static PoseWithCovarianceStampedMap pose_map
static std::string do_diagnostics_
bool g_velcovgeodetic_has_arrived_gpsfix
For GPSFix: Whether the VelCovGeodetic block of the current epoch has arrived or not.