blob: b3c975a9a2bcc874ce1fe33841564313ff32e9a7 [file] [log] [blame]
Norman James42c1be82015-10-22 14:34:26 -05001#!/usr/bin/python -u
Norman James91dac392015-10-14 09:38:55 -05002
3import sys
4#from gi.repository import GObject
5import gobject
6import dbus
7import dbus.service
8import dbus.mainloop.glib
9import Openbmc
10
Norman James91dac392015-10-14 09:38:55 -050011DBUS_NAME = 'org.openbmc.sensor.Power8Virtual'
Norman James18d45912015-10-18 20:45:06 -050012OBJ_PATH = '/org/openbmc/sensor/virtual/'
Norman James91dac392015-10-14 09:38:55 -050013
Norman Jamesa3e47c42015-10-18 14:43:10 -050014class SensorValue(Openbmc.DbusProperties):
15 IFACE_NAME = 'org.openbmc.SensorValue'
16 def __init__(self):
17 Openbmc.DbusProperties.__init__(self)
18 self.Set(SensorValue.IFACE_NAME,'units',"")
19
20 @dbus.service.method(IFACE_NAME,
21 in_signature='v', out_signature='')
22 def setValue(self,value):
23 changed = False
24 try:
25 old_value = self.Get(SensorValue.IFACE_NAME,'value')
26 if (value != old_value):
27 changed = True
28 except:
29 changed = True
30
31 if (changed == True):
32 self.Set(SensorValue.IFACE_NAME,'value',value)
33 self.Changed(self.getValue(),self.getUnits())
34
35
36
37 @dbus.service.method(IFACE_NAME,
38 in_signature='', out_signature='v')
39 def getValue(self):
40 return self.Get(SensorValue.IFACE_NAME,'value')
41
42 @dbus.service.method(IFACE_NAME,
43 in_signature='', out_signature='s')
44 def getUnits(self):
45 return self.Get(SensorValue.IFACE_NAME,'units')
46
47 @dbus.service.signal(IFACE_NAME,signature='vs')
48 def Changed(self,value,units):
49 pass
50
Norman James18d45912015-10-18 20:45:06 -050051class VirtualSensor(SensorValue):
Norman James91dac392015-10-14 09:38:55 -050052 def __init__(self,bus,name):
Norman Jamesa3e47c42015-10-18 14:43:10 -050053 SensorValue.__init__(self)
Norman James18d45912015-10-18 20:45:06 -050054 dbus.service.Object.__init__(self,bus,name)
Norman James91dac392015-10-14 09:38:55 -050055
Norman Jamesd6da29d2015-10-19 11:13:14 -050056CONTROL_IFACE = 'org.openbmc.Control'
Norman James18d45912015-10-18 20:45:06 -050057class HostStatusSensor(SensorValue):
Norman James91dac392015-10-14 09:38:55 -050058 def __init__(self,bus,name):
Norman Jamesa3e47c42015-10-18 14:43:10 -050059 SensorValue.__init__(self)
Norman James18d45912015-10-18 20:45:06 -050060 dbus.service.Object.__init__(self,bus,name)
Norman James91dac392015-10-14 09:38:55 -050061
Norman James18d45912015-10-18 20:45:06 -050062 ##override setValue method
63 @dbus.service.method(SensorValue.IFACE_NAME,
64 in_signature='v', out_signature='')
65 def setValue(self,value):
66 SensorValue.setValue(self,value)
Norman Jamesd6da29d2015-10-19 11:13:14 -050067 if (value == "BLAH"):
68 self.GotoSystemState("OS_BOOTED")
Norman James18d45912015-10-18 20:45:06 -050069
Norman Jamesd6da29d2015-10-19 11:13:14 -050070 @dbus.service.signal(CONTROL_IFACE,signature='s')
71 def GotoSystemState(self,state):
Norman James18d45912015-10-18 20:45:06 -050072 pass
73
Norman Jamesd6da29d2015-10-19 11:13:14 -050074CONTROL_IFACE = 'org.openbmc.Control'
75class BootProgressSensor(SensorValue):
76 def __init__(self,bus,name):
77 SensorValue.__init__(self)
78 dbus.service.Object.__init__(self,bus,name)
79
80 ##override setValue method
81 @dbus.service.method(SensorValue.IFACE_NAME,
82 in_signature='v', out_signature='')
83 def setValue(self,value):
84 SensorValue.setValue(self,value)
85 if (value == "FW Progress, Starting OS"):
86 self.GotoSystemState("HOST_BOOTED")
87
88 @dbus.service.signal(CONTROL_IFACE,signature='s')
89 def GotoSystemState(self,state):
90 pass
91
92
Norman James91dac392015-10-14 09:38:55 -050093
Norman James91dac392015-10-14 09:38:55 -050094
95if __name__ == '__main__':
Norman James18d45912015-10-18 20:45:06 -050096
97 sensors = {
Norman James18d45912015-10-18 20:45:06 -050098 'OperatingSystemStatus' : None,
99 'BootCount' : None,
100 'OccStatus' : None,
101 }
102 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
103 bus = Openbmc.getDBus()
104 name = dbus.service.BusName(DBUS_NAME,bus)
105 for instance in sensors.keys():
106 sensors[instance]= VirtualSensor(bus,OBJ_PATH+instance)
Norman James91dac392015-10-14 09:38:55 -0500107
Norman James18d45912015-10-18 20:45:06 -0500108 sensors['HostStatus'] = HostStatusSensor(bus,OBJ_PATH+"HostStatus")
Norman Jamesd6da29d2015-10-19 11:13:14 -0500109 sensors['BootProgress'] = BootProgressSensor(bus,OBJ_PATH+"BootProgress")
Norman James18d45912015-10-18 20:45:06 -0500110 mainloop = gobject.MainLoop()
111
112 ## Initialize sensors
113 sensors['BootProgress'].setValue("INACTIVE")
114 sensors['HostStatus'].setValue("OFF")
115 sensors['OperatingSystemStatus'].setValue("OFF")
116 sensors['BootCount'].setValue(0)
117 sensors['OccStatus'].setValue(0)
118
119 print "Starting virtual sensors"
120 mainloop.run()
Norman James91dac392015-10-14 09:38:55 -0500121