Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,41 +55,38 @@ class ThermalUtil(object):
THERMAL_NUM_5_IDX: ['54', '4c'],
}
thermal_sysfspath ={
THERMAL_NUM_1_IDX: ["/sys/bus/i2c/devices/55-0048/hwmon/hwmon4/temp1_input"],
THERMAL_NUM_2_IDX: ["/sys/bus/i2c/devices/55-0049/hwmon/hwmon5/temp1_input"],
THERMAL_NUM_3_IDX: ["/sys/bus/i2c/devices/55-004a/hwmon/hwmon6/temp1_input"],
THERMAL_NUM_4_IDX: ["/sys/bus/i2c/devices/55-004b/hwmon/hwmon7/temp1_input"],
THERMAL_NUM_5_IDX: ["/sys/bus/i2c/devices/54-004c/hwmon/hwmon3/temp1_input"],
THERMAL_NUM_1_IDX: ["/sys/bus/i2c/devices/55-0048/hwmon/hwmon*/temp1_input"],
THERMAL_NUM_2_IDX: ["/sys/bus/i2c/devices/55-0049/hwmon/hwmon*/temp1_input"],
THERMAL_NUM_3_IDX: ["/sys/bus/i2c/devices/55-004a/hwmon/hwmon*/temp1_input"],
THERMAL_NUM_4_IDX: ["/sys/bus/i2c/devices/55-004b/hwmon/hwmon*/temp1_input"],
THERMAL_NUM_5_IDX: ["/sys/bus/i2c/devices/54-004c/hwmon/hwmon*/temp1_input"],
}

#def __init__(self):

def _get_thermal_val(self, thermal_num):
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

device_path = self.get_thermal_to_device_path(thermal_num)
if(os.path.isfile(device_path)):
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

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
content = val_file.readline().rstrip()
if content == '':
logging.debug('GET. content is NULL. device_path:%s', device_path)
return None
try:
val_file.close()
val_file.close()
except:
logging.debug('GET. unable to close file. device_path:%s', device_path)
return None
return int(content)

else:
print "No such device_path=%s"%device_path
return 0

return 0

def get_num_thermals(self):
return self.THERMAL_NUM_MAX
Expand All @@ -116,16 +113,10 @@ def get_thermal_temp(self):

def main():
thermal = ThermalUtil()
print "termal1=%d" %thermal._get_thermal_val(1)
print "termal2=%d" %thermal._get_thermal_val(2)
print "termal3=%d" %thermal._get_thermal_val(3)
print "termal4=%d" %thermal._get_thermal_val(4)
print "termal5=%d" %thermal._get_thermal_val(5)
#
# print 'get_size_node_map : %d' % thermal.get_size_node_map()
# print 'get_size_path_map : %d' % thermal.get_size_path_map()
# for x in range(thermal.get_idx_thermal_start(), thermal.get_num_thermals()+1):
# print thermal.get_thermal_to_device_path(x)
#
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))
logging.debug('thermal5=%d', thermal._get_thermal_val(5))
if __name__ == '__main__':
main()
main()
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,12 @@ def __init__(self, log_file, log_level):
sys_handler = handler = logging.handlers.SysLogHandler(address = '/dev/log')
sys_handler.setLevel(logging.WARNING)
logging.getLogger('').addHandler(sys_handler)

#logging.debug('SET. logfile:%s / loglevel:%d', log_file, log_level)

def get_state_from_fan_policy(self, temp, policy):
state=0

logging.debug('temp=%d', temp)
for i in range(0, len(policy)):
#logging.debug('policy[%d][0]=%d, policy[%d][1]=%d, policy[%d][2]=%d', i,policy[i][0],i, policy[i][1], i, policy[i][2])
if temp > policy[i][2]:
if temp <= policy[i][3]:
state =i
Expand All @@ -141,7 +138,6 @@ def get_state_from_fan_policy(self, temp, policy):
break

return state


def manage_fans(self):

Expand All @@ -156,8 +152,7 @@ def manage_fans(self):
LEVEL_FAN_MID=1
LEVEL_FAN_MAX=2
LEVEL_TEMP_HIGH=3
LEVEL_TEMP_CRITICAL=4

LEVEL_TEMP_CRITICAL=4

fan_policy_f2b = {
LEVEL_FAN_DEF: [38, 0x4, 0, 38000],
Expand Down Expand Up @@ -212,16 +207,14 @@ def manage_fans(self):
temp_get= (temp3 + temp4)/2 # Use (sensor_LM75_4a + sensor_LM75_4b) /2
ori_state=fan_policy_state

#temp_test_data=temp_test_data+1000
#temp_get = temp_get + temp_test_data
#print "Unit test:temp_get=%d"%temp_get
if test_temp!=0:
temp_test_data=temp_test_data+1000
temp_get = temp_get + temp_test_data
logging.debug('Unit test:temp_get=%d', temp_get)

fan_policy_state=self.get_state_from_fan_policy(temp_get, fan_policy)
#print "temp3=%d"%temp3
#print "temp4=%d"%temp4
#print "temp_get=%d"%temp_get

logging.debug('lm75_48=%d, lm75_49=%d, lm75_4a=%d, lm_4b=%d, lm_4b=%d', temp1,temp2,temp3,temp4,temp5)

logging.debug('lm75_48=%d, lm75_49=%d, lm75_4a=%d, lm_4b=%d, lm_4c=%d', temp1,temp2,temp3,temp4,temp5)
logging.debug('ori_state=%d, fan_policy_state=%d', ori_state, fan_policy_state)
new_pwm = fan_policy[fan_policy_state][0]
if fan_fail==0:
Expand All @@ -244,12 +237,8 @@ def manage_fans(self):
else:
fan_fail=0

#if fan_policy_state == ori_state:
# return True
#else:
new_state = fan_policy_state

#logging.warning('Temperature high alarm testing')

if ori_state==LEVEL_FAN_DEF:
if new_state==LEVEL_TEMP_HIGH:
if alarm_state==0:
Expand Down