mirror of
https://github.com/espressif/openthread.git
synced 2026-08-20 09:29:51 +00:00
[link-quality] fix corner case of ScaleRawValueToRssi (#9102)
Currently if we call `ScaleRawValueToRssi` with value 0 or 1, the result is incorrect. Because it tries to static_cast `-130` or `-129` to `int8_t`. I think it's not worthwhile to widen int8_t to int16_t only for the 2 corner cases. So I prefer returning the smallest value -128 for the 2 cases.
This commit is contained in:
@@ -518,6 +518,13 @@ public:
|
||||
VerifyOrQuit(LinkMetrics::ScaleRssiToRawValue(1) == 255);
|
||||
VerifyOrQuit(LinkMetrics::ScaleRssiToRawValue(10) == 255);
|
||||
VerifyOrQuit(LinkMetrics::ScaleRssiToRawValue(127) == 255);
|
||||
|
||||
// Test corner case of ScaleRawValueToRssi
|
||||
for (uint8_t rawValue = 0; rawValue < 2; rawValue++)
|
||||
{
|
||||
int8_t rssi = LinkMetrics::ScaleRawValueToRssi(rawValue);
|
||||
printf("\nRaw Value: %u -> RSSI : %-3d", rawValue, rssi);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user