blob: b5aac533c2324a13e21d19d34e8322fddfda0549 [file] [log] [blame]
Norman James323ed972015-12-09 09:06:37 -06001#!/usr/bin/python -u
2
3import sys
4import os
5import gobject
6import dbus
7import dbus.service
8import dbus.mainloop.glib
9import Openbmc
10import Sensors
11
12DBUS_NAME = 'org.openbmc.Sensors'
13OBJ_PATH = '/org/openbmc/sensors'
14
15
16class SensorManager(Openbmc.DbusProperties,Openbmc.DbusObjectManager):
17 def __init__(self,bus,name):
18 Openbmc.DbusProperties.__init__(self)
19 Openbmc.DbusObjectManager.__init__(self)
20 dbus.service.Object.__init__(self,bus,name)
21 self.InterfacesAdded(name,self.properties)
22
23 @dbus.service.method(DBUS_NAME,
24 in_signature='ss', out_signature='')
25 def register(self,object_name,obj_path):
26 if (self.objects.has_key(obj_path) == False):
27 print "Register: "+object_name+" : "+obj_path
28 sensor = eval('Sensors.'+object_name+'(bus,obj_path)')
29 self.add(obj_path,sensor)
30
31 @dbus.service.method(DBUS_NAME,
32 in_signature='s', out_signature='')
33 def delete(self,obj_path):
34 if (self.objects.has_key(obj_path) == True):
35 print "Delete: "+obj_path
36 self.remove(obj_path)
37
38 def SensorChange(self,value,path=None):
39 if (self.objects.has_key(path)):
40 self.objects[path].setValue(value)
41 else:
42 print "ERROR: Sensor not found: "+path
43
44if __name__ == '__main__':
45 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
46 bus = Openbmc.getDBus()
47 name = dbus.service.BusName(DBUS_NAME,bus)
48 root_sensor = SensorManager(bus,OBJ_PATH)
49
50
51 ## instantiate non-polling sensors
52 ## these don't need to be in seperate process
53 ## TODO: this should not be hardcoded
54
Chris Austen4c9ea5d2015-12-09 23:26:08 -060055 obj_path = OBJ_PATH+"/host/PowerCap"
Yi Lif3be5ac2016-01-19 21:17:01 +080056 sensor_obj = Sensors.PowerCap(bus,obj_path)
57 ## hwmon3 is default for master OCC on Barreleye.
58 ## should rewrite sensor_manager to remove hardcode
59 sensor_obj.sysfs_attr = "/sys/class/hwmon/hwmon3/user_powercap"
60 root_sensor.add(obj_path,sensor_obj)
61
Norman James323ed972015-12-09 09:06:37 -060062 obj_path = OBJ_PATH+"/host/BootProgress"
63 root_sensor.add(obj_path,Sensors.BootProgressSensor(bus,obj_path))
Yi Li99ed56f2016-01-20 13:39:15 +080064
Norman James86f2a072016-01-30 22:48:54 -060065 obj_path = OBJ_PATH+"/host/cpu0/OccStatus"
Yi Li99ed56f2016-01-20 13:39:15 +080066 sensor_obj = Sensors.OccStatusSensor(bus,obj_path)
67 sensor_obj.sysfs_attr = "/sys/class/i2c-adapter/i2c-3/3-0050/online"
68 root_sensor.add(obj_path,sensor_obj)
69
Norman James86f2a072016-01-30 22:48:54 -060070 obj_path = OBJ_PATH+"/host/cpu1/OccStatus"
Norman James7d524e02016-01-30 21:42:39 -060071 sensor_obj = Sensors.OccStatusSensor(bus,obj_path)
72 sensor_obj.sysfs_attr = "/sys/class/i2c-adapter/i2c-3/3-0051/online"
73 root_sensor.add(obj_path,sensor_obj)
74
Norman James323ed972015-12-09 09:06:37 -060075 obj_path = OBJ_PATH+"/host/BootCount"
76 root_sensor.add(obj_path,Sensors.BootCountSensor(bus,obj_path))
77 obj_path = OBJ_PATH+"/host/OperatingSystemStatus"
78 root_sensor.add(obj_path,Sensors.OperatingSystemStatusSensor(bus,obj_path))
79
80 mainloop = gobject.MainLoop()
81 print "Starting sensor manager"
82 mainloop.run()
83