From f1ae618627b88e36f3086ec6b54850d7a1f952c7 Mon Sep 17 00:00:00 2001 From: "CSSC-WORK\\murmur" Date: Tue, 31 Dec 2024 09:51:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A01=E5=AD=97=E8=8A=82=E5=AF=B9?= =?UTF-8?q?=E9=BD=90=EF=BC=8C=E9=81=BF=E5=85=8D=E7=BB=93=E6=9E=84=E4=BD=93?= =?UTF-8?q?=E5=A4=A7=E5=B0=8F=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- protocol.c | 2 +- protocol.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/protocol.c b/protocol.c index 5ccde65..8fc38eb 100644 --- a/protocol.c +++ b/protocol.c @@ -1347,7 +1347,7 @@ static void packMsgToHost(uint16_t funcCode, uint8_t isOK) { if(funcCode == HOST_CMD_STATUS_QUERY) { dlen = sizeof(DeviceStatus_t); index = sizeof(FRAME_TAIL)+2; - msgBuf[index] = 17; + msgBuf[index] = dlen;//#pragma pack(1)后大小正确 index += 1; //系统是小端序,将deviceStatus转换为大端序 memcpy(msgBuf+index, &deviceStatus.sensorStatus, 1); diff --git a/protocol.h b/protocol.h index 2f929b9..d7ee3d4 100644 --- a/protocol.h +++ b/protocol.h @@ -375,6 +375,8 @@ typedef enum { INIT_FAILED = 2 } InitStatus_t; +// 大小对齐至1字节 +#pragma pack(1) // 三通阀结构体 typedef struct { uint16_t angle[2]; // 阀门实时角度