Files

90 lines
3.3 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/******************************************************************************
* @file usr_usb_jb.h
* @brief USB CDC 见宝帧解析:设置 ProdtCode / productCode 并落盘重广播
* @author cyWu <1917507415@qq.com>
* @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, 首次发布
******************************************************************************/
#ifndef __USR_USB_JB_H__
#define __USR_USB_JB_H__
#include <stdint.h>
/*============================================================================*/
/* 宏定义 */
/*============================================================================*/
#define USR_PRODCODE_LEN (4)
#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 */
/** COM 未打开时,BLE 下发需设备本地自动应答的 JB 命令 */
#define USR_JB_CMD_CTRL (0x03) /**< → ACK 0x04 */
#define USR_JB_CMD_READ (0x05) /**< → ACK 0x06 */
/** OTA 相关命令 */
#define USR_JB_CMD_OTA_NOTIFY (0x30) /**< → ACK 0x31 */
#define USR_JB_CMD_OTA_DATA (0x32) /**< → ACK 0x33 */
#define USR_JB_CMD_OTA_STOP_BLE (0x36) /**< → ACK 0x37 */
/*============================================================================*/
/* 外部接口 */
/*============================================================================*/
/**
* @brief 上电加载产品码(flash 优先,否则默认值)
* @return void
*/
void usr_prodcode_init(void);
/**
* @brief 获取当前产品码缓存
* @param prodcode 输出 ProdtCode,长度 USR_PRODCODE_LEN,可为 NULL
* @param pcode 输出 productCode,长度 USR_PCODE_LEN,可为 NULL
* @return void
*/
void usr_prodcode_get(uint8_t *prodcode, uint8_t *pcode);
/**
* @brief 记录最近一次 BLE 收到的 msgid(供 USB 回包复用)
* @param msgid BLE 包头 msgid4bit
* @return void
*/
void usr_ble_rx_msgid_save(uint8_t msgid);
/**
* @brief 获取最近一次 BLE 收到的 msgid
* @return msgid
*/
uint8_t usr_ble_rx_msgid_get(void);
/**
* @brief USB CDC 喂数:仅入环并挂定时器(可在中断调用)
* @note 帧解析 / syscfg_write / ACK / 重广播在定时器任务中执行
* @param buf 接收缓冲
* @param len 长度
* @return void
*/
void usr_usb_jb_feed(uint8_t *buf, uint32_t len);
/**
* @brief BLE RUNCMD_V2 下发的 JB 字节流处理
* @note COM 已打开 → 透传 CDC 给上位机;
* COM 未打开 → 调用 usr_usb_jb_feed,统一走 get_one_packet 解析后本地自动应答
* @param data bytes_data
* @param len 长度
* @return void
*/
void usr_jb_on_runcmd_bytes(const uint8_t *data, uint16_t len);
#endif /* __USR_USB_JB_H__ */