This commit is contained in:
Thies Lennart Alff 2025-02-25 13:30:35 +01:00
parent 061f7d6c4b
commit 18f9ab4581
Signed by: lennartalff
GPG key ID: 4EC67D34D594104D
6 changed files with 104 additions and 25 deletions

19
.gdb_history Normal file
View file

@ -0,0 +1,19 @@
c
q
c
q
c
q
c
q
q
c
q
c
q
c
q
q
c
q
c

View file

@ -1,20 +1,32 @@
#pragma once #pragma once
#include "protocol.h" #include "protocol.h"
#define HYDROLINK_MSG_ID_ACK 1 #define HYDROLINK_MSG_ID_ACK 1
#define HYDROLINK_MSG_ID_ACK_LEN 1 #define HYDROLINK_MSG_ACK_LEN 1
#define HYDROLINK_MSG_ID_1_LEN 1 #define HYDROLINK_MSG_1_LEN 1
#define HYDROLINK_MSG_ID_ACK_CRC_EXTRA 73 #define HYDROLINK_MSG_ACK_CRC_EXTRA 73
typedef struct hydrolink_msg_ack_t_s { typedef struct hydrolink_msg_ack_t_s {
uint8_t ack; /// uint8_t ack; ///
} hydrolink_msg_ack_t; } hydrolink_msg_ack_t;
static inline void hydrolink_msg_ack_encode(uint8_t src_id, uint8_t dst_id, const hydrolink_msg_ack_t *msg, hydrolink_msg_t *packet) { static inline void hydrolink_msg_ack_encode(uint8_t src_id, uint8_t dst_id, const hydrolink_msg_ack_t *msg, hydrolink_msg_t *packet) {
uint16_t crc;
crc_xmodem_init(&crc);
packet->id = HYDROLINK_MSG_ID_ACK; packet->id = HYDROLINK_MSG_ID_ACK;
packet->src_id = src_id; crc_xmodem_accumulate(packet->id, &crc);
packet->dst_id = dst_id; packet->dst_id = dst_id;
packet->payload_length = HYDROLINK_MSG_ID_1_LEN + HYDROLINK_NON_PAYLOAD_LEN; crc_xmodem_accumulate(packet->dst_id, &crc);
packet->src_id = src_id;
crc_xmodem_accumulate(packet->src_id, &crc);
packet->payload_length = HYDROLINK_MSG_1_LEN + HYDROLINK_NON_PAYLOAD_LEN;
crc_xmodem_accumulate(packet->payload_length, &crc);
hydrolink_put_uint8_t(HYDROLINK_PAYLOAD_NON_CONST(packet), 0, msg->ack); hydrolink_put_uint8_t(HYDROLINK_PAYLOAD_NON_CONST(packet), 0, msg->ack);
for(int i = 0; i < packet->payload_length; ++i) {
crc_xmodem_accumulate(packet->payload[i], &crc);
}
crc_xmodem_accumulate(HYDROLINK_MSG_ACK_CRC_EXTRA, &crc);
packet->crc = crc;
} }
static inline uint8_t hydrolink_msg_ack_get_ack(const hydrolink_msg_t *packet) { static inline uint8_t hydrolink_msg_ack_get_ack(const hydrolink_msg_t *packet) {

View file

@ -1,9 +1,9 @@
#pragma once #pragma once
#include "protocol.h" #include "protocol.h"
#define HYDROLINK_MSG_ID_GET_CMD 4 #define HYDROLINK_MSG_ID_GET_CMD 4
#define HYDROLINK_MSG_ID_GET_CMD_LEN 2 #define HYDROLINK_MSG_GET_CMD_LEN 2
#define HYDROLINK_MSG_ID_4_LEN 2 #define HYDROLINK_MSG_4_LEN 2
#define HYDROLINK_MSG_ID_GET_CMD_CRC_EXTRA 38 #define HYDROLINK_MSG_GET_CMD_CRC_EXTRA 38
typedef struct hydrolink_msg_get_cmd_t_s { typedef struct hydrolink_msg_get_cmd_t_s {
uint8_t index; /// uint8_t index; ///
@ -11,12 +11,24 @@ uint8_t cmd_id; ///
} hydrolink_msg_get_cmd_t; } hydrolink_msg_get_cmd_t;
static inline void hydrolink_msg_get_cmd_encode(uint8_t src_id, uint8_t dst_id, const hydrolink_msg_get_cmd_t *msg, hydrolink_msg_t *packet) { static inline void hydrolink_msg_get_cmd_encode(uint8_t src_id, uint8_t dst_id, const hydrolink_msg_get_cmd_t *msg, hydrolink_msg_t *packet) {
uint16_t crc;
crc_xmodem_init(&crc);
packet->id = HYDROLINK_MSG_ID_GET_CMD; packet->id = HYDROLINK_MSG_ID_GET_CMD;
packet->src_id = src_id; crc_xmodem_accumulate(packet->id, &crc);
packet->dst_id = dst_id; packet->dst_id = dst_id;
packet->payload_length = HYDROLINK_MSG_ID_4_LEN + HYDROLINK_NON_PAYLOAD_LEN; crc_xmodem_accumulate(packet->dst_id, &crc);
packet->src_id = src_id;
crc_xmodem_accumulate(packet->src_id, &crc);
packet->payload_length = HYDROLINK_MSG_4_LEN + HYDROLINK_NON_PAYLOAD_LEN;
crc_xmodem_accumulate(packet->payload_length, &crc);
hydrolink_put_uint8_t(HYDROLINK_PAYLOAD_NON_CONST(packet), 0, msg->index); hydrolink_put_uint8_t(HYDROLINK_PAYLOAD_NON_CONST(packet), 0, msg->index);
hydrolink_put_uint8_t(HYDROLINK_PAYLOAD_NON_CONST(packet), 1, msg->cmd_id); hydrolink_put_uint8_t(HYDROLINK_PAYLOAD_NON_CONST(packet), 1, 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_CMD_CRC_EXTRA, &crc);
packet->crc = crc;
} }
static inline uint8_t hydrolink_msg_get_cmd_get_index(const hydrolink_msg_t *packet) { static inline uint8_t hydrolink_msg_get_cmd_get_index(const hydrolink_msg_t *packet) {

View file

@ -1,9 +1,9 @@
#pragma once #pragma once
#include "protocol.h" #include "protocol.h"
#define HYDROLINK_MSG_ID_GET_RESPONSE 5 #define HYDROLINK_MSG_ID_GET_RESPONSE 5
#define HYDROLINK_MSG_ID_GET_RESPONSE_LEN 6 #define HYDROLINK_MSG_GET_RESPONSE_LEN 6
#define HYDROLINK_MSG_ID_5_LEN 6 #define HYDROLINK_MSG_5_LEN 6
#define HYDROLINK_MSG_ID_GET_RESPONSE_CRC_EXTRA 28 #define HYDROLINK_MSG_GET_RESPONSE_CRC_EXTRA 28
typedef struct hydrolink_msg_get_response_t_s { typedef struct hydrolink_msg_get_response_t_s {
int32_t value; /// int32_t value; ///
@ -12,13 +12,25 @@ uint8_t cmd_id; ///
} hydrolink_msg_get_response_t; } 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) { 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; packet->id = HYDROLINK_MSG_ID_GET_RESPONSE;
packet->src_id = src_id; crc_xmodem_accumulate(packet->id, &crc);
packet->dst_id = dst_id; packet->dst_id = dst_id;
packet->payload_length = HYDROLINK_MSG_ID_5_LEN + HYDROLINK_NON_PAYLOAD_LEN; 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_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), 4, msg->result);
hydrolink_put_uint8_t(HYDROLINK_PAYLOAD_NON_CONST(packet), 5, msg->cmd_id); 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) { static inline int32_t hydrolink_msg_get_response_get_value(const hydrolink_msg_t *packet) {

View file

@ -1,9 +1,9 @@
#pragma once #pragma once
#include "protocol.h" #include "protocol.h"
#define HYDROLINK_MSG_ID_SET_CMD 2 #define HYDROLINK_MSG_ID_SET_CMD 2
#define HYDROLINK_MSG_ID_SET_CMD_LEN 6 #define HYDROLINK_MSG_SET_CMD_LEN 6
#define HYDROLINK_MSG_ID_2_LEN 6 #define HYDROLINK_MSG_2_LEN 6
#define HYDROLINK_MSG_ID_SET_CMD_CRC_EXTRA 58 #define HYDROLINK_MSG_SET_CMD_CRC_EXTRA 58
typedef struct hydrolink_msg_set_cmd_t_s { typedef struct hydrolink_msg_set_cmd_t_s {
int32_t value; /// int32_t value; ///
@ -12,13 +12,25 @@ uint8_t cmd_id; /// Command defined as in CMD_ID enum.
} hydrolink_msg_set_cmd_t; } hydrolink_msg_set_cmd_t;
static inline void hydrolink_msg_set_cmd_encode(uint8_t src_id, uint8_t dst_id, const hydrolink_msg_set_cmd_t *msg, hydrolink_msg_t *packet) { static inline void hydrolink_msg_set_cmd_encode(uint8_t src_id, uint8_t dst_id, const hydrolink_msg_set_cmd_t *msg, hydrolink_msg_t *packet) {
uint16_t crc;
crc_xmodem_init(&crc);
packet->id = HYDROLINK_MSG_ID_SET_CMD; packet->id = HYDROLINK_MSG_ID_SET_CMD;
packet->src_id = src_id; crc_xmodem_accumulate(packet->id, &crc);
packet->dst_id = dst_id; packet->dst_id = dst_id;
packet->payload_length = HYDROLINK_MSG_ID_2_LEN + HYDROLINK_NON_PAYLOAD_LEN; crc_xmodem_accumulate(packet->dst_id, &crc);
packet->src_id = src_id;
crc_xmodem_accumulate(packet->src_id, &crc);
packet->payload_length = HYDROLINK_MSG_2_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_int32_t(HYDROLINK_PAYLOAD_NON_CONST(packet), 0, msg->value);
hydrolink_put_uint8_t(HYDROLINK_PAYLOAD_NON_CONST(packet), 4, msg->index); hydrolink_put_uint8_t(HYDROLINK_PAYLOAD_NON_CONST(packet), 4, msg->index);
hydrolink_put_uint8_t(HYDROLINK_PAYLOAD_NON_CONST(packet), 5, msg->cmd_id); 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_SET_CMD_CRC_EXTRA, &crc);
packet->crc = crc;
} }
static inline int32_t hydrolink_msg_set_cmd_get_value(const hydrolink_msg_t *packet) { static inline int32_t hydrolink_msg_set_cmd_get_value(const hydrolink_msg_t *packet) {

View file

@ -1,9 +1,9 @@
#pragma once #pragma once
#include "protocol.h" #include "protocol.h"
#define HYDROLINK_MSG_ID_SET_RESPONSE 3 #define HYDROLINK_MSG_ID_SET_RESPONSE 3
#define HYDROLINK_MSG_ID_SET_RESPONSE_LEN 2 #define HYDROLINK_MSG_SET_RESPONSE_LEN 2
#define HYDROLINK_MSG_ID_3_LEN 2 #define HYDROLINK_MSG_3_LEN 2
#define HYDROLINK_MSG_ID_SET_RESPONSE_CRC_EXTRA 250 #define HYDROLINK_MSG_SET_RESPONSE_CRC_EXTRA 250
typedef struct hydrolink_msg_set_response_t_s { typedef struct hydrolink_msg_set_response_t_s {
uint8_t result; /// uint8_t result; ///
@ -11,12 +11,24 @@ uint8_t cmd_id; ///
} hydrolink_msg_set_response_t; } hydrolink_msg_set_response_t;
static inline void hydrolink_msg_set_response_encode(uint8_t src_id, uint8_t dst_id, const hydrolink_msg_set_response_t *msg, hydrolink_msg_t *packet) { static inline void hydrolink_msg_set_response_encode(uint8_t src_id, uint8_t dst_id, const hydrolink_msg_set_response_t *msg, hydrolink_msg_t *packet) {
uint16_t crc;
crc_xmodem_init(&crc);
packet->id = HYDROLINK_MSG_ID_SET_RESPONSE; packet->id = HYDROLINK_MSG_ID_SET_RESPONSE;
packet->src_id = src_id; crc_xmodem_accumulate(packet->id, &crc);
packet->dst_id = dst_id; packet->dst_id = dst_id;
packet->payload_length = HYDROLINK_MSG_ID_3_LEN + HYDROLINK_NON_PAYLOAD_LEN; crc_xmodem_accumulate(packet->dst_id, &crc);
packet->src_id = src_id;
crc_xmodem_accumulate(packet->src_id, &crc);
packet->payload_length = HYDROLINK_MSG_3_LEN + HYDROLINK_NON_PAYLOAD_LEN;
crc_xmodem_accumulate(packet->payload_length, &crc);
hydrolink_put_uint8_t(HYDROLINK_PAYLOAD_NON_CONST(packet), 0, msg->result); hydrolink_put_uint8_t(HYDROLINK_PAYLOAD_NON_CONST(packet), 0, msg->result);
hydrolink_put_uint8_t(HYDROLINK_PAYLOAD_NON_CONST(packet), 1, msg->cmd_id); hydrolink_put_uint8_t(HYDROLINK_PAYLOAD_NON_CONST(packet), 1, msg->cmd_id);
for(int i = 0; i < packet->payload_length; ++i) {
crc_xmodem_accumulate(packet->payload[i], &crc);
}
crc_xmodem_accumulate(HYDROLINK_MSG_SET_RESPONSE_CRC_EXTRA, &crc);
packet->crc = crc;
} }
static inline uint8_t hydrolink_msg_set_response_get_result(const hydrolink_msg_t *packet) { static inline uint8_t hydrolink_msg_set_response_get_result(const hydrolink_msg_t *packet) {