新增.gitignore文件以排除构建产物和临时文件,同时删除不再需要的AC701N依赖文件和多个工具及输出文件,优化项目结构。

新增BLE MAC地址上报功能
This commit is contained in:
2026-09-08 18:04:54 +08:00
parent 59361cd9d5
commit 20629fd537
404 changed files with 119 additions and 168630 deletions
+79 -1
View File
@@ -3,8 +3,9 @@
* @brief USB CDC 见宝帧解析:校验后写入产品码并重广播
* @author cyWu <1917507415@qq.com>
* @date 2026.07.24
* @version V1.0.2
* @version V1.0.3
* @history
* - V1.0.3, 2026.09.08, cyWu, 0x65 成功应答后延时 1s 主动上报 BLE MAC(0x68)
* - V1.0.2, 2026.07.28, cyWu, 非产品码命令整帧透传 BLE REPORTCMD_V2
* - V1.0.1, 2026.07.24, cyWu, CDC 中断内禁止 syscfg_write,改延时到任务上下文
* - V1.0.0, 2026.07.24, cyWu, 首次发布
@@ -86,6 +87,8 @@ static uint8_t s_pending_sn;
static uint8_t s_pending_prod[USR_PRODCODE_LEN];
static uint8_t s_pending_pcode[USR_PCODE_LEN];
static int s_process_timer;
static int s_mac_rpt_timer; /* 0x65 后延时上报 0x68 */
static uint8_t s_mac_rpt_sn; /* 待上报 MAC 复用的 SN */
static uint8_t s_ble_txbuf[USR_JB_BLE_TX_SZ];
static uint8_t s_last_ble_msgid; /* 最近一次 BLE RX 的 msgid */
static uint8_t s_rsp_buf[JB_RSP_BUF_SZ];
@@ -366,6 +369,7 @@ void usr_prodcode_init(void)
usr_jb_rb_init(&s_rb);
s_pending_save = 0;
s_process_timer = 0;
s_mac_rpt_timer = 0;
usr_prodcode_set_default();
memset(&info, 0, sizeof(info));
@@ -510,6 +514,73 @@ static void usr_jb_send_rsp(uint8_t cmd, uint8_t sn,
printf("usr_jb rsp cmd=0x%02x plen=%u total=%u\n", cmd + 1, payload_len, total);
}
/**
* @brief 定时器回调:发送 0x68 BLE MAC 上报帧
* @note le_controller_get_mac 为小端存储,需反转为手机扫码显示顺序后再上报
*/
static void usr_jb_mac_rpt_timeout(void *priv)
{
uint8_t mac_le[6];
uint8_t mac[6];
uint8_t body[1 + 6];
uint16_t len_field;
uint16_t total;
uint8_t sn;
uint8_t i;
extern int le_controller_get_mac(void *addr);
extern u8 usr_mac_addr[6];
(void)priv;
s_mac_rpt_timer = 0;
sn = s_mac_rpt_sn;
if (le_controller_get_mac(mac_le) != 0) {
memcpy(mac_le, usr_mac_addr, 6);
}
/* 小端 → 手机显示序:AA:BB:CC:DD:EE:FF */
for (i = 0; i < 6; i++) {
mac[i] = mac_le[5 - i];
}
/* TLV:与产品码字段风格一致 [len=6][MAC 6B] */
body[0] = 6;
memcpy(&body[1], mac, 6);
len_field = (uint16_t)(2 + sizeof(body) + 1); /* CMD+SN+payload+CKSUM */
total = (uint16_t)(len_field + 4);
s_rsp_buf[0] = PKT_HEAD_0;
s_rsp_buf[1] = PKT_HEAD_1;
s_rsp_buf[2] = (uint8_t)(len_field >> 8);
s_rsp_buf[3] = (uint8_t)(len_field & 0xFF);
s_rsp_buf[4] = USR_JB_CMD_RPT_BLE_MAC;
s_rsp_buf[5] = sn;
memcpy(&s_rsp_buf[6], body, sizeof(body));
s_rsp_buf[total - 1] = usr_jb_checksum(s_rsp_buf, total);
cdc_write_data(0, s_rsp_buf, total);
printf("usr_jb rpt mac sn=%u disp=%02X:%02X:%02X:%02X:%02X:%02X le=",
sn, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
printf_buf(mac_le, 6);
printf_buf(s_rsp_buf, total);
}
/**
* @brief 0x65 成功应答后,延时 1s 再主动上报 BLE MACCMD=0x68
* @param sn 复用本次 0x64/0x65 的流水号
*/
static void usr_jb_schedule_ble_mac_report(uint8_t sn)
{
s_mac_rpt_sn = sn;
if (s_mac_rpt_timer) {
sys_timeout_del(s_mac_rpt_timer);
s_mac_rpt_timer = 0;
}
s_mac_rpt_timer = sys_timeout_add(NULL, usr_jb_mac_rpt_timeout, 1000);
printf("usr_jb mac rpt scheduled sn=%u delay=1000ms\n", sn);
}
/**
* @brief Dengle 查询:空/0xFF=全部;单字节槽位=查一条
* @note 应答 0x75
@@ -664,6 +735,11 @@ static void usr_jb_process_timeout(void *priv)
#endif
break;
case (USR_JB_CMD_RPT_BLE_MAC + 1): /* 0x69:上位机对 0x68 的 ACK,仅消费 */
printf("usr_jb mac rpt ack sn=%u result=0x%02x\n",
sn, (payload_len >= 1) ? pkt[6] : 0xFF);
break;
default:
/*
* COM 未打开:0x03/0x05 等需本地自动应答回 BLE;
@@ -695,6 +771,7 @@ static void usr_jb_process_timeout(void *priv)
memcmp(s_pcode, s_pending_pcode, USR_PCODE_LEN) == 0) {
#if TCFG_USB_SLAVE_CDC_ENABLE
usr_jb_send_ack(s_pending_cmd, s_pending_sn, 0x00);
usr_jb_schedule_ble_mac_report(s_pending_sn);
#endif
printf("prodcode unchanged, skip adv rebuild\n");
return;
@@ -703,6 +780,7 @@ static void usr_jb_process_timeout(void *priv)
if (usr_prodcode_save(s_pending_prod, s_pending_pcode) == 0) {
#if TCFG_USB_SLAVE_CDC_ENABLE
usr_jb_send_ack(s_pending_cmd, s_pending_sn, 0x00);
usr_jb_schedule_ble_mac_report(s_pending_sn);
#endif
extern void usr_goto_pair_mode(void);
usr_goto_pair_mode();
+4 -2
View File
@@ -2,9 +2,10 @@
* @file usr_usb_jb.h
* @brief USB CDC 见宝帧解析:设置 ProdtCode / productCode 并落盘重广播
* @author cyWu <1917507415@qq.com>
* @date 2026.07.24
* @version V1.0.0
* @date 2026.09.08
* @version V1.0.1
* @history
* - V1.0.1, 2026.09.08, cyWu, 增加 0x68 BLE MAC 主动上报命令定义
* - V1.0.0, 2026.07.24, cyWu, 首次发布
******************************************************************************/
@@ -21,6 +22,7 @@
#define USR_PCODE_LEN (6)
#define USR_JB_CMD_SET_PRODCODE (0x64) /**< USB 设置产品码;ACK=0x65 */
#define USR_JB_CMD_GET_PRODCODE (0x66) /**< USB 查询产品码;RSP=0x67 */
#define USR_JB_CMD_RPT_BLE_MAC (0x68) /**< 设备主动上报 BLE MACACK=0x69 */
#define USR_JB_CMD_DENGLE_SET (0x70) /**< USB 设置 Dengle 定时;ACK=0x71 */
#define USR_JB_CMD_DENGLE_CLR (0x72) /**< USB 清除全部 DengleACK=0x73 */
#define USR_JB_CMD_DENGLE_QRY (0x74) /**< USB 查询 Dengle 配置;RSP=0x75 */