Ejemplo n.º 1
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));
		}
	}
}
static char *get_chip_name_string(const sensors_chip_name *chip) {
	char *name;

#if SENSORS_API_VERSION < 0x400
	// taken from lm-sensors:prog/sensors/main.c:sprintf_chip_name
	switch (chip->bus) {
	case SENSORS_CHIP_NAME_BUS_ISA:
		name = g_strdup_printf ("%s-isa-%04x", chip->prefix, chip->addr);
		break;
	case SENSORS_CHIP_NAME_BUS_DUMMY:
		name = g_strdup_printf ("%s-%s-%04x", chip->prefix, chip->busname, chip->addr);
		break;
        case SENSORS_CHIP_NAME_BUS_PCI:
                name = g_strdup_printf ("%s-pci-%04x", chip->prefix, chip->addr);
                break;
	default:
		name = g_strdup_printf ("%s-i2c-%d-%02x", chip->prefix, chip->bus, chip->addr);
		break;
	}
#else
	// adapted from lm-sensors:prog/sensors/main.c:sprintf_chip_name 
        // in lm-sensors-3.0
#define BUF_SIZE 200
	name = g_malloc0(BUF_SIZE);
	if (sensors_snprintf_chip_name(name, BUF_SIZE, chip) < 0) {
		g_free(name);
                name = NULL;
        }
        
#endif

	return name;
}
Ejemplo n.º 3
0
static const char *chipName(const sensors_chip_name *chip)
{
	static char buffer[256];
	if (sensors_snprintf_chip_name(buffer, 256, chip) < 0)
		return NULL;
	return buffer;
}
Ejemplo n.º 4
0
static const char *sprintf_chip_name(const sensors_chip_name *name)
{
#define BUF_SIZE 200
    static char buf[BUF_SIZE];

    if (sensors_snprintf_chip_name(buf, BUF_SIZE, name) < 0)
        return NULL;
    return buf;
}
Ejemplo n.º 5
0
// Not re-entrant/thread-safe
static const char *
_j4status_sensors_get_feature_name(const sensors_chip_name *chip, const sensors_feature *feature)
{
    int n;
    static char name[MAX_CHIP_NAME_SIZE + NAME_MAX + 1];
    n = sensors_snprintf_chip_name(name, MAX_CHIP_NAME_SIZE, chip);
    name[n++] = '/';
    strcpy(name + n, feature->name);

    return name;
}
   Chip(const sensors_chip_name * c) : chip(c) {
      // populate name
      if(sensors_snprintf_chip_name(name, NAME_SZ, c) < 0) {
         // error: bad chip name
         snprintf(name, NAME_SZ, "Unknown chip");
      }

      // populate features
      int i = 0;
      const sensors_feature * feature;
      while( (feature = sensors_get_features(chip, &i)) ) {
         features.push_back(Feature(c, feature));
      }
   }
SensorChip::SensorChip(sensors_chip_name const *chip_name,
    const std::vector<std::string> &ignore) :
  internal_name_(chip_name)
{
  char name_buffer[NAME_BUFFER_SIZE];
  sensors_snprintf_chip_name(name_buffer, NAME_BUFFER_SIZE, internal_name_);
  name_ = name_buffer;

  ROS_DEBUG("Found Sensor: %s", getName().c_str());

  // enumerate the features of this sensor
  sensors_feature const *feature;
  int number = 0;

  while ((feature = sensors_get_features(internal_name_, &number)) != NULL) {
    sensors_feature_type type = feature->type;
    SensorChipFeaturePtr feature_ptr;
    switch(type){
    case SENSORS_FEATURE_FAN:
      feature_ptr.reset(new FanSensor(*this, feature));
      break;
    case SENSORS_FEATURE_TEMP:
      feature_ptr.reset(new TempSensor(*this, feature));
      break;
    case SENSORS_FEATURE_IN:
      feature_ptr.reset(new VoltageSensor(*this, feature));
      break;
    default:
      feature_ptr.reset(new OtherSensor(*this, feature));
      break;
    }

    if( std::count(ignore.begin(), ignore.end(),
          feature_ptr->getFullName()) > 0 ) {
      ROS_INFO_STREAM("Ignoring sensor " << feature_ptr->getFullName());
    } else {
      features_.push_back(feature_ptr);
    }
  }

  std::stringstream info_msg;
  info_msg << "Found sensor " << getName();
  if( features_.size() > 0 ) {
    info_msg << " with features: ";
    size_t remain = features_.size();
    BOOST_FOREACH(const SensorChipFeaturePtr & feature, features_) {
      remain--;
      info_msg << feature->getFeatureName();
      if( remain > 0 ) info_msg << ", ";
    }
Ejemplo n.º 8
0
static void
build_sensor_list(void)
{
   const sensors_chip_name *chip;
   const sensors_chip_name *match = 0;
   const sensors_feature *feature;
   int chip_nr = 0;

   char name[256];
   while ((chip = sensors_get_detected_chips(match, &chip_nr))) {
      sensors_snprintf_chip_name(name, sizeof(name), chip);

      /* Get all features and filter accordingly. */
      int fnr = 0;
      while ((feature = sensors_get_features(chip, &fnr))) {
         char *featurename = sensors_get_label(chip, feature);
         if (!featurename)
            continue;

         /* Create a 'current' and 'critical' object pair.
          * Ignore sensor if its not temperature based.
          */
         switch(feature->type) {
         case SENSORS_FEATURE_TEMP:
            create_object(name, featurename, chip, feature,
                          SENSORS_TEMP_CURRENT);
            create_object(name, featurename, chip, feature,
                          SENSORS_TEMP_CRITICAL);
            break;
         case SENSORS_FEATURE_IN:
            create_object(name, featurename, chip, feature,
                          SENSORS_VOLTAGE_CURRENT);
            break;
         case SENSORS_FEATURE_CURR:
            create_object(name, featurename, chip, feature,
                          SENSORS_CURRENT_CURRENT);
            break;
         case SENSORS_FEATURE_POWER:
            create_object(name, featurename, chip, feature,
                          SENSORS_POWER_CURRENT);
            break;
         default:
            break;
         }
         free(featurename);
      }
   }
}
Ejemplo n.º 9
0
static PyObject*
str(ChipName *self)
{
    char buffer[512];
    int status;

    status = sensors_snprintf_chip_name(buffer, sizeof buffer,
                                        &(self->chip_name));

    if (status < 0)
    {
        PyErr_SetString(SensorsException, sensors_strerror(status));
        return NULL;
    }

    return PyString_FromString(buffer);
}
Ejemplo n.º 10
0
HwmonCounter::HwmonCounter(HwmonCounter *next, const sensors_chip_name *chip, const sensors_feature *feature) : next(next), key(getEventKey()), polled(false), readable(false), enabled(false), duplicate(false), chip(chip), feature(feature) {

	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", chip_name, feature->number) + 1;
	name = new char[len];
	snprintf(name, len, "hwmon_%s_%d", chip_name, feature->number);

	delete [] chip_name;

	label = sensors_get_label(chip, feature);

	switch (feature->type) {
	case SENSORS_FEATURE_IN:
		title = "Voltage";
		input = SENSORS_SUBFEATURE_IN_INPUT;
		display = "maximum";
		counter_class = "absolute";
		unit = "V";
		modifier = 1000;
		monotonic = false;
		break;
	case SENSORS_FEATURE_FAN:
		title = "Fan";
		input = SENSORS_SUBFEATURE_FAN_INPUT;
		display = "average";
		counter_class = "absolute";
		unit = "RPM";
		modifier = 1;
		monotonic = false;
		break;
	case SENSORS_FEATURE_TEMP:
		title = "Temperature";
		input = SENSORS_SUBFEATURE_TEMP_INPUT;
		display = "maximum";
		counter_class = "absolute";
		unit = "°C";
		modifier = 1000;
		monotonic = false;
		break;
	case SENSORS_FEATURE_POWER:
		title = "Power";
		input = SENSORS_SUBFEATURE_POWER_INPUT;
		display = "maximum";
		counter_class = "absolute";
		unit = "W";
		modifier = 1000000;
		monotonic = false;
		break;
	case SENSORS_FEATURE_ENERGY:
		title = "Energy";
		input = SENSORS_SUBFEATURE_ENERGY_INPUT;
		display = "accumulate";
		counter_class = "delta";
		unit = "J";
		modifier = 1000000;
		monotonic = true;
		break;
	case SENSORS_FEATURE_CURR:
		title = "Current";
		input = SENSORS_SUBFEATURE_CURR_INPUT;
		display = "maximum";
		counter_class = "absolute";
		unit = "A";
		modifier = 1000;
		monotonic = false;
		break;
	case SENSORS_FEATURE_HUMIDITY:
		title = "Humidity";
		input = SENSORS_SUBFEATURE_HUMIDITY_INPUT;
		display = "average";
		counter_class = "absolute";
		unit = "%";
		modifier = 1000;
		monotonic = false;
		break;
	default:
		logg->logError(__FILE__, __LINE__, "Unsupported hwmon feature %i", feature->type);
		handleException();
	}

	for (HwmonCounter * counter = next; counter != NULL; counter = counter->getNext()) {
		if (strcmp(label, counter->getLabel()) == 0 && strcmp(title, counter->getTitle()) == 0) {
			duplicate = true;
			counter->duplicate = true;
			break;
		}
	}
}
Ejemplo n.º 11
0
static int sensors_read (void)
{
	if (sensors_load_conf () != 0)
		return (-1);

#if SENSORS_API_VERSION < 0x400
	for (featurelist_t *fl = first_feature; fl != NULL; fl = fl->next)
	{
		double value;
		int status;
		char plugin_instance[DATA_MAX_NAME_LEN];
		char type_instance[DATA_MAX_NAME_LEN];

		status = sensors_get_feature (*fl->chip,
				fl->data->number, &value);
		if (status < 0)
			continue;

		status = sensors_snprintf_chip_name (plugin_instance,
				sizeof (plugin_instance), fl->chip);
		if (status < 0)
			continue;

		sstrncpy (type_instance, fl->data->name,
				sizeof (type_instance));

		sensors_submit (plugin_instance,
				sensor_type_name_map[fl->type],
				type_instance,
				value);
	} /* for fl = first_feature .. NULL */
/* #endif SENSORS_API_VERSION < 0x400 */

#elif (SENSORS_API_VERSION >= 0x400) && (SENSORS_API_VERSION < 0x500)
	for (featurelist_t *fl = first_feature; fl != NULL; fl = fl->next)
	{
		double value;
		int status;
		char plugin_instance[DATA_MAX_NAME_LEN];
		char type_instance[DATA_MAX_NAME_LEN];
		char *sensor_label;
		const char *type;

		status = sensors_get_value (fl->chip,
				fl->subfeature->number, &value);
		if (status < 0)
			continue;

		status = sensors_snprintf_chip_name (plugin_instance,
				sizeof (plugin_instance), fl->chip);
		if (status < 0)
			continue;

		if (use_labels)
		{
			sensor_label = sensors_get_label (fl->chip, fl->feature);
			sstrncpy (type_instance, sensor_label, sizeof (type_instance));
			free (sensor_label);
		}
		else
		{
			sstrncpy (type_instance, fl->feature->name,
					sizeof (type_instance));
		}

		if (fl->feature->type == SENSORS_FEATURE_IN)
			type = "voltage";
		else if (fl->feature->type
				== SENSORS_FEATURE_FAN)
			type = "fanspeed";
		else if (fl->feature->type
				== SENSORS_FEATURE_TEMP)
			type = "temperature";
		else if (fl->feature->type
				== SENSORS_FEATURE_POWER)
			type = "power";
		else
			continue;

		sensors_submit (plugin_instance, type, type_instance, value);
	} /* for fl = first_feature .. NULL */
#endif /* (SENSORS_API_VERSION >= 0x400) && (SENSORS_API_VERSION < 0x500) */

	return (0);
} /* int sensors_read */