From f1747df3451fe40c440f3c2fd1216bee57f2d6d4 Mon Sep 17 00:00:00 2001
From: Fancy code <258828110.@qq.com>
Date: Sun, 11 Feb 2024 05:49:00 -0800
Subject: [PATCH] Improve Protocol handle code.
---
doc/design.md | 12 ++++++++++--
middleware/McuManager/include/IMcuManager.h | 6 +++++-
utils/McuProtocol/src/ProtocolHandle.cpp | 10 +++++-----
3 files changed, 20 insertions(+), 8 deletions(-)
diff --git a/doc/design.md b/doc/design.md
index 847d3b3..6929447 100644
--- a/doc/design.md
+++ b/doc/design.md
@@ -634,12 +634,13 @@ unsigned short calculate_check_sum(const unsigned char* pData, unsigned short le
**基本描述**
1. 大于等于0x8000的命令字由CPU发给MCU;
2. 小于0x8000的命令字由MCU发给CPU;
-3. 问答型协议只有按位最高位相反,其它位相等,例如:0x8101与0x0101是一问一答的协议;
+3. 大于0x0801而小于0xC101的命令由CPU主动发送给MCU,大于等于0xC101的命令由CPU回复发送给MCU;
+4. 问答型协议只有按位最高位相反,其它位相等,例如:0x8101与0x0101是一问一答的协议;
| 命令字 | CPU | MCU | 数据段 | 协议解析 | 备注 |
|----|----|----|----|----|----|
| 0x8101 | ask | - | - | 获取启动模式 | - |
-| 0x0101 | - | reply | Data[0]:启动模式
0x01:PIR启动
0x02:TEST启动
0x03:连拍启动
0x04:PIR延时启动 | 回复启动模式 | - |
+| 0x0101 | - | reply/ask | Data[0]:启动模式
0x01:PIR启动
0x02:TEST启动
0x03:连拍启动
0x04:PIR延时启动
0x05:定时(间隔一定时间)启动 | 回复启动模式 | - |
| 0x8102 | ask | - | - | 断电关机 | - |
| 0x8103 | ask | - | - | 喂狗 | - |
| 0x8104 | ask | - | Data[0]:Hour
0-23
Data[1]:Min
0-59
Data[2]:Sec
0-59 | 开启狗/设置喂狗周期 | - |
@@ -654,6 +655,13 @@ unsigned short calculate_check_sum(const unsigned char* pData, unsigned short le
| 0x0108 | - | reply | Data[0]:结果
0x01:成功
0x02:失败 | 设置PIR灵敏度回复 | - |
| 0x8109 | ask | - | Data[0]:Hour
0-23
Data[1]:Min
0-59
Data[2]:Sec
0-59 | 设置连拍间隔 | - |
| 0x0109 | - | reply | Data[0]:结果
0x01:成功
0x02:失败 | 设置连拍间隔回复 | - |
+| 0x810A | ask | - | Data[0]:控制模式
0-关闭红外灯
1-开启红外灯 | 红外灯控制 | - |
+| 0x010A | - | reply | Data[0]:结果
0x01:成功
0x02:失败 | 红外灯控制回复 | - |
+| 0x810B | ask | - | - | 获取光敏值 | - |
+| 0x010B | - | reply | Data[0]:结果
0-100 | 获取光敏值回复 | - |
+| ====== | === | ====== | ============================ | ==================== | ======= |
+| 0xC101 | reply | - | Data[0]:结果
0x01:成功
0x02:失败 | 发送启动模式回复 | - |
+| 0x4101 | - | ask | Data[0]:启动模式
0x01:PIR启动
0x02:TEST启动
0x03:连拍启动
0x04:PIR延时启动
0x05:定时(间隔一定时间)启动 | 发送启动模式 | - |
##### 1.4.3.2.6. IPC配置库
diff --git a/middleware/McuManager/include/IMcuManager.h b/middleware/McuManager/include/IMcuManager.h
index a1374f1..16c1365 100644
--- a/middleware/McuManager/include/IMcuManager.h
+++ b/middleware/McuManager/include/IMcuManager.h
@@ -20,7 +20,11 @@ bool CreateMcuManager(void);
bool DestroyMcuManager(void);
enum class IpcMission
{
- TEST = 0,
+ PIR_TRIGGERED = 0,
+ TEST,
+ CONTINUOUS_SHOOTING,
+ PIR_TRIGGERED_DELAY,
+ REGULAR_START,
END
};
enum class ASK_RESULT
diff --git a/utils/McuProtocol/src/ProtocolHandle.cpp b/utils/McuProtocol/src/ProtocolHandle.cpp
index 2acd737..8e2d447 100644
--- a/utils/McuProtocol/src/ProtocolHandle.cpp
+++ b/utils/McuProtocol/src/ProtocolHandle.cpp
@@ -157,6 +157,11 @@ void ProtocolHandle::AnalyzeProtocolPacket(void)
LogError("CheckoutTheCheckCode failed.\n");
return;
}
+ /**
+ * @brief unsigned int number = packet.mSerialNumber This line of code is for
+ * avoiding errors: runtime error: reference binding to misaligned address xxxx
+ */
+ mProtocolSerialNumber = packet.mSerialNumber;
LogInfo("AnalyzeProtocolPacket, command = 0x%04X\n", packet.mCommand);
PROTOCOL_COMMAND command = static_cast(packet.mCommand);
std::map::iterator iter;
@@ -174,11 +179,6 @@ unsigned char ProtocolHandle::ReplyOneBytePacketResult(const ProtocolPacket &pac
constexpr unsigned int PROTOCOL_DATA_START_ADDRESS = KEY_HEAD_LENGTH;
unsigned char replyResult = UNKNOWN_RESULT;
replyResult = mProtocolData[PROTOCOL_DATA_START_ADDRESS];
- /**
- * @brief unsigned int number = packet.mSerialNumber This line of code is for
- * avoiding errors: runtime error: reference binding to misaligned address xxxx
- */
- mProtocolSerialNumber = packet.mSerialNumber;
LogInfo("reply result = 0x%02X\n", replyResult);
return replyResult;
}