From 38a70ccb8e7cf36d130c254fc73a0a905d1cdf26 Mon Sep 17 00:00:00 2001 From: pNexus Date: Tue, 19 May 2026 14:50:16 +0800 Subject: [PATCH] =?UTF-8?q?chore(ble):=20=E5=A2=9E=E5=BC=BA=E8=BF=9E?= =?UTF-8?q?=E6=8E=A5=E4=B8=8E=E5=8F=91=E9=80=81=E6=97=A5=E5=BF=97=EF=BC=8C?= =?UTF-8?q?=E8=A1=A5=E5=85=85=20README=20TODO?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 连接/断开事件打印详细信息 - 发送统计计数(成功/失败) - README 补充 L1 标定、BR 通道排查、马达频率确认待办 --- README.md | 6 ++++++ src/ble_transport.c | 18 ++++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 3d9e04d..52dae32 100644 --- a/README.md +++ b/README.md @@ -369,3 +369,9 @@ Heartbeat 接收路径已经接入,但默认 `DBG` 级别下才单独打印。 - 传感器线程没有额外 `k_msleep()` 节流,实际帧率由 ADS1256 采样和 BLE 发送耗时共同决定 - README 中的频率描述按当前 `3750 SPS + 4 通道 * 17 次均值` 这套实现估算,目标运行频率约 `50 Hz` - 当前实现默认四角传感器是固定几何布局,半宽和半长都是 `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 级做抗混叠或调整采样策略 diff --git a/src/ble_transport.c b/src/ble_transport.c index e8c96cb..c6ce300 100644 --- a/src/ble_transport.c +++ b/src/ble_transport.c @@ -37,11 +37,15 @@ static void adv_work_handler(struct k_work *work) { /** @brief 连接建立回调,接管连接引用并收紧连接参数。 */ 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); k_work_cancel_delayable(&adv_work); nus_notification_enabled = false; + LOG_INF("BLE connected"); struct bt_le_conn_param param = { .interval_min = 6, .interval_max = 12, .latency = 0, .timeout = 400 }; bt_conn_le_param_update(conn, ¶m); @@ -50,7 +54,7 @@ static void connected(struct bt_conn *conn, uint8_t err) { /** @brief 断开回调,释放连接引用并安排延时重广播。 */ static void disconnected(struct bt_conn *conn, uint8_t reason) { ARG_UNUSED(conn); - ARG_UNUSED(reason); + LOG_WRN("BLE disconnected (reason 0x%02x)", reason); if (current_conn) { bt_conn_unref(current_conn); current_conn = NULL; @@ -108,23 +112,29 @@ void ble_transport_adv_start(void) { void ble_transport_send(const uint8_t *data, uint16_t len) { 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; for (int i = 0; i < 3; i++) { int err = bt_nus_send(current_conn, data, len); if (err == 0) { + send_ok_count++; if (!first_send_logged) { LOG_INF("First NUS send OK (len=%u)", len); first_send_logged = true; } return; } + if (i == 0) { + LOG_DBG("NUS send retry (err=%d)", err); + } 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) { return nus_notification_enabled && (current_conn != NULL); }