@@ -284,6 +284,26 @@ sl_status_t get_all_counters(void)
284
284
return result;
285
285
}
286
286
287
+ /* *
288
+ * @brief Convert RCPI to RSSI
289
+
290
+ * This function converts the Received Channel Power Indicator (RCPI) to
291
+ * the Received Signal Strength Indicator (RSSI). If the result of the
292
+ * conversion exceeds the range of a int16_t, it will be clamped to the maximum
293
+ * or minimum value of int16_t.
294
+
295
+ * @param[in] rcpi: Received Channel Power Indicator value
296
+
297
+ * @return RSSI value
298
+ */
299
+ inline int16_t ConvertRcpiToRssi (uint32_t rcpi)
300
+ {
301
+ int64_t rssi = (rcpi / 2 ) - 110 ;
302
+ // Checking for overflows
303
+ VerifyOrReturnValue (rssi <= std::numeric_limits<int16_t >::max (), std::numeric_limits<int16_t >::max ());
304
+ VerifyOrReturnValue (rssi >= std::numeric_limits<int16_t >::min (), std::numeric_limits<int16_t >::min ());
305
+ return rssi;
306
+ }
287
307
} // namespace
288
308
289
309
CHIP_ERROR GetMacAddress (sl_wfx_interface_t interface, MutableByteSpan & address)
@@ -404,7 +424,7 @@ CHIP_ERROR GetAccessPointInfo(wfx_wifi_scan_result_t & info)
404
424
sl_status_t status = sl_wfx_get_signal_strength (&signal_strength);
405
425
VerifyOrReturnError (status == SL_STATUS_OK, CHIP_ERROR_INTERNAL);
406
426
407
- info.rssi = (signal_strength - 220 ) / 2 ;
427
+ info.rssi = ConvertRcpiToRssi (signal_strength) ;
408
428
409
429
ChipLogDetail (DeviceLayer, " WIFI:SSID : %s" , ap_info.ssid );
410
430
ChipLogDetail (DeviceLayer, " WIFI:BSSID : %02x:%02x:%02x:%02x:%02x:%02x" , ap_info.bssid [0 ], ap_info.bssid [1 ],
@@ -583,7 +603,7 @@ static void sl_wfx_scan_result_callback(sl_wfx_scan_result_ind_body_t * scan_res
583
603
{
584
604
585
605
ChipLogDetail (DeviceLayer, " # %2d %2d %03d %02X:%02X:%02X:%02X:%02X:%02X %s" , scan_count, scan_result->channel ,
586
- (( int16_t ) ( scan_result->rcpi - 220 ) / 2 ), scan_result->mac [0 ], scan_result->mac [1 ], scan_result->mac [2 ],
606
+ (ConvertRcpiToRssi ( scan_result->rcpi ) ), scan_result->mac [0 ], scan_result->mac [1 ], scan_result->mac [2 ],
587
607
scan_result->mac [3 ], scan_result->mac [4 ], scan_result->mac [5 ], scan_result->ssid_def .ssid );
588
608
589
609
chip::ByteSpan requestedSsid (scan_ssid, scan_ssid_length);
@@ -628,7 +648,7 @@ static void sl_wfx_scan_result_callback(sl_wfx_scan_result_ind_body_t * scan_res
628
648
}
629
649
630
650
ap->scan .chan = scan_result->channel ;
631
- ap->scan .rssi = (scan_result->rcpi - 220 ) / 2 ;
651
+ ap->scan .rssi = ConvertRcpiToRssi (scan_result->rcpi ) ;
632
652
633
653
chip::ByteSpan scannedBssid (scan_result->mac , kWifiMacAddressLength );
634
654
chip::MutableByteSpan outputBssid (ap->scan .bssid , kWifiMacAddressLength );
0 commit comments