把 business 层改名为 logic 层,入口改为 mcu_logic,避免 business 语义不清。

目录 business/ → logic/,mcu_business → mcu_logic;Makefile、工程文件和打包脚本里的路径一并改掉。
This commit is contained in:
2026-09-12 10:21:50 +08:00
parent 1972a1fb58
commit 6cee0c36c3
24 changed files with 161 additions and 158 deletions
+14 -14
View File
@@ -176,7 +176,7 @@
<Add directory="apps/usr_le_code/thirdpart" /> <Add directory="apps/usr_le_code/thirdpart" />
<Add directory="apps/usr_mcu_bridge" /> <Add directory="apps/usr_mcu_bridge" />
<Add directory="apps/usr_mcu_bridge/protocol" /> <Add directory="apps/usr_mcu_bridge/protocol" />
<Add directory="apps/usr_mcu_bridge/business" /> <Add directory="apps/usr_mcu_bridge/logic" />
<Add directory="apps/usr_ota" /> <Add directory="apps/usr_ota" />
<Add directory="apps/usr_periph" /> <Add directory="apps/usr_periph" />
</Compiler> </Compiler>
@@ -787,41 +787,41 @@
<Unit filename="apps/usr_le_code/usr_le_recieve.c"> <Unit filename="apps/usr_le_code/usr_le_recieve.c">
<Option compilerVar="CC" /> <Option compilerVar="CC" />
</Unit> </Unit>
<Unit filename="apps/usr_mcu_bridge/business/mcu_business.c"> <Unit filename="apps/usr_mcu_bridge/logic/mcu_logic.c">
<Option compilerVar="CC" /> <Option compilerVar="CC" />
</Unit> </Unit>
<Unit filename="apps/usr_mcu_bridge/business/mcu_business.h" /> <Unit filename="apps/usr_mcu_bridge/logic/mcu_logic.h" />
<Unit filename="apps/usr_mcu_bridge/business/mcu_identity.c"> <Unit filename="apps/usr_mcu_bridge/logic/mcu_identity.c">
<Option compilerVar="CC" /> <Option compilerVar="CC" />
</Unit> </Unit>
<Unit filename="apps/usr_mcu_bridge/business/mcu_identity.h" /> <Unit filename="apps/usr_mcu_bridge/logic/mcu_identity.h" />
<Unit filename="apps/usr_mcu_bridge/business/mcu_link_status.c"> <Unit filename="apps/usr_mcu_bridge/logic/mcu_link_status.c">
<Option compilerVar="CC" /> <Option compilerVar="CC" />
</Unit> </Unit>
<Unit filename="apps/usr_mcu_bridge/business/mcu_link_status.h" /> <Unit filename="apps/usr_mcu_bridge/logic/mcu_link_status.h" />
<Unit filename="apps/usr_mcu_bridge/business/mcu_mgmt.c"> <Unit filename="apps/usr_mcu_bridge/logic/mcu_mgmt.c">
<Option compilerVar="CC" /> <Option compilerVar="CC" />
</Unit> </Unit>
<Unit filename="apps/usr_mcu_bridge/business/mcu_ota.c"> <Unit filename="apps/usr_mcu_bridge/logic/mcu_ota.c">
<Option compilerVar="CC" /> <Option compilerVar="CC" />
</Unit> </Unit>
<Unit filename="apps/usr_mcu_bridge/business/mcu_ota.h" /> <Unit filename="apps/usr_mcu_bridge/logic/mcu_ota.h" />
<Unit filename="apps/usr_ota/usr_ota.c"> <Unit filename="apps/usr_ota/usr_ota.c">
<Option compilerVar="CC" /> <Option compilerVar="CC" />
</Unit> </Unit>
<Unit filename="apps/usr_ota/usr_ota.h" /> <Unit filename="apps/usr_ota/usr_ota.h" />
<Unit filename="apps/usr_mcu_bridge/business/mcu_pairing.c"> <Unit filename="apps/usr_mcu_bridge/logic/mcu_pairing.c">
<Option compilerVar="CC" /> <Option compilerVar="CC" />
</Unit> </Unit>
<Unit filename="apps/usr_mcu_bridge/business/mcu_pairing.h" /> <Unit filename="apps/usr_mcu_bridge/logic/mcu_pairing.h" />
<Unit filename="apps/usr_mcu_bridge/business/mcu_time.c"> <Unit filename="apps/usr_mcu_bridge/logic/mcu_time.c">
<Option compilerVar="CC" /> <Option compilerVar="CC" />
</Unit> </Unit>
<Unit filename="apps/usr_periph/usr_rtc.c"> <Unit filename="apps/usr_periph/usr_rtc.c">
<Option compilerVar="CC" /> <Option compilerVar="CC" />
</Unit> </Unit>
<Unit filename="apps/usr_periph/usr_rtc.h" /> <Unit filename="apps/usr_periph/usr_rtc.h" />
<Unit filename="apps/usr_mcu_bridge/business/mcu_version.c"> <Unit filename="apps/usr_mcu_bridge/logic/mcu_version.c">
<Option compilerVar="CC" /> <Option compilerVar="CC" />
</Unit> </Unit>
<Unit filename="apps/usr_mcu_bridge/mcu_bridge.c"> <Unit filename="apps/usr_mcu_bridge/mcu_bridge.c">
+9 -9
View File
@@ -262,7 +262,7 @@ INCLUDES := \
-Iapps/usr_le_code/thirdpart/mjson \ -Iapps/usr_le_code/thirdpart/mjson \
-Iapps/usr_mcu_bridge \ -Iapps/usr_mcu_bridge \
-Iapps/usr_mcu_bridge/protocol \ -Iapps/usr_mcu_bridge/protocol \
-Iapps/usr_mcu_bridge/business \ -Iapps/usr_mcu_bridge/logic \
-Iapps/usr_ota \ -Iapps/usr_ota \
-Iapps/usr_periph \ -Iapps/usr_periph \
-I$(SYS_INC_DIR) \ -I$(SYS_INC_DIR) \
@@ -400,16 +400,16 @@ c_SRC_FILES := \
apps/usr_le_code/thirdpart/mjson/mjson.c \ apps/usr_le_code/thirdpart/mjson/mjson.c \
apps/usr_le_code/usr_le_adv.c \ apps/usr_le_code/usr_le_adv.c \
apps/usr_le_code/usr_le_recieve.c \ apps/usr_le_code/usr_le_recieve.c \
apps/usr_mcu_bridge/business/mcu_business.c \ apps/usr_mcu_bridge/logic/mcu_logic.c \
apps/usr_mcu_bridge/business/mcu_identity.c \ apps/usr_mcu_bridge/logic/mcu_identity.c \
apps/usr_mcu_bridge/business/mcu_link_status.c \ apps/usr_mcu_bridge/logic/mcu_link_status.c \
apps/usr_mcu_bridge/business/mcu_mgmt.c \ apps/usr_mcu_bridge/logic/mcu_mgmt.c \
apps/usr_mcu_bridge/business/mcu_ota.c \ apps/usr_mcu_bridge/logic/mcu_ota.c \
apps/usr_ota/usr_ota.c \ apps/usr_ota/usr_ota.c \
apps/usr_mcu_bridge/business/mcu_pairing.c \ apps/usr_mcu_bridge/logic/mcu_pairing.c \
apps/usr_mcu_bridge/business/mcu_time.c \ apps/usr_mcu_bridge/logic/mcu_time.c \
apps/usr_periph/usr_rtc.c \ apps/usr_periph/usr_rtc.c \
apps/usr_mcu_bridge/business/mcu_version.c \ apps/usr_mcu_bridge/logic/mcu_version.c \
apps/usr_mcu_bridge/mcu_bridge.c \ apps/usr_mcu_bridge/mcu_bridge.c \
apps/usr_mcu_bridge/protocol/mcu_frame.c \ apps/usr_mcu_bridge/protocol/mcu_frame.c \
apps/usr_mcu_bridge/protocol/mcu_protocol.c \ apps/usr_mcu_bridge/protocol/mcu_protocol.c \
@@ -8,7 +8,7 @@
* - V1.0.0, 2026.08.03, cyWu, 首次发布 * - V1.0.0, 2026.08.03, cyWu, 首次发布
* - V1.1.0, 2026.08.06, cyWu, 改为非 const,由 mcu_bridge 从 MCU 0x02 写入 * - V1.1.0, 2026.08.06, cyWu, 改为非 const,由 mcu_bridge 从 MCU 0x02 写入
* - V1.2.0, 2026.08.12, cyWu, 改由 mcu_link 从 MCU 0x02 写入 * - V1.2.0, 2026.08.12, cyWu, 改由 mcu_link 从 MCU 0x02 写入
* - V1.3.0, 2026.08.12, cyWu, 改由 business/mcu_identity 从 MCU 0x02 写入 * - V1.3.0, 2026.08.12, cyWu, 改由 logic/mcu_identity 从 MCU 0x02 写入
******************************************************************************/ ******************************************************************************/
#ifndef __USR_LE_PRODUCT_H__ #ifndef __USR_LE_PRODUCT_H__
@@ -32,13 +32,13 @@ extern "C" {
/** /**
* @brief 产品类别码,对应 BLE 广播 prodcode(固定 4 字节 ASCII * @brief 产品类别码,对应 BLE 广播 prodcode(固定 4 字节 ASCII
* @note 由 business/mcu_identity 从 MCU 身份应答取前 4 字节写入 * @note 由 logic/mcu_identity 从 MCU 身份应答取前 4 字节写入
*/ */
extern uint8_t g_usr_le_prodcode[USR_LE_PRODCODE_LEN]; extern uint8_t g_usr_le_prodcode[USR_LE_PRODCODE_LEN];
/** /**
* @brief 平台产品码,对应 BLE 广播 pcode(固定 6 字节 ASCII * @brief 平台产品码,对应 BLE 广播 pcode(固定 6 字节 ASCII
* @note 由 business/mcu_identity 从 MCU 身份应答取前 6 字节写入 * @note 由 logic/mcu_identity 从 MCU 身份应答取前 6 字节写入
*/ */
extern uint8_t g_usr_le_pcode[USR_LE_PCODE_LEN]; extern uint8_t g_usr_le_pcode[USR_LE_PCODE_LEN];
@@ -1,19 +1,20 @@
/****************************************************************************** /******************************************************************************
* @file mcu_business.c * @file mcu_logic.c
* @brief * @brief
* @author cyWu <1917507415@qq.com> * @author cyWu <1917507415@qq.com>
* @date 2026.09.11 * @date 2026.09.11
* @version V1.3.0 * @version V1.4.0
* @history * @history
* - V1.0.0, 2026.08.12, cyWu, mcu_link * - V1.0.0, 2026.08.12, cyWu, mcu_link
* - V1.1.0, 2026.08.13, cyWu, P1 // * - V1.1.0, 2026.08.13, cyWu, P1 //
* - V1.2.0, 2026.08.15, cyWu, P2 OTA OTA * - V1.2.0, 2026.08.15, cyWu, P2 OTA OTA
* - V1.3.0, 2026.09.11, cyWu, APP 0x40 mcu_version * - V1.3.0, 2026.09.11, cyWu, APP 0x40 mcu_version
* - V1.4.0, 2026.09.11, cyWu, mcu_business mcu_logic
******************************************************************************/ ******************************************************************************/
#include "system/includes.h" #include "system/includes.h"
#include "app_main.h" #include "app_main.h"
#include "mcu_business.h" #include "mcu_logic.h"
#include "mcu_cmd.h" #include "mcu_cmd.h"
#include "mcu_identity.h" #include "mcu_identity.h"
#include "mcu_link_status.h" #include "mcu_link_status.h"
@@ -24,17 +25,17 @@
#include "mcu_ota.h" #include "mcu_ota.h"
#define LOG_TAG_CONST APP #define LOG_TAG_CONST APP
#define LOG_TAG "[MCU_BIZ]" #define LOG_TAG "[MCU_LOGIC]"
#define LOG_ERROR_ENABLE #define LOG_ERROR_ENABLE
#define LOG_INFO_ENABLE #define LOG_INFO_ENABLE
#include "debug.h" #include "debug.h"
/** /**
* @brief * @brief
* @note 广 mcu_identity_on_ack * @note 广 mcu_identity_on_ack
* usr_ble_adv_init * usr_ble_adv_init
*/ */
void mcu_business_init(void) void mcu_logic_init(void)
{ {
mcu_identity_init(); mcu_identity_init();
mcu_pairing_init(); mcu_pairing_init();
@@ -51,7 +52,7 @@ void mcu_business_init(void)
/** /**
* @brief * @brief
*/ */
void mcu_business_periodic(void) void mcu_logic_periodic(void)
{ {
mcu_identity_periodic(); mcu_identity_periodic();
mcu_link_status_periodic(); mcu_link_status_periodic();
@@ -69,7 +70,7 @@ void mcu_business_periodic(void)
* @brief * @brief
* @return 1/0 * @return 1/0
*/ */
uint8_t mcu_business_is_identity_ready(void) uint8_t mcu_logic_is_identity_ready(void)
{ {
return mcu_identity_is_ready(); return mcu_identity_is_ready();
} }
@@ -78,7 +79,7 @@ uint8_t mcu_business_is_identity_ready(void)
* @brief * @brief
* @return work_status * @return work_status
*/ */
uint8_t mcu_business_get_work_status(void) uint8_t mcu_logic_get_work_status(void)
{ {
return mcu_link_status_get(); return mcu_link_status_get();
} }
@@ -88,7 +89,7 @@ uint8_t mcu_business_get_work_status(void)
* @param frame * @param frame
* @param len * @param len
*/ */
void mcu_business_on_identity_ack(const uint8_t *frame, uint16_t len) void mcu_logic_on_identity_ack(const uint8_t *frame, uint16_t len)
{ {
mcu_identity_on_ack(frame, len); mcu_identity_on_ack(frame, len);
} }
@@ -98,7 +99,7 @@ void mcu_business_on_identity_ack(const uint8_t *frame, uint16_t len)
* @param mode * @param mode
* @param timeout_s * @param timeout_s
*/ */
void mcu_business_on_pair_cfg(uint8_t mode, uint16_t timeout_s) void mcu_logic_on_pair_cfg(uint8_t mode, uint16_t timeout_s)
{ {
mcu_pairing_start(mode, timeout_s); mcu_pairing_start(mode, timeout_s);
} }
@@ -106,7 +107,7 @@ void mcu_business_on_pair_cfg(uint8_t mode, uint16_t timeout_s)
/** /**
* @brief * @brief
*/ */
void mcu_business_on_paired(void) void mcu_logic_on_paired(void)
{ {
usr_var.usr_goto_pair = 0; usr_var.usr_goto_pair = 0;
mcu_pairing_stop(); mcu_pairing_stop();
@@ -121,7 +122,7 @@ void mcu_business_on_paired(void)
* @note phase==PAIRING * @note phase==PAIRING
* *
*/ */
void mcu_business_on_pair_cleared(void) void mcu_logic_on_pair_cleared(void)
{ {
/* 正在走 0x10 配网:清配对表是配网流程的一部分,过程态保持 PAIRING。 /* 正在走 0x10 配网:清配对表是配网流程的一部分,过程态保持 PAIRING。
* */ * */
@@ -134,7 +135,7 @@ void mcu_business_on_pair_cleared(void)
/** /**
* @brief * @brief
*/ */
void mcu_business_on_factory_reset(void) void mcu_logic_on_factory_reset(void)
{ {
mcu_mgmt_on_factory_reset(); mcu_mgmt_on_factory_reset();
} }
@@ -142,7 +143,7 @@ void mcu_business_on_factory_reset(void)
/** /**
* @brief * @brief
*/ */
void mcu_business_on_mod_reboot(void) void mcu_logic_on_mod_reboot(void)
{ {
mcu_mgmt_on_mod_reboot(); mcu_mgmt_on_mod_reboot();
} }
@@ -152,7 +153,7 @@ void mcu_business_on_mod_reboot(void)
* @param frame * @param frame
* @param len * @param len
*/ */
void mcu_business_on_mcu_reboot_ack(const uint8_t *frame, uint16_t len) void mcu_logic_on_mcu_reboot_ack(const uint8_t *frame, uint16_t len)
{ {
mcu_mgmt_on_mcu_reboot_ack(frame, len); mcu_mgmt_on_mcu_reboot_ack(frame, len);
} }
@@ -162,7 +163,7 @@ void mcu_business_on_mcu_reboot_ack(const uint8_t *frame, uint16_t len)
* @param payload * @param payload
* @param plen * @param plen
*/ */
void mcu_business_build_time_ack(uint8_t *payload, uint16_t *plen) void mcu_logic_build_time_ack(uint8_t *payload, uint16_t *plen)
{ {
mcu_time_build_ack(payload, plen); mcu_time_build_ack(payload, plen);
} }
@@ -172,7 +173,7 @@ void mcu_business_build_time_ack(uint8_t *payload, uint16_t *plen)
* @param unix_s UTC Unix * @param unix_s UTC Unix
* @param gmtoff_s * @param gmtoff_s
*/ */
void mcu_business_on_network_time(uint64_t unix_s, int32_t gmtoff_s) void mcu_logic_on_network_time(uint64_t unix_s, int32_t gmtoff_s)
{ {
mcu_time_set_from_gateway(unix_s, gmtoff_s); mcu_time_set_from_gateway(unix_s, gmtoff_s);
} }
@@ -182,7 +183,7 @@ void mcu_business_on_network_time(uint64_t unix_s, int32_t gmtoff_s)
* @param frame * @param frame
* @param len * @param len
*/ */
void mcu_business_on_mcu_info_ack(const uint8_t *frame, uint16_t len) void mcu_logic_on_mcu_info_ack(const uint8_t *frame, uint16_t len)
{ {
mcu_version_on_mcu_info_ack(frame, len); mcu_version_on_mcu_info_ack(frame, len);
} }
@@ -191,7 +192,7 @@ void mcu_business_on_mcu_info_ack(const uint8_t *frame, uint16_t len)
* @brief APP 0x40 * @brief APP 0x40
* @param sn * @param sn
*/ */
void mcu_business_on_app_get_mcu_info(uint8_t sn) void mcu_logic_on_app_get_mcu_info(uint8_t sn)
{ {
mcu_version_on_app_query(sn); mcu_version_on_app_query(sn);
} }
@@ -201,7 +202,7 @@ void mcu_business_on_app_get_mcu_info(uint8_t sn)
* @param success * @param success
* @param mcu_report_consumed MCU 0x07 * @param mcu_report_consumed MCU 0x07
*/ */
void mcu_business_on_gateway_ack(uint8_t success, uint8_t mcu_report_consumed) void mcu_logic_on_gateway_ack(uint8_t success, uint8_t mcu_report_consumed)
{ {
mcu_version_on_gateway_ack(success, mcu_report_consumed); mcu_version_on_gateway_ack(success, mcu_report_consumed);
} }
@@ -209,7 +210,7 @@ void mcu_business_on_gateway_ack(uint8_t success, uint8_t mcu_report_consumed)
/** /**
* @brief APP OTA * @brief APP OTA
*/ */
void mcu_business_on_app_ota_frame(const uint8_t *frame, uint16_t len) void mcu_logic_on_app_ota_frame(const uint8_t *frame, uint16_t len)
{ {
mcu_ota_on_app_frame(frame, len); mcu_ota_on_app_frame(frame, len);
} }
@@ -217,7 +218,7 @@ void mcu_business_on_app_ota_frame(const uint8_t *frame, uint16_t len)
/** /**
* @brief MCU OTA * @brief MCU OTA
*/ */
void mcu_business_on_mcu_ota_frame(const uint8_t *frame, uint16_t len) void mcu_logic_on_mcu_ota_frame(const uint8_t *frame, uint16_t len)
{ {
mcu_ota_on_uart_frame(frame, len); mcu_ota_on_uart_frame(frame, len);
} }
@@ -225,7 +226,7 @@ void mcu_business_on_mcu_ota_frame(const uint8_t *frame, uint16_t len)
/** /**
* @brief 0x15 * @brief 0x15
*/ */
void mcu_business_on_ota_ws_ack(void) void mcu_logic_on_ota_ws_ack(void)
{ {
mcu_ota_on_work_status_ack(); mcu_ota_on_work_status_ack();
} }
@@ -233,7 +234,7 @@ void mcu_business_on_ota_ws_ack(void)
/** /**
* @brief BLE * @brief BLE
*/ */
void mcu_business_on_ble_disconnected(void) void mcu_logic_on_ble_disconnected(void)
{ {
mcu_ota_on_disconnect(); mcu_ota_on_disconnect();
} }
@@ -242,7 +243,7 @@ void mcu_business_on_ble_disconnected(void)
* @brief OTA * @brief OTA
* @return 1/0 * @return 1/0
*/ */
uint8_t mcu_business_ota_is_active(void) uint8_t mcu_logic_ota_is_active(void)
{ {
return mcu_ota_is_active(); return mcu_ota_is_active();
} }
@@ -251,7 +252,7 @@ uint8_t mcu_business_ota_is_active(void)
* @brief OTA * @brief OTA
* @return 1/0 * @return 1/0
*/ */
uint8_t mcu_business_ota_is_ble_active(void) uint8_t mcu_logic_ota_is_ble_active(void)
{ {
return mcu_ota_is_ble_active(); return mcu_ota_is_ble_active();
} }
@@ -1,25 +1,26 @@
/****************************************************************************** /******************************************************************************
* @file mcu_business.h * @file mcu_logic.h
* @brief / / / / / * @brief / / / OTA
* @author cyWu <1917507415@qq.com> * @author cyWu <1917507415@qq.com>
* @date 2026.09.11 * @date 2026.09.11
* @version V1.3.0 * @version V1.4.0
* @history * @history
* - V1.0.0, 2026.08.12, cyWu, mcu_linkmcu_protocol * - V1.0.0, 2026.08.12, cyWu, mcu_linkmcu_protocol
* identity/pairing/link_status * identity/pairing/link_status
* - V1.1.0, 2026.08.13, cyWu, P1 // * - V1.1.0, 2026.08.13, cyWu, P1 //
* - V1.2.0, 2026.08.15, cyWu, P2 OTA访 OTA * - V1.2.0, 2026.08.15, cyWu, P2 OTA访 OTA
* - V1.3.0, 2026.09.11, cyWu, APP 0x40 UART * - V1.3.0, 2026.09.11, cyWu, APP 0x40 UART
* - V1.4.0, 2026.09.11, cyWu, mcu_business mcu_logic
******************************************************************************/ ******************************************************************************/
#ifndef __MCU_BUSINESS_H__ #ifndef __MCU_LOGIC_H__
#define __MCU_BUSINESS_H__ #define __MCU_LOGIC_H__
#include <stdint.h> #include <stdint.h>
/*============================================================================*/ /*============================================================================*/
/* 说明 */ /* 说明 */
/* 本模块只做业务编排,不含具体状态具体逻辑见: */ /* 本文件只做转发,不存状态具体功能见: */
/* mcu_identity.c —— 身份获取 */ /* mcu_identity.c —— 身份获取 */
/* mcu_pairing.c —— 配网请求 / 超时 */ /* mcu_pairing.c —— 配网请求 / 超时 */
/* mcu_link_status.c —— 连接状态位图(Bit0/1/2) */ /* mcu_link_status.c —— 连接状态位图(Bit0/1/2) */
@@ -31,74 +32,74 @@
/*============================================================================*/ /*============================================================================*/
/** /**
* @brief * @brief
*/ */
void mcu_business_init(void); void mcu_logic_init(void);
/** /**
* @brief * @brief
*/ */
void mcu_business_periodic(void); void mcu_logic_periodic(void);
/** /**
* @brief MCU * @brief MCU
* @return 1=0= * @return 1=0=
*/ */
uint8_t mcu_business_is_identity_ready(void); uint8_t mcu_logic_is_identity_ready(void);
/** /**
* @brief 0x14 * @brief 0x14
* @return bitmap * @return bitmap
*/ */
uint8_t mcu_business_get_work_status(void); uint8_t mcu_logic_get_work_status(void);
/** /**
* @brief 0x02 * @brief 0x02
* @param frame * @param frame
* @param len * @param len
*/ */
void mcu_business_on_identity_ack(const uint8_t *frame, uint16_t len); void mcu_logic_on_identity_ack(const uint8_t *frame, uint16_t len);
/** /**
* @brief 0x10 * @brief 0x10
* @param mode 1 2 * @param mode 1 2
* @param timeout_s 0 * @param timeout_s 0
*/ */
void mcu_business_on_pair_cfg(uint8_t mode, uint16_t timeout_s); void mcu_logic_on_pair_cfg(uint8_t mode, uint16_t timeout_s);
/** /**
* @brief AUTHSETUP * @brief AUTHSETUP
*/ */
void mcu_business_on_paired(void); void mcu_logic_on_paired(void);
/** /**
* @brief * @brief
*/ */
void mcu_business_on_pair_cleared(void); void mcu_logic_on_pair_cleared(void);
/** /**
* @brief MCU ACK * @brief MCU ACK
*/ */
void mcu_business_on_factory_reset(void); void mcu_logic_on_factory_reset(void);
/** /**
* @brief MCU ACK * @brief MCU ACK
*/ */
void mcu_business_on_mod_reboot(void); void mcu_logic_on_mod_reboot(void);
/** /**
* @brief UART 0x1B * @brief UART 0x1B
* @param frame * @param frame
* @param len * @param len
*/ */
void mcu_business_on_mcu_reboot_ack(const uint8_t *frame, uint16_t len); void mcu_logic_on_mcu_reboot_ack(const uint8_t *frame, uint16_t len);
/** /**
* @brief 0x1D * @brief 0x1D
* @param payload * @param payload
* @param plen * @param plen
*/ */
void mcu_business_build_time_ack(uint8_t *payload, uint16_t *plen); void mcu_logic_build_time_ack(uint8_t *payload, uint16_t *plen);
/** /**
* @brief * @brief
@@ -106,30 +107,30 @@ void mcu_business_build_time_ack(uint8_t *payload, uint16_t *plen);
* @param gmtoff_s * @param gmtoff_s
* @note 12 * @note 12
*/ */
void mcu_business_on_network_time(uint64_t unix_s, int32_t gmtoff_s); void mcu_logic_on_network_time(uint64_t unix_s, int32_t gmtoff_s);
/** /**
* @brief UART 0x41 * @brief UART 0x41
* @param frame * @param frame
* @param len * @param len
*/ */
void mcu_business_on_mcu_info_ack(const uint8_t *frame, uint16_t len); void mcu_logic_on_mcu_info_ack(const uint8_t *frame, uint16_t len);
/** /**
* @brief APP 0x40 UART * @brief APP 0x40 UART
* @param sn APP * @param sn APP
*/ */
void mcu_business_on_app_get_mcu_info(uint8_t sn); void mcu_logic_on_app_get_mcu_info(uint8_t sn);
/** /**
* @brief REPORTCMD_V2 * @brief REPORTCMD_V2
* @param success 1= * @param success 1=
* @param mcu_report_consumed 1= MCU 0x07 0x08 * @param mcu_report_consumed 1= MCU 0x07 0x08
*/ */
void mcu_business_on_gateway_ack(uint8_t success, uint8_t mcu_report_consumed); void mcu_logic_on_gateway_ack(uint8_t success, uint8_t mcu_report_consumed);
/*============================================================================*/ /*============================================================================*/
/* OTA(协议层只调门面,不直接 include mcu_ota.h */ /* OTA(协议层只调本入口,不直接 include mcu_ota.h */
/*============================================================================*/ /*============================================================================*/
/** /**
@@ -137,35 +138,35 @@ void mcu_business_on_gateway_ack(uint8_t success, uint8_t mcu_report_consumed);
* @param frame 55AA * @param frame 55AA
* @param len * @param len
*/ */
void mcu_business_on_app_ota_frame(const uint8_t *frame, uint16_t len); void mcu_logic_on_app_ota_frame(const uint8_t *frame, uint16_t len);
/** /**
* @brief MCU OTA 0x31/0x33/0x34/0x37/0x38 * @brief MCU OTA 0x31/0x33/0x34/0x37/0x38
* @param frame 55AA * @param frame 55AA
* @param len * @param len
*/ */
void mcu_business_on_mcu_ota_frame(const uint8_t *frame, uint16_t len); void mcu_logic_on_mcu_ota_frame(const uint8_t *frame, uint16_t len);
/** /**
* @brief UART 0x15 BLE OTA Bit6 * @brief UART 0x15 BLE OTA Bit6
*/ */
void mcu_business_on_ota_ws_ack(void); void mcu_logic_on_ota_ws_ack(void);
/** /**
* @brief BLE OTA bank * @brief BLE OTA bank
*/ */
void mcu_business_on_ble_disconnected(void); void mcu_logic_on_ble_disconnected(void);
/** /**
* @brief OTA /0x14/ * @brief OTA /0x14/
* @return 1= * @return 1=
*/ */
uint8_t mcu_business_ota_is_active(void); uint8_t mcu_logic_ota_is_active(void);
/** /**
* @brief BLEOTA MCU 0x07 * @brief BLEOTA MCU 0x07
* @return 1= * @return 1=
*/ */
uint8_t mcu_business_ota_is_ble_active(void); uint8_t mcu_logic_ota_is_ble_active(void);
#endif /* __MCU_BUSINESS_H__ */ #endif /* __MCU_LOGIC_H__ */
@@ -91,7 +91,7 @@ void mcu_pairing_periodic(void)
if (s_pairing.timeout_s == 0) { if (s_pairing.timeout_s == 0) {
return; return;
} }
/* 已经配上:切态由 mcu_business_on_paired 做,这里别抢 */ /* 已经配上:切态由 mcu_logic_on_paired 做,这里别抢 */
if (usr_get_pair_flag()) { if (usr_get_pair_flag()) {
return; return;
} }
@@ -2,8 +2,8 @@
* @file mcu_bridge.c * @file mcu_bridge.c
* @brief BLE+MCU 接入模块对外总入口实现(组合门面,仅转调) * @brief BLE+MCU 接入模块对外总入口实现(组合门面,仅转调)
* @author cyWu <1917507415@qq.com> * @author cyWu <1917507415@qq.com>
* @date 2026.08.13 * @date 2026.09.11
* @version V2.1.0 * @version V2.3.0
* @history * @history
* - V1.0.0, 2026.08.06, cyWu, 首次发布 * - V1.0.0, 2026.08.06, cyWu, 首次发布
* - V1.1.0, 2026.08.06, cyWu, 改为事件队列 + 独立任务驱动 * - V1.1.0, 2026.08.06, cyWu, 改为事件队列 + 独立任务驱动
@@ -13,11 +13,12 @@
* - V2.0.0, 2026.08.12, cyWu, 拆分为 protocol/ + business/ 分层, * - V2.0.0, 2026.08.12, cyWu, 拆分为 protocol/ + business/ 分层,
* 本文件收敛为纯组合门面,不再持有任何状态 * 本文件收敛为纯组合门面,不再持有任何状态
* - V2.1.0, 2026.08.13, cyWu, P1 增加网络时间入口 * - V2.1.0, 2026.08.13, cyWu, P1 增加网络时间入口
* - V2.3.0, 2026.09.11, cyWu, 转调 mcu_logic(原 mcu_business
******************************************************************************/ ******************************************************************************/
#include "mcu_bridge.h" #include "mcu_bridge.h"
#include "mcu_protocol.h" #include "mcu_protocol.h"
#include "mcu_business.h" #include "mcu_logic.h"
/** /**
* @brief 初始化 MCU 接入模块 * @brief 初始化 MCU 接入模块
@@ -45,15 +46,15 @@ void mcu_bridge_on_app_frame(const uint8_t *data, uint16_t len)
} }
/** /**
* @brief 身份是否就绪,转调业务门面 * @brief 身份是否就绪,转调逻辑层
*/ */
uint8_t mcu_bridge_is_identity_ready(void) uint8_t mcu_bridge_is_identity_ready(void)
{ {
return mcu_business_is_identity_ready(); return mcu_logic_is_identity_ready();
} }
/** /**
* @brief 配网成功:经协议层事件队列串行化,再转业务门面处理 * @brief 配网成功:经协议层事件队列串行化,再转逻辑层处理
*/ */
void mcu_bridge_on_paired(void) void mcu_bridge_on_paired(void)
{ {
@@ -69,11 +70,11 @@ void mcu_bridge_on_pair_cleared(void)
} }
/** /**
* @brief 获取工作状态,转调业务门面 * @brief 获取工作状态,转调逻辑层
*/ */
uint8_t mcu_bridge_get_work_status(void) uint8_t mcu_bridge_get_work_status(void)
{ {
return mcu_business_get_work_status(); return mcu_logic_get_work_status();
} }
/** /**
@@ -99,7 +100,7 @@ void mcu_bridge_on_network_time(uint64_t unix_s, int32_t gmtoff_s)
*/ */
void mcu_bridge_on_ble_disconnected(void) void mcu_bridge_on_ble_disconnected(void)
{ {
if (!mcu_business_ota_is_active()) { if (!mcu_logic_ota_is_active()) {
return; return;
} }
mcu_protocol_notify_disconnected(); mcu_protocol_notify_disconnected();
@@ -111,5 +112,5 @@ void mcu_bridge_on_ble_disconnected(void)
*/ */
uint8_t mcu_bridge_ota_is_active(void) uint8_t mcu_bridge_ota_is_active(void)
{ {
return mcu_business_ota_is_active(); return mcu_logic_ota_is_active();
} }
@@ -2,8 +2,8 @@
* @file mcu_bridge.h * @file mcu_bridge.h
* @brief BLE+MCU 接入模块对外总入口(组合门面) * @brief BLE+MCU 接入模块对外总入口(组合门面)
* @author cyWu <1917507415@qq.com> * @author cyWu <1917507415@qq.com>
* @date 2026.08.13 * @date 2026.09.11
* @version V2.1.0 * @version V2.3.0
* @history * @history
* - V1.0.0, 2026.08.06, cyWu, 首次发布 * - V1.0.0, 2026.08.06, cyWu, 首次发布
* - V1.1.0, 2026.08.06, cyWu, 内部改为事件队列 + 独立任务驱动 * - V1.1.0, 2026.08.06, cyWu, 内部改为事件队列 + 独立任务驱动
@@ -13,6 +13,7 @@
* 外部调用方(app_main.c / usr_le_adv.c / usr_le_recieve.c 等)无需改动 * 外部调用方(app_main.c / usr_le_adv.c / usr_le_recieve.c 等)无需改动
* - V2.1.0, 2026.08.13, cyWu, P1 增加网络时间入口;业务子模块扩到管理/对时/版本 * - V2.1.0, 2026.08.13, cyWu, P1 增加网络时间入口;业务子模块扩到管理/对时/版本
* - V2.2.0, 2026.08.15, cyWu, P2 OTA 入口走本门面,usr_le_code 不再 include mcu_ota.h * - V2.2.0, 2026.08.15, cyWu, P2 OTA 入口走本门面,usr_le_code 不再 include mcu_ota.h
* - V2.3.0, 2026.09.11, cyWu, business 更名为 logic(逻辑层),入口改为 mcu_logic
******************************************************************************/ ******************************************************************************/
#ifndef __MCU_BRIDGE_H__ #ifndef __MCU_BRIDGE_H__
@@ -26,28 +27,28 @@
/* */ /* */
/* apps/usr_mcu_bridge/ */ /* apps/usr_mcu_bridge/ */
/* ├── mcu_bridge.c/h —— 本文件:组合根,稳定对外 API */ /* ├── mcu_bridge.c/h —— 本文件:组合根,稳定对外 API */
/* ├── protocol/ —— 协议层:只做协议机制,不含业务判断 */ /* ├── protocol/ —— 协议层:组帧、收发、ACK、心跳,不管具体功能 */
/* │ ├── mcu_cmd.h 命令字 / 结果码 / work_status 位定义 */ /* │ ├── mcu_cmd.h 命令字 / 结果码 / work_status 位定义 */
/* │ ├── mcu_frame.c/h 55AA 组帧/解帧 */ /* │ ├── mcu_frame.c/h 55AA 组帧/解帧 */
/* │ ├── mcu_uart.c/h UART 收发驱动 */ /* │ ├── mcu_uart.c/h UART 收发驱动 */
/* │ ├── mcu_util.c/h 校验和/大端序/毫秒工具 */ /* │ ├── mcu_util.c/h 校验和/大端序/毫秒工具 */
/* │ └── mcu_protocol.c/h 事件队列/任务/分发/ACK/透传重传/心跳 */ /* │ └── mcu_protocol.c/h 事件队列/任务/分发/ACK/透传重传/心跳 */
/* └── business/ —— 业务层:按业务拆分,互不直接依赖对方实现 */ /* └── logic/ —— 逻辑层:配网、版本、OTA 等具体功能 */
/* ├── mcu_identity.c/h 身份业务0x01/0x02 */ /* ├── mcu_identity.c/h 身份(0x01/0x02 */
/* ├── mcu_pairing.c/h 配网业务(0x10、超时) */ /* ├── mcu_pairing.c/h 配网(0x10、超时) */
/* ├── mcu_link_status.c/h 连接状态业务Bit0/1/2/6 位图 */ /* ├── mcu_link_status.c/h 连接状态位图Bit0/1/2/6 */
/* ├── mcu_mgmt.c/h 模组管理(0x16/0x18/0x1A */ /* ├── mcu_mgmt.c/h 模组管理(0x16/0x18/0x1A */
/* ├── mcu_time.c/h 对时(0x1C/0x1D,写入 usr_rtc */ /* ├── mcu_time.c/h 对时(0x1C/0x1D,写入 usr_rtc */
/* ├── mcu_version.c/h MCU 信息 + SOC 0x41 上报 */ /* ├── mcu_version.c/h MCU 信息 + SOC 0x41 上报 */
/* ├── mcu_ota.c/h P2 OTAType 分流 / MCU 透传 / Bit6 */ /* ├── mcu_ota.c/h OTAType 分流 / MCU 透传 / Bit6 */
/* └── mcu_business.c/h 业务门面:协调子模块,供协议层调用 */ /* └── mcu_logic.c/h 逻辑层入口:协议层只调这里,再分到各模块 */
/* */ /* */
/* 依赖方向(单向,禁止反向 include): */ /* 依赖方向(单向,禁止反向 include): */
/* usr_le_code / app_main → mcu_bridge.h */ /* usr_le_code / app_main → mcu_bridge.h */
/* mcu_bridge → mcu_protocol + mcu_business(门面) */ /* mcu_bridge → mcu_protocol + mcu_logic */
/* mcu_protocol → mcu_business.h(不 include 业务子模块) */ /* mcu_protocol → mcu_logic.h(不直接 include 各功能模块) */
/* mcu_business 门面 → identity/pairing/link/mgmt/time/version/ota */ /* mcu_logic → identity/pairing/link/mgmt/time/version/ota */
/* 业务子模块互不 include;只经 mcu_protocol_send_* 回调协议层发送 */ /* 功能模块互不 include;只经 mcu_protocol_send_* 回调协议层发送 */
/* mcu_ota → usr_ota(协议无关 dual_bank 引擎,不感知 55AA */ /* mcu_ota → usr_ota(协议无关 dual_bank 引擎,不感知 55AA */
/*============================================================================*/ /*============================================================================*/
@@ -69,7 +70,7 @@ typedef enum {
/*============================================================================*/ /*============================================================================*/
/** /**
* @brief 初始化 MCU 接入模块(组合 protocol + business * @brief 初始化 MCU 接入模块(组合协议层 + 逻辑层
* @return McuBridge_Ret_t * @return McuBridge_Ret_t
*/ */
McuBridge_Ret_t mcu_bridge_init(void); McuBridge_Ret_t mcu_bridge_init(void);
@@ -17,7 +17,7 @@
#include "system/includes.h" #include "system/includes.h"
#include "asm/power/power_api.h" #include "asm/power/power_api.h"
#include "mcu_protocol.h" #include "mcu_protocol.h"
#include "mcu_business.h" #include "mcu_logic.h"
#include "mcu_frame.h" #include "mcu_frame.h"
#include "mcu_uart.h" #include "mcu_uart.h"
#include "mcu_util.h" #include "mcu_util.h"
@@ -230,13 +230,13 @@ static void mcu_protocol_dispatch_event(const McuEvt_t *evt)
mcu_protocol_handle_gateway_ack(evt->gw_cmd, evt->gw_int_cnt, evt->gw_int0); mcu_protocol_handle_gateway_ack(evt->gw_cmd, evt->gw_int_cnt, evt->gw_int0);
break; break;
case MCU_EVT_BLE_PAIRED: case MCU_EVT_BLE_PAIRED:
mcu_business_on_paired(); mcu_logic_on_paired();
break; break;
case MCU_EVT_BLE_PAIR_CLEARED: case MCU_EVT_BLE_PAIR_CLEARED:
mcu_business_on_pair_cleared(); mcu_logic_on_pair_cleared();
break; break;
case MCU_EVT_NET_TIME: case MCU_EVT_NET_TIME:
mcu_business_on_network_time(evt->unix_s, evt->gmtoff_s); mcu_logic_on_network_time(evt->unix_s, evt->gmtoff_s);
break; break;
case MCU_EVT_APP_OTA_DATA: case MCU_EVT_APP_OTA_DATA:
mcu_protocol_handle_app_frame(s_proto.ota_rx.buf, s_proto.ota_rx.len); mcu_protocol_handle_app_frame(s_proto.ota_rx.buf, s_proto.ota_rx.len);
@@ -244,7 +244,7 @@ static void mcu_protocol_dispatch_event(const McuEvt_t *evt)
break; break;
case MCU_EVT_BLE_DISCONNECTED: case MCU_EVT_BLE_DISCONNECTED:
s_proto.disc_posted = 0; s_proto.disc_posted = 0;
mcu_business_on_ble_disconnected(); mcu_logic_on_ble_disconnected();
break; break;
default: default:
log_error("unknown evt type=%d", evt->type); log_error("unknown evt type=%d", evt->type);
@@ -332,7 +332,7 @@ static int32_t mcu_protocol_send_frame(uint8_t cmd, uint8_t sn,
} }
/** /**
* @brief 自动 SN 发送(供 business 层调用) * @brief 自动 SN 发送(供逻辑层调用)
* @param cmd 命令 * @param cmd 命令
* @param payload 载荷 * @param payload 载荷
* @param plen 长度 * @param plen 长度
@@ -468,7 +468,7 @@ void mcu_protocol_invalidate_work_status_push(void)
/*============================================================================*/ /*============================================================================*/
/** /**
* @brief 处理 0x10:协议校验 + ACK,业务交给 business * @brief 处理 0x10:协议校验 + ACK,再交给逻辑
* @param frame 完整帧 * @param frame 完整帧
* @param len 长度 * @param len 长度
*/ */
@@ -493,18 +493,18 @@ static void mcu_protocol_handle_pair_cfg(const uint8_t *frame, uint16_t len)
return; return;
} }
/* 还没拿到 MCU 身份,广播都发不了,回忙让 MCU 稍后再试 */ /* 还没拿到 MCU 身份,广播都发不了,回忙让 MCU 稍后再试 */
if (!mcu_business_is_identity_ready()) if (!mcu_logic_is_identity_ready())
{ {
mcu_protocol_send_ack(MCU_CMD_PAIR_CFG_ACK, sn, MCU_RESULT_BUSY); mcu_protocol_send_ack(MCU_CMD_PAIR_CFG_ACK, sn, MCU_RESULT_BUSY);
return; return;
} }
mcu_protocol_send_ack(MCU_CMD_PAIR_CFG_ACK, sn, MCU_RESULT_OK); mcu_protocol_send_ack(MCU_CMD_PAIR_CFG_ACK, sn, MCU_RESULT_OK);
mcu_business_on_pair_cfg(mode, timeout_s); mcu_logic_on_pair_cfg(mode, timeout_s);
} }
/** /**
* @brief 处理 0x1C:组 0x1D(时间由 business 填充) * @brief 处理 0x1C:组 0x1D(时间由逻辑层填充)
* @param frame 完整帧 * @param frame 完整帧
* @param len 长度 * @param len 长度
*/ */
@@ -520,7 +520,7 @@ static void mcu_protocol_handle_get_time(const uint8_t *frame, uint16_t len)
return; return;
} }
sn = frame[MCU_FRAME_OFF_SN]; sn = frame[MCU_FRAME_OFF_SN];
mcu_business_build_time_ack(payload, &plen); mcu_logic_build_time_ack(payload, &plen);
if (plen == 0) if (plen == 0)
{ {
plen = 1; plen = 1;
@@ -603,19 +603,19 @@ static void mcu_protocol_handle_frame(const uint8_t *frame, uint16_t len)
s_proto.hb_waiting = 0; s_proto.hb_waiting = 0;
s_proto.hb_fail_cnt = 0; s_proto.hb_fail_cnt = 0;
} }
/* 0x41/0x1B 等其余 ACK 继续走 switch,交给 business */ /* 0x41/0x1B 等其余 ACK 继续走 switch,交给逻辑层 */
} }
switch (cmd) switch (cmd)
{ {
case MCU_CMD_GET_IDENTITY_ACK: case MCU_CMD_GET_IDENTITY_ACK:
mcu_business_on_identity_ack(frame, len); mcu_logic_on_identity_ack(frame, len);
break; break;
case MCU_CMD_PAIR_CFG: case MCU_CMD_PAIR_CFG:
mcu_protocol_handle_pair_cfg(frame, len); mcu_protocol_handle_pair_cfg(frame, len);
break; break;
case MCU_CMD_REPORT: case MCU_CMD_REPORT:
if (mcu_business_ota_is_ble_active()) { if (mcu_logic_ota_is_ble_active()) {
log_info("drop MCU 0x07 during BLE OTA"); log_info("drop MCU 0x07 during BLE OTA");
return; return;
} }
@@ -628,45 +628,45 @@ static void mcu_protocol_handle_frame(const uint8_t *frame, uint16_t len)
break; break;
case MCU_CMD_RESET: case MCU_CMD_RESET:
mcu_protocol_send_ack(MCU_CMD_RESET_ACK, sn, MCU_RESULT_OK); mcu_protocol_send_ack(MCU_CMD_RESET_ACK, sn, MCU_RESULT_OK);
mcu_business_on_factory_reset(); mcu_logic_on_factory_reset();
break; break;
case MCU_CMD_REBOOT: case MCU_CMD_REBOOT:
mcu_protocol_send_ack(MCU_CMD_REBOOT_ACK, sn, MCU_RESULT_OK); mcu_protocol_send_ack(MCU_CMD_REBOOT_ACK, sn, MCU_RESULT_OK);
mcu_business_on_mod_reboot(); mcu_logic_on_mod_reboot();
break; break;
case MCU_CMD_GET_TIME: case MCU_CMD_GET_TIME:
mcu_protocol_handle_get_time(frame, len); mcu_protocol_handle_get_time(frame, len);
break; break;
case MCU_CMD_GET_MCU_INFO_ACK: case MCU_CMD_GET_MCU_INFO_ACK:
mcu_business_on_mcu_info_ack(frame, len); /* 只本地解析,不原样转发网关 */ mcu_logic_on_mcu_info_ack(frame, len); /* 只本地解析,不原样转发网关 */
break; break;
case MCU_CMD_MCU_REBOOT_ACK: case MCU_CMD_MCU_REBOOT_ACK:
mcu_business_on_mcu_reboot_ack(frame, len); mcu_logic_on_mcu_reboot_ack(frame, len);
break; break;
case MCU_CMD_HEARTBEAT_ACK: case MCU_CMD_HEARTBEAT_ACK:
break; break;
case MCU_CMD_WORK_STATUS_ACK: case MCU_CMD_WORK_STATUS_ACK:
mcu_business_on_ota_ws_ack(); mcu_logic_on_ota_ws_ack();
break; break;
case MCU_CMD_OTA_NOTIFY_ACK: case MCU_CMD_OTA_NOTIFY_ACK:
case MCU_CMD_OTA_DATA_ACK: case MCU_CMD_OTA_DATA_ACK:
case MCU_CMD_OTA_COMPLETE: case MCU_CMD_OTA_COMPLETE:
case MCU_CMD_OTA_STOP_BLE_ACK: case MCU_CMD_OTA_STOP_BLE_ACK:
case MCU_CMD_OTA_STOP_MCU: case MCU_CMD_OTA_STOP_MCU:
mcu_business_on_mcu_ota_frame(frame, len); mcu_logic_on_mcu_ota_frame(frame, len);
break; break;
case MCU_CMD_FACTORY: case MCU_CMD_FACTORY:
case MCU_CMD_PHOTO: case MCU_CMD_PHOTO:
case MCU_CMD_RECORD: case MCU_CMD_RECORD:
case MCU_CMD_AUDIO: case MCU_CMD_AUDIO:
if (mcu_business_ota_is_active()) { if (mcu_logic_ota_is_active()) {
log_info("drop MCU cmd=0x%02X during OTA", cmd); log_info("drop MCU cmd=0x%02X during OTA", cmd);
break; break;
} }
mcu_protocol_send_ack((uint8_t)(cmd + 1), sn, MCU_RESULT_NOT_SUPPORT); mcu_protocol_send_ack((uint8_t)(cmd + 1), sn, MCU_RESULT_NOT_SUPPORT);
break; break;
default: default:
if (mcu_business_ota_is_active()) { if (mcu_logic_ota_is_active()) {
log_info("drop MCU cmd=0x%02X during OTA", cmd); log_info("drop MCU cmd=0x%02X during OTA", cmd);
} }
break; break;
@@ -693,7 +693,7 @@ static void mcu_protocol_handle_app_frame(const uint8_t *data, uint16_t len)
case MCU_CMD_OTA_DATA: case MCU_CMD_OTA_DATA:
case MCU_CMD_OTA_COMPLETE_ACK: case MCU_CMD_OTA_COMPLETE_ACK:
case MCU_CMD_OTA_STOP_BLE: case MCU_CMD_OTA_STOP_BLE:
mcu_business_on_app_ota_frame(data, len); mcu_logic_on_app_ota_frame(data, len);
return; return;
/* 反向 OTA 命令:模组→APP,或会话已结束后的 0x39,禁止透传到 UART */ /* 反向 OTA 命令:模组→APP,或会话已结束后的 0x39,禁止透传到 UART */
@@ -708,11 +708,11 @@ static void mcu_protocol_handle_app_frame(const uint8_t *data, uint16_t len)
case MCU_CMD_GET_MCU_INFO: case MCU_CMD_GET_MCU_INFO:
/* APP 问版本:模组用缓存回 SOC 0x41,不要把 0x40 转给 MCU */ /* APP 问版本:模组用缓存回 SOC 0x41,不要把 0x40 转给 MCU */
mcu_business_on_app_get_mcu_info(sn); mcu_logic_on_app_get_mcu_info(sn);
return; return;
case MCU_CMD_CONTROL: case MCU_CMD_CONTROL:
if (mcu_business_ota_is_active()) { if (mcu_logic_ota_is_active()) {
mcu_protocol_reply_app_result(MCU_CMD_CONTROL_ACK, sn, MCU_RESULT_BUSY); mcu_protocol_reply_app_result(MCU_CMD_CONTROL_ACK, sn, MCU_RESULT_BUSY);
return; return;
} }
@@ -720,7 +720,7 @@ static void mcu_protocol_handle_app_frame(const uint8_t *data, uint16_t len)
break; break;
case MCU_CMD_READ: case MCU_CMD_READ:
if (mcu_business_ota_is_active()) { if (mcu_logic_ota_is_active()) {
mcu_protocol_reply_app_result(MCU_CMD_READ_ACK, sn, MCU_RESULT_BUSY); mcu_protocol_reply_app_result(MCU_CMD_READ_ACK, sn, MCU_RESULT_BUSY);
return; return;
} }
@@ -728,7 +728,7 @@ static void mcu_protocol_handle_app_frame(const uint8_t *data, uint16_t len)
break; break;
default: default:
if (mcu_business_ota_is_active()) { if (mcu_logic_ota_is_active()) {
log_info("drop APP cmd=0x%02X during OTA", cmd); log_info("drop APP cmd=0x%02X during OTA", cmd);
return; return;
} }
@@ -790,7 +790,7 @@ static void mcu_protocol_handle_gateway_ack(uint16_t cmd,
} }
/* 再交给版本上报:若已被 0x07 占用,版本侧会继续等,不会误当成自己的 ACK */ /* 再交给版本上报:若已被 0x07 占用,版本侧会继续等,不会误当成自己的 ACK */
mcu_business_on_gateway_ack(success, mcu_consumed); mcu_logic_on_gateway_ack(success, mcu_consumed);
} }
/*============================================================================*/ /*============================================================================*/
@@ -808,7 +808,7 @@ static void mcu_protocol_try_heartbeat(void)
int32_t total; int32_t total;
/* 身份都还没通,先别发心跳 */ /* 身份都还没通,先别发心跳 */
if (!mcu_business_is_identity_ready() || mcu_business_ota_is_active()) if (!mcu_logic_is_identity_ready() || mcu_logic_ota_is_active())
{ {
return; return;
} }
@@ -867,7 +867,7 @@ static void mcu_protocol_try_heartbeat(void)
} }
/** /**
* @brief 工作状态变化时推送 0x14(状态值来自 business 层) * @brief 工作状态变化时推送 0x14(状态值来自逻辑层)
*/ */
static void mcu_protocol_try_work_status(void) static void mcu_protocol_try_work_status(void)
{ {
@@ -878,12 +878,12 @@ static void mcu_protocol_try_work_status(void)
uint32_t now; uint32_t now;
uint8_t ws; uint8_t ws;
if (!mcu_business_is_identity_ready() || mcu_business_ota_is_active()) if (!mcu_logic_is_identity_ready() || mcu_logic_ota_is_active())
{ {
return; return;
} }
ws = mcu_business_get_work_status(); ws = mcu_logic_get_work_status();
/* 状态没变就不再推 0x14;0xFF 表示强制重推 */ /* 状态没变就不再推 0x14;0xFF 表示强制重推 */
if (ws == s_proto.last_pushed_status) if (ws == s_proto.last_pushed_status)
{ {
@@ -994,16 +994,16 @@ static void mcu_protocol_check_ble_pending(void)
} }
/** /**
* @brief 周期处理:串口防睡 / 业务周期 / pending 重试 / 心跳 / 状态推送 * @brief 周期处理:串口防睡 / 逻辑层周期 / pending 重试 / 心跳 / 状态推送
*/ */
static void mcu_protocol_periodic(void) static void mcu_protocol_periodic(void)
{ {
mcu_uart_rx_keep_awake_tick(); /* 串口防睡 */ mcu_uart_rx_keep_awake_tick(); /* 串口防睡 */
mcu_business_periodic(); /* 业务周期 */ mcu_logic_periodic(); /* 逻辑层周期 */
mcu_protocol_check_app_pending(); /* APP 透传超时重发;重试用尽后主动回 FAIL,不让 APP 干等 */ mcu_protocol_check_app_pending(); /* APP 透传超时重发;重试用尽后主动回 FAIL,不让 APP 干等 */
mcu_protocol_check_ble_pending(); /* BLE 主动帧 pending 超时清理 */ mcu_protocol_check_ble_pending(); /* BLE 主动帧 pending 超时清理 */
mcu_protocol_try_heartbeat(); /* 心跳 */ mcu_protocol_try_heartbeat(); /* 心跳 */
mcu_protocol_try_work_status(); /* 工作状态变化时推送 0x14(状态值来自 business 层) */ mcu_protocol_try_work_status(); /* 工作状态变化时推送 0x14(状态值来自逻辑层) */
} }
/*============================================================================*/ /*============================================================================*/
@@ -1023,7 +1023,7 @@ uint8_t mcu_protocol_init(void)
memset(&s_proto, 0, sizeof(s_proto)); memset(&s_proto, 0, sizeof(s_proto));
mcu_frame_parser_reset(); mcu_frame_parser_reset();
mcu_business_init(); mcu_logic_init();
if (mcu_uart_init() != MCU_UART_OK) if (mcu_uart_init() != MCU_UART_OK)
{ {
@@ -6,7 +6,7 @@
* @version V1.1.0 * @version V1.1.0
* @history * @history
* - V1.0.0, 2026.08.12, cyWu, 从 mcu_bridge.c 拆出,仅保留协议机制, * - V1.0.0, 2026.08.12, cyWu, 从 mcu_bridge.c 拆出,仅保留协议机制,
* 不含任何业务判断(身份/配网/连接状态见 ../business * 不含功能处理(身份/配网/连接状态见 ../logic
* - V1.1.0, 2026.08.13, cyWu, P1:管理命令分发、pending 发送、网关时间入队 * - V1.1.0, 2026.08.13, cyWu, P1:管理命令分发、pending 发送、网关时间入队
* - V1.2.0, 2026.08.15, cyWu, P2OTA 大包旁路、按 SN 发送、原始帧转发 * - V1.2.0, 2026.08.15, cyWu, P2OTA 大包旁路、按 SN 发送、原始帧转发
******************************************************************************/ ******************************************************************************/
@@ -20,12 +20,11 @@
/*============================================================================*/ /*============================================================================*/
/* 说明 */ /* 说明 */
/* 本模块只做协议机制:组帧收发、事件队列驱动的单一任务、命令分发、 */ /* 本模块只做协议机制:组帧收发、事件队列驱动的单一任务、命令分发、 */
/* ACK 与超时重传、心跳保活。所有业务判断(该不该配网/该发什么广播/ */ /* ACK 与超时重传、心跳保活。配网/版本/OTA 等具体功能一律转交逻辑层。 */
/* work_status 具体取值)一律转交 business 层,本模块不感知业务细节。 */
/*============================================================================*/ /*============================================================================*/
/** /**
* @brief 初始化协议引擎(UART + 事件队列 + 独立任务 + business 层) * @brief 初始化协议引擎(UART + 事件队列 + 独立任务 + 逻辑层)
* @return 1=成功,0=失败 * @return 1=成功,0=失败
*/ */
uint8_t mcu_protocol_init(void); uint8_t mcu_protocol_init(void);
@@ -45,7 +44,7 @@ void mcu_protocol_on_uart_rx(const uint8_t *data, uint16_t len);
void mcu_protocol_on_app_frame(const uint8_t *data, uint16_t len); void mcu_protocol_on_app_frame(const uint8_t *data, uint16_t len);
/** /**
* @brief 配网成功通知(入队,交由协议任务在自身上下文调用 business 层) * @brief 配网成功通知(入队,交由协议任务在自身上下文调用逻辑层)
*/ */
void mcu_protocol_notify_paired(void); void mcu_protocol_notify_paired(void);
@@ -77,7 +76,7 @@ void mcu_protocol_notify_network_time(uint64_t unix_s, int32_t gmtoff_s);
void mcu_protocol_notify_disconnected(void); void mcu_protocol_notify_disconnected(void);
/*============================================================================*/ /*============================================================================*/
/* 供 business 层调用的协议发送接口 */ /* 供逻辑层调用的协议发送接口 */
/*============================================================================*/ /*============================================================================*/
/** /**
@@ -132,7 +131,7 @@ uint8_t mcu_protocol_is_ble_pending(void);
uint8_t mcu_protocol_is_mcu_report_waiting(void); uint8_t mcu_protocol_is_mcu_report_waiting(void);
/** /**
* @brief 强制下一轮重新推送 0x14(业务状态变化后调用) * @brief 强制下一轮重新推送 0x14(逻辑层状态变化后调用)
*/ */
void mcu_protocol_invalidate_work_status_push(void); void mcu_protocol_invalidate_work_status_push(void);
+1 -1
View File
@@ -23,7 +23,7 @@ if ([string]::IsNullOrWhiteSpace($SdkRoot)) {
$SdkRoot = Join-Path $RepoRoot "JBao_JL7016_MOD_FW" $SdkRoot = Join-Path $RepoRoot "JBao_JL7016_MOD_FW"
} }
$VersionHeader = Join-Path $SdkRoot "apps\usr_mcu_bridge\business\mcu_version.h" $VersionHeader = Join-Path $SdkRoot "apps\usr_mcu_bridge\logic\mcu_version.h"
$DownloadDir = Join-Path $SdkRoot "cpu\br28\tools\download\earphone" $DownloadDir = Join-Path $SdkRoot "cpu\br28\tools\download\earphone"
$ReleaseRoot = Join-Path $RepoRoot "release" $ReleaseRoot = Join-Path $RepoRoot "release"