[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:
Li Cao
2023-05-30 22:31:14 -07:00
committed by GitHub
parent 74c5e4ba01
commit fa81b21f4c
3 changed files with 31 additions and 1 deletions
+7
View File
@@ -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);
}
}
};