Frame and validate incoming RTCM 3 messages.
This class locates and validates RTCM 3 messages within a stream of binary data. Data may be stored in an internally allocated buffer, or in an external buffer supplied by the user.
The callback function provided to SetMessageCallback() will be called each time a complete message is received. Any messages that do not pass the CRC check, or that are too big to be stored in the data buffer, will be discarded.
Example usage:
Definition at line 39 of file rtcm_framer.h.
#include <point_one/rtcm/rtcm_framer.h>
Public Types | |
using | MessageCallback = void(*)(uint16_t, const void *, size_t) |
Public Member Functions | |
RTCMFramer ()=default | |
Construct a framer instance with no buffer allocated. More... | |
RTCMFramer (const RTCMFramer &)=delete | |
RTCMFramer (RTCMFramer &&)=delete | |
RTCMFramer (size_t capacity_bytes) | |
Construct a framer instance with an internally allocated buffer. More... | |
RTCMFramer (void *buffer, size_t capacity_bytes) | |
Construct a framer instance with a user-specified buffer. More... | |
~RTCMFramer () | |
uint32_t | GetNumDecodedMessages () const |
Get the number of decoded messages. More... | |
uint32_t | GetNumErrors () const |
Get the number of preamble synchronizations that resulted in errors. More... | |
size_t | OnData (const uint8_t *buffer, size_t length_bytes) |
Process incoming data. More... | |
RTCMFramer & | operator= (const RTCMFramer &)=delete |
RTCMFramer & | operator= (RTCMFramer &&)=delete |
void | Reset () |
Reset the framer and discard all pending data. More... | |
void | SetBuffer (void *buffer, size_t capacity_bytes) |
Set the buffer to use for message framing. More... | |
void | SetMessageCallback (MessageCallback callback) |
Specify a function to be called when a message is framed. More... | |
void | WarnOnError (bool enabled) |
Enable/disable warnings for CRC and "message too large" failures. More... | |
Private Types | |
enum | State { State::SYNC = 0, State::HEADER = 1, State::DATA = 2 } |
Private Member Functions | |
void | ClearManagedBuffer () |
Free the buffer_ if it's being managed internally. More... | |
int32_t | OnByte (bool quiet) |
Process a single byte. More... | |
uint32_t | Resync () |
Perform a resynchronization operation starting at buffer_[1] . More... | |
Private Attributes | |
uint8_t * | buffer_ {nullptr} |
MessageCallback | callback_ = nullptr |
uint32_t | capacity_bytes_ {0} |
size_t | current_message_size_ {0} |
uint32_t | decoded_msg_count_ {0} |
uint32_t | error_count_ {0} |
bool | is_buffer_managed_ = false |
uint32_t | next_byte_index_ {0} |
State | state_ {State::SYNC} |
bool | warn_on_error_ = true |
using point_one::rtcm::RTCMFramer::MessageCallback = void (*)(uint16_t, const void*, size_t) |
Definition at line 41 of file rtcm_framer.h.
|
strongprivate |
Enumerator | |
---|---|
SYNC | |
HEADER | |
DATA |
Definition at line 147 of file rtcm_framer.h.
|
default |
Construct a framer instance with no buffer allocated.
|
inlineexplicit |
Construct a framer instance with an internally allocated buffer.
capacity_bytes | The maximum framing buffer capacity (in bytes). |
Definition at line 57 of file rtcm_framer.h.
RTCMFramer::RTCMFramer | ( | void * | buffer, |
size_t | capacity_bytes | ||
) |
Construct a framer instance with a user-specified buffer.
buffer
must exist for the lifetime of this instance.buffer | The framing buffer to use. Set to nullptr to allocate a buffer internally. |
capacity_bytes | The maximum framing buffer capacity (in bytes). |
Definition at line 176 of file rtcm_framer.cc.
RTCMFramer::~RTCMFramer | ( | ) |
Definition at line 190 of file rtcm_framer.cc.
|
delete |
|
delete |
|
private |
Free the buffer_ if it's being managed internally.
Definition at line 527 of file rtcm_framer.cc.
|
inline |
Get the number of decoded messages.
Definition at line 133 of file rtcm_framer.h.
|
inline |
Get the number of preamble synchronizations that resulted in errors.
This is not an accurate count of failed messages since the RTCM preamble is not unique and may appear anywhere in the data stream, but gives an approximate count.
Definition at line 144 of file rtcm_framer.h.
|
private |
Process a single byte.
buffer_[next_byte_index_ - 1]
.quiet | If true , suppress failure warning messages. |
Transport header (big endian): Preamble = 8 bits Reserved = 6 bits Message Length = 10 bits
Definition at line 277 of file rtcm_framer.cc.
size_t RTCMFramer::OnData | ( | const uint8_t * | buffer, |
size_t | length_bytes | ||
) |
Process incoming data.
buffer | A buffer containing data to be framed. |
length_bytes | The number of bytes to be framed. |
Definition at line 237 of file rtcm_framer.cc.
|
delete |
|
delete |
void RTCMFramer::Reset | ( | ) |
Reset the framer and discard all pending data.
Definition at line 228 of file rtcm_framer.cc.
|
private |
Perform a resynchronization operation starting at buffer_[1]
.
Definition at line 430 of file rtcm_framer.cc.
void RTCMFramer::SetBuffer | ( | void * | buffer, |
size_t | capacity_bytes | ||
) |
Set the buffer to use for message framing.
buffer
must exist for the lifetime of this instance.buffer | The framing buffer to use. Set to nullptr to allocate a buffer internally. |
capacity_bytes | The maximum framing buffer capacity (in bytes). |
Definition at line 193 of file rtcm_framer.cc.
|
inline |
Specify a function to be called when a message is framed.
callback | The function to be called with the message header and a pointer to the message payload. |
Definition at line 110 of file rtcm_framer.h.
|
inline |
Enable/disable warnings for CRC and "message too large" failures.
This is typically used when the incoming stream has multiple types of binary content (e.g., interleaved FusionEngine and RTCM messages), and the RTCM message preamble is expected to appear in the non-RTCM content occasionally.
enabled | If true , issue warnings on errors. |
Definition at line 102 of file rtcm_framer.h.
|
private |
Definition at line 157 of file rtcm_framer.h.
|
private |
Definition at line 153 of file rtcm_framer.h.
|
private |
Definition at line 158 of file rtcm_framer.h.
|
private |
Definition at line 162 of file rtcm_framer.h.
|
private |
Definition at line 165 of file rtcm_framer.h.
|
private |
Definition at line 164 of file rtcm_framer.h.
|
private |
Definition at line 156 of file rtcm_framer.h.
|
private |
Definition at line 161 of file rtcm_framer.h.
|
private |
Definition at line 160 of file rtcm_framer.h.
|
private |
Definition at line 155 of file rtcm_framer.h.