diff options
author | Sugandha Gupta <sugandha.gupta@ettus.com> | 2019-02-15 17:18:33 -0800 |
---|---|---|
committer | Brent Stapleton <brent.stapleton@ettus.com> | 2019-05-01 15:17:23 -0700 |
commit | b709c03e8bcf6ff64ab85b87aba8c21ecc3509d3 (patch) | |
tree | 8c85b804130dffab265ea30c93b417808057b2a2 /mpm | |
parent | 600f655e8e13c934873ad72a9228f1cfb28c05bc (diff) | |
download | uhd-b709c03e8bcf6ff64ab85b87aba8c21ecc3509d3.tar.gz uhd-b709c03e8bcf6ff64ab85b87aba8c21ecc3509d3.tar.bz2 uhd-b709c03e8bcf6ff64ab85b87aba8c21ecc3509d3.zip |
mpm: sys_utils: Remove hardcoded 'subsystem' for temp sensor
This is needed for E31x with thermal sensors on different
subsystems e.g. iio, hwmon.
Diffstat (limited to 'mpm')
-rw-r--r-- | mpm/python/usrp_mpm/sys_utils/sysfs_thermal.py | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/mpm/python/usrp_mpm/sys_utils/sysfs_thermal.py b/mpm/python/usrp_mpm/sys_utils/sysfs_thermal.py index 7409fbe17..01930d48e 100644 --- a/mpm/python/usrp_mpm/sys_utils/sysfs_thermal.py +++ b/mpm/python/usrp_mpm/sys_utils/sysfs_thermal.py @@ -1,5 +1,5 @@ # -# Copyright 2017 Ettus Research, A National Instruments Company +# Copyright 2017-2019 Ettus Research, A National Instruments Company # # SPDX-License-Identifier: GPL-3.0-or-later """ @@ -8,7 +8,26 @@ sysfs thermal sensors API import pyudev -def read_thermal_sensors_value(sensor_type, data_probe): +def read_sysfs_sensors_value(sensor_type, data_probe, subsystem, attribute): + """ + This function will return a list of all the float value of + the sysfs thermal sensor subsystems and attribute + + Arguments: + sensor_type -- Is "attribute" of udev. This can be fpga-thermal-zone, + magnesium-db0-zone, croc-ec-thermal etc. + data_probe -- is one of the attribute of that sensor. This can be 'temp' in + the case of thermal-zone or 'cur_state' in the case of a + cooling device. + subsystem -- of the thermal sensor + attribute -- matching attribute for the sensor e.g. 'type', 'name' + """ + reading_sensors = [float(x.attributes.asstring(data_probe)) for x in pyudev.Context() + .list_devices(subsystem=subsystem) + .match_attribute(attribute, sensor_type)] + return reading_sensors + +def read_thermal_sensors_value(sensor_type, data_probe, subsystem='thermal', attribute='type'): """ This function will return a list of all the float value of the thermal sensor subsystem = 'thermal' and type = sensor_type @@ -20,12 +39,9 @@ def read_thermal_sensors_value(sensor_type, data_probe): the case of thermal-zone or 'cur_state' in the case of a cooling device. """ - reading_sensors = [x.attributes.asint(data_probe) for x in pyudev.Context() - .list_devices(subsystem='thermal') - .match_attribute('type', sensor_type)] - return reading_sensors + return read_sysfs_sensors_value(sensor_type, data_probe, subsystem, attribute) -def read_thermal_sensor_value(sensor_type, data_probe): +def read_thermal_sensor_value(sensor_type, data_probe, subsystem='thermal', attribute='type'): """ This function will return the float value of the thermal sensor which is under thermal subsystem. @@ -37,7 +53,7 @@ def read_thermal_sensor_value(sensor_type, data_probe): the case of thermal-zone or 'cur_state' in the case of a cooling device. """ - sensor_val = read_thermal_sensors_value(sensor_type, data_probe) + sensor_val = read_thermal_sensors_value(sensor_type, data_probe, subsystem, attribute) if not sensor_val: raise IndexError("No {} attribute found for {} sensor.".format(data_probe, sensor_type)) return sensor_val[0] |