From f40b4612ece8d38760acd44015c38c62c19a87c2 Mon Sep 17 00:00:00 2001 From: Rahul Tank Date: Wed, 8 Apr 2026 14:14:26 +0530 Subject: [PATCH] fix(nimble): Fix prox service to handle negative values --- nimble/host/services/prox/src/ble_svc_prox.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/nimble/host/services/prox/src/ble_svc_prox.c b/nimble/host/services/prox/src/ble_svc_prox.c index fad972344..4d4177a3c 100644 --- a/nimble/host/services/prox/src/ble_svc_prox.c +++ b/nimble/host/services/prox/src/ble_svc_prox.c @@ -16,9 +16,12 @@ #if MYNEWT_VAL(BLE_GATTS) && CONFIG_BT_NIMBLE_PROX_SERVICE /* Characteristic values */ static uint8_t ble_svc_prox_link_loss_alert; -static uint8_t ble_svc_prox_alert; +static int8_t ble_svc_prox_alert; static uint8_t ble_svc_prox_tx_pwr_lvl = BLE_HS_ADV_TX_PWR_LVL_AUTO; +#define BLE_SVC_PROX_HIGH_THRESHOLD (-70) +#define BLE_SVC_PROX_LOW_THRESHOLD (-100) + /* Characteristic value handles */ static uint16_t ble_svc_prox_link_loss_val_handle; static uint16_t ble_svc_prox_immediate_alert_loc_val_handle; @@ -129,11 +132,13 @@ ble_prox_prph_alert_unalert(uint16_t conn_handle) MODLOG_DFLT(ERROR, "conn_handle %d exceeds max connections", conn_handle); return; } - if (ble_svc_prox_alert != 0 && !ble_svc_prox_alert_conn[conn_handle]) { + if (ble_svc_prox_alert > BLE_SVC_PROX_HIGH_THRESHOLD && + !ble_svc_prox_alert_conn[conn_handle]) { MODLOG_DFLT(INFO, "Path loss exceeded threshold, starting alert for device with " "conn_handle %d", conn_handle); ble_svc_prox_alert_conn[conn_handle] = true; - } else if (ble_svc_prox_alert == 0 && ble_svc_prox_alert_conn[conn_handle]) { + } else if (ble_svc_prox_alert < BLE_SVC_PROX_LOW_THRESHOLD && + ble_svc_prox_alert_conn[conn_handle]) { MODLOG_DFLT(INFO, "Path loss lower than threshold, stopping alert for device with " "conn_handle %d", conn_handle); ble_svc_prox_alert_conn[conn_handle] = false;