Exemplo n.º 1
0
void Hwmon::start() {
	for (HwmonCounter * counter = counters; counter != NULL; counter = counter->getNext()) {
		if (!counter->isEnabled()) {
			continue;
		}
		counter->read();
	}
}
Exemplo n.º 2
0
void Hwmon::read(Buffer * const buffer) {
	for (HwmonCounter * counter = counters; counter != NULL; counter = counter->getNext()) {
		if (!counter->isEnabled()) {
			continue;
		}
		buffer->event(counter->getKey(), counter->read());
	}
}
Exemplo n.º 3
0
bool Hwmon::countersEnabled() const {
	for (HwmonCounter * counter = counters; counter != NULL; counter = counter->getNext()) {
		if (counter->isEnabled()) {
			return true;
		}
	}
	return false;
}
Exemplo n.º 4
0
Hwmon::~Hwmon() {
	while (counters != NULL) {
		HwmonCounter * counter = counters;
		counters = counter->getNext();
		delete counter;
	}
	sensors_cleanup();
}
Exemplo n.º 5
0
HwmonCounter *Hwmon::findCounter(const Counter &counter) const {
	for (HwmonCounter * hwmonCounter = counters; hwmonCounter != NULL; hwmonCounter = hwmonCounter->getNext()) {
		if (hwmonCounter->canRead() && strcmp(hwmonCounter->getName(), counter.getType()) == 0) {
			return hwmonCounter;
		}
	}

	return NULL;
}
Exemplo n.º 6
0
int Hwmon::writeCounters(mxml_node_t *root) const {
	int count = 0;
	for (HwmonCounter * counter = counters; counter != NULL; counter = counter->getNext()) {
		if (!counter->canRead()) {
			continue;
		}
		mxml_node_t *node = mxmlNewElement(root, "counter");
		mxmlElementSetAttr(node, "name", counter->getName());
		++count;
	}

	return count;
}
Exemplo n.º 7
0
HwmonCounter::HwmonCounter(DriverCounter *next, char *const name, const sensors_chip_name *chip, const sensors_feature *feature) : DriverCounter(next, name), chip(chip), feature(feature), duplicate(false) {
	label = sensors_get_label(chip, feature);

	switch (feature->type) {
	case SENSORS_FEATURE_IN:
		title = "Voltage";
		display = "maximum";
		counter_class = "absolute";
		unit = "V";
		modifier = 1000;
		monotonic = false;
		break;
	case SENSORS_FEATURE_FAN:
		title = "Fan";
		display = "average";
		counter_class = "absolute";
		unit = "RPM";
		modifier = 1;
		monotonic = false;
		break;
	case SENSORS_FEATURE_TEMP:
		title = "Temperature";
		display = "maximum";
		counter_class = "absolute";
		unit = "°C";
		modifier = 1000;
		monotonic = false;
		break;
	case SENSORS_FEATURE_POWER:
		title = "Power";
		display = "maximum";
		counter_class = "absolute";
		unit = "W";
		modifier = 1000000;
		monotonic = false;
		break;
	case SENSORS_FEATURE_ENERGY:
		title = "Energy";
		display = "accumulate";
		counter_class = "delta";
		unit = "J";
		modifier = 1000000;
		monotonic = true;
		break;
	case SENSORS_FEATURE_CURR:
		title = "Current";
		display = "maximum";
		counter_class = "absolute";
		unit = "A";
		modifier = 1000;
		monotonic = false;
		break;
	case SENSORS_FEATURE_HUMIDITY:
		title = "Humidity";
		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 = static_cast<HwmonCounter *>(next); counter != NULL; counter = static_cast<HwmonCounter *>(counter->getNext())) {
		if (strcmp(label, counter->getLabel()) == 0 && strcmp(title, counter->getTitle()) == 0) {
			duplicate = true;
			counter->duplicate = true;
			break;
		}
	}
}
Exemplo n.º 8
0
void HwmonDriver::writeEvents(mxml_node_t *root) const {
	root = mxmlNewElement(root, "category");
	mxmlElementSetAttr(root, "name", "hwmon");

	char buf[1024];
	for (HwmonCounter *counter = static_cast<HwmonCounter *>(getCounters()); counter != NULL; counter = static_cast<HwmonCounter *>(counter->getNext())) {
		mxml_node_t *node = mxmlNewElement(root, "event");
		mxmlElementSetAttr(node, "counter", counter->getName());
		mxmlElementSetAttr(node, "title", counter->getTitle());
		if (counter->isDuplicate()) {
			mxmlElementSetAttrf(node, "name", "%s (0x%x)", counter->getLabel(), counter->getKey());
		} else {
			mxmlElementSetAttr(node, "name", counter->getLabel());
		}
		mxmlElementSetAttr(node, "display", counter->getDisplay());
		mxmlElementSetAttr(node, "class", counter->getCounterClass());
		mxmlElementSetAttr(node, "units", counter->getUnit());
		if (counter->getModifier() != 1) {
			mxmlElementSetAttrf(node, "modifier", "%d", counter->getModifier());
		}
		if (strcmp(counter->getDisplay(), "average") == 0 || strcmp(counter->getDisplay(), "maximum") == 0) {
			mxmlElementSetAttr(node, "average_selection", "yes");
		}
		snprintf(buf, sizeof(buf), "libsensors %s sensor %s (%s)", counter->getTitle(), counter->getLabel(), counter->getName());
		mxmlElementSetAttr(node, "description", buf);
	}
}
Exemplo n.º 9
0
HwmonCounter::HwmonCounter(DriverCounter *next, char *const name, const sensors_chip_name *const chip, const sensors_feature *feature) : DriverCounter(next, name), mChip(chip), mFeature(feature), mDuplicate(false) {
    mLabel = sensors_get_label(mChip, mFeature);

    switch (mFeature->type) {
    case SENSORS_FEATURE_IN:
        mTitle = "Voltage";
        mDisplay = "maximum";
        mCounterClass = "absolute";
        mUnit = "V";
        mMultiplier = 0.001;
        mMonotonic = false;
        break;
    case SENSORS_FEATURE_FAN:
        mTitle = "Fan";
        mDisplay = "average";
        mCounterClass = "absolute";
        mUnit = "RPM";
        mMultiplier = 1.0;
        mMonotonic = false;
        break;
    case SENSORS_FEATURE_TEMP:
        mTitle = "Temperature";
        mDisplay = "maximum";
        mCounterClass = "absolute";
        mUnit = "°C";
        mMultiplier = 0.001;
        mMonotonic = false;
        break;
    case SENSORS_FEATURE_POWER:
        mTitle = "Power";
        mDisplay = "maximum";
        mCounterClass = "absolute";
        mUnit = "W";
        mMultiplier = 0.000001;
        mMonotonic = false;
        break;
    case SENSORS_FEATURE_ENERGY:
        mTitle = "Energy";
        mDisplay = "accumulate";
        mCounterClass = "delta";
        mUnit = "J";
        mMultiplier = 0.000001;
        mMonotonic = true;
        break;
    case SENSORS_FEATURE_CURR:
        mTitle = "Current";
        mDisplay = "maximum";
        mCounterClass = "absolute";
        mUnit = "A";
        mMultiplier = 0.001;
        mMonotonic = false;
        break;
    case SENSORS_FEATURE_HUMIDITY:
        mTitle = "Humidity";
        mDisplay = "average";
        mCounterClass = "absolute";
        mUnit = "%";
        mMultiplier = 0.001;
        mMonotonic = false;
        break;
    default:
        logg.logError("Unsupported hwmon feature %i", mFeature->type);
        handleException();
    }

    for (HwmonCounter * counter = static_cast<HwmonCounter *>(next); counter != NULL; counter = static_cast<HwmonCounter *>(counter->getNext())) {
        if (strcmp(mLabel, counter->getLabel()) == 0 && strcmp(mTitle, counter->getTitle()) == 0) {
            mDuplicate = true;
            counter->mDuplicate = true;
            break;
        }
    }
}
Exemplo 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;
		}
	}
}
Exemplo n.º 11
0
void Hwmon::resetCounters() {
	for (HwmonCounter * counter = counters; counter != NULL; counter = counter->getNext()) {
		counter->setEnabled(false);
	}
}