MTU에 따른 BLE 패킷 분할 - Piezo echo ADC 응답 패킷

- 협상된 MTU 기준으로 reb: 응답 패킷 크기 판단
- 기존 reb:가 MTU에 들어가지 않으면 rec: chunk 분할 전송
This commit is contained in:
2026-07-20 17:09:59 +09:00
parent e691b4f2b6
commit 540c17e890
3 changed files with 146 additions and 1 deletions
+36
View File
@@ -37,6 +37,7 @@ static bool dfu_advertising_mode;
static bool advertising_unlimited;
static uint8_t conn_param_update_attempts;
static int64_t last_rx_conn_param_update_ms;
static uint16_t current_notify_mtu = 23U;
#if IS_ENABLED(CONFIG_BT_SMP)
#define BLE_REQUIRED_SECURITY_LEVEL BT_SECURITY_L4
@@ -55,6 +56,33 @@ static struct k_work adv_restart_work;
static struct k_work_delayable adv_timeout_work;
static struct k_work_delayable conn_param_update_work;
/*
* Store the UATT MTU used by normal GATT/NUS notifications.
* NUS notifications can carry application payload up to UATT MTU - 3 bytes.
*/
static void att_mtu_updated(struct bt_conn *conn, uint16_t tx, uint16_t rx)
{
uint16_t uatt = bt_gatt_get_uatt_mtu(conn);
if (uatt != 0U)
{
current_notify_mtu = uatt;
}
else
{
current_notify_mtu = (tx < rx) ? tx : rx;
}
DBG_PRINTF("[BLE] ATT MTU updated tx=%u rx=%u uatt=%u used=%u notify_payload=%u\r\n",
tx, rx, uatt, current_notify_mtu,
(current_notify_mtu > 3U) ? (current_notify_mtu - 3U) : 0U);
}
static struct bt_gatt_cb gatt_callbacks =
{
.att_mtu_updated = att_mtu_updated,
};
/* 로컬 BLE MAC 주소 로그 */
static void ble_log_local_identity(void)
{
@@ -424,6 +452,7 @@ static void disconnected(struct bt_conn *conn, uint8_t reason)
}
ble_connection_st = false;
current_notify_mtu = 23U;
if (dfu_advertising_mode)
{
// DFU 광고는 미연결 10분 타임아웃 적용
@@ -578,6 +607,7 @@ int ble_service_init(ble_data_rx_cb_t rx_cb)
ble_log_local_identity();
bt_gatt_cb_register(&gatt_callbacks);
#if IS_ENABLED(CONFIG_BT_SMP)
err = ble_security_init();
if (err)
@@ -790,3 +820,9 @@ bool ble_is_connected(void)
{
return (current_conn != NULL);
}
/* ATT MTU used to calculate notify payload size */
uint16_t ble_current_mtu(void)
{
return current_notify_mtu;
}