Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Silabs][Wf200] Adding inline function for the rssi calculation for WF200 #37578

Merged
merged 6 commits into from
Feb 20, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions src/platform/silabs/wifi/wf200/WifiInterfaceImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,23 @@ sl_status_t get_all_counters(void)
return result;
}

/**
* @brief Convert RCPI to RSSI
* This function converts the Received Channel Power Indicator (RCPI) value to
* the Received Signal Strength Indicator (RSSI) value. If the result of the
* conversion exceeds the range of int16_t, it will be clamped to the maximum
* or minimum value of int16_t.
* @param[in] rcpi: Received Channel Power Indicator value
* @return RSSI value
*/
inline int16_t ConvertRcpiToRssi(uint32_t rcpi)
{
int64_t rssi = (rcpi / 2) - 110;
// Checking for overflows
VerifyOrReturnValue(rssi < std::numeric_limits<int16_t>::max(), std::numeric_limits<int16_t>::max());
VerifyOrReturnValue(rssi > std::numeric_limits<int16_t>::min(), std::numeric_limits<int16_t>::min());
return rssi;
}
} // namespace

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

info.rssi = (signal_strength - 220) / 2;
info.rssi = ConvertRcpiToRssi(signal_strength);

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

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

chip::ByteSpan requestedSsid(scan_ssid, scan_ssid_length);
Expand Down Expand Up @@ -614,7 +631,7 @@ static void sl_wfx_scan_result_callback(sl_wfx_scan_result_ind_body_t * scan_res
}

ap->scan.chan = scan_result->channel;
ap->scan.rssi = (scan_result->rcpi - 220) / 2;
ap->scan.rssi = ConvertRcpiToRssi(scan_result->rcpi);

chip::ByteSpan scannedBssid(scan_result->mac, kWifiMacAddressLength);
chip::MutableByteSpan outputBssid(ap->scan.bssid, kWifiMacAddressLength);
Expand Down
Loading