コード例 #1
0
ファイル: chips.c プロジェクト: pexip/os-lm-sensors
static void print_chip_power(const sensors_chip_name *name,
			     const sensors_feature *feature,
			     int label_size)
{
	double val;
	const sensors_subfeature *sf;
	struct sensor_subfeature_data sensors[6];
	struct sensor_subfeature_data alarms[3];
	int sensor_count, alarm_count;
	char *label;
	const char *unit;
	int i;

	if (!(label = sensors_get_label(name, feature))) {
		fprintf(stderr, "ERROR: Can't get label of feature %s!\n",
			feature->name);
		return;
	}
	print_label(label, label_size);
	free(label);

	sensor_count = alarm_count = 0;

	/* Power sensors come in 2 flavors: instantaneous and averaged.
	   To keep things simple, we assume that each sensor only implements
	   one flavor. */
	sf = sensors_get_subfeature(name, feature,
				    SENSORS_SUBFEATURE_POWER_INPUT);
	get_sensor_limit_data(name, feature,
			      sf ? power_inst_sensors : power_avg_sensors,
			      sensors, ARRAY_SIZE(sensors), &sensor_count,
			      alarms, ARRAY_SIZE(alarms), &alarm_count);
	/* Add sensors common to both flavors. */
	get_sensor_limit_data(name, feature,
			      power_common_sensors,
			      sensors, ARRAY_SIZE(sensors), &sensor_count,
			      alarms, ARRAY_SIZE(alarms), &alarm_count);
	if (!sf)
		sf = sensors_get_subfeature(name, feature,
					    SENSORS_SUBFEATURE_POWER_AVERAGE);

	if (sf && get_input_value(name, sf, &val) == 0) {
		scale_value(&val, &unit);
		printf("%6.2f %sW  ", val, unit);
	} else
		printf("     N/A  ");

	for (i = 0; i < sensor_count; i++)
		scale_value(&sensors[i].value, &sensors[i].unit);

	print_limits(sensors, sensor_count, alarms, alarm_count,
		     label_size, "%s = %6.2f %sW");

	printf("\n");
}
コード例 #2
0
ファイル: chips.c プロジェクト: pexip/os-lm-sensors
static void print_chip_fan(const sensors_chip_name *name,
			   const sensors_feature *feature,
			   int label_size)
{
	const sensors_subfeature *sf, *sfmin, *sfdiv;
	double val;
	char *label;

	if (!(label = sensors_get_label(name, feature))) {
		fprintf(stderr, "ERROR: Can't get label of feature %s!\n",
			feature->name);
		return;
	}
	print_label(label, label_size);
	free(label);

	sf = sensors_get_subfeature(name, feature,
				    SENSORS_SUBFEATURE_FAN_FAULT);
	if (sf && get_value(name, sf))
		printf("   FAULT");
	else {
		sf = sensors_get_subfeature(name, feature,
					    SENSORS_SUBFEATURE_FAN_INPUT);
		if (sf && get_input_value(name, sf, &val) == 0)
			printf("%4.0f RPM", val);
		else
			printf("     N/A");
	}

	sfmin = sensors_get_subfeature(name, feature,
				       SENSORS_SUBFEATURE_FAN_MIN);
	sfdiv = sensors_get_subfeature(name, feature,
				       SENSORS_SUBFEATURE_FAN_DIV);
	if (sfmin && sfdiv)
		printf("  (min = %4.0f RPM, div = %1.0f)",
		       get_value(name, sfmin),
		       get_value(name, sfdiv));
	else if (sfmin)
		printf("  (min = %4.0f RPM)",
		       get_value(name, sfmin));
	else if (sfdiv)
		printf("  (div = %1.0f)",
		       get_value(name, sfdiv));

	sf = sensors_get_subfeature(name, feature,
				    SENSORS_SUBFEATURE_FAN_ALARM);
	if (sf && get_value(name, sf)) {
		printf("  ALARM");
	}

	printf("\n");
}
コード例 #3
0
ファイル: chips.c プロジェクト: AlisonSchofield/lm-sensors
static void fillChipFan(FeatureDescriptor *fan,
			const sensors_chip_name *name,
			const sensors_feature *feature)
{
	const sensors_subfeature *sf, *sfmin, *sfdiv;
	int pos = 0;

	fan->rrd = rrdF0;
	fan->type = DataType_rpm;

	sf = sensors_get_subfeature(name, feature,
				    SENSORS_SUBFEATURE_FAN_INPUT);
	if (sf)
		fan->dataNumbers[pos++] = sf->number;

	sfmin = sensors_get_subfeature(name, feature,
				       SENSORS_SUBFEATURE_FAN_MIN);
	if (sfmin) {
		fan->dataNumbers[pos++] = sfmin->number;
		sfdiv = sensors_get_subfeature(name, feature,
					       SENSORS_SUBFEATURE_FAN_DIV);
		if (sfdiv) {
			fan->format = fmtFans_0;
			fan->dataNumbers[pos++] = sfdiv->number;
		} else {
			fan->format = fmtFans_nodiv_0;
		}
	} else {
		fan->format = fmtFan_only;
	}

	/* terminate the list */
	fan->dataNumbers[pos] = -1;

	/* alarm if applicable */
	sf = sensors_get_subfeature(name, feature,
				    SENSORS_SUBFEATURE_FAN_ALARM);
	if (sf) {
		fan->alarmNumber = sf->number;
	} else {
		fan->alarmNumber = -1;
	}
	/* beep if applicable */
	sf = sensors_get_subfeature(name, feature,
				    SENSORS_SUBFEATURE_FAN_BEEP);
	if (sf) {
		fan->beepNumber = sf->number;
	} else {
		fan->beepNumber = -1;
	}
}
コード例 #4
0
ファイル: sensors.c プロジェクト: SteveJones/j4status
static void
_j4status_sensors_add_feature_temp(J4statusPluginContext *context, const sensors_chip_name *chip, const sensors_feature *feature)
{
    const char *name = _j4status_sensors_get_feature_name(chip, feature);

    const sensors_subfeature *input;

    input = sensors_get_subfeature(chip, feature, SENSORS_SUBFEATURE_TEMP_INPUT);
    if ( input == NULL )
    {
        g_warning("No temperature input on chip '%s', skipping", name);
        return;
    }

    J4statusSensorsFeature *sensor_feature;
    sensor_feature = g_new0(J4statusSensorsFeature, 1);
    sensor_feature->section = j4status_section_new(context->core);
    sensor_feature->chip = chip;
    sensor_feature->feature = feature;
    sensor_feature->input = input;
    sensor_feature->max = sensors_get_subfeature(chip, feature, SENSORS_SUBFEATURE_TEMP_MAX);
    sensor_feature->crit = sensors_get_subfeature(chip, feature, SENSORS_SUBFEATURE_TEMP_CRIT);

    char *label;
    label = sensors_get_label(chip, feature);

    gint64 max_width = strlen("+100.0*C");
    if ( context->config.show_details )
    {
        if ( ( sensor_feature->crit != NULL ) && ( sensor_feature->max != NULL ) )
            max_width += strlen(" (high = +100.0°C, crit = +100.0°C)");
        else if ( sensor_feature->crit != NULL )
            max_width += strlen(" (crit = +100.0°C)");
        else if ( sensor_feature->max != NULL )
            max_width += strlen(" (high = +100.0°C)");
    }

    j4status_section_set_name(sensor_feature->section, "sensors");
    j4status_section_set_instance(sensor_feature->section, name);
    j4status_section_set_label(sensor_feature->section, label);
    j4status_section_set_max_width(sensor_feature->section, -max_width);

    free(label);

    if ( j4status_section_insert(sensor_feature->section) )
        context->sections = g_list_prepend(context->sections, sensor_feature);
    else
        _j4status_sensors_feature_free(sensor_feature);
}
コード例 #5
0
void HwmonDriver::readEvents(mxml_node_t *const) {
	int err = sensors_init(NULL);
	if (err) {
		logg->logMessage("Failed to initialize libsensors! (%d)", err);
		return;
	}
	sensors_sysfs_no_scaling = 1;

	int chip_nr = 0;
	const sensors_chip_name *chip;
	while ((chip = sensors_get_detected_chips(NULL, &chip_nr))) {
		int feature_nr = 0;
		const sensors_feature *feature;
		while ((feature = sensors_get_features(chip, &feature_nr))) {
			// Keep in sync with HwmonCounter::read
			// Can this counter be read?
			double value;
			const sensors_subfeature *const subfeature = sensors_get_subfeature(chip, feature, getInput(feature->type));
			if ((subfeature == NULL) || (sensors_get_value(chip, subfeature->number, &value) != 0)) {
				continue;
			}

			// Get the name of the counter
			int len = sensors_snprintf_chip_name(NULL, 0, chip) + 1;
			char *chip_name = new char[len];
			sensors_snprintf_chip_name(chip_name, len, chip);
			len = snprintf(NULL, 0, "hwmon_%s_%d_%d", chip_name, chip_nr, feature->number) + 1;
			char *const name = new char[len];
			snprintf(name, len, "hwmon_%s_%d_%d", chip_name, chip_nr, feature->number);
			delete [] chip_name;

			setCounters(new HwmonCounter(getCounters(), name, chip, feature));
		}
	}
}
コード例 #6
0
 virtual double getValue() { 
    const sensors_subfeature * sf;
    sf = sensors_get_subfeature(name, feature, 
          SENSORS_SUBFEATURE_TEMP_FAULT);
    if( sf && get_value(name, sf) ) {
       return INFINITY;
    } else {
       double val = 0.0;
       sf = sensors_get_subfeature(name, feature,
             SENSORS_SUBFEATURE_TEMP_INPUT);
       if(sf && get_input_value(name, sf, &val) == 0 ) {
          return val;
       }
    }
    return INFINITY; 
 }
コード例 #7
0
ファイル: chips.c プロジェクト: AlisonSchofield/lm-sensors
static void print_chip_energy(const sensors_chip_name *name,
			      const sensors_feature *feature,
			      int label_size)
{
	double val;
	const sensors_subfeature *sf;
	char *label;
	const char *unit;

	if (!(label = sensors_get_label(name, feature))) {
		fprintf(stderr, "ERROR: Can't get label of feature %s!\n",
			feature->name);
		return;
	}
	print_label(label, label_size);
	free(label);

	sf = sensors_get_subfeature(name, feature,
				    SENSORS_SUBFEATURE_ENERGY_INPUT);
	if (sf && get_input_value(name, sf, &val) == 0) {
		scale_value(&val, &unit);
		printf("%6.2f %sJ", val, unit);
	} else
		printf("     N/A");

	printf("\n");
}
コード例 #8
0
ファイル: chips.c プロジェクト: AlisonSchofield/lm-sensors
static void print_chip_curr(const sensors_chip_name *name,
			    const sensors_feature *feature,
			    int label_size)
{
	const sensors_subfeature *sf;
	double val;
	char *label;
	struct sensor_subfeature_data sensors[NUM_CURR_SENSORS];
	struct sensor_subfeature_data alarms[NUM_CURR_ALARMS];
	int sensor_count, alarm_count;

	if (!(label = sensors_get_label(name, feature))) {
		fprintf(stderr, "ERROR: Can't get label of feature %s!\n",
			feature->name);
		return;
	}
	print_label(label, label_size);
	free(label);

	sf = sensors_get_subfeature(name, feature,
				    SENSORS_SUBFEATURE_CURR_INPUT);
	if (sf && get_input_value(name, sf, &val) == 0)
		printf("%+6.2f A  ", val);
	else
		printf("     N/A  ");

	sensor_count = alarm_count = 0;
	get_sensor_limit_data(name, feature, current_sensors,
			      sensors, &sensor_count, alarms, &alarm_count);

	print_limits(sensors, sensor_count, alarms, alarm_count, label_size,
		     "%s = %+6.2f A");

	printf("\n");
}
コード例 #9
0
ファイル: chipname.c プロジェクト: sophiekovalevsky/pysensors
static PyObject*
get_subfeature(ChipName *self, PyObject *args, PyObject *kwargs)
{
    char *kwlist[] = {"feature", "type", NULL};
    Feature *feature = NULL;
    int type = -1;

    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!i", kwlist,
                                     &FeatureType, &feature, &type))
    {
        return NULL;
    }

    const sensors_subfeature *subfeature = sensors_get_subfeature(
        &self->chip_name, &feature->feature, type);

    if (subfeature == NULL)
    {
        Py_RETURN_NONE;
    }

    Subfeature *py_subfeature = PyObject_New(Subfeature, &SubfeatureType);

    if (py_subfeature == NULL)
    {
        return NULL;
    }

    py_subfeature->subfeature = *subfeature;
    py_subfeature->subfeature.name = strdup(subfeature->name);
    py_subfeature->py_name = PyString_FromString(subfeature->name);

    return (PyObject*)py_subfeature;
}
コード例 #10
0
ファイル: chips.c プロジェクト: pexip/os-lm-sensors
/*
 * Get sensor limit information.
 * *num_limits and *num_alarms must be initialized by the caller.
 */
static void get_sensor_limit_data(const sensors_chip_name *name,
				  const sensors_feature *feature,
				  const struct sensor_subfeature_list *sfl,
				  struct sensor_subfeature_data *limits,
				  int max_limits,
				  int *num_limits,
				  struct sensor_subfeature_data *alarms,
				  int max_alarms,
				  int *num_alarms)
{
	const sensors_subfeature *sf;

	for (; sfl->subfeature >= 0; sfl++) {
		sf = sensors_get_subfeature(name, feature, sfl->subfeature);
		if (sf) {
			if (sfl->alarm) {
				/*
				 * Only queue alarm subfeatures if the alarm
				 * is active, and don't store the alarm value
				 * (it is implied to be active if queued).
				 */
				if (get_value(name, sf)) {
					if (*num_alarms >= max_alarms) {
						fprintf(stderr,
							"Not enough %s buffers (%d)\n",
							"alarm", max_alarms);
					} else {
						alarms[*num_alarms].name = sfl->name;
						(*num_alarms)++;
					}
				}
			} else {
				/*
				 * Always queue limit subfeatures with their value.
				 */
				if (*num_limits >= max_limits) {
					fprintf(stderr,
						"Not enough %s buffers (%d)\n",
						"limit", max_limits);
				} else {
					limits[*num_limits].value = get_value(name, sf);
					limits[*num_limits].name = sfl->name;
					(*num_limits)++;
				}
			}
			if (sfl->exists) {
				get_sensor_limit_data(name, feature, sfl->exists,
						      limits, max_limits, num_limits,
						      alarms, max_alarms, num_alarms);
			}
		}
	}
}
コード例 #11
0
ファイル: hud_sensors_temp.c プロジェクト: etnaviv/mesa
static void
get_sensor_values(struct sensors_temp_info *sti)
{
   const sensors_subfeature *sf;

   switch(sti->mode) {
   case SENSORS_VOLTAGE_CURRENT:
      sf = sensors_get_subfeature(sti->chip, sti->feature,
                                  SENSORS_SUBFEATURE_IN_INPUT);
      if (sf)
         sti->current = get_value(sti->chip, sf);
      break;
   case SENSORS_CURRENT_CURRENT:
      sf = sensors_get_subfeature(sti->chip, sti->feature,
                                  SENSORS_SUBFEATURE_CURR_INPUT);
      if (sf) {
         /* Sensors API returns in AMPs, even though driver is reporting mA,
          * convert back to mA */
         sti->current = get_value(sti->chip, sf) * 1000;
      }
     break;
   case SENSORS_TEMP_CURRENT:
      sf = sensors_get_subfeature(sti->chip, sti->feature,
                                  SENSORS_SUBFEATURE_TEMP_INPUT);
      if (sf)
         sti->current = get_value(sti->chip, sf);
      break;
   case SENSORS_TEMP_CRITICAL:
      sf = sensors_get_subfeature(sti->chip, sti->feature,
                                  SENSORS_SUBFEATURE_TEMP_CRIT);
      if (sf)
         sti->critical = get_value(sti->chip, sf);
      break;
   case SENSORS_POWER_CURRENT:
      sf = sensors_get_subfeature(sti->chip, sti->feature,
                                  SENSORS_SUBFEATURE_POWER_INPUT);
      if (sf) {
         /* Sensors API returns in WATTs, even though driver is reporting mW,
          * convert back to mW */
         sti->current = get_value(sti->chip, sf) * 1000;
      }
      break;
   }

   sf = sensors_get_subfeature(sti->chip, sti->feature,
                               SENSORS_SUBFEATURE_TEMP_MIN);
   if (sf)
      sti->min = get_value(sti->chip, sf);

   sf = sensors_get_subfeature(sti->chip, sti->feature,
                               SENSORS_SUBFEATURE_TEMP_MAX);
   if (sf)
      sti->max = get_value(sti->chip, sf);
}
コード例 #12
0
ファイル: chips.c プロジェクト: AlisonSchofield/lm-sensors
static void fillChipTemperature(FeatureDescriptor *temperature,
				const sensors_chip_name *name,
				const sensors_feature *feature)
{
	const sensors_subfeature *sf, *sfmin, *sfmax, *sfhyst;
	int pos = 0;

	temperature->rrd = rrdF1;
	temperature->type = DataType_temperature;

	sf = sensors_get_subfeature(name, feature,
				    SENSORS_SUBFEATURE_TEMP_INPUT);
	if (sf)
		temperature->dataNumbers[pos++] = sf->number;

	sfmin = sensors_get_subfeature(name, feature,
				       SENSORS_SUBFEATURE_TEMP_MIN);
	sfmax = sensors_get_subfeature(name, feature,
				       SENSORS_SUBFEATURE_TEMP_MAX);
	sfhyst = sensors_get_subfeature(name, feature,
					SENSORS_SUBFEATURE_TEMP_MAX_HYST);
	if (sfmin && sfmax) {
		temperature->format = fmtTemps_minmax_1;
		temperature->dataNumbers[pos++] = sfmin->number;
		temperature->dataNumbers[pos++] = sfmax->number;
	} else if (sfmax && sfhyst) {
		temperature->format = fmtTemps_1;
		temperature->dataNumbers[pos++] = sfmax->number;
		temperature->dataNumbers[pos++] = sfhyst->number;
	} else {
		temperature->format = fmtTemp_only;
	}

	/* terminate the list */
	temperature->dataNumbers[pos] = -1;

	/* alarm if applicable */
	if ((sf = sensors_get_subfeature(name, feature,
					 SENSORS_SUBFEATURE_TEMP_ALARM)) ||
	    (sf = sensors_get_subfeature(name, feature,
					 SENSORS_SUBFEATURE_TEMP_MAX_ALARM))) {
		temperature->alarmNumber = sf->number;
	} else {
		temperature->alarmNumber = -1;
	}
	/* beep if applicable */
	if ((sf = sensors_get_subfeature(name, feature,
					 SENSORS_SUBFEATURE_TEMP_BEEP))) {
		temperature->beepNumber = sf->number;
	} else {
		temperature->beepNumber = -1;
	}
}
コード例 #13
0
ファイル: feature.cpp プロジェクト: B-Rich/razor-qt
double Feature::getValue(sensors_subfeature_type subfeature_type) const
{
    double result = 0;

    const sensors_subfeature *subfeature;

    // Find feature
    subfeature = sensors_get_subfeature(mSensorsChipName, mSensorsFeature, subfeature_type);

    if (subfeature)
    {
        sensors_get_value(mSensorsChipName, subfeature->number, &result);
    }

    return result;
}
コード例 #14
0
ファイル: main.c プロジェクト: Biolunar/dstatus
static struct temperature* temperature_init(void)
{
	int chip_nr = 0;
	struct temperature* temp = 0;

	if (sensors_init(0))
	{
		fprintf(stderr, u8"Could not initialize libsensors.\n");
		return 0;
	}

	temp = calloc(1, sizeof(struct temperature));
	if (!temp)
	{
		fprintf(stderr, u8"Could not allocate memory for temperature struct.\n");
		return 0;
	}

	while ((temp->chip = sensors_get_detected_chips(0, &chip_nr)))
	{
		if (!strcmp(chip_name, temp->chip->prefix))
		{
			int feature_nr = 0;
			sensors_feature const* feat = 0;
			while ((feat = sensors_get_features(temp->chip, &feature_nr)))
			{
				if (feat->type == SENSORS_FEATURE_TEMP)
				{
					sensors_subfeature const* sub = sensors_get_subfeature(temp->chip, feat, SENSORS_SUBFEATURE_TEMP_INPUT);
					if (!sub)
					{
						fprintf(stderr, u8"Could not get chip subfeature.\n");
						return 0;
					}

					++temp->count;
					temp->numbers = realloc(temp->numbers, temp->count * sizeof(int));
					temp->numbers[temp->count - 1] = sub->number;
				}
			}

			return temp;
		}
	}

	return 0;
}
コード例 #15
0
ファイル: chips.c プロジェクト: AlisonSchofield/lm-sensors
static void fillChipVoltage(FeatureDescriptor *voltage,
			    const sensors_chip_name *name,
			    const sensors_feature *feature)
{
	const sensors_subfeature *sf, *sfmin, *sfmax;
	int pos = 0;

	voltage->rrd = rrdF2;
	voltage->type = DataType_voltage;

	sf = sensors_get_subfeature(name, feature,
				    SENSORS_SUBFEATURE_IN_INPUT);
	if (sf)
		voltage->dataNumbers[pos++] = sf->number;

	sfmin = sensors_get_subfeature(name, feature,
				       SENSORS_SUBFEATURE_IN_MIN);
	sfmax = sensors_get_subfeature(name, feature,
				       SENSORS_SUBFEATURE_IN_MAX);
	if (sfmin && sfmax) {
		voltage->format = fmtVolts_2;
		voltage->dataNumbers[pos++] = sfmin->number;
		voltage->dataNumbers[pos++] = sfmax->number;
	} else {
		voltage->format = fmtVolt_2;
	}

	/* terminate the list */
	voltage->dataNumbers[pos] = -1;

	/* alarm if applicable */
	if ((sf = sensors_get_subfeature(name, feature,
					 SENSORS_SUBFEATURE_IN_ALARM)) ||
	    (sf = sensors_get_subfeature(name, feature,
					 SENSORS_SUBFEATURE_IN_MIN_ALARM)) ||
	    (sf = sensors_get_subfeature(name, feature,
					 SENSORS_SUBFEATURE_IN_MAX_ALARM))) {
		voltage->alarmNumber = sf->number;
	} else {
		voltage->alarmNumber = -1;
	}
	/* beep if applicable */
	if ((sf = sensors_get_subfeature(name, feature,
					 SENSORS_SUBFEATURE_IN_BEEP))) {
		voltage->beepNumber = sf->number;
	} else {
		voltage->beepNumber = -1;
	}
}
コード例 #16
0
ファイル: chips.c プロジェクト: AlisonSchofield/lm-sensors
static void fillChipVid(FeatureDescriptor *vid,
			const sensors_chip_name *name,
			const sensors_feature *feature)
{
	const sensors_subfeature *sub;

	sub = sensors_get_subfeature(name, feature, SENSORS_SUBFEATURE_VID);
	if (!sub)
		return;

	vid->format = fmtVolt_3;
	vid->rrd = rrdF3;
	vid->type = DataType_voltage;
	vid->alarmNumber = -1;
	vid->beepNumber = -1;
	vid->dataNumbers[0] = sub->number;
	vid->dataNumbers[1] = -1;
}
コード例 #17
0
ファイル: chips.c プロジェクト: AlisonSchofield/lm-sensors
static void fillChipBeepEnable(FeatureDescriptor *beepen,
			       const sensors_chip_name *name,
			       const sensors_feature *feature)
{
	const sensors_subfeature *sub;

	sub = sensors_get_subfeature(name, feature,
				     SENSORS_SUBFEATURE_BEEP_ENABLE);
	if (!sub)
		return;

	beepen->format = fmtSoundAlarm;
	beepen->rrd = rrdF0;
	beepen->type = DataType_other;
	beepen->alarmNumber = -1;
	beepen->beepNumber = -1;
	beepen->dataNumbers[0] = sub->number;
	beepen->dataNumbers[1] = -1;
}
コード例 #18
0
ファイル: chips.c プロジェクト: AlisonSchofield/lm-sensors
static void print_chip_beep_enable(const sensors_chip_name *name,
				   const sensors_feature *feature,
				   int label_size)
{
	char *label;
	const sensors_subfeature *subfeature;
	double beep_enable;

	subfeature = sensors_get_subfeature(name, feature,
					    SENSORS_SUBFEATURE_BEEP_ENABLE);
	if (!subfeature)
		return;

	if ((label = sensors_get_label(name, feature))
	 && !sensors_get_value(name, subfeature->number, &beep_enable)) {
		print_label(label, label_size);
		printf("%s\n", beep_enable ? "enabled" : "disabled");
	}
	free(label);
}
コード例 #19
0
ファイル: chips.c プロジェクト: AlisonSchofield/lm-sensors
static void print_chip_intrusion(const sensors_chip_name *name,
				 const sensors_feature *feature,
				 int label_size)
{
	char *label;
	const sensors_subfeature *subfeature;
	double alarm;

	subfeature = sensors_get_subfeature(name, feature,
					    SENSORS_SUBFEATURE_INTRUSION_ALARM);
	if (!subfeature)
		return;

	if ((label = sensors_get_label(name, feature))
	 && !sensors_get_value(name, subfeature->number, &alarm)) {
		print_label(label, label_size);
		printf("%s\n", alarm ? "ALARM" : "OK");
	}
	free(label);
}
コード例 #20
0
ファイル: chips.c プロジェクト: AlisonSchofield/lm-sensors
static void print_chip_humidity(const sensors_chip_name *name,
				const sensors_feature *feature,
				int label_size)
{
	char *label;
	const sensors_subfeature *subfeature;
	double humidity;

	subfeature = sensors_get_subfeature(name, feature,
					    SENSORS_SUBFEATURE_HUMIDITY_INPUT);
	if (!subfeature)
		return;

	if ((label = sensors_get_label(name, feature))
	 && !sensors_get_value(name, subfeature->number, &humidity)) {
		print_label(label, label_size);
		printf("%6.1f %%RH\n", humidity);
	}
	free(label);
}
コード例 #21
0
ファイル: chips.c プロジェクト: AlisonSchofield/lm-sensors
static void print_chip_vid(const sensors_chip_name *name,
			   const sensors_feature *feature,
			   int label_size)
{
	char *label;
	const sensors_subfeature *subfeature;
	double vid;

	subfeature = sensors_get_subfeature(name, feature,
					    SENSORS_SUBFEATURE_VID);
	if (!subfeature)
		return;

	if ((label = sensors_get_label(name, feature))
	 && !sensors_get_value(name, subfeature->number, &vid)) {
		print_label(label, label_size);
		printf("%+6.3f V\n", vid);
	}
	free(label);
}
コード例 #22
0
ファイル: Hwmon.cpp プロジェクト: mreyna1216/gator
bool HwmonCounter::canRead() {
	if (!polled) {
		double value;
		const sensors_subfeature *subfeature;
		bool result = true;

		subfeature = sensors_get_subfeature(chip, feature, input);
		if (!subfeature) {
			result = false;
		} else {
			result = sensors_get_value(chip, subfeature->number, &value) == 0;
		}

		polled = true;
		readable = result;
	}

	enabled &= readable;

	return readable;
}
コード例 #23
0
int64_t HwmonCounter::read() {
	double value;
	double result;
	const sensors_subfeature *subfeature;

	// Keep in sync with the read check in HwmonDriver::readEvents
	subfeature = sensors_get_subfeature(chip, feature, getInput(feature->type));
	if (!subfeature) {
		logg->logError(__FILE__, __LINE__, "No input value for hwmon sensor %s", label);
		handleException();
	}

	if (sensors_get_value(chip, subfeature->number, &value) != 0) {
		logg->logError(__FILE__, __LINE__, "Can't get input value for hwmon sensor %s", label);
		handleException();
	}

	result = (monotonic ? value - previous_value : value);
	previous_value = value;

	return result;
}
コード例 #24
0
ファイル: HwmonDriver.cpp プロジェクト: freedomtan/gator
int64_t HwmonCounter::read() {
    double value;
    double result;
    const sensors_subfeature *subfeature;

    // Keep in sync with the read check in HwmonDriver::readEvents
    subfeature = sensors_get_subfeature(mChip, mFeature, getInput(mFeature->type));
    if (!subfeature) {
        logg.logError("No input value for hwmon sensor %s", mLabel);
        handleException();
    }

    if (sensors_get_value(mChip, subfeature->number, &value) != 0) {
        logg.logError("Can't get input value for hwmon sensor %s", mLabel);
        handleException();
    }

    result = (mMonotonic ? value - mPreviousValue : value);
    mPreviousValue = value;

    return result;
}
コード例 #25
0
ファイル: chips.c プロジェクト: AlisonSchofield/lm-sensors
static void print_chip_temp(const sensors_chip_name *name,
			    const sensors_feature *feature,
			    int label_size)
{
	struct sensor_subfeature_data sensors[NUM_TEMP_SENSORS];
	struct sensor_subfeature_data alarms[NUM_TEMP_ALARMS];
	int sensor_count, alarm_count;
	const sensors_subfeature *sf;
	double val;
	char *label;
	int i;

	if (!(label = sensors_get_label(name, feature))) {
		fprintf(stderr, "ERROR: Can't get label of feature %s!\n",
			feature->name);
		return;
	}
	print_label(label, label_size);
	free(label);

	sf = sensors_get_subfeature(name, feature,
				    SENSORS_SUBFEATURE_TEMP_FAULT);
	if (sf && get_value(name, sf)) {
		printf("   FAULT  ");
	} else {
		sf = sensors_get_subfeature(name, feature,
					    SENSORS_SUBFEATURE_TEMP_INPUT);
		if (sf && get_input_value(name, sf, &val) == 0) {
			get_input_value(name, sf, &val);
			if (fahrenheit)
				val = deg_ctof(val);
			printf("%+6.1f%s  ", val, degstr);
		} else
			printf("     N/A  ");
	}

	sensor_count = alarm_count = 0;
	get_sensor_limit_data(name, feature, temp_sensors,
			      sensors, &sensor_count, alarms, &alarm_count);

	for (i = 0; i < sensor_count; i++) {
		if (fahrenheit)
			sensors[i].value = deg_ctof(sensors[i].value);
		sensors[i].unit = degstr;
	}

	print_limits(sensors, sensor_count, alarms, alarm_count, label_size,
		     "%-4s = %+5.1f%s");

	/* print out temperature sensor info */
	sf = sensors_get_subfeature(name, feature,
				    SENSORS_SUBFEATURE_TEMP_TYPE);
	if (sf) {
		int sens = (int)get_value(name, sf);

		/* older kernels / drivers sometimes report a beta value for
		   thermistors */
		if (sens > 1000)
			sens = 4;

		printf("  sensor = %s", sens == 0 ? "disabled" :
		       sens == 1 ? "CPU diode" :
		       sens == 2 ? "transistor" :
		       sens == 3 ? "thermal diode" :
		       sens == 4 ? "thermistor" :
		       sens == 5 ? "AMD AMDSI" :
		       sens == 6 ? "Intel PECI" : "unknown");
	}
	printf("\n");
}
コード例 #26
0
static GList *libsensors_plugin_get_sensors(void) {
	const sensors_chip_name *chip_name;
	int i;
        GList *sensors = NULL;

#if SENSORS_API_VERSION < 0x400        
	FILE *file;
        g_debug("%s: using libsensors version < 4", __FUNCTION__);

	/* try to open config file, otherwise try alternate config
	 * file - if neither succeed, exit */
	if ((file = fopen (LIBSENSORS_CONFIG_FILE, "r")) == NULL) {
		if ((file = fopen (LIBSENSORS_ALTERNATIVE_CONFIG_FILE, "r")) == NULL) {
                        g_debug("%s: error opening libsensors config file... ", __FUNCTION__);
			return sensors;
		}
	}
	
	/* at this point should have an open config file, if is not
	 * valid, close file and return */
	if (sensors_init(file) != 0) {
		fclose(file);
                g_debug("%s: error initing libsensors from config file...", __FUNCTION__);
		return sensors;
	}
	fclose(file);

	/* libsensors exposes a number of chips -  ... */
	i = 0;
	while ((chip_name = sensors_get_detected_chips (&i)) != NULL) {
		char *chip_name_string;
		const sensors_feature_data *data;
		int n1 = 0, n2 = 0;
                
		chip_name_string = get_chip_name_string(chip_name);
		
		/* ... each of which has one or more 'features' ... */
		while ((data = sensors_get_all_features (*chip_name, &n1, &n2)) != NULL) { // error
                        // fill in list for us
                        check_sensor_with_data(&sensors, chip_name_string, 
                                               chip_name, &n1, &n2, data);
                }
		g_free (chip_name_string);
	}

#else
        g_debug("%s: using libsensors version >= 4", __FUNCTION__);
        
        int nr = 0;
        if (sensors_init(NULL) != 0) {
                g_debug("%s: error initing libsensors", __FUNCTION__);
                return sensors;
        }
	i = 0;
	while ((chip_name = sensors_get_detected_chips(NULL, &nr)))
        {
                char *chip_name_string, *label;                
                const sensors_subfeature *input_feature;
                const sensors_subfeature *low_feature;
                const sensors_subfeature *high_feature;
		const sensors_feature *main_feature;
                SensorType type;
		gint nr1 = 0;
                gdouble value, low, high;
                gchar *path;
                gboolean visible;
                IconType icon;
                
		chip_name_string = get_chip_name_string(chip_name);
                if (chip_name_string == NULL) {
                        g_debug("%s: %d: error getting name string for sensor: %s\n",
                                        __FILE__, __LINE__, chip_name->path);
                        continue;
                }
                
		while ((main_feature = sensors_get_features(chip_name, &nr1)))
                {
			switch (main_feature->type)
                        {
                        case SENSORS_FEATURE_IN:
				type = VOLTAGE_SENSOR;
				input_feature = sensors_get_subfeature(chip_name, 
                                                                    main_feature, 
                                                                    SENSORS_SUBFEATURE_IN_INPUT);
				low_feature = sensors_get_subfeature(chip_name, 
                                                                     main_feature, 
                                                                     SENSORS_SUBFEATURE_IN_MIN);
				high_feature = sensors_get_subfeature(chip_name, 
                                                                      main_feature, 
                                                                      SENSORS_SUBFEATURE_IN_MAX);
			  	break;
                        case SENSORS_FEATURE_FAN:
				type = FAN_SENSOR;
				input_feature = sensors_get_subfeature(chip_name, 
                                                                    main_feature, 
                                                                    SENSORS_SUBFEATURE_FAN_INPUT);
				low_feature = sensors_get_subfeature(chip_name, 
                                                                     main_feature, 
                                                                     SENSORS_SUBFEATURE_FAN_MIN);
                                // no fan max feature
				high_feature = NULL;
				break;
                        case SENSORS_FEATURE_TEMP:
				type = TEMP_SENSOR;
				input_feature = sensors_get_subfeature(chip_name, 
                                                                    main_feature, 
                                                                    SENSORS_SUBFEATURE_TEMP_INPUT);
				low_feature = sensors_get_subfeature(chip_name, 
                                                                     main_feature, 
                                                                     SENSORS_SUBFEATURE_TEMP_MIN);
				high_feature = sensors_get_subfeature(chip_name, 
                                                                      main_feature, 
                                                                      SENSORS_SUBFEATURE_TEMP_MAX);
				if (!high_feature)
					high_feature = sensors_get_subfeature(chip_name, 
									      main_feature, 
									      SENSORS_SUBFEATURE_TEMP_CRIT);
				break;
                        default:
                                g_debug("%s: %d: error determining type for: %s\n",
                                        __FILE__, __LINE__, chip_name_string);
				continue;
                        }
                        
			if (!input_feature)
                        {
                                g_debug("%s: %d: could not get input subfeature for: %s\n",
                                        __FILE__, __LINE__, chip_name_string);
				continue;
                        }
                        // if still here we got input feature so get label
                        label = sensors_get_label(chip_name, main_feature);
                        if (!label) 
                        {
                                g_debug("%s: %d: error: could not get label for: %s\n",
                                        __FILE__, __LINE__, chip_name_string);
                                continue;
                        }

                        g_assert(chip_name_string && label);
                        
                        icon = get_sensor_icon(type);
                        visible = (type == TEMP_SENSOR ? TRUE : FALSE);
                        sensors_applet_plugin_default_sensor_limits(type, 
                                                                    &low, 
                                                                    &high);                        
                        if (low_feature) {
                                sensors_get_value(chip_name, low_feature->number, &low);
                        }

                        if (high_feature) {
                                sensors_get_value(chip_name, high_feature->number, &high);
                        }
                        
                                
                        if (sensors_get_value(chip_name, input_feature->number, &value) < 0) {
                                g_debug("%s: %d: error: could not get value for input feature of sensor: %s\n",
                                        __FILE__, __LINE__, chip_name_string);
                                free(label);
                                continue;
                        }

                        g_debug("for chip %s (type %s) got label %s and value %f", chip_name_string, 
                                (type == TEMP_SENSOR ? "temp" :
                                 (type == FAN_SENSOR ? "fan" :
                                  (type == VOLTAGE_SENSOR ? "voltage" : "error"))), label, value);

                        path = g_strdup_printf ("sensor://%s/%d", chip_name_string, input_feature->number);
			g_hash_table_insert(hash_table, g_strdup(path), (void *)chip_name);
                        sensors_applet_plugin_add_sensor_with_limits(&sensors,
                                                                     path,
                                                                     label,
                                                                     label,
                                                                     type, 
                                                                     visible,
                                                                     low, 
                                                                     high,
                                                                     icon,
                                                                     DEFAULT_GRAPH_COLOR);
                }
                g_free(chip_name_string);
                
                
        }
#endif

        return sensors;
}
コード例 #27
0
ファイル: chips.c プロジェクト: AlisonSchofield/lm-sensors
static void print_chip_power(const sensors_chip_name *name,
			     const sensors_feature *feature,
			     int label_size)
{
	double val;
	const sensors_subfeature *sf;
	struct sensor_subfeature_data sensors[NUM_POWER_SENSORS];
	struct sensor_subfeature_data alarms[NUM_POWER_ALARMS];
	int sensor_count, alarm_count;
	char *label;
	const char *unit;
	int i;

	if (!(label = sensors_get_label(name, feature))) {
		fprintf(stderr, "ERROR: Can't get label of feature %s!\n",
			feature->name);
		return;
	}
	print_label(label, label_size);
	free(label);

	sensor_count = alarm_count = 0;

	/*
	 * Power sensors come in 2 flavors: instantaneous and averaged.
	 * Most devices only support one flavor, so we try to display the
	 * average power if the instantaneous power attribute does not exist.
	 * If both instantaneous power and average power are supported,
	 * average power is displayed as limit.
	 */
	sf = sensors_get_subfeature(name, feature,
				    SENSORS_SUBFEATURE_POWER_INPUT);
	get_sensor_limit_data(name, feature,
			      sf ? power_inst_sensors : power_avg_sensors,
			      sensors, &sensor_count, alarms, &alarm_count);
	/* Add sensors common to both flavors. */
	get_sensor_limit_data(name, feature, power_common_sensors,
			      sensors, &sensor_count, alarms, &alarm_count);
	if (!sf)
		sf = sensors_get_subfeature(name, feature,
					    SENSORS_SUBFEATURE_POWER_AVERAGE);

	if (sf && get_input_value(name, sf, &val) == 0) {
		scale_value(&val, &unit);
		printf("%6.2f %sW%*s", val, unit, 2 - (int)strlen(unit), "");
	} else
		printf("     N/A  ");

	for (i = 0; i < sensor_count; i++) {
		/*
		 * Unit is W and needs to be scaled for all attributes except
		 * interval, which does not need to be scaled and is reported in
		 * seconds.
		 */
		if (strcmp(sensors[i].name, "interval")) {
			char *tmpstr;

			tmpstr = alloca(4);
			scale_value(&sensors[i].value, &unit);
			snprintf(tmpstr, 4, "%sW", unit);
			sensors[i].unit = tmpstr;
		} else {
			sensors[i].unit = "s";
		}
	}
	print_limits(sensors, sensor_count, alarms, alarm_count,
		     label_size, "%s = %6.2f %s");

	printf("\n");
}