blob: 840ee04dd2d7a2d259260ac59008e8798ed4bc3e [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',"")
Norman Jamescfc2b442015-10-31 17:31:46 -050019 self.ObjectAdded(name,SensorValue.IFACE_NAME)
Norman Jamesa3e47c42015-10-18 14:43:10 -050020
21 @dbus.service.method(IFACE_NAME,
22 in_signature='v', out_signature='')
23 def setValue(self,value):
24 changed = False
25 try:
26 old_value = self.Get(SensorValue.IFACE_NAME,'value')
27 if (value != old_value):
28 changed = True
29 except:
30 changed = True
31
32 if (changed == True):
33 self.Set(SensorValue.IFACE_NAME,'value',value)
34 self.Changed(self.getValue(),self.getUnits())
35
36
37
38 @dbus.service.method(IFACE_NAME,
39 in_signature='', out_signature='v')
40 def getValue(self):
41 return self.Get(SensorValue.IFACE_NAME,'value')
42
43 @dbus.service.method(IFACE_NAME,
44 in_signature='', out_signature='s')
45 def getUnits(self):
46 return self.Get(SensorValue.IFACE_NAME,'units')
47
48 @dbus.service.signal(IFACE_NAME,signature='vs')
49 def Changed(self,value,units):
50 pass
51
Norman James18d45912015-10-18 20:45:06 -050052class VirtualSensor(SensorValue):
Norman James91dac392015-10-14 09:38:55 -050053 def __init__(self,bus,name):
Norman Jamesa3e47c42015-10-18 14:43:10 -050054 SensorValue.__init__(self)
Norman James18d45912015-10-18 20:45:06 -050055 dbus.service.Object.__init__(self,bus,name)
Norman James91dac392015-10-14 09:38:55 -050056
Norman Jamesd6da29d2015-10-19 11:13:14 -050057CONTROL_IFACE = 'org.openbmc.Control'
Norman James18d45912015-10-18 20:45:06 -050058class HostStatusSensor(SensorValue):
Norman James91dac392015-10-14 09:38:55 -050059 def __init__(self,bus,name):
Norman Jamesa3e47c42015-10-18 14:43:10 -050060 SensorValue.__init__(self)
Norman James18d45912015-10-18 20:45:06 -050061 dbus.service.Object.__init__(self,bus,name)
Norman James91dac392015-10-14 09:38:55 -050062
Norman James18d45912015-10-18 20:45:06 -050063 ##override setValue method
64 @dbus.service.method(SensorValue.IFACE_NAME,
65 in_signature='v', out_signature='')
66 def setValue(self,value):
67 SensorValue.setValue(self,value)
Norman Jamesd6da29d2015-10-19 11:13:14 -050068 if (value == "BLAH"):
69 self.GotoSystemState("OS_BOOTED")
Norman James18d45912015-10-18 20:45:06 -050070
Norman Jamesd6da29d2015-10-19 11:13:14 -050071 @dbus.service.signal(CONTROL_IFACE,signature='s')
72 def GotoSystemState(self,state):
Norman James18d45912015-10-18 20:45:06 -050073 pass
74
Norman Jamesd6da29d2015-10-19 11:13:14 -050075CONTROL_IFACE = 'org.openbmc.Control'
76class BootProgressSensor(SensorValue):
77 def __init__(self,bus,name):
78 SensorValue.__init__(self)
79 dbus.service.Object.__init__(self,bus,name)
80
81 ##override setValue method
82 @dbus.service.method(SensorValue.IFACE_NAME,
83 in_signature='v', out_signature='')
84 def setValue(self,value):
85 SensorValue.setValue(self,value)
86 if (value == "FW Progress, Starting OS"):
87 self.GotoSystemState("HOST_BOOTED")
88
89 @dbus.service.signal(CONTROL_IFACE,signature='s')
90 def GotoSystemState(self,state):
91 pass
92
93
Norman James91dac392015-10-14 09:38:55 -050094
Norman James91dac392015-10-14 09:38:55 -050095
96if __name__ == '__main__':
Norman James18d45912015-10-18 20:45:06 -050097
98 sensors = {
Norman James18d45912015-10-18 20:45:06 -050099 'OperatingSystemStatus' : None,
100 'BootCount' : None,
101 'OccStatus' : None,
102 }
103 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
104 bus = Openbmc.getDBus()
105 name = dbus.service.BusName(DBUS_NAME,bus)
106 for instance in sensors.keys():
107 sensors[instance]= VirtualSensor(bus,OBJ_PATH+instance)
Norman James91dac392015-10-14 09:38:55 -0500108
Norman James18d45912015-10-18 20:45:06 -0500109 sensors['HostStatus'] = HostStatusSensor(bus,OBJ_PATH+"HostStatus")
Norman Jamesd6da29d2015-10-19 11:13:14 -0500110 sensors['BootProgress'] = BootProgressSensor(bus,OBJ_PATH+"BootProgress")
Norman James18d45912015-10-18 20:45:06 -0500111 mainloop = gobject.MainLoop()
112
113 ## Initialize sensors
114 sensors['BootProgress'].setValue("INACTIVE")
115 sensors['HostStatus'].setValue("OFF")
116 sensors['OperatingSystemStatus'].setValue("OFF")
117 sensors['BootCount'].setValue(0)
118 sensors['OccStatus'].setValue(0)
119
120 print "Starting virtual sensors"
121 mainloop.run()
Norman James91dac392015-10-14 09:38:55 -0500122