blob: 5700922fbe209d250f4d1c4dfacf8dad5236e355 [file] [log] [blame]
Brad Bishop179b39b2016-05-12 16:45:57 -04001# Contributors Listed Below - COPYRIGHT 2016
2# [+] International Business Machines Corp.
3#
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14# implied. See the License for the specific language governing
15# permissions and limitations under the License.
16
17import os
18import subprocess
19import dbus
20import dbus.service
21from obmc.dbuslib.bindings import DbusProperties
22
23
24## Abstract class, must subclass
25class SensorValue(DbusProperties):
26 IFACE_NAME = 'org.openbmc.SensorValue'
27
28 def __init__(self, bus, name):
29 self.Set(SensorValue.IFACE_NAME, 'units', "")
30 self.Set(SensorValue.IFACE_NAME, 'error', False)
31
32 @dbus.service.method(
33 IFACE_NAME, in_signature='v', out_signature='')
34 def setValue(self, value):
35 self.Set(SensorValue.IFACE_NAME, 'value', value)
36
37 @dbus.service.method(
38 IFACE_NAME, in_signature='', out_signature='v')
39 def getValue(self):
40 return self.Get(SensorValue.IFACE_NAME, 'value')
41
42
Brad Bishop179b39b2016-05-12 16:45:57 -040043class VirtualSensor(SensorValue):
44 def __init__(self, bus, name):
45 DbusProperties.__init__(self)
46 SensorValue.__init__(self, bus, name)
47 dbus.service.Object.__init__(self, bus, name)
48
49
Brad Bishop179b39b2016-05-12 16:45:57 -040050CONTROL_IFACE = 'org.openbmc.Control'
51
52
Brad Bishop179b39b2016-05-12 16:45:57 -040053class BootProgressSensor(VirtualSensor):
54 def __init__(self, bus, name):
55 VirtualSensor.__init__(self, bus, name)
56 self.setValue("Off")
57 bus.add_signal_receiver(
58 self.SystemStateHandler, signal_name="GotoSystemState")
59
60 def SystemStateHandler(self, state):
61 if (state == "HOST_POWERED_OFF"):
62 self.setValue("Off")
63
64 ##override setValue method
65 @dbus.service.method(
66 SensorValue.IFACE_NAME,
67 in_signature='v', out_signature='')
68 def setValue(self, value):
69 SensorValue.setValue(self, value)
70 if (value == "FW Progress, Starting OS"):
71 self.GotoSystemState("HOST_BOOTED")
Yi Li57e3bf92016-09-08 17:58:00 +080072 self.BootProgress(value)
Brad Bishop179b39b2016-05-12 16:45:57 -040073
74 @dbus.service.signal(CONTROL_IFACE, signature='s')
75 def GotoSystemState(self, state):
76 pass
77
Yi Li57e3bf92016-09-08 17:58:00 +080078 @dbus.service.signal(CONTROL_IFACE, signature='s')
79 def BootProgress(self, state):
80 pass
81
Brad Bishop179b39b2016-05-12 16:45:57 -040082
Brad Bishop179b39b2016-05-12 16:45:57 -040083class BootCountSensor(VirtualSensor):
84 def __init__(self, bus, name):
85 VirtualSensor.__init__(self, bus, name)
Andrew Geissler9070d1b2017-05-22 14:46:34 -050086 # Default boot count is 2. Add 1 onto this to allow for an
87 # SBE side switch boot attempt
88 self.setValue(3)
89
90 ## override setValue method for debug purposes
91 @dbus.service.method(
92 SensorValue.IFACE_NAME, in_signature='v', out_signature='')
93 def setValue(self, value):
94 print "Setting boot count to " + str(value)
Brad Bishop10ad8c32017-07-01 00:23:06 -040095 SensorValue.setValue(self, value)
Brad Bishop179b39b2016-05-12 16:45:57 -040096
97
98class OperatingSystemStatusSensor(VirtualSensor):
99 def __init__(self, bus, name):
100 VirtualSensor.__init__(self, bus, name)
101 self.setValue("Off")
102 bus.add_signal_receiver(
103 self.SystemStateHandler, signal_name="GotoSystemState")
104
105 def SystemStateHandler(self, state):
106 if (state == "HOST_POWERED_OFF"):
107 self.setValue("Off")
Dhruvaraj Sdc0dc122017-03-21 02:13:29 -0500108
Brad Bishop10ad8c32017-07-01 00:23:06 -0400109
Dhruvaraj Sdc0dc122017-03-21 02:13:29 -0500110class PowerSupplyRedundancySensor(VirtualSensor):
111 def __init__(self, bus, name):
112 VirtualSensor.__init__(self, bus, name)
Andrew Geissler7c08c352017-11-21 15:15:14 -0600113 super(PowerSupplyRedundancySensor, self).setValue("Enabled")
Dhruvaraj Sdc0dc122017-03-21 02:13:29 -0500114
115 ## override setValue method
116 @dbus.service.method(
117 SensorValue.IFACE_NAME, in_signature='v', out_signature='')
118 def setValue(self, value):
119 print "Setting Power Supply Redundancy is not allowed"
Jayanth Othayoth7a57f952017-03-28 07:15:29 -0500120
Brad Bishop10ad8c32017-07-01 00:23:06 -0400121
Jayanth Othayoth857e4b82017-03-27 08:25:45 -0500122class PowerSupplyDeratingSensor(VirtualSensor):
123 def __init__(self, bus, name):
124 VirtualSensor.__init__(self, bus, name)
Brad Bishop10ad8c32017-07-01 00:23:06 -0400125 super(PowerSupplyDeratingSensor, self).setValue(10)
Jayanth Othayoth857e4b82017-03-27 08:25:45 -0500126
127 ## override setValue method
128 @dbus.service.method(
129 SensorValue.IFACE_NAME, in_signature='v', out_signature='')
130 def setValue(self, value):
131 print "Setting Power Supply Derating is not allowed"
132
Brad Bishop10ad8c32017-07-01 00:23:06 -0400133
Jayanth Othayoth7a57f952017-03-28 07:15:29 -0500134class TurboAllowedSensor(VirtualSensor):
135 def __init__(self, bus, name):
136 VirtualSensor.__init__(self, bus, name)
137 self.setValue(0)
138
139 ## override setValue method
140 @dbus.service.method(
141 SensorValue.IFACE_NAME, in_signature='b', out_signature='')
142 def setValue(self, value):
Brad Bishop10ad8c32017-07-01 00:23:06 -0400143 super(TurboAllowedSensor, self).setValue(value)