From 571df7df050c5711609779d4b6f07a9b0ac4d19e Mon Sep 17 00:00:00 2001 From: jhchun Date: Fri, 26 Jun 2026 11:00:18 +0900 Subject: [PATCH] =?UTF-8?q?BLE=20connection=20disconnect(reason)=EC=97=90?= =?UTF-8?q?=20=EB=94=B0=EB=A5=B8=20Advertising=20Timeout?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 비정상 연결 해제 시 무제한 광고 - 그 외 10분 광고 후 전원 OFF --- src/ble/ble_service.c | 22 ++++++++++++++++++++-- src/main.c | 7 ++++++- src/main.h | 1 + 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/ble/ble_service.c b/src/ble/ble_service.c index 22499b8..c091461 100644 --- a/src/ble/ble_service.c +++ b/src/ble/ble_service.c @@ -276,6 +276,21 @@ static void adv_restart_handler(struct k_work *work) led_set_state(LED_STATE_ADVERTISING); } +static bool ble_disconnect_reason_uses_unlimited_adv(uint8_t reason) +{ + switch (reason) + { + case BT_HCI_ERR_CONN_TIMEOUT: + case BT_HCI_ERR_LL_RESP_TIMEOUT: + case BT_HCI_ERR_TERM_DUE_TO_MIC_FAIL: + case BT_HCI_ERR_CONN_FAIL_TO_ESTAB: + return true; + + default: + return false; + } +} + static void adv_timeout_handler(struct k_work *work) { ARG_UNUSED(work); @@ -284,6 +299,7 @@ static void adv_timeout_handler(struct k_work *work) { DBG_PRINTF("[BLE] Advertising timeout\r\n"); (void)ble_advertising_stop(); + device_power_off_reason("ble-advertising-timeout"); } } @@ -424,8 +440,10 @@ static void disconnected(struct bt_conn *conn, uint8_t reason) } ble_connection_st = false; - advertising_unlimited = true; - DBG_CORE("[BLE] Disconnected (reason 0x%02x)\r\n", reason); + advertising_unlimited = ble_disconnect_reason_uses_unlimited_adv(reason); + DBG_CORE("[BLE] Disconnected reason=0x%02x adv=%s\r\n", + reason, + advertising_unlimited ? "unlimited" : "10min"); /* 워크큐에서 advertising 재시작 */ k_work_submit(&adv_restart_work); diff --git a/src/main.c b/src/main.c index 5191e2a..4498407 100644 --- a/src/main.c +++ b/src/main.c @@ -426,7 +426,12 @@ void sleep_mode_enter(void) void device_power_off(void) { - power_off_schedule("device_power_off", LED_STATE_POWER_OFF); + device_power_off_reason("device_power_off"); +} + +void device_power_off_reason(const char *reason) +{ + power_off_schedule(reason, LED_STATE_POWER_OFF); } void device_power_keep_on(void) diff --git a/src/main.h b/src/main.h index 38ba65d..a0eb889 100644 --- a/src/main.h +++ b/src/main.h @@ -65,6 +65,7 @@ typedef enum void sleep_mode_enter(void); void sleep_mode_enter_reason(const char *reason); void device_power_off(void); +void device_power_off_reason(const char *reason); void device_power_keep_on(void); void power_button_suspend(bool suspend);