Go to the documentation of this file.
29 #ifndef UBLOX_GPS_CALLBACK_H
30 #define UBLOX_GPS_CALLBACK_H
33 #include <ublox/serialization/ublox_msgs.h>
34 #include <boost/format.hpp>
35 #include <boost/function.hpp>
36 #include <boost/thread.hpp>
53 bool wait(
const boost::posix_time::time_duration& timeout) {
54 boost::mutex::scoped_lock lock(
mutex_);
70 typedef boost::function<void(
const T&)>
Callback;
88 boost::mutex::scoped_lock lock(
mutex_);
92 "U-Blox Decoder error for 0x%02x / 0x%02x (%d bytes)",
93 static_cast<unsigned int>(reader.
classId()),
94 static_cast<unsigned int>(reader.
messageId()),
99 }
catch (std::runtime_error& e) {
101 "U-Blox Decoder error for 0x%02x / 0x%02x (%d bytes)",
102 static_cast<unsigned int>(reader.
classId()),
103 static_cast<unsigned int>(reader.
messageId()),
128 template <
typename T>
133 std::make_pair(std::make_pair(T::CLASS_ID, T::MESSAGE_ID),
145 template <
typename T>
148 unsigned int message_id) {
152 std::make_pair(std::make_pair(T::CLASS_ID, message_id),
172 Callbacks::key_type key =
174 for (Callbacks::iterator callback =
callbacks_.lower_bound(key);
175 callback !=
callbacks_.upper_bound(key); ++callback)
176 callback->second->handle(reader);
189 size_t nmea_start = buffer.find(
'$', 0);
190 size_t nmea_end = buffer.find(
'\n', nmea_start);
191 while(nmea_start != std::string::npos && nmea_end != std::string::npos) {
192 std::string sentence = buffer.substr(nmea_start, nmea_end - nmea_start + 1);
195 nmea_start = buffer.find(
'$', nmea_end+1);
196 nmea_end = buffer.find(
'\n', nmea_start);
205 template <
typename T>
206 bool read(T& message,
const boost::posix_time::time_duration& timeout) {
211 Callbacks::iterator callback =
callbacks_.insert(
212 (std::make_pair(std::make_pair(T::CLASS_ID, T::MESSAGE_ID),
217 if (handler->
wait(timeout)) {
218 message = handler->
get();
241 std::ostringstream oss;
243 it != reader.
pos() + reader.
length() + 8; ++it)
244 oss << boost::format(
"%02x") %
static_cast<unsigned int>(*it) <<
" ";
259 typedef std::multimap<std::pair<uint8_t, uint8_t>,
272 #endif // UBLOX_GPS_CALLBACK_H
CallbackHandler_(const Callback &func=Callback())
Initialize the Callback Handler with a callback function.
Callback handlers for incoming u-blox messages.
virtual const T & get()
Get the last received message.
T message_
The last received message.
void handle(ublox::Reader &reader)
Calls the callback handler for the message in the reader.
void handle(ublox::Reader &reader)
Decode the U-Blox message & call the callback function if it exists.
bool wait(const boost::posix_time::time_duration &timeout)
Wait for on the condition.
Callback func_
the callback function to handle the message
boost::mutex mutex_
Lock for the handler.
#define ROS_DEBUG_COND(cond,...)
boost::function< void(const T &)> Callback
A callback function.
bool read(T &message, const boost::posix_time::time_duration &timeout)
Read a u-blox message of the given type.
std::multimap< std::pair< uint8_t, uint8_t >, boost::shared_ptr< CallbackHandler > > Callbacks
void insert(typename CallbackHandler_< T >::Callback callback)
A callback handler for a u-blox message.
void handle_nmea(ublox::Reader &reader)
Calls the callback handler for the nmea messages in the reader.
boost::function< void(const std::string &)> callback_nmea_
Callback handler for nmea messages.
bool read(typename boost::call_traits< T >::reference message, bool search=false)
void set_nmea_callback(boost::function< void(const std::string &)> callback)
Add a callback handler for nmea messages.
boost::mutex callback_mutex_
const std::string & getUnusedData() const
virtual void handle(ublox::Reader &reader)=0
Decode the u-blox message.
boost::condition_variable condition_
Condition for the handler lock.
void insert(typename CallbackHandler_< T >::Callback callback, unsigned int message_id)
void readCallback(unsigned char *data, std::size_t &size)
Processes u-blox messages in the given buffer & clears the read messages from the buffer.
const typedef uint8_t * iterator
int debug
Used to determine which debug messages to display.
ublox_gps
Author(s): Johannes Meyer
autogenerated on Wed Dec 7 2022 03:47:53