@@ -284,6 +284,23 @@ sl_status_t get_all_counters(void)
284
284
return result;
285
285
}
286
286
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
+ }
287
304
} // namespace
288
305
289
306
CHIP_ERROR GetMacAddress (sl_wfx_interface_t interface, MutableByteSpan & address)
@@ -404,7 +421,7 @@ CHIP_ERROR GetAccessPointInfo(wfx_wifi_scan_result_t & info)
404
421
sl_status_t status = sl_wfx_get_signal_strength (&signal_strength);
405
422
VerifyOrReturnError (status == SL_STATUS_OK, CHIP_ERROR_INTERNAL);
406
423
407
- info.rssi = (signal_strength - 220 ) / 2 ;
424
+ info.rssi = ConvertRcpiToRssi (signal_strength) ;
408
425
409
426
ChipLogDetail (DeviceLayer, " WIFI:SSID : %s" , ap_info.ssid );
410
427
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
569
586
{
570
587
571
588
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 ],
573
590
scan_result->mac [3 ], scan_result->mac [4 ], scan_result->mac [5 ], scan_result->ssid_def .ssid );
574
591
575
592
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
614
631
}
615
632
616
633
ap->scan .chan = scan_result->channel ;
617
- ap->scan .rssi = (scan_result->rcpi - 220 ) / 2 ;
634
+ ap->scan .rssi = ConvertRcpiToRssi (scan_result->rcpi ) ;
618
635
619
636
chip::ByteSpan scannedBssid (scan_result->mac , kWifiMacAddressLength );
620
637
chip::MutableByteSpan outputBssid (ap->scan .bssid , kWifiMacAddressLength );
0 commit comments