Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7a590b0

Browse files
committedFeb 14, 2025·
adding inline function for the rssi calculation
1 parent 2a77a11 commit 7a590b0

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed
 

‎src/platform/silabs/wifi/wf200/WifiInterfaceImpl.cpp

+20-3
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,23 @@ sl_status_t get_all_counters(void)
284284
return result;
285285
}
286286

287+
/**
288+
* @brief Convert RCPI to RSSI
289+
* This function converts the Received Channel Power Indicator (RCPI) value to
290+
* the Received Signal Strength Indicator (RSSI) value. If the result of the
291+
* conversion exceeds the range of int16_t, it will be clamped to the maximum
292+
* or minimum value of int16_t.
293+
* @param[in] rcpi: Received Channel Power Indicator value
294+
* @return RSSI value
295+
*/
296+
inline int16_t ConvertRcpiToRssi(uint32_t rcpi)
297+
{
298+
int64_t rssi = (rcpi / 2) - 110;
299+
// Checking for overflows
300+
VerifyOrReturnValue(rssi < std::numeric_limits<int16_t>::max(), std::numeric_limits<int16_t>::max());
301+
VerifyOrReturnValue(rssi > std::numeric_limits<int16_t>::min(), std::numeric_limits<int16_t>::min());
302+
return rssi;
303+
}
287304
} // namespace
288305

289306
CHIP_ERROR GetMacAddress(sl_wfx_interface_t interface, MutableByteSpan & address)
@@ -404,7 +421,7 @@ CHIP_ERROR GetAccessPointInfo(wfx_wifi_scan_result_t & info)
404421
sl_status_t status = sl_wfx_get_signal_strength(&signal_strength);
405422
VerifyOrReturnError(status == SL_STATUS_OK, CHIP_ERROR_INTERNAL);
406423

407-
info.rssi = (signal_strength - 220) / 2;
424+
info.rssi = ConvertRcpiToRssi(signal_strength);
408425

409426
ChipLogDetail(DeviceLayer, "WIFI:SSID : %s", ap_info.ssid);
410427
ChipLogDetail(DeviceLayer, "WIFI:BSSID : %02x:%02x:%02x:%02x:%02x:%02x", ap_info.bssid[0], ap_info.bssid[1],
@@ -569,7 +586,7 @@ static void sl_wfx_scan_result_callback(sl_wfx_scan_result_ind_body_t * scan_res
569586
{
570587

571588
ChipLogDetail(DeviceLayer, "# %2d %2d %03d %02X:%02X:%02X:%02X:%02X:%02X %s", scan_count, scan_result->channel,
572-
((int16_t) (scan_result->rcpi - 220) / 2), scan_result->mac[0], scan_result->mac[1], scan_result->mac[2],
589+
(ConvertRcpiToRssi(scan_result->rcpi)), scan_result->mac[0], scan_result->mac[1], scan_result->mac[2],
573590
scan_result->mac[3], scan_result->mac[4], scan_result->mac[5], scan_result->ssid_def.ssid);
574591

575592
chip::ByteSpan requestedSsid(scan_ssid, scan_ssid_length);
@@ -614,7 +631,7 @@ static void sl_wfx_scan_result_callback(sl_wfx_scan_result_ind_body_t * scan_res
614631
}
615632

616633
ap->scan.chan = scan_result->channel;
617-
ap->scan.rssi = (scan_result->rcpi - 220) / 2;
634+
ap->scan.rssi = ConvertRcpiToRssi(scan_result->rcpi);
618635

619636
chip::ByteSpan scannedBssid(scan_result->mac, kWifiMacAddressLength);
620637
chip::MutableByteSpan outputBssid(ap->scan.bssid, kWifiMacAddressLength);

0 commit comments

Comments
 (0)
Please sign in to comment.