def manage_fans(self):
        max_duty = DUTY_MAX
        fan_policy = {
            0: [52, 0, 43000],
            1: [63, 43000, 46000],
            2: [75, 46000, 52000],
            3: [88, 52000, 57000],
            4: [max_duty, 57000, sys.maxsize],
        }

        thermal = ThermalUtil()
        fan = FanUtil()
        for x in range(fan.get_idx_fan_start(), fan.get_num_fans() + 1):
            fan_status = fan.get_fan_status(x)
            if fan_status is None:
                logging.debug(
                    'INFO. SET new_perc to %d (FAN stauts is None. fan_num:%d)',
                    max_duty, x)
                return False
            if fan_status is False:
                logging.debug(
                    'INFO. SET new_perc to %d (FAN fault. fan_num:%d)',
                    max_duty, x)
                fan.set_fan_duty_cycle(max_duty)
                return True
            #logging.debug('INFO. fan_status is True (fan_num:%d)', x)

        #Find if current duty matched any of define duty.

#If not, set it to highest one.
        cur_duty_cycle = fan.get_fan_duty_cycle()
        new_duty_cycle = DUTY_DEF
        for x in range(0, len(fan_policy)):
            if cur_duty_cycle == fan_policy[x][0]:
                break
        if x == len(fan_policy):
            fan.set_fan_duty_cycle(fan_policy[0][0])
            cur_duty_cycle = max_duty

        #Decide fan duty by if sum of sensors falls into any of fan_policy{}
        get_temp = thermal.get_thermal_temp()
        for x in range(0, len(fan_policy)):
            y = len(fan_policy) - x - 1  #checked from highest
            if get_temp > fan_policy[y][1] and get_temp < fan_policy[y][2]:
                new_duty_cycle = fan_policy[y][0]
                logging.debug('INFO. Sum of temp %d > %d , new_duty_cycle=%d',
                              get_temp, fan_policy[y][1], new_duty_cycle)

        logging.debug('INFO. Final duty_cycle=%d', new_duty_cycle)
        if (new_duty_cycle != cur_duty_cycle):
            fan.set_fan_duty_cycle(new_duty_cycle)
        return True
    def manage_fans(self):
        max_duty = 100
        fan_policy_f2b = {
           0: [52, 0,      43000],
           1: [64, 43000,  46000],
           2: [76, 46000,  52000],
           3: [88, 52000,  57000],
           4: [max_duty, 57000, sys.maxsize],
        }
  
        thermal = ThermalUtil()
        fan = FanUtil()
        for x in range(fan.get_idx_fan_start(), fan.get_num_fans()+1):
            fan_status = fan.get_fan_status(x)
            if fan_status is None:
                logging.debug('INFO. SET new_perc to %d (FAN stauts is None. fan_num:%d)', max_duty, x)
                return False
            if fan_status is False:             
                logging.debug('INFO. SET new_perc to %d (FAN fault. fan_num:%d)', max_duty, x)
                fan.set_fan_duty_cycle(max_duty)
                return True
            #logging.debug('INFO. fan_status is True (fan_num:%d)', x)
 
        fan_policy = fan_policy_f2b
        cur_duty_cycle = fan.get_fan_duty_cycle()       

        #Decide fan duty by if average of sensors falls into any of fan_policy{}
        get_temp = thermal.get_thermal_temp()            
        new_duty_cycle = cur_duty_cycle
        for x in range(0, len(fan_policy)):
            y = len(fan_policy) - x -1 #checked from highest
            if get_temp > fan_policy[y][1] and get_temp < fan_policy[y][2] :
                new_duty_cycle= fan_policy[y][0]
                logging.debug('INFO. AVG. of temp %d > %d , new_duty_cycle=%d', get_temp, fan_policy[y][1], new_duty_cycle)

        logging.debug('INFO. Final duty_cycle=%d', new_duty_cycle)
        if(new_duty_cycle != cur_duty_cycle):
            fan.set_fan_duty_cycle(new_duty_cycle)
        return True
Esempio n. 3
0
    def __init__(self, log_file, log_level):
        """Needs a logger and a logger level."""

        self.thermal = ThermalUtil()
        self.fan = FanUtil()
        # set up logging to file
        logging.basicConfig(
            filename=log_file,
            filemode='w',
            level=log_level,
            format=
            '[%(asctime)s] {%(pathname)s:%(lineno)d} %(levelname)s - %(message)s',
            datefmt='%H:%M:%S')

        # set up logging to console
        if log_level == logging.DEBUG:
            console = logging.StreamHandler()
            console.setLevel(log_level)
            formatter = logging.Formatter(
                '%(name)-12s: %(levelname)-8s %(message)s')
            console.setFormatter(formatter)
            logging.getLogger('').addHandler(console)

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