From f4c8fc30b42ca7634764135be953e44957ac9b42 Mon Sep 17 00:00:00 2001 From: OPTOC <9159397+optoc@user.noreply.gitee.com> Date: Thu, 18 Sep 2025 16:49:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=8F=E8=AE=AE=E4=BF=AE=E6=94=B9=E4=B8=BA?= =?UTF-8?q?=E5=B0=8F=E7=AB=AF=E8=A7=84=E5=88=99=EF=BC=8C=E5=B9=B6=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E6=96=B0=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/drivers/sertrf/protocol/resend_protl.c | 23 ++++++++++++++-------- app/drivers/sertrf/protocol/resend_protl.h | 8 ++++++-- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/app/drivers/sertrf/protocol/resend_protl.c b/app/drivers/sertrf/protocol/resend_protl.c index e13f415..451c63b 100644 --- a/app/drivers/sertrf/protocol/resend_protl.c +++ b/app/drivers/sertrf/protocol/resend_protl.c @@ -38,14 +38,14 @@ int resend_encode(resend_device_t *resend_device, void *out, uint8_t cmd, void* // retry_cnt c[4] = resend_device->tx_frame.retry_cnt; // len big endian - c[5] = (uint8_t)((len >> 8) & 0xFF); - c[6] = (uint8_t)(len & 0xFF); + c[5] = (uint8_t)((len) & 0xFF); + c[6] = (uint8_t)((len >> 8) & 0xFF); // payload if (len > 0 && data) memcpy(&c[7], data, len); // compute crc over seq..payload (i.e. bytes p+1 .. p+5+len) uint16_t crc = fmav_crc_calculate(&c[2], 5 + len); - c[7 + len] = (uint8_t)((crc >> 8) & 0xFF); - c[7 + len + 1] = (uint8_t)(crc & 0xFF); + c[7 + len] = (uint8_t)(crc & 0xFF); + c[7 + len + 1] = (uint8_t)((crc >> 8) & 0xFF); return (int)(len + RESEND_MAX_PAYLOAD); } @@ -91,12 +91,12 @@ int resend_decode(resend_device_t *resend_device, uint8_t c) break; case RESEND_LEN_1: resend_device->rx_frame.len = 0; - resend_device->rx_frame.len = (uint16_t)(c << 8); + resend_device->rx_frame.len |= c; fmav_crc_accumulate(&frame_crc, c); resend_device->status.c_state = RESEND_LEN_2; break; case RESEND_LEN_2: - resend_device->rx_frame.len |= c; + resend_device->rx_frame.len |= (uint16_t)(c << 8);; fmav_crc_accumulate(&frame_crc, c); if(resend_device->rx_frame.len > 0) { @@ -118,14 +118,14 @@ int resend_decode(resend_device_t *resend_device, uint8_t c) } break; case RESEND_CRC_1: - if((uint8_t)(frame_crc >> 8 & 0xFF) == c){ + if((uint8_t)(frame_crc) == c){ resend_device->status.c_state = RESEND_CRC_2; }else{ resend_device->status.c_state = RESEND_IDLE; } break; case RESEND_CRC_2: - if((uint8_t)(frame_crc) == c){ + if((uint8_t)(frame_crc >> 8 & 0xFF) == c){ resend_device->status.c_state = RESEND_IDLE; resend_device->rx_frame.crc = frame_crc; if(resend_device->rx_frame.cmd != RESEND_CMD_DATA && resend_device->rx_frame.cmd != RESEND_CMD_ACK && resend_device->rx_frame.retry_cnt == 0) @@ -242,10 +242,17 @@ int resend_parse_data(resend_device_t *resend_device) printf("ACK\n"); resend_device->status.ack_flag = 0; break; + case RESEND_CMD_GET_STATUS: + resend_send_cmd(resend_device, RESEND_CMD_ACK, 0); + resend_device->handle_flag = RESEND_CMD_GET_STATUS; + break; case RESEND_CMD_STATUS: resend_set(resend_device); resend_send_cmd(resend_device, RESEND_CMD_ACK, 0); break; + case RESEND_CMD_SET_STATUS: + resend_send_cmd(resend_device, RESEND_CMD_ACK, 0); + break; case RESEND_CMD_DATA_ACK: for (size_t i = 0; i < resend_device->rx_frame.len; i++) { diff --git a/app/drivers/sertrf/protocol/resend_protl.h b/app/drivers/sertrf/protocol/resend_protl.h index d3e2c29..952cd38 100644 --- a/app/drivers/sertrf/protocol/resend_protl.h +++ b/app/drivers/sertrf/protocol/resend_protl.h @@ -25,9 +25,11 @@ typedef enum { RESEND_CMD_DATA = 0x01, RESEND_CMD_ACK = 0x02, - RESEND_CMD_STATUS = 0x03, - RESEND_CMD_DATA_ACK = 0x04, + RESEND_CMD_GET_STATUS = 0x03, + RESEND_CMD_STATUS = 0x04, + RESEND_CMD_SET_STATUS = 0x05, + RESEND_CMD_DATA_ACK = 0x06, RESEND_CMD_OTA_START = 0x011, RESEND_CMD_OTA_DATA = 0x012, @@ -74,6 +76,8 @@ typedef struct resend_frame_t tx_frame; // 发送帧 resend_status_t status; // 帧状态 + uint8_t handle_flag; // 接收请求帧处理标志 + int (*send)(void* data, uint16_t len, int timeout); // 发送数据 int (*recv)(void* data, uint16_t len, int timeout); // 接收数据 int (*get_length )(void); // 获取数据长度