chore(ble): 增强连接与发送日志,补充 README TODO

- 连接/断开事件打印详细信息
- 发送统计计数(成功/失败)
- README 补充 L1 标定、BR 通道排查、马达频率确认待办
This commit is contained in:
2026-05-19 14:50:16 +08:00
parent a2d6ef8893
commit 38a70ccb8e
2 changed files with 20 additions and 4 deletions
+6
View File
@@ -369,3 +369,9 @@ Heartbeat 接收路径已经接入,但默认 `DBG` 级别下才单独打印。
- 传感器线程没有额外 `k_msleep()` 节流,实际帧率由 ADS1256 采样和 BLE 发送耗时共同决定 - 传感器线程没有额外 `k_msleep()` 节流,实际帧率由 ADS1256 采样和 BLE 发送耗时共同决定
- README 中的频率描述按当前 `3750 SPS + 4 通道 * 17 次均值` 这套实现估算,目标运行频率约 `50 Hz` - README 中的频率描述按当前 `3750 SPS + 4 通道 * 17 次均值` 这套实现估算,目标运行频率约 `50 Hz`
- 当前实现默认四角传感器是固定几何布局,半宽和半长都是 `100 mm` - 当前实现默认四角传感器是固定几何布局,半宽和半长都是 `100 mm`
### 10.3 TODO
- [ ] L1 增益标定:当前使用理论推导值 `ADC_TO_FORCE_SCALE`,实测 10 kg 砝码显示 9 kg(约 10% 误差),需用已知砝码通过标定命令校准每通道增益
- [ ] BR 通道硬件排查:静止无马达状态下 BR 通道有 ±4600 counts 异常抖动(其余通道仅 ±500),疑似接触不良或安装松动
- [ ] 马达振动频率确认:当前 IIR 截止 1.2 Hz,若实际振动低于帧率一半(23.5 Hz)存在混叠,可能需要在 ADC 级做抗混叠或调整采样策略
+14 -4
View File
@@ -37,11 +37,15 @@ static void adv_work_handler(struct k_work *work) {
/** @brief 连接建立回调,接管连接引用并收紧连接参数。 */ /** @brief 连接建立回调,接管连接引用并收紧连接参数。 */
static void connected(struct bt_conn *conn, uint8_t err) { static void connected(struct bt_conn *conn, uint8_t err) {
if (err) return; if (err) {
LOG_WRN("Connection failed (err %u)", err);
return;
}
current_conn = bt_conn_ref(conn); current_conn = bt_conn_ref(conn);
k_work_cancel_delayable(&adv_work); k_work_cancel_delayable(&adv_work);
nus_notification_enabled = false; nus_notification_enabled = false;
LOG_INF("BLE connected");
struct bt_le_conn_param param = { .interval_min = 6, .interval_max = 12, .latency = 0, .timeout = 400 }; struct bt_le_conn_param param = { .interval_min = 6, .interval_max = 12, .latency = 0, .timeout = 400 };
bt_conn_le_param_update(conn, &param); bt_conn_le_param_update(conn, &param);
@@ -50,7 +54,7 @@ static void connected(struct bt_conn *conn, uint8_t err) {
/** @brief 断开回调,释放连接引用并安排延时重广播。 */ /** @brief 断开回调,释放连接引用并安排延时重广播。 */
static void disconnected(struct bt_conn *conn, uint8_t reason) { static void disconnected(struct bt_conn *conn, uint8_t reason) {
ARG_UNUSED(conn); ARG_UNUSED(conn);
ARG_UNUSED(reason); LOG_WRN("BLE disconnected (reason 0x%02x)", reason);
if (current_conn) { if (current_conn) {
bt_conn_unref(current_conn); bt_conn_unref(current_conn);
current_conn = NULL; current_conn = NULL;
@@ -108,23 +112,29 @@ void ble_transport_adv_start(void) {
void ble_transport_send(const uint8_t *data, uint16_t len) { void ble_transport_send(const uint8_t *data, uint16_t len) {
static bool first_send_logged = false; static bool first_send_logged = false;
static uint32_t send_ok_count;
static uint32_t send_fail_count;
if (!nus_notification_enabled || !current_conn) return; if (!nus_notification_enabled || !current_conn) return;
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
int err = bt_nus_send(current_conn, data, len); int err = bt_nus_send(current_conn, data, len);
if (err == 0) { if (err == 0) {
send_ok_count++;
if (!first_send_logged) { if (!first_send_logged) {
LOG_INF("First NUS send OK (len=%u)", len); LOG_INF("First NUS send OK (len=%u)", len);
first_send_logged = true; first_send_logged = true;
} }
return; return;
} }
if (i == 0) {
LOG_DBG("NUS send retry (err=%d)", err);
}
k_usleep(500); k_usleep(500);
} }
LOG_WRN("NUS send failed after retries (len=%u)", len); send_fail_count++;
LOG_WRN("NUS send failed x3 (len=%u, ok=%u, fail=%u)", len, send_ok_count, send_fail_count);
} }
bool ble_transport_is_ready(void) { bool ble_transport_is_ready(void) {
return nus_notification_enabled && (current_conn != NULL); return nus_notification_enabled && (current_conn != NULL);
} }