Go to the documentation of this file.
29 #ifndef UBLOX_SERIALIZATION_H
30 #define UBLOX_SERIALIZATION_H
34 #include <boost/call_traits.hpp>
78 static void read(
const uint8_t *data, uint32_t count,
79 typename boost::call_traits<T>::reference message);
88 typename boost::call_traits<T>::param_type message);
96 static void write(uint8_t *data, uint32_t size,
97 typename boost::call_traits<T>::param_type message);
104 template <
typename T>
113 static bool canDecode(uint8_t class_id, uint8_t message_id) {
115 std::make_pair(class_id, message_id)) !=
keys_.end();
124 static void addKey(uint8_t class_id, uint8_t message_id) {
125 keys_.push_back(std::make_pair(class_id, message_id));
136 static std::vector<std::pair<uint8_t,uint8_t> >
keys_;
203 ROS_ERROR(
"U-Blox message exceeds maximum payload length %u: "
277 if (
count_ < 6)
return 0u;
297 template <
typename T>
298 bool read(
typename boost::call_traits<T>::reference message,
301 if (!
found())
return false;
321 template <
typename T>
323 if (!
found())
return false;
333 if (!
found())
return false;
375 template <
typename T>
bool write(
const T& message,
376 uint8_t class_id = T::CLASS_ID,
377 uint8_t message_id = T::MESSAGE_ID) {
381 ROS_ERROR(
"u-blox write buffer overflow. Message %u / %u not written",
382 class_id, message_id);
388 return write(0, length, class_id, message_id);
400 bool write(
const uint8_t* message, uint32_t length, uint8_t class_id,
401 uint8_t message_id) {
403 ROS_ERROR(
"u-blox write buffer overflow. Message %u / %u not written",
404 class_id, message_id);
413 *
data_++ = message_id;
414 *
data_++ = length & 0xFF;
415 *
data_++ = (length >> 8) & 0xFF;
419 if (message) std::copy(message, message + length,
data_);
450 #define DECLARE_UBLOX_MESSAGE(class_id, message_id, package, message) \
451 template class ublox::Serializer<package::message>; \
452 template class ublox::Message<package::message>; \
453 namespace package { namespace { \
454 static const ublox::Message<message>::StaticKeyInitializer static_key_initializer_##message(class_id, message_id); \
460 #define DECLARE_UBLOX_MESSAGE_ID(class_id, message_id, package, message, name) \
461 namespace package { namespace { \
462 static const ublox::Message<message>::StaticKeyInitializer static_key_initializer_##name(class_id, message_id); \
469 #endif // UBLOX_SERIALIZATION_H
bool write(const uint8_t *message, uint32_t length, uint8_t class_id, uint8_t message_id)
Wrap the encoded message payload with a header and checksum and add it to the buffer.
static uint32_t serializedLength(typename boost::call_traits< T >::param_type message)
Get the length of the message payload in bytes.
Reader(const uint8_t *data, uint32_t count, const Options &options=Options())
Options for the Reader and Writer for encoding and decoding messages.
bool found_
Whether or not a message has been found.
uint32_t length()
Get the length of the u-blox message payload.
uint8_t header_length
The length of the message header in bytes (everything before the payload)
uint8_t sync_a
The sync_a byte value identifying the start of a message.
Writer(uint8_t *data, uint32_t size, const Options &options=Options())
Construct a Writer with the given buffer.
uint8_t checksum_length
The length of the checksum in bytes.
iterator pos()
Get the current position in the read buffer.
Encodes and decodes messages.
static const uint8_t DEFAULT_SYNC_B
u-blox message Sync B char
static std::vector< std::pair< uint8_t, uint8_t > > keys_
static const uint8_t kHeaderLength
Number of bytes in a message header (Sync chars + class ID + message ID)
bool isMessage(uint8_t class_id, uint8_t message_id)
Does the u-blox message have the given class and message ID?
static void calculateChecksum(const uint8_t *data, uint32_t size, uint8_t &ck_a, uint8_t &ck_b)
calculate the checksum of a u-blox_message
uint8_t sync_b
The sync_b byte value identifying the start of a message.
iterator next()
Go to the start of the next message based on the received message length.
static bool canDecode(uint8_t class_id, uint8_t message_id)
Can this message type decode a u-blox message with the given ID?
Options options_
Options representing the sync char values, etc.
static const uint8_t DEFAULT_SYNC_A
u-blox message Sync A char
bool hasType()
Can the given message type decode the current message in the buffer?
static void addKey(uint8_t class_id, uint8_t message_id)
Indicate that this message type can decode u-blox messages with the given ID.
Encodes a u-blox ROS message as a byte array.
iterator search()
Search the buffer for the beginning of the next u-blox message.
Options options_
Options representing the sync char values, etc.
Decodes byte messages into u-blox ROS messages.
bool write(const T &message, uint8_t class_id=T::CLASS_ID, uint8_t message_id=T::MESSAGE_ID)
Encode the u-blox message.
const uint8_t * data_
The buffer of message bytes.
iterator data_
The buffer of message bytes.
static void write(uint8_t *data, uint32_t size, typename boost::call_traits< T >::param_type message)
Encode the message payload as a byte array.
bool found()
Has a u-blox message been found in the buffer?
uint32_t count_
the number of bytes in the buffer, //! decrement as the buffer is read
bool read(typename boost::call_traits< T >::reference message, bool search=false)
Decode the given message.
uint16_t checksum()
Get the checksum of the u-blox message.
static const uint32_t kMaxPayloadLength
Maximum payload length.
uint32_t size_
The number of remaining bytes in the buffer.
const std::string & getUnusedData() const
static const uint8_t kChecksumLength
Number of checksum bytes in the u-blox message.
std::string unused_data_
Unused data from the read buffer, contains nmea messages.
Keeps track of which class and message IDs can be decoded by a given message type.
int wrapper_length()
Get the number of bytes in the header and footer.
uint32_t max_payload_length
The maximum payload length.
const typedef uint8_t * iterator
static void read(const uint8_t *data, uint32_t count, typename boost::call_traits< T >::reference message)
Decode the message payload from the data buffer.
StaticKeyInitializer(uint8_t class_id, uint8_t message_id)