BLE 上报自动分包 + 切慢广播宏

This commit is contained in:
2026-09-09 15:03:53 +08:00
parent 866b522c59
commit 074960eb02
5 changed files with 111 additions and 45 deletions
+15 -7
View File
@@ -2,11 +2,12 @@
* @file usr_le_recieve.c
* @brief BLE 收包入口:bleproto 解析后分发配网 / 对时 / JB 协议 / 组应答
* @author cyWu <1917507415@qq.com>
* @date 2026.08.19
* @version V1.1.0
* @date 2026.09.09
* @version V1.2.0
* @history
* - V1.0.0, 2026.08.03, cyWu, 首次发布
* - V1.1.0, 2026.08.19, cyWu, 对齐模组结构;废弃 JSON OTA;修 AUTHDELETE serviceid
* - V1.2.0, 2026.09.09, cyWu, JB 上报超 255 走 wrap_raw 自动分包;加大 txbuf
******************************************************************************/
#include "system/includes.h"
@@ -27,15 +28,21 @@
#define LOG_INFO_ENABLE
#include "debug.h"
/* GATT 分包:业务包 ≈ bleproto头 + V2 开销 + JB 帧(<=128)1024 足够 */
/* 收:GATT 拼包缓冲。发:V2 + bleproto 多帧(单帧总长 247,与 ATT 对齐) */
#define USR_LE_RX_BUF_LEN 1024
#define USR_LE_V2_WRAP_OVERHEAD 32u /* V2 头开销JB 帧最大 128 → 约 160 */
#define USR_LE_V2_WRAP_OVERHEAD 32u /* V2 头开销 */
#define USR_LE_V2_MAX_LEN (512u + USR_LE_V2_WRAP_OVERHEAD)
#define USR_LE_APPDATA_PACKETLEN 247u /* 对齐 ATT_LOCAL_PAYLOAD_SIZE8B头+239B数据 */
#define USR_LE_APPDATA_FRAME_PAYLOAD (USR_LE_APPDATA_PACKETLEN - 8u)
#define USR_LE_TX_BUF_LEN (USR_LE_V2_MAX_LEN + \
8u * ((USR_LE_V2_MAX_LEN + USR_LE_APPDATA_FRAME_PAYLOAD - 1u) / \
USR_LE_APPDATA_FRAME_PAYLOAD))
#define USR_LE_V2_CMD_REPORT 100u /* REPORTCMD_V2 内层 cmd */
#define USR_LE_V2_CMD_RUN 110u /* RUNCMD_V2 内层 cmd */
#define USR_LE_JB_CMD_OFF 4u /* 55 AA | LEN_H LEN_L | CMD */
static int encode_len = 0;
static u8 txbuf[384] = {0};
static u8 txbuf[USR_LE_TX_BUF_LEN];
static u8 rxbuf[USR_LE_RX_BUF_LEN] = {0};
static u8 s_last_runcmd_msgid = 0; /* RUNCMD_V2 应答须回填最近 msgid */
@@ -75,7 +82,7 @@ static void usr_le_fill_rsp_header(bleproto_appdata_desc_t *out,
*/
static void usr_le_encode_and_send(bleproto_appdata_desc_t *desc)
{
encode_len = bleproto_appdata_encode(txbuf, sizeof(txbuf), sizeof(txbuf), desc);
encode_len = bleproto_appdata_encode(txbuf, sizeof(txbuf), USR_LE_APPDATA_PACKETLEN, desc);
if (encode_len > 0)
{
printf("encode_len = %d\n", encode_len);
@@ -365,7 +372,8 @@ void ble_send_data(u8 *data, u16 len)
return;
}
elen = bleproto_appdata_wrap_raw(txbuf, sizeof(txbuf), &hdr, v2_buf, (uint16_t)plen);
elen = bleproto_appdata_wrap_raw(txbuf, sizeof(txbuf), USR_LE_APPDATA_PACKETLEN,
&hdr, v2_buf, (uint16_t)plen);
printf("ble_send_data jb_cmd=0x%02X active=%d encode_len=%d msgid=%d\n",
jb_cmd, is_active_send, elen, hdr.msgid);
if (elen <= 0)