본딩 삭제 후 재부팅 복귀 처리 수정
- 초록 power-on LED 2초 → advertising LED 패턴으로 정상 전환
This commit is contained in:
+54
-3
@@ -36,6 +36,7 @@ static struct bt_conn *current_conn;
|
|||||||
static ble_data_rx_cb_t rx_callback;
|
static ble_data_rx_cb_t rx_callback;
|
||||||
static bool dfu_advertising_mode;
|
static bool dfu_advertising_mode;
|
||||||
static bool advertising_unlimited;
|
static bool advertising_unlimited;
|
||||||
|
static bool advertising_restart_suspended;
|
||||||
static uint8_t conn_param_update_attempts;
|
static uint8_t conn_param_update_attempts;
|
||||||
static int64_t last_rx_conn_param_update_ms;
|
static int64_t last_rx_conn_param_update_ms;
|
||||||
static uint16_t current_notify_mtu = 23U;
|
static uint16_t current_notify_mtu = 23U;
|
||||||
@@ -203,18 +204,33 @@ static void ble_pairing_window_init_from_bonds(void)
|
|||||||
{
|
{
|
||||||
bool reset_request = ble_consume_pairing_window_reset_request();
|
bool reset_request = ble_consume_pairing_window_reset_request();
|
||||||
|
|
||||||
|
if (reset_request)
|
||||||
|
{
|
||||||
|
int err = bt_unpair(BT_ID_DEFAULT, NULL);
|
||||||
|
|
||||||
|
if (err)
|
||||||
|
{
|
||||||
|
DBG_ERR("[BLE] Reset-window bt_unpair retry failed err=%d\r\n", err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bond_peer_exists = false;
|
bond_peer_exists = false;
|
||||||
bt_foreach_bond(BT_ID_DEFAULT, bond_check_cb, &bond_peer_exists);
|
bt_foreach_bond(BT_ID_DEFAULT, bond_check_cb, &bond_peer_exists);
|
||||||
|
|
||||||
DBG_CORE("[BLE] Bond peer exists=%u reset_window=%u\r\n", bond_peer_exists ? 1U : 0U, reset_request ? 1U : 0U);
|
DBG_CORE("[BLE] Bond peer exists=%u reset_window=%u\r\n", bond_peer_exists ? 1U : 0U, reset_request ? 1U : 0U);
|
||||||
|
|
||||||
if (bond_peer_exists)
|
if (reset_request)
|
||||||
|
{
|
||||||
|
bond_peer_exists = false;
|
||||||
|
pairing_window_open_set(true);
|
||||||
|
}
|
||||||
|
else if (bond_peer_exists)
|
||||||
{
|
{
|
||||||
pairing_window_close();
|
pairing_window_close();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
pairing_window_open_set(reset_request);
|
pairing_window_open_set(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -389,6 +405,13 @@ static int ble_security_init(void)
|
|||||||
static void adv_restart_handler(struct k_work *work)
|
static void adv_restart_handler(struct k_work *work)
|
||||||
{
|
{
|
||||||
ARG_UNUSED(work);
|
ARG_UNUSED(work);
|
||||||
|
|
||||||
|
if (advertising_restart_suspended)
|
||||||
|
{
|
||||||
|
DBG_CORE("[BLE] Advertising restart skipped (suspended)\r\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ble_advertising_start();
|
ble_advertising_start();
|
||||||
led_set_state(LED_STATE_ADVERTISING);
|
led_set_state(LED_STATE_ADVERTISING);
|
||||||
}
|
}
|
||||||
@@ -539,7 +562,10 @@ static void connected(struct bt_conn *conn, uint8_t err)
|
|||||||
if (err)
|
if (err)
|
||||||
{
|
{
|
||||||
DBG_ERR("[BLE] Connect failed (err %d) -> re-adv\r\n", err);
|
DBG_ERR("[BLE] Connect failed (err %d) -> re-adv\r\n", err);
|
||||||
k_work_submit(&adv_restart_work);
|
if (!advertising_restart_suspended)
|
||||||
|
{
|
||||||
|
k_work_submit(&adv_restart_work);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -610,6 +636,12 @@ static void disconnected(struct bt_conn *conn, uint8_t reason)
|
|||||||
reason,
|
reason,
|
||||||
advertising_unlimited ? "unlimited" : "10min");
|
advertising_unlimited ? "unlimited" : "10min");
|
||||||
|
|
||||||
|
if (advertising_restart_suspended)
|
||||||
|
{
|
||||||
|
DBG_CORE("[BLE] Disconnected while adv restart suspended\r\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// 워크큐에서 advertising 재시작
|
// 워크큐에서 advertising 재시작
|
||||||
k_work_submit(&adv_restart_work);
|
k_work_submit(&adv_restart_work);
|
||||||
}
|
}
|
||||||
@@ -814,6 +846,7 @@ int ble_advertising_start(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ble_tx_power_apply_advertising();
|
ble_tx_power_apply_advertising();
|
||||||
|
led_set_state(LED_STATE_ADVERTISING);
|
||||||
|
|
||||||
k_work_cancel_delayable(&adv_timeout_work);
|
k_work_cancel_delayable(&adv_timeout_work);
|
||||||
if (!advertising_unlimited) // DFU 광고 포함, 미연결 10분 시 전원 OFF
|
if (!advertising_unlimited) // DFU 광고 포함, 미연결 10분 시 전원 OFF
|
||||||
@@ -974,6 +1007,24 @@ void ble_pairing_window_mark_reset_open(void)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ble_pairing_window_reset_requested(void)
|
||||||
|
{
|
||||||
|
#if IS_ENABLED(CONFIG_BT_SMP) && NRF_POWER_HAS_GPREGRET
|
||||||
|
return (nrf_power_gpregret_get(NRF_POWER, PAIRING_WINDOW_GPREGRET_REG) == PAIRING_WINDOW_GPREGRET_MAGIC);
|
||||||
|
#else
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void ble_advertising_restart_suspend(bool suspend)
|
||||||
|
{
|
||||||
|
advertising_restart_suspended = suspend;
|
||||||
|
if (suspend)
|
||||||
|
{
|
||||||
|
k_work_cancel(&adv_restart_work);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool ble_is_connected(void)
|
bool ble_is_connected(void)
|
||||||
{
|
{
|
||||||
return (current_conn != NULL);
|
return (current_conn != NULL);
|
||||||
|
|||||||
@@ -37,5 +37,7 @@ bool ble_dfu_advertising_is_enabled(void);
|
|||||||
bool ble_is_connected(void);
|
bool ble_is_connected(void);
|
||||||
int ble_disconnect_active(void);
|
int ble_disconnect_active(void);
|
||||||
void ble_pairing_window_mark_reset_open(void);
|
void ble_pairing_window_mark_reset_open(void);
|
||||||
|
bool ble_pairing_window_reset_requested(void);
|
||||||
|
void ble_advertising_restart_suspend(bool suspend);
|
||||||
|
|
||||||
#endif /* BLE_SERVICE_H__ */
|
#endif /* BLE_SERVICE_H__ */
|
||||||
|
|||||||
+1
-1
@@ -62,7 +62,7 @@ static void boot_context_detect(void)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// soft reset 후 복귀 (전원 버튼 새 부팅 X)
|
// soft reset 후 복귀 (전원 버튼 새 부팅 X)
|
||||||
resume_without_power_button = (boot_reset_reason & (NRF_POWER_RESETREAS_SREQ_MASK | NRF_POWER_RESETREAS_DOG_MASK | NRF_POWER_RESETREAS_LOCKUP_MASK | NRF_POWER_RESETREAS_RESETPIN_MASK)) != 0U;
|
resume_without_power_button = ((boot_reset_reason & (NRF_POWER_RESETREAS_SREQ_MASK | NRF_POWER_RESETREAS_DOG_MASK | NRF_POWER_RESETREAS_LOCKUP_MASK | NRF_POWER_RESETREAS_RESETPIN_MASK)) != 0U) || ble_pairing_window_reset_requested();
|
||||||
|
|
||||||
// 다음 부팅 오판 방지를 위해 RESETREAS 플래그 정리
|
// 다음 부팅 오판 방지를 위해 RESETREAS 플래그 정리
|
||||||
if (boot_reset_reason != 0U)
|
if (boot_reset_reason != 0U)
|
||||||
|
|||||||
Reference in New Issue
Block a user