Norman James | 323ed97 | 2015-12-09 09:06:37 -0600 | [diff] [blame] | 1 | #!/usr/bin/python -u |
| 2 | |
| 3 | import sys |
| 4 | import os |
| 5 | import gobject |
| 6 | import dbus |
| 7 | import dbus.service |
| 8 | import dbus.mainloop.glib |
| 9 | import Openbmc |
| 10 | import Sensors |
| 11 | |
| 12 | DBUS_NAME = 'org.openbmc.Sensors' |
| 13 | OBJ_PATH = '/org/openbmc/sensors' |
| 14 | |
| 15 | |
| 16 | class 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 | |
| 44 | if __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 Austen | 4c9ea5d | 2015-12-09 23:26:08 -0600 | [diff] [blame] | 55 | obj_path = OBJ_PATH+"/host/PowerCap" |
Yi Li | f3be5ac | 2016-01-19 21:17:01 +0800 | [diff] [blame] | 56 | 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 James | 323ed97 | 2015-12-09 09:06:37 -0600 | [diff] [blame] | 62 | obj_path = OBJ_PATH+"/host/BootProgress" |
| 63 | root_sensor.add(obj_path,Sensors.BootProgressSensor(bus,obj_path)) |
Yi Li | 99ed56f | 2016-01-20 13:39:15 +0800 | [diff] [blame] | 64 | |
Norman James | 86f2a07 | 2016-01-30 22:48:54 -0600 | [diff] [blame] | 65 | obj_path = OBJ_PATH+"/host/cpu0/OccStatus" |
Yi Li | 99ed56f | 2016-01-20 13:39:15 +0800 | [diff] [blame] | 66 | 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 James | 86f2a07 | 2016-01-30 22:48:54 -0600 | [diff] [blame] | 70 | obj_path = OBJ_PATH+"/host/cpu1/OccStatus" |
Norman James | 7d524e0 | 2016-01-30 21:42:39 -0600 | [diff] [blame] | 71 | 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 James | 323ed97 | 2015-12-09 09:06:37 -0600 | [diff] [blame] | 75 | 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 | |