hydrolink-headers/include/hydrolink/hydrolink_msg_get_response.h
2025-02-25 13:30:35 +01:00

49 lines
No EOL
2.1 KiB
C

#pragma once
#include "protocol.h"
#define HYDROLINK_MSG_ID_GET_RESPONSE 5
#define HYDROLINK_MSG_GET_RESPONSE_LEN 6
#define HYDROLINK_MSG_5_LEN 6
#define HYDROLINK_MSG_GET_RESPONSE_CRC_EXTRA 28
typedef struct hydrolink_msg_get_response_t_s {
int32_t value; ///
uint8_t result; ///
uint8_t cmd_id; ///
} hydrolink_msg_get_response_t;
static inline void hydrolink_msg_get_response_encode(uint8_t src_id, uint8_t dst_id, const hydrolink_msg_get_response_t *msg, hydrolink_msg_t *packet) {
uint16_t crc;
crc_xmodem_init(&crc);
packet->id = HYDROLINK_MSG_ID_GET_RESPONSE;
crc_xmodem_accumulate(packet->id, &crc);
packet->dst_id = dst_id;
crc_xmodem_accumulate(packet->dst_id, &crc);
packet->src_id = src_id;
crc_xmodem_accumulate(packet->src_id, &crc);
packet->payload_length = HYDROLINK_MSG_5_LEN + HYDROLINK_NON_PAYLOAD_LEN;
crc_xmodem_accumulate(packet->payload_length, &crc);
hydrolink_put_int32_t(HYDROLINK_PAYLOAD_NON_CONST(packet), 0, msg->value);
hydrolink_put_uint8_t(HYDROLINK_PAYLOAD_NON_CONST(packet), 4, msg->result);
hydrolink_put_uint8_t(HYDROLINK_PAYLOAD_NON_CONST(packet), 5, msg->cmd_id);
for(int i = 0; i < packet->payload_length; ++i) {
crc_xmodem_accumulate(packet->payload[i], &crc);
}
crc_xmodem_accumulate(HYDROLINK_MSG_GET_RESPONSE_CRC_EXTRA, &crc);
packet->crc = crc;
}
static inline int32_t hydrolink_msg_get_response_get_value(const hydrolink_msg_t *packet) {
return HYDROLINK_RETURN_int32_t(packet, 0);
}
static inline uint8_t hydrolink_msg_get_response_get_result(const hydrolink_msg_t *packet) {
return HYDROLINK_RETURN_uint8_t(packet, 4);
}
static inline uint8_t hydrolink_msg_get_response_get_cmd_id(const hydrolink_msg_t *packet) {
return HYDROLINK_RETURN_uint8_t(packet, 5);
}
static inline void hydrolink_msg_get_response_decode(const hydrolink_msg_t *packet, hydrolink_msg_get_response_t *get_response) {
get_response->value = hydrolink_msg_get_response_get_value(packet);
get_response->result = hydrolink_msg_get_response_get_result(packet);
get_response->cmd_id = hydrolink_msg_get_response_get_cmd_id(packet);
}