class ugcs::vsm::mavlink::Checksum¶
Overview¶
Mavlink compatible checksum (ITU X.25/SAE AS-4 hash) calculation class. More…
#include <mavlink.h> class Checksum { public: // typedefs typedef ugcs::vsm::Param_exception<Exception_dummy_struct,> Exception; typedef ugcs::vsm::Derived_exception<Exception, Invalid_id_exception_dummy_struct> Invalid_id_exception; // structs struct Exception_dummy_struct; struct Invalid_id_exception_dummy_struct; // construction Checksum(); Checksum(const void* buffer, size_t len); Checksum(const Io_buffer::Ptr& buffer); // methods uint16_t Accumulate(const void* buffer, size_t len); uint16_t Accumulate(const Io_buffer::Ptr& buffer); uint16_t Accumulate(uint8_t byte); uint16_t Get() const; void Reset(); static uint16_t Calculate( const void* buffer, size_t len, uint16_t* accumulator = nullptr ); static bool Get_extra_byte_length_pair(MESSAGE_ID_TYPE message_id, Extra_byte_length_pair& ret, const Extension& ext = Extension::Get()); };
Detailed Documentation¶
Mavlink compatible checksum (ITU X.25/SAE AS-4 hash) calculation class.
It can be used statically to calculate checksum of arbitrary buffer, or used as an instance to incrementally accumulate checksum for multiple buffers.
Typedefs¶
typedef ugcs::vsm::Derived_exception<Exception, Invalid_id_exception_dummy_struct> Invalid_id_exception
Definition of a new exception type.
Construction¶
Checksum()
Instance initialized with initial checksum value for empty buffer.
Checksum(const void* buffer, size_t len)
Instance initialized and checksum is calculated based on provided buffer.
Checksum(const Io_buffer::Ptr& buffer)
Instance initialized and checksum is calculated based on provided buffer.
Methods¶
uint16_t Accumulate(const void* buffer, size_t len)
Incrementally calculate the checksum of a new buffer and accumulate it to the current value.
Parameters:
buffer |
Byte buffer. |
len |
Size of the buffer. |
Returns:
New checksum value.
uint16_t Accumulate(const Io_buffer::Ptr& buffer)
Incrementally calculate the checksum of a new buffer and accumulate it to the current value.
Parameters:
buffer |
Byte buffer. |
Returns:
New checksum value.
uint16_t Accumulate(uint8_t byte)
Incrementally calculate the checksum of one new byte and accumulate it to the current value.
Parameters:
byte |
byte. |
Returns:
New checksum value.
uint16_t Get() const
Get current checksum value.
void Reset()
Reset checksum to initial seed value for zero-length buffer.
static uint16_t Calculate( const void* buffer, size_t len, uint16_t* accumulator = nullptr )
Calculate checksum either incrementally or from initial seed value.
Parameters:
buffer |
Byte buffer. |
len |
Size of the buffer. |
accumulator |
If not nullptr, then incremental calculation is made, otherwise initial seed value is used. |
Returns:
Calculated checksum value.
static bool Get_extra_byte_length_pair(MESSAGE_ID_TYPE message_id, Extra_byte_length_pair& ret, const Extension& ext = Extension::Get())
Get CRC extra byte and expected payload length of a specific Mavlink message type.
Parameters:
Invalid_id_exception |
for unknown Mavlink messages. |
message_id |
Mavlink message id. |
ret |
[out] CRC extra byte and length pair mavlink::Extra_byte_length_pair. |
ext |
Extension the message belongs to. |
Returns:
false if message_id is not recognized.