1、封装 usr_le_code 为静态库,并增加 Release 客户包自动生成工具

2、将 BLE 协议实现收敛为 libusr_le_code.a + 公开头文件,应用侧通过
usr_le_api / usr_le_product 对接;新增 package_release.py,按 version.txt
3、生成去除协议源码的客户交付包,开发工程继续保留完整源码。
This commit is contained in:
2026-08-04 12:30:06 +08:00
parent 158b74447d
commit 4e1bf445b2
16 changed files with 920 additions and 65 deletions
+50
View File
@@ -0,0 +1,50 @@
@echo off
chcp 65001 >nul
REM Rebuild apps/usr_le_code/lib/libusr_le_code.a
REM Double-click this bat; window will pause so you can read the result.
cd /d "%~dp0..\.."
if errorlevel 1 (
echo [FAIL] cannot cd to project root
echo SCRIPT dir: %~dp0
goto :END
)
echo ==== build libusr_le_code.a ====
echo Project root: %CD%
echo.
SET PATH=%CD%\tools\utils;C:\JL\pi32\bin;%PATH%
where make >nul 2>&1
if errorlevel 1 (
echo [FAIL] make.exe not found
echo Check: %CD%\tools\utils\make.exe
goto :END
)
where clang.exe >nul 2>&1
if errorlevel 1 (
echo [FAIL] clang.exe not found
echo Check: C:\JL\pi32\bin\clang.exe
goto :END
)
make lib_usr_le -j %NUMBER_OF_PROCESSORS%
if errorlevel 1 (
echo.
echo [FAIL] build libusr_le_code.a
goto :END
)
echo.
if exist "apps\usr_le_code\lib\libusr_le_code.a" (
echo [OK] apps\usr_le_code\lib\libusr_le_code.a
dir "apps\usr_le_code\lib\libusr_le_code.a"
) else (
echo [FAIL] lib file not found after build
)
:END
echo.
pause
Binary file not shown.
+55 -26
View File
@@ -14,8 +14,7 @@
#include "vm.h"
#include "bleproto.h"
#include "bleproto_api.h"
#include "bleproto.h"
#include "usr_le_product.h"
#define LOG_TAG_CONST APP
#define LOG_TAG "[APP]"
#define LOG_ERROR_ENABLE
@@ -28,6 +27,9 @@
extern u8 muti_adv_data[31];//={0};
extern u8 muti_adv_data_len;
/* 定义在 usr_le_recieve.c,库内共用,不对外导出 */
extern bleproto_authsetup_req_t usr_auth_data;
extern u8 usr_get_full();
extern u16 usr_get_conn_service();
extern int muti_make_set_adv_data(u8* data,u8 data_len);
@@ -95,9 +97,14 @@ void usr_ble_adv_init()
{
int8_t txpower = 0;
uint8_t manucode[BLEPROTO_ADV_TLV_LENGTH_MANUCODE] = { 0 };
uint8_t prodcode[BLEPROTO_ADV_TLV_LENGTH_PRODCODE] = {'C', 'B', 'C', '0'};///CBP0
uint8_t gmac[6]={0};
uint8_t pcode[6]={'P','I','C','B','C','0'};
uint8_t prodcode[BLEPROTO_ADV_TLV_LENGTH_PRODCODE];
uint8_t gmac[6] = {0};
uint8_t pcode[BLE_PROTO_ADV_LENGTH_PCODE];
/* 产品身份由应用层 g_usr_le_* 提供(见 usr_jb_main.c */
memcpy(prodcode, g_usr_le_prodcode, BLEPROTO_ADV_TLV_LENGTH_PRODCODE);
memcpy(pcode, g_usr_le_pcode, BLE_PROTO_ADV_LENGTH_PCODE);
usr_set_adv_interval(80);
if(usr_var.usr_ota_succ_flag)return;
//muti_adv_data
@@ -214,29 +221,51 @@ void usr_soft_off()
void usr_ble_adv_updata_OTA()
{
//printf("usr_ble_adv_updata\n");
if(1)
ble_trans_module_enable(0);
usr_var.usr_adv_flag=0;
extern u8 usr_mac_addr[6];
extern int le_controller_set_mac(void *addr);
usr_mac_addr[0]=usr_mac_addr[0]+1;
le_controller_set_mac(usr_mac_addr); //修改BLE地址
muti_make_set_adv_data_updata();
printf("###muti_adv_data = ");
printf_buf(muti_adv_data,muti_adv_data_len);
ble_trans_module_enable(1);
}
void usr_ota_process()
{
static u8 cnt = 0;
if (cnt == 0)
{
ble_trans_module_enable(0);
usr_var.usr_adv_flag=0;
ble_multi_trans_disconnect();
}
#if 1
extern u8 usr_mac_addr[6];
//u8 ble_mac[6];
extern int le_controller_set_mac(void *addr);
//extern void lib_make_ble_address(u8 * ble_address, u8 * edr_address);
//bt_update_mac_addr(mac);
//lmp_hci_write_local_address(mac);
//bt_update_testbox_addr(mac);
//lib_make_ble_address(ble_mac, mac);
usr_mac_addr[0]=usr_mac_addr[0]+1;
le_controller_set_mac(usr_mac_addr); //修改BLE地址
if (usr_get_conn_service() == 0)
{
cnt++;
if (cnt == 2)
{
usr_ble_adv_updata_OTA();
}
if (cnt >= 60)
{
cnt = 0;
cpu_reset();
}
}
else
{
cnt = 1;
}
}
#endif
muti_make_set_adv_data_updata();
printf("###muti_adv_data = ");
printf_buf(muti_adv_data,muti_adv_data_len);
ble_trans_module_enable(1);
void usr_app_ota_init()
{
usr_var.usr_goto_updata = 1;
if (usr_var.ota_timer == 0)
{
usr_var.ota_timer = sys_timer_add(NULL, usr_ota_process, 1000);
}
}
+66
View File
@@ -0,0 +1,66 @@
/******************************************************************************
* @file usr_le_api.h
* @brief usr_le_code 静态库对外 API(广播 / 收发 / 配网)
* @author cyWu <1917507415@qq.com>
* @date 2026.08.03
* @version V1.0.0
* @history
* - V1.0.0, 2026.08.03, cyWu, 首次发布
******************************************************************************/
#ifndef __USR_LE_API_H__
#define __USR_LE_API_H__
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief 初始化 BLE 广播数据(绑定广播或重连广播)
* @note 根据配对状态与 usr_goto_pair 选择 bind/reconn 广播,并启动 500ms 周期更新
*/
void usr_ble_adv_init(void);
/**
* @brief BLE 协议栈接收数据入口
* @param data 接收缓冲区
* @param len 本次接收长度
* @note 组包后解析 bleproto,并分发 DEVICEINFO/AUTH/RUNCMD/OTA 等服务
*/
void usr_le_data_recieve(uint8_t *data, uint16_t len);
/**
* @brief 进入配对/配网模式
* @note 断开当前连接、清除配对信息(不复位),重新发绑定广播
*/
void usr_goto_pair_mode(void);
/**
* @brief 清除配对信息但不复位
*/
void usr_clear_pair_info_noreset(void);
/**
* @brief 清除配对信息并延时复位
*/
void usr_clear_pair_info(void);
/**
* @brief 获取当前是否已配对
* @return 1=已配对,0=未配对
*/
uint8_t usr_get_pair_flag(void);
/**
* @brief 启动应用侧 OTA 流程
* @note 置位 usr_goto_updata,并创建 1s 周期定时器驱动断连与 OTA 广播切换
*/
void usr_app_ota_init(void);
#ifdef __cplusplus
}
#endif
#endif /* __USR_LE_API_H__ */
+46
View File
@@ -0,0 +1,46 @@
/******************************************************************************
* @file usr_le_product.h
* @brief usr_le_code 产品身份配置接口(由应用层提供符号,库内不写死)
* @author cyWu <1917507415@qq.com>
* @date 2026.08.03
* @version V1.0.0
* @history
* - V1.0.0, 2026.08.03, cyWu, 首次发布
******************************************************************************/
#ifndef __USR_LE_PRODUCT_H__
#define __USR_LE_PRODUCT_H__
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/** 与 bleproto_packer.h 中 BLEPROTO_ADV_TLV_LENGTH_PRODCODE 一致 */
#ifndef USR_LE_PRODCODE_LEN
#define USR_LE_PRODCODE_LEN 4
#endif
/** 与 bleproto_packer.h 中 BLE_PROTO_ADV_LENGTH_PCODE 一致 */
#ifndef USR_LE_PCODE_LEN
#define USR_LE_PCODE_LEN 6
#endif
/**
* @brief 产品类别码,对应 BLE 广播 prodcode(固定 4 字节 ASCII
* @note 应用层用 JB_CATEGORY_CODE 填充,见 usr_jb_main.c
*/
extern const uint8_t g_usr_le_prodcode[USR_LE_PRODCODE_LEN];
/**
* @brief 平台产品码,对应 BLE 广播 pcode(固定 6 字节 ASCII
* @note 应用层用 JB_PRODUCT_CODE 填充,见 usr_jb_main.c
*/
extern const uint8_t g_usr_le_pcode[USR_LE_PCODE_LEN];
#ifdef __cplusplus
}
#endif
#endif /* __USR_LE_PRODUCT_H__ */
+3 -4
View File
@@ -16,7 +16,6 @@
#include "bleproto.h"
#include "bleproto_api.h"
#include "ble_proto.h"
#include "jb_protocol.h"
#define LOG_TAG_CONST APP
#define LOG_TAG "[APP]"
#define LOG_ERROR_ENABLE
@@ -37,7 +36,6 @@ static u8 ota_source_data[FIRM_PACK_LEN * 2] = {0};
extern u16 usr_get_conn_service();
extern void ble_multi_trans_disconnect(void);
extern void usr_ble_adv_updata_OTA();
extern void usr_ble_send_data(u8 *data, u16 len); /// BLE发送接口,MTU 244
extern void usr_write_pair_info();
extern void usr_clear_pair_info();
@@ -45,6 +43,8 @@ extern void app_audio_volume_set(u8 value);
extern int dual_ota_app_data_deal(u32 msg, u8 *buf, u32 len);
extern int uart_tr_send_data(u8 *data, u32 len);
extern void usr_intterupt_close();
extern void usr_jb_le_recieve_data(u8 *data, u16 len);
extern int8_t jbReportAckCheck(u16 cmd, u8 gateway_int_cnt, int32_t gateway_int0);
void usr_ota_deal_task();
void usr_data_ana(bleproto_appdata_desc_t *desc);
@@ -429,10 +429,9 @@ void usr_ota_deal_task()
/* 最近一次收到 RUNCMD_V2 请求的 msgid,应答时回填 */
static u8 s_last_runcmd_msgid = 0;
extern void usr_jb_le_recieve_data(u8 *data, u16 len);
void usr_run_cmd_code_v2(ble_proto_packet_t *runcmd_par, u8 usr_msg_id)
{
u8 jb_frame[MAX_PACKAGE_LEN];
u8 jb_frame[128]; /* 与 jb_protocol.h MAX_PACKAGE_LEN 一致 */
u16 copy_len;
if (!runcmd_par || !runcmd_par->bytes_data || runcmd_par->device_bytes_len == 0)