Esempio n. 1
0
float measures_intTemp(void)
{
	sem_obtain(&i2c_sem);
	float res = DEG_T_TO_FLOATDEG(lm75_read(&i2c_bus, LM75_ADDR));
	sem_release(&i2c_sem);

	return res;
}
// read sensor temperature and calculate status/fan speed setting
static void
tempd_read_sensor(struct locl_sensor *sensor)
{
    const YamlSensor *yaml_sensor = sensor->yaml_sensor;

    if (strcmp(yaml_sensor->type, "lm75") == 0) {
        lm75_read(sensor);
    } else {
        VLOG_WARN("Unrecognized sensor type %s", yaml_sensor->type);
        sensor->temp = DEFAULT_TEMP * MILI_DEGREES;
    }

    // recalculate alarm and fan state

    // decreasing alarms

    if (SENSOR_STATUS_FAILED == sensor->status) {
        // no temp to report, unable to read sensor
        return;
    }

    // adjust min and max values
    if (sensor->min > sensor->temp) {
        sensor->min = sensor->temp;
    }

    if (sensor->max < sensor->temp) {
        sensor->max = sensor->temp;
    }

    // decreasing alarms
    if (SENSOR_STATUS_EMERGENCY == sensor->status &&
            (float)sensor->temp/MILI_DEGREES_FLOAT <= yaml_sensor->alarm_thresholds.emergency_off) {
        sensor->status = SENSOR_STATUS_CRITICAL;
    }

    if (SENSOR_STATUS_CRITICAL == sensor->status &&
            (float)sensor->temp /MILI_DEGREES_FLOAT<= yaml_sensor->alarm_thresholds.critical_off) {
        sensor->status = SENSOR_STATUS_MAX;
    }

    if (SENSOR_STATUS_MAX == sensor->status &&
            (float)sensor->temp/MILI_DEGREES_FLOAT <= yaml_sensor->alarm_thresholds.max_off) {
        sensor->status = SENSOR_STATUS_NORMAL;
    }

    if (SENSOR_STATUS_NORMAL == sensor->status &&
            (float)sensor->temp/MILI_DEGREES_FLOAT > yaml_sensor->alarm_thresholds.low_crit) {
        sensor->status = SENSOR_STATUS_MIN;
    }

    if (SENSOR_STATUS_MIN == sensor->status &&
            (float)sensor->temp/MILI_DEGREES_FLOAT > yaml_sensor->alarm_thresholds.min) {
        sensor->status = SENSOR_STATUS_NORMAL;
    }

    // increasing alarms
    if (SENSOR_STATUS_NORMAL == sensor->status &&
            (float)sensor->temp/MILI_DEGREES_FLOAT >= yaml_sensor->alarm_thresholds.max_on) {
        sensor->status = SENSOR_STATUS_MAX;
    }

    if (SENSOR_STATUS_MAX == sensor->status &&
            (float)sensor->temp/MILI_DEGREES_FLOAT >= yaml_sensor->alarm_thresholds.critical_on) {
        sensor->status = SENSOR_STATUS_CRITICAL;
    }

    if (SENSOR_STATUS_CRITICAL == sensor->status &&
            (float)sensor->temp/MILI_DEGREES_FLOAT >= yaml_sensor->alarm_thresholds.emergency_on) {
        sensor->status = SENSOR_STATUS_EMERGENCY;
    }

    if (SENSOR_STATUS_NORMAL == sensor->status &&
            (float)sensor->temp/MILI_DEGREES_FLOAT <= yaml_sensor->alarm_thresholds.min) {
        sensor->status = SENSOR_STATUS_MIN;
    }

    if (SENSOR_STATUS_MIN == sensor->status &&
            (float)sensor->temp/MILI_DEGREES_FLOAT <= yaml_sensor->alarm_thresholds.low_crit) {
        sensor->status = SENSOR_STATUS_LOWCRIT;
    }

    // calculate requested fan speed
    if (SENSOR_FAN_NORMAL == sensor->fan_speed &&
            (float)sensor->temp/MILI_DEGREES_FLOAT >= yaml_sensor->fan_thresholds.medium_on) {
        sensor->fan_speed = SENSOR_FAN_MEDIUM;
    }

    if (SENSOR_FAN_MEDIUM == sensor->fan_speed &&
            (float)sensor->temp/MILI_DEGREES_FLOAT >= yaml_sensor->fan_thresholds.fast_on) {
        sensor->fan_speed = SENSOR_FAN_FAST;
    }

    if (SENSOR_FAN_FAST == sensor->fan_speed &&
            (float)sensor->temp/MILI_DEGREES_FLOAT >= yaml_sensor->fan_thresholds.max_on) {
        sensor->fan_speed = SENSOR_FAN_MAX;
    }

    if (SENSOR_FAN_MAX == sensor->fan_speed &&
            (float)sensor->temp/MILI_DEGREES_FLOAT <= yaml_sensor->fan_thresholds.max_off) {
        sensor->fan_speed = SENSOR_FAN_FAST;
    }

    if (SENSOR_FAN_FAST == sensor->fan_speed &&
            (float)sensor->temp/MILI_DEGREES_FLOAT <= yaml_sensor->fan_thresholds.fast_off) {
        sensor->fan_speed = SENSOR_FAN_MEDIUM;
    }

    if (SENSOR_FAN_MEDIUM == sensor->fan_speed &&
            (float)sensor->temp/MILI_DEGREES_FLOAT <= yaml_sensor->fan_thresholds.medium_off) {
        sensor->fan_speed = SENSOR_FAN_NORMAL;
    }
}