2017-12-22 02:22:37 +00:00
|
|
|
#
|
2019-02-16 01:18:33 +00:00
|
|
|
# Copyright 2017-2019 Ettus Research, A National Instruments Company
|
2017-12-22 02:22:37 +00:00
|
|
|
#
|
2018-02-20 00:53:15 +00:00
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
2017-12-22 02:22:37 +00:00
|
|
|
"""
|
|
|
|
|
sysfs thermal sensors API
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
import pyudev
|
|
|
|
|
|
2019-02-16 01:18:33 +00:00
|
|
|
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'):
|
2018-08-03 23:23:55 +00:00
|
|
|
"""
|
|
|
|
|
This function will return a list of all the float value of
|
|
|
|
|
the thermal sensor subsystem = 'thermal' and type = sensor_type
|
|
|
|
|
|
|
|
|
|
Arguments:
|
|
|
|
|
sensor_type -- Is attribute "type" 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.
|
|
|
|
|
"""
|
2019-02-16 01:18:33 +00:00
|
|
|
return read_sysfs_sensors_value(sensor_type, data_probe, subsystem, attribute)
|
2018-08-03 23:23:55 +00:00
|
|
|
|
2019-02-16 01:18:33 +00:00
|
|
|
def read_thermal_sensor_value(sensor_type, data_probe, subsystem='thermal', attribute='type'):
|
2017-12-22 02:22:37 +00:00
|
|
|
"""
|
|
|
|
|
This function will return the float value of the thermal sensor
|
|
|
|
|
which is under thermal subsystem.
|
|
|
|
|
|
|
|
|
|
Arguments:
|
|
|
|
|
sensor_type -- Is attribute "type" of udev. This can be fpga-thermal-zone,
|
|
|
|
|
magnesium-db0-zone, 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.
|
|
|
|
|
"""
|
2019-02-16 01:18:33 +00:00
|
|
|
sensor_val = read_thermal_sensors_value(sensor_type, data_probe, subsystem, attribute)
|
2018-08-03 23:23:55 +00:00
|
|
|
if not sensor_val:
|
|
|
|
|
raise IndexError("No {} attribute found for {} sensor.".format(data_probe, sensor_type))
|
|
|
|
|
return sensor_val[0]
|