Group dxl2_protocol¶
CRC-16, incremental stream parser and packet encoder with byte stuffing. More...
Classes¶
| Type | Name |
|---|---|
| struct | dxl2_packet One decoded Protocol 2.0 packet. |
| struct | dxl2_parser Incremental parser state for a byte stream. |
Public Functions¶
| Type | Name |
|---|---|
| uint16_t | dxl2_crc16 (const uint8_t * data, size_t length) Calculate the Protocol 2.0 CRC-16 checksum. |
| int | dxl2_encode (uint8_t id, uint8_t instruction, const uint8_t * parameters, uint16_t parameter_length, uint8_t * output, size_t output_capacity, size_t * output_length) Encode a Protocol 2.0 packet, adding byte stuffing and CRC. |
| int | dxl2_parser_feed (struct dxl2_parser * parser, uint8_t byte, struct dxl2_packet * packet) Feed one byte to the incremental packet parser. |
| void | dxl2_parser_init (struct dxl2_parser * parser) Reset a parser before starting or restarting a byte stream. |
Macros¶
| Type | Name |
|---|---|
| define | DXL2_MAX_PARAMETER_SIZE ([**DXL2\_MAX\_PACKET\_SIZE**](group__dxl2__config.md#define-dxl2_max_packet_size) - 10U)Maximum unstuffed parameter payload size supported by this implementation. |
| define | DXL2_PARSE_ERROR (-1)Error returned for invalid input, malformed packets, or insufficient capacity. |
Detailed Description¶
** **
- CRC: dxl2_crc16.
- Parser: dxl2_parser_init, dxl2_parser_feed.
- Encoder: dxl2_encode.
Public Functions Documentation¶
function dxl2_crc16¶
Calculate the Protocol 2.0 CRC-16 checksum.
Uses polynomial 0x8005 and an initial CRC value of zero.
Parameters:
dataBytes covered by the CRC.lengthNumber of bytes to process.
Returns:
Calculated 16-bit CRC; 0 (the initial value) when data is NULL.
function dxl2_encode¶
Encode a Protocol 2.0 packet, adding byte stuffing and CRC.
int dxl2_encode (
uint8_t id,
uint8_t instruction,
const uint8_t * parameters,
uint16_t parameter_length,
uint8_t * output,
size_t output_capacity,
size_t * output_length
)
Parameters:
idPacket ID.instructionInstruction byte.parametersUnstuffed parameter bytes, or NULL when the length is zero.parameter_lengthNumber of parameter bytes.outputDestination buffer for the complete wire packet.output_capacityCapacity ofoutputin bytes.output_lengthReceives the encoded packet length on success.
Return value:
0Packet encoded successfully.DXL2_PARSE_ERRORInvalid input or insufficient output capacity.
function dxl2_parser_feed¶
Feed one byte to the incremental packet parser.
The parser searches for the Protocol 2.0 header, waits for the declared packet length, validates CRC, then removes byte stuffing. Continue feeding bytes after a parse error so the parser can find the next packet header.
Parameters:
parserParser state.byteNext byte from the input stream.packetOutput packet; its contents are valid only when the call returns 1.
Return value:
1A complete valid packet is available inpacket.0More bytes are required.DXL2_PARSE_ERRORInvalid arguments or a malformed/CRC-invalid packet.
function dxl2_parser_init¶
Reset a parser before starting or restarting a byte stream.
Parameters:
parserParser state to initialize; NULL is ignored.
Macro Definition Documentation¶
define DXL2_MAX_PARAMETER_SIZE¶
Maximum unstuffed parameter payload size supported by this implementation.
define DXL2_PARSE_ERROR¶
Error returned for invalid input, malformed packets, or insufficient capacity.