blob: 7bd8c6c4b2263ed8742598d18b78cfab4d830708 [file] [log] [blame]
Tony Lee6c595012019-06-19 10:54:59 +08001#include "nvmes.hpp"
2
Brandon Kimd5838d12021-05-19 12:51:55 -07003#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 Lee6c595012019-06-19 10:54:59 +08007namespace phosphor
8{
9namespace nvme
10{
11
12void 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 Hung9ebfa482021-05-20 09:53:03 +080019 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 Lee6c595012019-06-19 10:54:59 +080027
George Hung9ebfa482021-05-20 09:53:03 +080028 CriticalInterface::criticalAlarmHigh(criticalAlarmHigh);
Tony Lee6c595012019-06-19 10:54:59 +080029
George Hung9ebfa482021-05-20 09:53:03 +080030 CriticalInterface::criticalAlarmLow(criticalAlarmLow);
Tony Lee6c595012019-06-19 10:54:59 +080031
George Hung9ebfa482021-05-20 09:53:03 +080032 WarningInterface::warningAlarmHigh(warningAlarmHigh);
Tony Lee6c595012019-06-19 10:54:59 +080033
George Hung9ebfa482021-05-20 09:53:03 +080034 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 Lee6c595012019-06-19 10:54:59 +080080}
81
82void NvmeSSD::setSensorThreshold(int8_t criticalHigh, int8_t criticalLow,
Tony Lee6c595012019-06-19 10:54:59 +080083 int8_t warningHigh, int8_t warningLow)
84{
Tony Lee6c595012019-06-19 10:54:59 +080085 CriticalInterface::criticalHigh(criticalHigh);
86 CriticalInterface::criticalLow(criticalLow);
87
88 WarningInterface::warningHigh(warningHigh);
89 WarningInterface::warningLow(warningLow);
George Hung831f2042021-05-19 17:02:29 +080090}
Tony Lee6c595012019-06-19 10:54:59 +080091
George Hung831f2042021-05-19 17:02:29 +080092void NvmeSSD::setSensorMaxMin(int8_t maxValue, int8_t minValue)
93{
Tony Lee6c595012019-06-19 10:54:59 +080094 ValueIface::maxValue(maxValue);
95 ValueIface::minValue(minValue);
96}
97
98void NvmeSSD::setSensorValueToDbus(const int8_t value)
99{
100 ValueIface::value(value);
101}
102
103} // namespace nvme
George Hung831f2042021-05-19 17:02:29 +0800104} // namespace phosphor