Frame and validate incoming FusionEngine messages.
This class locates and validates FusionEngine 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 43 of file fusion_engine_framer.h.
#include <point_one/fusion_engine/parsers/fusion_engine_framer.h>
Public Types | |
using | MessageCallback = void(*)(const messages::MessageHeader &, const void *) |
Public Member Functions | |
FusionEngineFramer ()=default | |
Construct a framer instance with no buffer allocated. More... | |
FusionEngineFramer (const FusionEngineFramer &)=delete | |
FusionEngineFramer (FusionEngineFramer &&)=delete | |
FusionEngineFramer (size_t capacity_bytes) | |
Construct a framer instance with an internally allocated buffer. More... | |
FusionEngineFramer (void *buffer, size_t capacity_bytes) | |
Construct a framer instance with a user-specified buffer. More... | |
~FusionEngineFramer () | |
size_t | OnData (const uint8_t *buffer, size_t length_bytes) |
Process incoming data. More... | |
FusionEngineFramer & | operator= (const FusionEngineFramer &)=delete |
FusionEngineFramer & | operator= (FusionEngineFramer &&)=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::SYNC0 = 0, State::SYNC1 = 1, State::HEADER = 2, State::DATA = 3 } |
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} |
uint32_t | current_message_size_ {0} |
bool | is_buffer_managed_ = false |
uint32_t | next_byte_index_ {0} |
State | state_ {State::SYNC0} |
bool | warn_on_error_ = true |
using point_one::fusion_engine::parsers::FusionEngineFramer::MessageCallback = void (*)(const messages::MessageHeader&, const void*) |
Definition at line 45 of file fusion_engine_framer.h.
|
strongprivate |
Enumerator | |
---|---|
SYNC0 | |
SYNC1 | |
HEADER | |
DATA |
Definition at line 135 of file fusion_engine_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 61 of file fusion_engine_framer.h.
FusionEngineFramer::FusionEngineFramer | ( | 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 95 of file fusion_engine_framer.cc.
FusionEngineFramer::~FusionEngineFramer | ( | ) |
Definition at line 109 of file fusion_engine_framer.cc.
|
delete |
|
delete |
|
private |
Free the buffer_ if it's being managed internally.
Definition at line 510 of file fusion_engine_framer.cc.
|
private |
Process a single byte.
buffer_[next_byte_index_ - 1]
.quiet | If true , suppress failure warning messages. |
Definition at line 195 of file fusion_engine_framer.cc.
size_t FusionEngineFramer::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 155 of file fusion_engine_framer.cc.
|
delete |
|
delete |
void FusionEngineFramer::Reset | ( | ) |
Reset the framer and discard all pending data.
Definition at line 148 of file fusion_engine_framer.cc.
|
private |
Perform a resynchronization operation starting at buffer_[1]
.
Definition at line 413 of file fusion_engine_framer.cc.
void FusionEngineFramer::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 112 of file fusion_engine_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 116 of file fusion_engine_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 FusionEngine message preamble is expected to appear in the non-FusionEngine content occasionally.
enabled | If true , issue warnings on errors. |
Definition at line 108 of file fusion_engine_framer.h.
|
private |
Definition at line 146 of file fusion_engine_framer.h.
|
private |
Definition at line 142 of file fusion_engine_framer.h.
|
private |
Definition at line 147 of file fusion_engine_framer.h.
|
private |
Definition at line 151 of file fusion_engine_framer.h.
|
private |
Definition at line 145 of file fusion_engine_framer.h.
|
private |
Definition at line 150 of file fusion_engine_framer.h.
|
private |
Definition at line 149 of file fusion_engine_framer.h.
|
private |
Definition at line 144 of file fusion_engine_framer.h.