2019-06-07 11:00:12 -05:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#
|
|
|
|
# Copyright (C) 2017 Accton Technology Corporation
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------
|
|
|
|
# HISTORY:
|
|
|
|
# mm/dd/yyyy (A.D.)
|
|
|
|
# 5/27/2019: Brandon_Chuang create
|
|
|
|
# ------------------------------------------------------------------
|
|
|
|
|
|
|
|
try:
|
|
|
|
import time
|
|
|
|
import logging
|
|
|
|
import glob
|
2021-09-28 13:26:50 -05:00
|
|
|
import subprocess
|
2019-06-07 11:00:12 -05:00
|
|
|
from collections import namedtuple
|
|
|
|
except ImportError as e:
|
|
|
|
raise ImportError('%s - required module not found' % str(e))
|
|
|
|
|
|
|
|
class ThermalUtil(object):
|
|
|
|
"""Platform-specific ThermalUtil class"""
|
|
|
|
THERMAL_NUM_MAX = 4
|
2022-03-17 19:47:08 -05:00
|
|
|
THERMAL_NUM_1_IDX = 1 # 1_ON_CPU_BROAD. LM75
|
2019-06-07 11:00:12 -05:00
|
|
|
THERMAL_NUM_2_IDX = 2 # 2_ON_MAIN_BROAD. LM75
|
|
|
|
THERMAL_NUM_3_IDX = 3 # 3_ON_MAIN_BROAD. LM75
|
|
|
|
THERMAL_NUM_4_IDX = 4 # 4_ON_MAIN_BROAD. LM75
|
|
|
|
|
|
|
|
""" Dictionary where
|
|
|
|
key1 = thermal id index (integer) starting from 1
|
|
|
|
value = path to fan device file (string) """
|
2022-03-17 19:47:08 -05:00
|
|
|
|
2019-06-07 11:00:12 -05:00
|
|
|
thermal_sysfspath ={
|
2022-03-17 19:47:08 -05:00
|
|
|
THERMAL_NUM_1_IDX: ["/sys/bus/i2c/devices/18-004b/hwmon/hwmon*/temp1_input"],
|
|
|
|
THERMAL_NUM_2_IDX: ["/sys/bus/i2c/devices/19-004c/hwmon/hwmon*/temp1_input"],
|
|
|
|
THERMAL_NUM_3_IDX: ["/sys/bus/i2c/devices/20-0049/hwmon/hwmon*/temp1_input"],
|
|
|
|
THERMAL_NUM_4_IDX: ["/sys/bus/i2c/devices/21-004a/hwmon/hwmon*/temp1_input"],
|
2019-06-07 11:00:12 -05:00
|
|
|
}
|
|
|
|
|
2022-03-17 19:47:08 -05:00
|
|
|
def get_thermal_val(self, thermal_num):
|
2019-06-07 11:00:12 -05:00
|
|
|
if thermal_num < self.THERMAL_NUM_1_IDX or thermal_num > self.THERMAL_NUM_MAX:
|
|
|
|
logging.debug('GET. Parameter error. thermal_num, %d', thermal_num)
|
|
|
|
return None
|
|
|
|
|
2022-03-17 19:47:08 -05:00
|
|
|
device_path = self.get_thermal_path(thermal_num)
|
|
|
|
for filename in glob.glob(device_path):
|
|
|
|
try:
|
|
|
|
val_file = open(filename, 'r')
|
|
|
|
except IOError as e:
|
|
|
|
logging.error('GET. unable to open file: %s', str(e))
|
|
|
|
return None
|
2019-06-07 11:00:12 -05:00
|
|
|
content = val_file.readline().rstrip()
|
|
|
|
if content == '':
|
|
|
|
logging.debug('GET. content is NULL. device_path:%s', device_path)
|
|
|
|
return None
|
|
|
|
try:
|
2022-03-17 19:47:08 -05:00
|
|
|
val_file.close()
|
2019-06-07 11:00:12 -05:00
|
|
|
except:
|
|
|
|
logging.debug('GET. unable to close file. device_path:%s', device_path)
|
|
|
|
return None
|
|
|
|
return int(content)
|
2022-03-17 19:47:08 -05:00
|
|
|
|
|
|
|
return 0
|
2019-06-07 11:00:12 -05:00
|
|
|
|
|
|
|
def get_num_thermals(self):
|
|
|
|
return self.THERMAL_NUM_MAX
|
2022-03-17 19:47:08 -05:00
|
|
|
|
|
|
|
def get_thermal_path(self, thermal_num):
|
2019-06-07 11:00:12 -05:00
|
|
|
return self.thermal_sysfspath[thermal_num][0]
|
|
|
|
|
|
|
|
def main():
|
|
|
|
thermal = ThermalUtil()
|
2022-03-17 19:47:08 -05:00
|
|
|
logging.basicConfig(level=logging.DEBUG)
|
|
|
|
logging.debug('thermal1=%d', thermal.get_thermal_val(1))
|
|
|
|
logging.debug('thermal2=%d', thermal.get_thermal_val(2))
|
|
|
|
logging.debug('thermal3=%d', thermal.get_thermal_val(3))
|
|
|
|
logging.debug('thermal4=%d', thermal.get_thermal_val(4))
|
|
|
|
|
2019-06-07 11:00:12 -05:00
|
|
|
if __name__ == '__main__':
|
2022-03-17 19:47:08 -05:00
|
|
|
main()
|