Norman James | 42c1be8 | 2015-10-22 14:34:26 -0500 | [diff] [blame] | 1 | #!/usr/bin/python -u |
Norman James | 91dac39 | 2015-10-14 09:38:55 -0500 | [diff] [blame] | 2 | |
| 3 | import sys |
| 4 | #from gi.repository import GObject |
| 5 | import gobject |
| 6 | import dbus |
| 7 | import dbus.service |
| 8 | import dbus.mainloop.glib |
| 9 | import Openbmc |
| 10 | |
Norman James | 91dac39 | 2015-10-14 09:38:55 -0500 | [diff] [blame] | 11 | DBUS_NAME = 'org.openbmc.sensor.Power8Virtual' |
Norman James | 18d4591 | 2015-10-18 20:45:06 -0500 | [diff] [blame] | 12 | OBJ_PATH = '/org/openbmc/sensor/virtual/' |
Norman James | 91dac39 | 2015-10-14 09:38:55 -0500 | [diff] [blame] | 13 | |
Norman James | a3e47c4 | 2015-10-18 14:43:10 -0500 | [diff] [blame] | 14 | class SensorValue(Openbmc.DbusProperties): |
| 15 | IFACE_NAME = 'org.openbmc.SensorValue' |
Norman James | 981f4dc | 2015-11-07 20:00:47 -0600 | [diff] [blame] | 16 | def __init__(self,bus,name): |
Norman James | a3e47c4 | 2015-10-18 14:43:10 -0500 | [diff] [blame] | 17 | Openbmc.DbusProperties.__init__(self) |
| 18 | self.Set(SensorValue.IFACE_NAME,'units',"") |
Norman James | 981f4dc | 2015-11-07 20:00:47 -0600 | [diff] [blame] | 19 | dbus.service.Object.__init__(self,bus,name) |
Norman James | cfc2b44 | 2015-10-31 17:31:46 -0500 | [diff] [blame] | 20 | self.ObjectAdded(name,SensorValue.IFACE_NAME) |
Norman James | a3e47c4 | 2015-10-18 14:43:10 -0500 | [diff] [blame] | 21 | |
| 22 | @dbus.service.method(IFACE_NAME, |
| 23 | in_signature='v', out_signature='') |
| 24 | def setValue(self,value): |
| 25 | changed = False |
| 26 | try: |
| 27 | old_value = self.Get(SensorValue.IFACE_NAME,'value') |
| 28 | if (value != old_value): |
| 29 | changed = True |
| 30 | except: |
| 31 | changed = True |
| 32 | |
| 33 | if (changed == True): |
| 34 | self.Set(SensorValue.IFACE_NAME,'value',value) |
| 35 | self.Changed(self.getValue(),self.getUnits()) |
| 36 | |
| 37 | |
| 38 | |
| 39 | @dbus.service.method(IFACE_NAME, |
| 40 | in_signature='', out_signature='v') |
| 41 | def getValue(self): |
| 42 | return self.Get(SensorValue.IFACE_NAME,'value') |
| 43 | |
| 44 | @dbus.service.method(IFACE_NAME, |
| 45 | in_signature='', out_signature='s') |
| 46 | def getUnits(self): |
| 47 | return self.Get(SensorValue.IFACE_NAME,'units') |
| 48 | |
| 49 | @dbus.service.signal(IFACE_NAME,signature='vs') |
| 50 | def Changed(self,value,units): |
| 51 | pass |
| 52 | |
Norman James | 18d4591 | 2015-10-18 20:45:06 -0500 | [diff] [blame] | 53 | class VirtualSensor(SensorValue): |
Norman James | 91dac39 | 2015-10-14 09:38:55 -0500 | [diff] [blame] | 54 | def __init__(self,bus,name): |
Norman James | 981f4dc | 2015-11-07 20:00:47 -0600 | [diff] [blame] | 55 | SensorValue.__init__(self,bus,name) |
Norman James | 87493b8 | 2015-11-05 23:00:16 -0600 | [diff] [blame] | 56 | |
Norman James | 91dac39 | 2015-10-14 09:38:55 -0500 | [diff] [blame] | 57 | |
Norman James | d6da29d | 2015-10-19 11:13:14 -0500 | [diff] [blame] | 58 | CONTROL_IFACE = 'org.openbmc.Control' |
Norman James | 981f4dc | 2015-11-07 20:00:47 -0600 | [diff] [blame] | 59 | class HostStatusSensor(VirtualSensor): |
Norman James | 91dac39 | 2015-10-14 09:38:55 -0500 | [diff] [blame] | 60 | def __init__(self,bus,name): |
Norman James | 981f4dc | 2015-11-07 20:00:47 -0600 | [diff] [blame] | 61 | VirtualSensor.__init__(self,bus,name) |
Norman James | 91dac39 | 2015-10-14 09:38:55 -0500 | [diff] [blame] | 62 | |
Norman James | 18d4591 | 2015-10-18 20:45:06 -0500 | [diff] [blame] | 63 | ##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 James | d6da29d | 2015-10-19 11:13:14 -0500 | [diff] [blame] | 68 | if (value == "BLAH"): |
| 69 | self.GotoSystemState("OS_BOOTED") |
Norman James | 18d4591 | 2015-10-18 20:45:06 -0500 | [diff] [blame] | 70 | |
Norman James | d6da29d | 2015-10-19 11:13:14 -0500 | [diff] [blame] | 71 | @dbus.service.signal(CONTROL_IFACE,signature='s') |
| 72 | def GotoSystemState(self,state): |
Norman James | 18d4591 | 2015-10-18 20:45:06 -0500 | [diff] [blame] | 73 | pass |
| 74 | |
Norman James | d6da29d | 2015-10-19 11:13:14 -0500 | [diff] [blame] | 75 | CONTROL_IFACE = 'org.openbmc.Control' |
Norman James | 981f4dc | 2015-11-07 20:00:47 -0600 | [diff] [blame] | 76 | class BootProgressSensor(VirtualSensor): |
Norman James | d6da29d | 2015-10-19 11:13:14 -0500 | [diff] [blame] | 77 | def __init__(self,bus,name): |
Norman James | 981f4dc | 2015-11-07 20:00:47 -0600 | [diff] [blame] | 78 | VirtualSensor.__init__(self,bus,name) |
Norman James | d6da29d | 2015-10-19 11:13:14 -0500 | [diff] [blame] | 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 James | 91dac39 | 2015-10-14 09:38:55 -0500 | [diff] [blame] | 93 | |
Norman James | 91dac39 | 2015-10-14 09:38:55 -0500 | [diff] [blame] | 94 | |
| 95 | if __name__ == '__main__': |
Norman James | 18d4591 | 2015-10-18 20:45:06 -0500 | [diff] [blame] | 96 | |
| 97 | sensors = { |
Norman James | 18d4591 | 2015-10-18 20:45:06 -0500 | [diff] [blame] | 98 | '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 James | 91dac39 | 2015-10-14 09:38:55 -0500 | [diff] [blame] | 107 | |
Norman James | 18d4591 | 2015-10-18 20:45:06 -0500 | [diff] [blame] | 108 | sensors['HostStatus'] = HostStatusSensor(bus,OBJ_PATH+"HostStatus") |
Norman James | d6da29d | 2015-10-19 11:13:14 -0500 | [diff] [blame] | 109 | sensors['BootProgress'] = BootProgressSensor(bus,OBJ_PATH+"BootProgress") |
Norman James | 18d4591 | 2015-10-18 20:45:06 -0500 | [diff] [blame] | 110 | 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 James | 91dac39 | 2015-10-14 09:38:55 -0500 | [diff] [blame] | 121 | |