diff options
-rw-r--r-- | include/ipmid/types.hpp | 10 | ||||
-rw-r--r-- | sensordatahandler.cpp | 6 | ||||
-rw-r--r-- | sensordatahandler.hpp | 11 | ||||
-rw-r--r-- | sensorhandler.cpp | 37 | ||||
-rw-r--r-- | sensorhandler.hpp | 20 |
5 files changed, 36 insertions, 48 deletions
diff --git a/include/ipmid/types.hpp b/include/ipmid/types.hpp index e2f80c0..3e64cb4 100644 --- a/include/ipmid/types.hpp +++ b/include/ipmid/types.hpp @@ -100,7 +100,15 @@ struct GetReadingResponse constexpr auto inventoryRoot = "/xyz/openbmc_project/inventory"; -using GetSensorResponse = std::array<uint8_t, sizeof(GetReadingResponse)>; +struct GetSensorResponse +{ + uint8_t reading; // sensor reading + bool readingOrStateUnavailable; // 1 = reading/state unavailable + bool scanningEnabled; // 0 = sensor scanning disabled + bool allEventMessagesEnabled; // 0 = All Event Messages disabled + uint8_t thresholdLevelsStates; // threshold/discrete sensor states + uint8_t discreteReadingSensorStates; // discrete-only, optional states +}; using OffsetValueMap = std::map<Offset, Values>; diff --git a/sensordatahandler.cpp b/sensordatahandler.cpp index 923b96a..0d1182d 100644 --- a/sensordatahandler.cpp +++ b/sensordatahandler.cpp @@ -132,7 +132,6 @@ GetSensorResponse mapDbusToAssertion(const Info& sensorInfo, { sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()}; GetSensorResponse response{}; - auto responseData = reinterpret_cast<GetReadingResponse*>(response.data()); auto service = ipmi::getService(bus, interface, path); @@ -149,7 +148,7 @@ GetSensorResponse mapDbusToAssertion(const Info& sensorInfo, { if (propValue == value.second.assert) { - setOffset(value.first, responseData); + setOffset(value.first, &response); break; } } @@ -169,7 +168,6 @@ GetSensorResponse eventdata2(const Info& sensorInfo) { sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()}; GetSensorResponse response{}; - auto responseData = reinterpret_cast<GetReadingResponse*>(response.data()); auto service = ipmi::getService(bus, sensorInfo.sensorInterface, sensorInfo.sensorPath); @@ -188,7 +186,7 @@ GetSensorResponse eventdata2(const Info& sensorInfo) { if (propValue == value.second.assert) { - setReading(value.first, responseData); + setReading(value.first, &response); break; } } diff --git a/sensordatahandler.hpp b/sensordatahandler.hpp index 129cbb4..99c3ae9 100644 --- a/sensordatahandler.hpp +++ b/sensordatahandler.hpp @@ -156,7 +156,6 @@ GetSensorResponse readingAssertion(const Info& sensorInfo) { sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()}; GetSensorResponse response{}; - auto responseData = reinterpret_cast<GetReadingResponse*>(response.data()); auto service = ipmi::getService(bus, sensorInfo.sensorInterface, sensorInfo.sensorPath); @@ -166,8 +165,7 @@ GetSensorResponse readingAssertion(const Info& sensorInfo) sensorInfo.propertyInterfaces.begin()->first, sensorInfo.propertyInterfaces.begin()->second.begin()->first); - setAssertionBytes(static_cast<uint16_t>(std::get<T>(propValue)), - responseData); + setAssertionBytes(static_cast<uint16_t>(std::get<T>(propValue)), &response); return response; } @@ -184,10 +182,10 @@ template <typename T> GetSensorResponse readingData(const Info& sensorInfo) { sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()}; + GetSensorResponse response{}; - auto responseData = reinterpret_cast<GetReadingResponse*>(response.data()); - enableScanning(responseData); + enableScanning(&response); auto service = ipmi::getService(bus, sensorInfo.sensorInterface, sensorInfo.sensorPath); @@ -228,8 +226,7 @@ GetSensorResponse readingData(const Info& sensorInfo) auto rawData = static_cast<uint8_t>((value - sensorInfo.scaledOffset) / sensorInfo.coefficientM); - - setReading(rawData, responseData); + setReading(rawData, &response); return response; } diff --git a/sensorhandler.cpp b/sensorhandler.cpp index a506c82..473f6bc 100644 --- a/sensorhandler.cpp +++ b/sensorhandler.cpp @@ -417,8 +417,8 @@ ipmi::RspType<uint8_t, // sensor reading uint5_t, // reserved bool, // reading state - bool, // sensor scanning state disabled - bool, // all event message state disabled + bool, // 0 = sensor scanning state disabled + bool, // 0 = all event messages disabled uint8_t, // threshold levels states uint8_t // discrete reading sensor states @@ -443,32 +443,15 @@ ipmi::RspType<uint8_t, // sensor reading try { - ipmi::sensor::GetSensorResponse getResponse{}; - getResponse = iter->second.getFunc(iter->second); + ipmi::sensor::GetSensorResponse getResponse = + iter->second.getFunc(iter->second); - constexpr uint8_t senReadingResp = 0; - constexpr uint8_t senScanStateResp = 1; - constexpr uint8_t assertionStatesLsbResp = 2; - constexpr uint8_t assertionStatesMsbResp = 3; - constexpr uint8_t senReadStateMask = 0x20; - constexpr uint8_t senScanStateMask = 0x40; - constexpr uint8_t allEventMessageStateMask = 0x80; - - uint8_t senReading = getResponse[senReadingResp]; - constexpr uint5_t reserved{0}; - bool readState = - static_cast<bool>(getResponse[senScanStateResp] & senReadStateMask); - bool senScanState = - static_cast<bool>(getResponse[senScanStateResp] & senScanStateMask); - bool allEventMessageState = static_cast<bool>( - getResponse[senScanStateResp] & allEventMessageStateMask); - - uint8_t assertionStatesLsb = getResponse[assertionStatesLsbResp]; - uint8_t assertionStatesMsb = getResponse[assertionStatesMsbResp]; - - return ipmi::responseSuccess(senReading, reserved, readState, - senScanState, allEventMessageState, - assertionStatesLsb, assertionStatesMsb); + return ipmi::responseSuccess(getResponse.reading, uint5_t(0), + getResponse.readingOrStateUnavailable, + getResponse.scanningEnabled, + getResponse.allEventMessagesEnabled, + getResponse.thresholdLevelsStates, + getResponse.discreteReadingSensorStates); } #ifdef UPDATE_FUNCTIONAL_ON_FAIL catch (const SensorFunctionalError& e) diff --git a/sensorhandler.hpp b/sensorhandler.hpp index f5a8b41..8780235 100644 --- a/sensorhandler.hpp +++ b/sensorhandler.hpp @@ -644,15 +644,15 @@ namespace sensor * @param[in] offset - offset number. * @param[in/out] resp - get sensor reading response. */ -inline void setOffset(uint8_t offset, ipmi::sensor::GetReadingResponse* resp) +inline void setOffset(uint8_t offset, ipmi::sensor::GetSensorResponse* resp) { if (offset > 7) { - resp->assertOffset8_14 |= 1 << (offset - 8); + resp->discreteReadingSensorStates |= 1 << (offset - 8); } else { - resp->assertOffset0_7 |= 1 << offset; + resp->thresholdLevelsStates |= 1 << offset; } } @@ -662,7 +662,7 @@ inline void setOffset(uint8_t offset, ipmi::sensor::GetReadingResponse* resp) * @param[in] offset - offset number. * @param[in/out] resp - get sensor reading response. */ -inline void setReading(uint8_t value, ipmi::sensor::GetReadingResponse* resp) +inline void setReading(uint8_t value, ipmi::sensor::GetSensorResponse* resp) { resp->reading = value; } @@ -675,10 +675,10 @@ inline void setReading(uint8_t value, ipmi::sensor::GetReadingResponse* resp) * @param[in/out] resp - get sensor reading response. */ inline void setAssertionBytes(uint16_t value, - ipmi::sensor::GetReadingResponse* resp) + ipmi::sensor::GetSensorResponse* resp) { - resp->assertOffset0_7 = static_cast<uint8_t>(value & 0x00FF); - resp->assertOffset8_14 = static_cast<uint8_t>(value >> 8); + resp->thresholdLevelsStates = static_cast<uint8_t>(value & 0x00FF); + resp->discreteReadingSensorStates = static_cast<uint8_t>(value >> 8); } /** @@ -686,9 +686,11 @@ inline void setAssertionBytes(uint16_t value, * * @param[in/out] resp - get sensor reading response. */ -inline void enableScanning(ipmi::sensor::GetReadingResponse* resp) +inline void enableScanning(ipmi::sensor::GetSensorResponse* resp) { - resp->operation = 1 << 6; + resp->readingOrStateUnavailable = false; + resp->scanningEnabled = true; + resp->allEventMessagesEnabled = false; } } // namespace sensor |