Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 1 | #include "nvmes.hpp" |
| 2 | |
Brandon Kim | d5838d1 | 2021-05-19 12:51:55 -0700 | [diff] [blame] | 3 | #include <xyz/openbmc_project/Sensor/Threshold/Critical/server.hpp> |
| 4 | #include <xyz/openbmc_project/Sensor/Threshold/Warning/server.hpp> |
| 5 | #include <xyz/openbmc_project/Sensor/Value/server.hpp> |
| 6 | |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 7 | namespace phosphor |
| 8 | { |
| 9 | namespace nvme |
| 10 | { |
| 11 | |
| 12 | void NvmeSSD::checkSensorThreshold() |
| 13 | { |
| 14 | int8_t value = ValueIface::value(); |
| 15 | int8_t criticalHigh = CriticalInterface::criticalHigh(); |
| 16 | int8_t criticalLow = CriticalInterface::criticalLow(); |
| 17 | int8_t warningHigh = WarningInterface::warningHigh(); |
| 18 | int8_t warningLow = WarningInterface::warningLow(); |
George Hung | 9ebfa48 | 2021-05-20 09:53:03 +0800 | [diff] [blame] | 19 | auto criticalAlarmLowState = CriticalInterface::criticalAlarmLow(); |
| 20 | auto criticalAlarmHighState = CriticalInterface::criticalAlarmHigh(); |
| 21 | auto warningAlarmLowState = WarningInterface::warningAlarmLow(); |
| 22 | auto warningAlarmHighState = WarningInterface::warningAlarmHigh(); |
| 23 | bool criticalAlarmLow = (value <= criticalLow); |
| 24 | bool criticalAlarmHigh = (value >= criticalHigh); |
| 25 | bool warningAlarmLow = (value <= warningLow); |
| 26 | bool warningAlarmHigh = (value >= warningHigh); |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 27 | |
George Hung | 9ebfa48 | 2021-05-20 09:53:03 +0800 | [diff] [blame] | 28 | CriticalInterface::criticalAlarmHigh(criticalAlarmHigh); |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 29 | |
George Hung | 9ebfa48 | 2021-05-20 09:53:03 +0800 | [diff] [blame] | 30 | CriticalInterface::criticalAlarmLow(criticalAlarmLow); |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 31 | |
George Hung | 9ebfa48 | 2021-05-20 09:53:03 +0800 | [diff] [blame] | 32 | WarningInterface::warningAlarmHigh(warningAlarmHigh); |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 33 | |
George Hung | 9ebfa48 | 2021-05-20 09:53:03 +0800 | [diff] [blame] | 34 | WarningInterface::warningAlarmLow(warningAlarmLow); |
| 35 | |
| 36 | if (criticalAlarmHighState != criticalAlarmHigh) |
| 37 | { |
| 38 | if (criticalAlarmHigh) |
| 39 | { |
| 40 | CriticalInterface::criticalHighAlarmAsserted(value); |
| 41 | } |
| 42 | else |
| 43 | { |
| 44 | CriticalInterface::criticalHighAlarmDeasserted(value); |
| 45 | } |
| 46 | } |
| 47 | if (criticalAlarmLowState != criticalAlarmLow) |
| 48 | { |
| 49 | if (criticalAlarmLow) |
| 50 | { |
| 51 | CriticalInterface::criticalLowAlarmAsserted(value); |
| 52 | } |
| 53 | else |
| 54 | { |
| 55 | CriticalInterface::criticalLowAlarmDeasserted(value); |
| 56 | } |
| 57 | } |
| 58 | if (warningAlarmHighState != warningAlarmHigh) |
| 59 | { |
| 60 | if (warningAlarmHigh) |
| 61 | { |
| 62 | WarningInterface::warningHighAlarmAsserted(value); |
| 63 | } |
| 64 | else |
| 65 | { |
| 66 | WarningInterface::warningHighAlarmDeasserted(value); |
| 67 | } |
| 68 | } |
| 69 | if (warningAlarmLowState != warningAlarmLow) |
| 70 | { |
| 71 | if (warningAlarmLow) |
| 72 | { |
| 73 | WarningInterface::warningLowAlarmAsserted(value); |
| 74 | } |
| 75 | else |
| 76 | { |
| 77 | WarningInterface::warningLowAlarmDeasserted(value); |
| 78 | } |
| 79 | } |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | void NvmeSSD::setSensorThreshold(int8_t criticalHigh, int8_t criticalLow, |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 83 | int8_t warningHigh, int8_t warningLow) |
| 84 | { |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 85 | CriticalInterface::criticalHigh(criticalHigh); |
| 86 | CriticalInterface::criticalLow(criticalLow); |
| 87 | |
| 88 | WarningInterface::warningHigh(warningHigh); |
| 89 | WarningInterface::warningLow(warningLow); |
George Hung | 831f204 | 2021-05-19 17:02:29 +0800 | [diff] [blame] | 90 | } |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 91 | |
George Hung | 831f204 | 2021-05-19 17:02:29 +0800 | [diff] [blame] | 92 | void NvmeSSD::setSensorMaxMin(int8_t maxValue, int8_t minValue) |
| 93 | { |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 94 | ValueIface::maxValue(maxValue); |
| 95 | ValueIface::minValue(minValue); |
| 96 | } |
| 97 | |
| 98 | void NvmeSSD::setSensorValueToDbus(const int8_t value) |
| 99 | { |
| 100 | ValueIface::value(value); |
| 101 | } |
| 102 | |
| 103 | } // namespace nvme |
George Hung | 831f204 | 2021-05-19 17:02:29 +0800 | [diff] [blame] | 104 | } // namespace phosphor |