Fix PXE VR reading negative
PXE VR uses 11 bit format. Also sign extend the 11bit
reading so that negatives show correctly.
Change-Id: I22f92a385532e69a283fdf02adf8d2edc6bd60c2
Signed-off-by: James Feist <james.feist@linux.intel.com>
diff --git a/src/IpmbSensor.cpp b/src/IpmbSensor.cpp
index cb7f6ef..bc9d842 100644
--- a/src/IpmbSensor.cpp
+++ b/src/IpmbSensor.cpp
@@ -155,7 +155,7 @@
// goto page 0
initData = {0x57, 0x01, 0x00, 0x14, 0x03, deviceAddress, 0x00,
0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00};
- readingFormat = ReadingFormat::byte3;
+ readingFormat = ReadingFormat::elevenBit;
}
else if (type == IpmbType::IR38363VR)
{
@@ -234,6 +234,7 @@
switch (readingFormat)
{
case (ReadingFormat::byte0):
+ {
if (command == ipmi::sensor::getSensorReading &&
!ipmi::sensor::isValid(data))
{
@@ -242,7 +243,9 @@
resp = data[0];
return true;
+ }
case (ReadingFormat::byte3):
+ {
if (data.size() < 4)
{
if (!errCount)
@@ -254,7 +257,9 @@
}
resp = data[3];
return true;
+ }
case (ReadingFormat::elevenBit):
+ {
if (data.size() < 5)
{
if (!errCount)
@@ -265,9 +270,15 @@
return false;
}
- resp = ((data[4] << 8) | data[3]);
+ int16_t value = ((data[4] << 8) | data[3]);
+ constexpr const size_t shift = 16 - 11; // 11bit into 16bit
+ value <<= shift;
+ value >>= shift;
+ resp = value;
return true;
+ }
case (ReadingFormat::elevenBitShift):
+ {
if (data.size() < 5)
{
if (!errCount)
@@ -280,6 +291,7 @@
resp = ((data[4] << 8) | data[3]) >> 3;
return true;
+ }
default:
throw std::runtime_error("Invalid reading type");
}