Fixed sensor value conversion issue.
While converting the sensor values as per sensor conversion formula
(IPMI spec 36.3), some portion of the decimal value is discarded.
Fixed this issue.
Tested:
// Get sensor treshold value
ipmitool raw 0x04 0x27 0x3D
1b 27 26 00 2d 2f 00
// Set sensor treshold value
ipmitool raw 0x04 0x26 0x3D 0x08 0x00 0x00 0x00 0xf0 0x00 0x00
// Get sensor treshold value
ipmitool raw 0x04 0x27 0x3D
1b 27 26 00 f0 2f 00
Signed-off-by: Rajashekar Gade Reddy <raja.sekhar.reddy.gade@linux.intel.com>
Change-Id: Ie560b038323b01bfa864a379d12f02d0c5a07d75
diff --git a/include/sensorutils.hpp b/include/sensorutils.hpp
index 3b109ae..577578b 100644
--- a/include/sensorutils.hpp
+++ b/include/sensorutils.hpp
@@ -137,7 +137,7 @@
const int8_t rExp, const uint16_t bValue,
const int8_t bExp, const bool bSigned)
{
- int32_t scaledValue =
+ double scaledValue =
(value - (bValue * std::pow(10, bExp) * std::pow(10, rExp))) /
(mValue * std::pow(10, rExp));
@@ -148,7 +148,7 @@
{
throw std::out_of_range("Value out of range");
}
- return static_cast<int8_t>(scaledValue);
+ return static_cast<int8_t>(std::round(scaledValue));
}
else
{
@@ -157,7 +157,7 @@
{
throw std::out_of_range("Value out of range");
}
- return static_cast<uint8_t>(scaledValue);
+ return static_cast<uint8_t>(std::round(scaledValue));
}
}