34#define STS_HEADER 0xFFU
35#define STS_HEADER_SIZE 2U
36#define STS_CHECKSUM_SIZE 1U
37#define STS_LENGTH_FIXED_OVERHEAD 2U
38#define STS_PKT_FIXED_TOTAL 4U
39#define STS_MIN_PACKET_SIZE 6U
40#define STS_MAX_PACKET_SIZE 255U
43#define STS_IDX_HEADER_1 0U
44#define STS_IDX_HEADER_2 1U
46#define STS_IDX_LENGTH 3U
47#define STS_IDX_INSTRUCTION 4U
48#define STS_IDX_STATUS 4U
49#define STS_IDX_PARAM_START 5U
52#define STS_MAX_ID 254U
53#define STS_MAX_PARAM_LEN 253U
54#define STS_HARDWARE_OK 0x00U
55#define STS_MAX_INSTRUCTION 0x05U
56#define STS_MIN_PKT_LEN_VAL 2U
59#define STS_ACK_BASE_LEN 6U
60#define STS_REG_ADDR_LEN 1U
61#define STS_DATA_LEN_8BIT 1U
62#define STS_DATA_LEN_16BIT 2U
65#define STS_WRITE8_PARAM_LEN (STS_REG_ADDR_LEN + STS_DATA_LEN_8BIT)
66#define STS_WRITE16_PARAM_LEN (STS_REG_ADDR_LEN + STS_DATA_LEN_16BIT)
67#define STS_READ_CMD_PARAM_LEN (STS_REG_ADDR_LEN + STS_DATA_LEN_8BIT)
111sts_result_t sts_create_packet(uint8_t
id, uint8_t instruction,
const uint8_t* param_buf, uint16_t param_len, uint8_t* pkt_buf, uint16_t pkt_buf_size);
126sts_result_t sts_parse_response(uint8_t expected_id,
const uint8_t* rx_buf, uint16_t rx_len, uint8_t* param_buf, uint16_t param_buf_size,uint16_t* param_len);
sts_result_t sts_calculate_checksum(const uint8_t *pkt_buf, uint16_t pkt_len, uint8_t *checksum_out)
Calculates the Feetech STS Checksum. Sums ID, Length, Instruction, and Parameters (skipping the initi...
Definition sts_protocol.c:31
sts_result_t sts_parse_response(uint8_t expected_id, const uint8_t *rx_buf, uint16_t rx_len, uint8_t *param_buf, uint16_t param_buf_size, uint16_t *param_len)
Parses a response packet from a servo, searching for valid headers in the buffer.
Definition sts_protocol.c:165
sts_result_t
Return codes for STS protocol operations.
Definition sts_protocol.h:71
@ STS_ERR_BUSY
Definition sts_protocol.h:85
@ STS_ERR_INVALID_LEN
Definition sts_protocol.h:74
@ STS_ERR_HARDWARE
Definition sts_protocol.h:82
@ STS_ERR_ID_MISMATCH
Definition sts_protocol.h:79
@ STS_ERR_CHECKSUM
Definition sts_protocol.h:80
@ STS_ERR_MALFORMED
Definition sts_protocol.h:81
@ STS_ERR_TIMEOUT
Definition sts_protocol.h:77
@ STS_ERR_TX_FAIL
Definition sts_protocol.h:83
@ STS_ERR_HEADER
Definition sts_protocol.h:78
@ STS_ERR_BUF_TOO_SMALL
Definition sts_protocol.h:76
@ STS_ERR_NULL_PTR
Definition sts_protocol.h:73
@ STS_OK
Definition sts_protocol.h:72
@ STS_ERR_INVALID_PARAM
Definition sts_protocol.h:75
sts_result_t sts_create_packet(uint8_t id, uint8_t instruction, const uint8_t *param_buf, uint16_t param_len, uint8_t *pkt_buf, uint16_t pkt_buf_size)
Constructs an STS packet in the provided buffer.
Definition sts_protocol.c:50