point_one::rtcm::RTCMFramer Class Reference

Detailed Description

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:

void MessageReceived(uint16_t message_type, const void* data, size_t data_len) {
...
}
RTCMFramer framer(1024);
framer.SetMessageCallback(MessageReceived);
framer.OnData(my_data, my_data_size);

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...
 
RTCMFrameroperator= (const RTCMFramer &)=delete
 
RTCMFrameroperator= (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
 

Member Typedef Documentation

◆ MessageCallback

using point_one::rtcm::RTCMFramer::MessageCallback = void (*)(uint16_t, const void*, size_t)

Definition at line 41 of file rtcm_framer.h.

Member Enumeration Documentation

◆ State

Enumerator
SYNC 
HEADER 
DATA 

Definition at line 147 of file rtcm_framer.h.

Constructor & Destructor Documentation

◆ RTCMFramer() [1/5]

point_one::rtcm::RTCMFramer::RTCMFramer ( )
default

Construct a framer instance with no buffer allocated.

Note
You must call SetBuffer() to assign a buffer, otherwise all incoming data will be discarded.

◆ RTCMFramer() [2/5]

point_one::rtcm::RTCMFramer::RTCMFramer ( size_t  capacity_bytes)
inlineexplicit

Construct a framer instance with an internally allocated buffer.

Parameters
capacity_bytesThe maximum framing buffer capacity (in bytes).

Definition at line 57 of file rtcm_framer.h.

◆ RTCMFramer() [3/5]

RTCMFramer::RTCMFramer ( void *  buffer,
size_t  capacity_bytes 
)

Construct a framer instance with a user-specified buffer.

Postcondition
buffer must exist for the lifetime of this instance.
Parameters
bufferThe framing buffer to use. Set to nullptr to allocate a buffer internally.
capacity_bytesThe maximum framing buffer capacity (in bytes).

Definition at line 176 of file rtcm_framer.cc.

◆ ~RTCMFramer()

RTCMFramer::~RTCMFramer ( )

Definition at line 190 of file rtcm_framer.cc.

◆ RTCMFramer() [4/5]

point_one::rtcm::RTCMFramer::RTCMFramer ( const RTCMFramer )
delete

◆ RTCMFramer() [5/5]

point_one::rtcm::RTCMFramer::RTCMFramer ( RTCMFramer &&  )
delete

Member Function Documentation

◆ ClearManagedBuffer()

void RTCMFramer::ClearManagedBuffer ( )
private

Free the buffer_ if it's being managed internally.

Definition at line 527 of file rtcm_framer.cc.

◆ GetNumDecodedMessages()

uint32_t point_one::rtcm::RTCMFramer::GetNumDecodedMessages ( ) const
inline

Get the number of decoded messages.

Returns
The number of RTCM messages successfully decoded.

Definition at line 133 of file rtcm_framer.h.

◆ GetNumErrors()

uint32_t point_one::rtcm::RTCMFramer::GetNumErrors ( ) const
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.

Returns
The number of length or CRC failures found in decoding so far.

Definition at line 144 of file rtcm_framer.h.

◆ OnByte()

int32_t RTCMFramer::OnByte ( bool  quiet)
private

Process a single byte.

Precondition
The byte must be located at buffer_[next_byte_index_ - 1].
Parameters
quietIf true, suppress failure warning messages.
Returns
The total size of all valid, complete messages, 0 if no messages were completed, or <0 CRC or "message too large" error.

Transport header (big endian): Preamble = 8 bits Reserved = 6 bits Message Length = 10 bits

Definition at line 277 of file rtcm_framer.cc.

◆ OnData()

size_t RTCMFramer::OnData ( const uint8_t *  buffer,
size_t  length_bytes 
)

Process incoming data.

Parameters
bufferA buffer containing data to be framed.
length_bytesThe number of bytes to be framed.
Returns
The total size of all valid, complete messages, or 0 if no messages were completed.

Definition at line 237 of file rtcm_framer.cc.

◆ operator=() [1/2]

RTCMFramer& point_one::rtcm::RTCMFramer::operator= ( const RTCMFramer )
delete

◆ operator=() [2/2]

RTCMFramer& point_one::rtcm::RTCMFramer::operator= ( RTCMFramer &&  )
delete

◆ Reset()

void RTCMFramer::Reset ( )

Reset the framer and discard all pending data.

Definition at line 228 of file rtcm_framer.cc.

◆ Resync()

uint32_t RTCMFramer::Resync ( )
private

Perform a resynchronization operation starting at buffer_[1].

Returns
The total size of all valid, complete messages, or 0 if no messages were completed.

Definition at line 430 of file rtcm_framer.cc.

◆ SetBuffer()

void RTCMFramer::SetBuffer ( void *  buffer,
size_t  capacity_bytes 
)

Set the buffer to use for message framing.

Postcondition
buffer must exist for the lifetime of this instance.
Parameters
bufferThe framing buffer to use. Set to nullptr to allocate a buffer internally.
capacity_bytesThe maximum framing buffer capacity (in bytes).

Definition at line 193 of file rtcm_framer.cc.

◆ SetMessageCallback()

void point_one::rtcm::RTCMFramer::SetMessageCallback ( MessageCallback  callback)
inline

Specify a function to be called when a message is framed.

Parameters
callbackThe function to be called with the message header and a pointer to the message payload.

Definition at line 110 of file rtcm_framer.h.

◆ WarnOnError()

void point_one::rtcm::RTCMFramer::WarnOnError ( bool  enabled)
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.

Parameters
enabledIf true, issue warnings on errors.

Definition at line 102 of file rtcm_framer.h.

Member Data Documentation

◆ buffer_

uint8_t* point_one::rtcm::RTCMFramer::buffer_ {nullptr}
private

Definition at line 157 of file rtcm_framer.h.

◆ callback_

MessageCallback point_one::rtcm::RTCMFramer::callback_ = nullptr
private

Definition at line 153 of file rtcm_framer.h.

◆ capacity_bytes_

uint32_t point_one::rtcm::RTCMFramer::capacity_bytes_ {0}
private

Definition at line 158 of file rtcm_framer.h.

◆ current_message_size_

size_t point_one::rtcm::RTCMFramer::current_message_size_ {0}
private

Definition at line 162 of file rtcm_framer.h.

◆ decoded_msg_count_

uint32_t point_one::rtcm::RTCMFramer::decoded_msg_count_ {0}
private

Definition at line 165 of file rtcm_framer.h.

◆ error_count_

uint32_t point_one::rtcm::RTCMFramer::error_count_ {0}
private

Definition at line 164 of file rtcm_framer.h.

◆ is_buffer_managed_

bool point_one::rtcm::RTCMFramer::is_buffer_managed_ = false
private

Definition at line 156 of file rtcm_framer.h.

◆ next_byte_index_

uint32_t point_one::rtcm::RTCMFramer::next_byte_index_ {0}
private

Definition at line 161 of file rtcm_framer.h.

◆ state_

State point_one::rtcm::RTCMFramer::state_ {State::SYNC}
private

Definition at line 160 of file rtcm_framer.h.

◆ warn_on_error_

bool point_one::rtcm::RTCMFramer::warn_on_error_ = true
private

Definition at line 155 of file rtcm_framer.h.


The documentation for this class was generated from the following files:
RTCMFramer()=default
Construct a framer instance with no buffer allocated.