refactor(protocol): 新增 comm_protocol 协议收发解析层,ble_transport 退化为纯传输
- 删除 protocol.h,帧定义和标定命令码统一迁入 comm_protocol.h - 新增 comm_protocol.c:上行组包(CoP/标定响应)、下行解析+msgq 分发 - ble_transport 剥离所有协议解析和参数 getter,仅保留字节收发+rx 回调注册 - main.c 初始化顺序:ble_transport → comm_protocol → adv_start → cal_init - 更新 README 架构图和项目结构表,补充标定流程章节 - 更新 BALANCE_BOARD_PROTOCOL.md 增加标定命令/响应帧格式文档
This commit is contained in:
+31
-7
@@ -2,15 +2,39 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/** @brief BLE 原始数据接收回调类型。 */
|
||||
typedef void (*ble_rx_cb_t)(const uint8_t *data, uint16_t len);
|
||||
|
||||
/**
|
||||
* @brief 初始化 BLE 协议栈和 NUS 服务。
|
||||
*
|
||||
* @retval 0 成功。
|
||||
* @retval 负值 初始化错误码。
|
||||
*/
|
||||
int ble_transport_init(void);
|
||||
|
||||
/** @brief 启动 BLE 可连接广播。 */
|
||||
void ble_transport_adv_start(void);
|
||||
|
||||
/**
|
||||
* @brief 通过 NUS 发送二进制数据,内部自动重试最多 3 次。
|
||||
*
|
||||
* @param data 待发送字节缓冲区。
|
||||
* @param len 字节数。
|
||||
*/
|
||||
void ble_transport_send(const uint8_t *data, uint16_t len);
|
||||
|
||||
/**
|
||||
* @brief 检查 BLE 连接是否就绪(已连接且通知已使能)。
|
||||
*
|
||||
* @retval true 可发送数据。
|
||||
* @retval false 未就绪。
|
||||
*/
|
||||
bool ble_transport_is_ready(void);
|
||||
|
||||
/* --- 下行参数 getter --- */
|
||||
float ble_transport_get_resistance_K(void);
|
||||
float ble_transport_get_resistance_B(void);
|
||||
float ble_transport_get_resistance_Tau(void);
|
||||
float ble_transport_get_spotter_threshold(void);
|
||||
bool ble_transport_get_spotter_enabled(void);
|
||||
int64_t ble_transport_get_last_heartbeat_ms(void);
|
||||
/**
|
||||
* @brief 注册上层原始数据接收回调,NUS 收到数据时透传调用。
|
||||
*
|
||||
* @param cb 回调函数指针。
|
||||
*/
|
||||
void ble_transport_register_rx_cb(ble_rx_cb_t cb);
|
||||
|
||||
Reference in New Issue
Block a user