1998-12-23 00:25:53 +00:00
|
|
|
/*
|
|
|
|
chips.c - Part of sensors, a user-space program for hardware monitoring
|
2007-09-29 19:08:30 +00:00
|
|
|
Copyright (C) 1998-2003 Frodo Looijaard <frodol@dds.nl> and
|
|
|
|
Mark D. Studebaker <mdsxyz123@yahoo.com>
|
2010-11-03 13:01:38 +00:00
|
|
|
Copyright (C) 2007-2010 Jean Delvare <khali@linux-fr.org>
|
1998-12-23 00:25:53 +00:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2008-03-26 13:37:12 +00:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
MA 02110-1301 USA.
|
1998-12-23 00:25:53 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2002-06-30 20:28:08 +00:00
|
|
|
#include <string.h>
|
2008-04-17 01:30:37 +00:00
|
|
|
#include <math.h>
|
1998-12-23 00:25:53 +00:00
|
|
|
|
2007-08-26 13:24:46 +00:00
|
|
|
#include "main.h"
|
1998-12-23 00:25:53 +00:00
|
|
|
#include "chips.h"
|
|
|
|
#include "lib/sensors.h"
|
2007-09-19 16:53:16 +00:00
|
|
|
#include "lib/error.h"
|
1998-12-23 00:25:53 +00:00
|
|
|
|
2007-08-23 07:45:58 +00:00
|
|
|
void print_chip_raw(const sensors_chip_name *name)
|
1999-05-01 15:03:14 +00:00
|
|
|
{
|
2007-09-29 18:11:38 +00:00
|
|
|
int a, b, err;
|
2007-09-23 12:05:16 +00:00
|
|
|
const sensors_feature *feature;
|
|
|
|
const sensors_subfeature *sub;
|
2007-08-26 10:57:16 +00:00
|
|
|
char *label;
|
|
|
|
double val;
|
1999-05-01 15:03:14 +00:00
|
|
|
|
2007-08-26 10:57:16 +00:00
|
|
|
a = 0;
|
2007-09-23 12:00:59 +00:00
|
|
|
while ((feature = sensors_get_features(name, &a))) {
|
2007-09-23 12:05:16 +00:00
|
|
|
if (!(label = sensors_get_label(name, feature))) {
|
2007-09-29 18:11:38 +00:00
|
|
|
fprintf(stderr, "ERROR: Can't get label of feature "
|
|
|
|
"%s!\n", feature->name);
|
2007-09-23 12:05:16 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
printf("%s:\n", label);
|
|
|
|
free(label);
|
|
|
|
|
2007-09-23 12:00:59 +00:00
|
|
|
b = 0;
|
2007-09-23 12:05:16 +00:00
|
|
|
while ((sub = sensors_get_all_subfeatures(name, feature, &b))) {
|
2007-09-23 12:00:59 +00:00
|
|
|
if (sub->flags & SENSORS_MODE_R) {
|
2007-09-29 18:11:38 +00:00
|
|
|
if ((err = sensors_get_value(name, sub->number,
|
|
|
|
&val)))
|
2007-09-29 14:31:07 +00:00
|
|
|
fprintf(stderr, "ERROR: Can't get "
|
2007-09-29 18:11:38 +00:00
|
|
|
"value of subfeature %s: %s\n",
|
|
|
|
sub->name,
|
|
|
|
sensors_strerror(err));
|
2007-09-23 12:00:59 +00:00
|
|
|
else
|
2010-11-03 11:59:55 +00:00
|
|
|
printf(" %s: %.3f\n", sub->name, val);
|
2007-09-23 12:00:59 +00:00
|
|
|
} else
|
|
|
|
printf("(%s)\n", label);
|
2007-08-26 10:57:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-08-26 12:19:07 +00:00
|
|
|
|
2007-08-26 20:55:36 +00:00
|
|
|
static inline double deg_ctof(double cel)
|
|
|
|
{
|
|
|
|
return cel * (9.0F / 5.0F) + 32.0F;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void print_label(const char *label, int space)
|
|
|
|
{
|
|
|
|
int len = strlen(label)+1;
|
|
|
|
printf("%s:%*s", label, space - len, "");
|
|
|
|
}
|
|
|
|
|
2007-09-29 18:11:38 +00:00
|
|
|
static double get_value(const sensors_chip_name *name,
|
|
|
|
const sensors_subfeature *sub)
|
2007-08-26 12:19:07 +00:00
|
|
|
{
|
2007-09-23 12:30:28 +00:00
|
|
|
double val;
|
|
|
|
int err;
|
2007-08-26 12:19:07 +00:00
|
|
|
|
2007-09-29 18:11:38 +00:00
|
|
|
err = sensors_get_value(name, sub->number, &val);
|
2007-09-23 12:30:28 +00:00
|
|
|
if (err) {
|
2007-09-29 18:11:38 +00:00
|
|
|
fprintf(stderr, "ERROR: Can't get value of subfeature %s: %s\n",
|
|
|
|
sub->name, sensors_strerror(err));
|
2007-09-23 12:30:28 +00:00
|
|
|
val = 0;
|
2007-08-26 12:19:07 +00:00
|
|
|
}
|
2007-09-23 12:30:28 +00:00
|
|
|
return val;
|
2007-08-26 12:19:07 +00:00
|
|
|
}
|
|
|
|
|
2010-05-23 09:04:13 +00:00
|
|
|
/* A variant for input values, where we want to handle errors gracefully */
|
|
|
|
static int get_input_value(const sensors_chip_name *name,
|
|
|
|
const sensors_subfeature *sub,
|
|
|
|
double *val)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = sensors_get_value(name, sub->number, val);
|
|
|
|
if (err && err != -SENSORS_ERR_ACCESS_R) {
|
|
|
|
fprintf(stderr, "ERROR: Can't get value of subfeature %s: %s\n",
|
|
|
|
sub->name, sensors_strerror(err));
|
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2007-09-23 12:33:12 +00:00
|
|
|
static int get_label_size(const sensors_chip_name *name)
|
2007-08-26 12:19:07 +00:00
|
|
|
{
|
|
|
|
int i;
|
2007-09-23 12:05:16 +00:00
|
|
|
const sensors_feature *iter;
|
2007-08-26 12:19:07 +00:00
|
|
|
char *label;
|
|
|
|
unsigned int max_size = 11; /* 11 as minumum label width */
|
|
|
|
|
|
|
|
i = 0;
|
2007-09-23 12:00:59 +00:00
|
|
|
while ((iter = sensors_get_features(name, &i))) {
|
2007-09-23 12:05:16 +00:00
|
|
|
if ((label = sensors_get_label(name, iter)) &&
|
2007-08-26 12:19:07 +00:00
|
|
|
strlen(label) > max_size)
|
|
|
|
max_size = strlen(label);
|
|
|
|
free(label);
|
|
|
|
}
|
2010-11-02 12:37:35 +00:00
|
|
|
|
|
|
|
/* One more for the colon, and one more to guarantee at least one
|
|
|
|
space between that colon and the value */
|
|
|
|
return max_size + 2;
|
2007-08-26 12:19:07 +00:00
|
|
|
}
|
|
|
|
|
2007-08-26 20:41:03 +00:00
|
|
|
static void print_temp_limits(double limit1, double limit2,
|
2007-08-26 20:37:15 +00:00
|
|
|
const char *name1, const char *name2, int alarm)
|
|
|
|
{
|
|
|
|
if (fahrenheit) {
|
|
|
|
limit1 = deg_ctof(limit1);
|
|
|
|
limit2 = deg_ctof(limit2);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (name2) {
|
|
|
|
printf("(%-4s = %+5.1f%s, %-4s = %+5.1f%s) ",
|
|
|
|
name1, limit1, degstr,
|
|
|
|
name2, limit2, degstr);
|
|
|
|
} else if (name1) {
|
|
|
|
printf("(%-4s = %+5.1f%s) ",
|
|
|
|
name1, limit1, degstr);
|
|
|
|
} else {
|
|
|
|
printf(" ");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (alarm)
|
|
|
|
printf("ALARM ");
|
|
|
|
}
|
|
|
|
|
2007-08-26 21:26:20 +00:00
|
|
|
static void print_chip_temp(const sensors_chip_name *name,
|
2007-09-23 12:05:16 +00:00
|
|
|
const sensors_feature *feature,
|
2007-08-26 21:26:20 +00:00
|
|
|
int label_size)
|
2007-08-26 12:19:07 +00:00
|
|
|
{
|
2007-09-23 12:30:28 +00:00
|
|
|
const sensors_subfeature *sf, *sfmin, *sfmax, *sfcrit, *sfhyst;
|
2007-08-26 20:37:15 +00:00
|
|
|
double val, limit1, limit2;
|
|
|
|
const char *s1, *s2;
|
|
|
|
int alarm, crit_displayed = 0;
|
2007-08-26 12:19:07 +00:00
|
|
|
char *label;
|
|
|
|
|
2007-09-23 12:05:16 +00:00
|
|
|
if (!(label = sensors_get_label(name, feature))) {
|
2007-09-29 18:11:38 +00:00
|
|
|
fprintf(stderr, "ERROR: Can't get label of feature %s!\n",
|
|
|
|
feature->name);
|
2007-08-26 12:19:07 +00:00
|
|
|
return;
|
|
|
|
}
|
2007-09-23 12:30:28 +00:00
|
|
|
print_label(label, label_size);
|
|
|
|
free(label);
|
2007-08-26 12:19:07 +00:00
|
|
|
|
2007-09-23 12:30:28 +00:00
|
|
|
sf = sensors_get_subfeature(name, feature,
|
|
|
|
SENSORS_SUBFEATURE_TEMP_ALARM);
|
2007-09-29 18:11:38 +00:00
|
|
|
alarm = sf && get_value(name, sf);
|
2007-09-23 12:30:28 +00:00
|
|
|
|
|
|
|
sfmin = sensors_get_subfeature(name, feature,
|
|
|
|
SENSORS_SUBFEATURE_TEMP_MIN);
|
|
|
|
sfmax = sensors_get_subfeature(name, feature,
|
|
|
|
SENSORS_SUBFEATURE_TEMP_MAX);
|
|
|
|
sfcrit = sensors_get_subfeature(name, feature,
|
|
|
|
SENSORS_SUBFEATURE_TEMP_CRIT);
|
|
|
|
if (sfmax) {
|
|
|
|
sf = sensors_get_subfeature(name, feature,
|
|
|
|
SENSORS_SUBFEATURE_TEMP_MAX_ALARM);
|
2007-09-29 18:11:38 +00:00
|
|
|
if (sf && get_value(name, sf))
|
2007-08-26 20:37:15 +00:00
|
|
|
alarm |= 1;
|
|
|
|
|
2007-09-23 12:30:28 +00:00
|
|
|
if (sfmin) {
|
2007-09-29 18:11:38 +00:00
|
|
|
limit1 = get_value(name, sfmin);
|
2007-08-26 20:37:15 +00:00
|
|
|
s1 = "low";
|
2007-09-29 18:11:38 +00:00
|
|
|
limit2 = get_value(name, sfmax);
|
2007-08-26 20:37:15 +00:00
|
|
|
s2 = "high";
|
|
|
|
|
2007-09-23 12:30:28 +00:00
|
|
|
sf = sensors_get_subfeature(name, feature,
|
|
|
|
SENSORS_SUBFEATURE_TEMP_MIN_ALARM);
|
2007-09-29 18:11:38 +00:00
|
|
|
if (sf && get_value(name, sf))
|
2007-08-26 20:37:15 +00:00
|
|
|
alarm |= 1;
|
2007-08-26 12:19:07 +00:00
|
|
|
} else {
|
2007-09-29 18:11:38 +00:00
|
|
|
limit1 = get_value(name, sfmax);
|
2007-08-26 20:37:15 +00:00
|
|
|
s1 = "high";
|
|
|
|
|
2007-09-23 12:30:28 +00:00
|
|
|
sfhyst = sensors_get_subfeature(name, feature,
|
|
|
|
SENSORS_SUBFEATURE_TEMP_MAX_HYST);
|
|
|
|
if (sfhyst) {
|
2007-09-29 18:11:38 +00:00
|
|
|
limit2 = get_value(name, sfhyst);
|
2007-08-26 20:37:15 +00:00
|
|
|
s2 = "hyst";
|
2007-09-23 12:30:28 +00:00
|
|
|
} else if (sfcrit) {
|
2007-09-29 18:11:38 +00:00
|
|
|
limit2 = get_value(name, sfcrit);
|
2007-08-26 20:37:15 +00:00
|
|
|
s2 = "crit";
|
|
|
|
|
2007-09-23 12:30:28 +00:00
|
|
|
sf = sensors_get_subfeature(name, feature,
|
|
|
|
SENSORS_SUBFEATURE_TEMP_CRIT_ALARM);
|
2007-09-29 18:11:38 +00:00
|
|
|
if (sf && get_value(name, sf))
|
2007-08-26 20:37:15 +00:00
|
|
|
alarm |= 1;
|
|
|
|
crit_displayed = 1;
|
|
|
|
} else {
|
|
|
|
limit2 = 0;
|
|
|
|
s2 = NULL;
|
|
|
|
}
|
2007-08-26 12:19:07 +00:00
|
|
|
}
|
2007-09-23 12:30:28 +00:00
|
|
|
} else if (sfcrit) {
|
2007-09-29 18:11:38 +00:00
|
|
|
limit1 = get_value(name, sfcrit);
|
2007-09-08 10:47:03 +00:00
|
|
|
s1 = "crit";
|
|
|
|
|
2007-09-23 12:30:28 +00:00
|
|
|
sfhyst = sensors_get_subfeature(name, feature,
|
|
|
|
SENSORS_SUBFEATURE_TEMP_CRIT_HYST);
|
|
|
|
if (sfhyst) {
|
2007-09-29 18:11:38 +00:00
|
|
|
limit2 = get_value(name, sfhyst);
|
2007-09-08 10:47:03 +00:00
|
|
|
s2 = "hyst";
|
|
|
|
} else {
|
|
|
|
limit2 = 0;
|
|
|
|
s2 = NULL;
|
|
|
|
}
|
|
|
|
|
2007-09-23 12:30:28 +00:00
|
|
|
sf = sensors_get_subfeature(name, feature,
|
|
|
|
SENSORS_SUBFEATURE_TEMP_CRIT_ALARM);
|
2007-09-29 18:11:38 +00:00
|
|
|
if (sf && get_value(name, sf))
|
2007-09-08 10:47:03 +00:00
|
|
|
alarm |= 1;
|
|
|
|
crit_displayed = 1;
|
2007-08-26 12:19:07 +00:00
|
|
|
} else {
|
2007-08-26 20:37:15 +00:00
|
|
|
limit1 = limit2 = 0;
|
|
|
|
s1 = s2 = NULL;
|
2007-08-26 12:19:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-23 12:30:28 +00:00
|
|
|
sf = sensors_get_subfeature(name, feature,
|
|
|
|
SENSORS_SUBFEATURE_TEMP_FAULT);
|
2007-09-29 18:11:38 +00:00
|
|
|
if (sf && get_value(name, sf)) {
|
2007-08-26 20:36:46 +00:00
|
|
|
printf(" FAULT ");
|
|
|
|
} else {
|
2007-09-30 17:56:19 +00:00
|
|
|
sf = sensors_get_subfeature(name, feature,
|
|
|
|
SENSORS_SUBFEATURE_TEMP_INPUT);
|
2010-05-23 09:04:13 +00:00
|
|
|
if (sf && get_input_value(name, sf, &val) == 0) {
|
|
|
|
get_input_value(name, sf, &val);
|
2007-09-30 17:56:19 +00:00
|
|
|
if (fahrenheit)
|
|
|
|
val = deg_ctof(val);
|
|
|
|
printf("%+6.1f%s ", val, degstr);
|
|
|
|
} else
|
|
|
|
printf(" N/A ");
|
2007-08-26 20:36:46 +00:00
|
|
|
}
|
2007-08-26 20:37:15 +00:00
|
|
|
print_temp_limits(limit1, limit2, s1, s2, alarm);
|
2007-08-26 12:19:07 +00:00
|
|
|
|
2007-09-23 12:30:28 +00:00
|
|
|
if (!crit_displayed && sfcrit) {
|
2007-09-29 18:11:38 +00:00
|
|
|
limit1 = get_value(name, sfcrit);
|
2007-08-26 20:37:15 +00:00
|
|
|
s1 = "crit";
|
2007-08-26 12:19:07 +00:00
|
|
|
|
2007-09-23 12:30:28 +00:00
|
|
|
sfhyst = sensors_get_subfeature(name, feature,
|
|
|
|
SENSORS_SUBFEATURE_TEMP_CRIT_HYST);
|
|
|
|
if (sfhyst) {
|
2007-09-29 18:11:38 +00:00
|
|
|
limit2 = get_value(name, sfhyst);
|
2007-08-26 20:37:15 +00:00
|
|
|
s2 = "hyst";
|
|
|
|
} else {
|
|
|
|
limit2 = 0;
|
|
|
|
s2 = NULL;
|
2007-08-26 12:19:07 +00:00
|
|
|
}
|
2007-08-26 20:37:15 +00:00
|
|
|
|
2007-09-23 12:30:28 +00:00
|
|
|
sf = sensors_get_subfeature(name, feature,
|
|
|
|
SENSORS_SUBFEATURE_TEMP_CRIT_ALARM);
|
2007-09-29 18:11:38 +00:00
|
|
|
alarm = sf && get_value(name, sf);
|
2007-08-26 20:37:15 +00:00
|
|
|
|
|
|
|
printf("\n%*s", label_size + 10, "");
|
|
|
|
print_temp_limits(limit1, limit2, s1, s2, alarm);
|
2007-08-26 12:19:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* print out temperature sensor info */
|
2007-09-23 12:30:28 +00:00
|
|
|
sf = sensors_get_subfeature(name, feature,
|
|
|
|
SENSORS_SUBFEATURE_TEMP_TYPE);
|
|
|
|
if (sf) {
|
2007-09-29 18:11:38 +00:00
|
|
|
int sens = (int)get_value(name, sf);
|
2007-08-26 12:19:07 +00:00
|
|
|
|
|
|
|
/* older kernels / drivers sometimes report a beta value for
|
|
|
|
thermistors */
|
|
|
|
if (sens > 1000)
|
|
|
|
sens = 4;
|
|
|
|
|
|
|
|
printf("sensor = %s", sens == 0 ? "disabled" :
|
|
|
|
sens == 1 ? "diode" :
|
|
|
|
sens == 2 ? "transistor" :
|
|
|
|
sens == 3 ? "thermal diode" :
|
|
|
|
sens == 4 ? "thermistor" :
|
|
|
|
sens == 5 ? "AMD AMDSI" :
|
|
|
|
sens == 6 ? "Intel PECI" : "unknown");
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
2007-08-26 21:26:20 +00:00
|
|
|
static void print_chip_in(const sensors_chip_name *name,
|
2007-09-23 12:05:16 +00:00
|
|
|
const sensors_feature *feature,
|
2007-08-26 21:26:20 +00:00
|
|
|
int label_size)
|
2007-08-26 12:19:07 +00:00
|
|
|
{
|
2007-09-23 12:30:28 +00:00
|
|
|
const sensors_subfeature *sf, *sfmin, *sfmax;
|
2010-05-23 09:04:13 +00:00
|
|
|
double val, alarm_max, alarm_min;
|
2007-08-26 12:19:07 +00:00
|
|
|
char *label;
|
|
|
|
|
2007-09-23 12:05:16 +00:00
|
|
|
if (!(label = sensors_get_label(name, feature))) {
|
2007-09-29 18:11:38 +00:00
|
|
|
fprintf(stderr, "ERROR: Can't get label of feature %s!\n",
|
|
|
|
feature->name);
|
2007-08-26 12:19:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
print_label(label, label_size);
|
|
|
|
free(label);
|
2007-09-23 12:30:28 +00:00
|
|
|
|
|
|
|
sf = sensors_get_subfeature(name, feature,
|
|
|
|
SENSORS_SUBFEATURE_IN_INPUT);
|
2010-05-23 09:04:13 +00:00
|
|
|
if (sf && get_input_value(name, sf, &val) == 0)
|
|
|
|
printf("%+6.2f V", val);
|
2007-10-22 18:27:04 +00:00
|
|
|
else
|
|
|
|
printf(" N/A");
|
2007-08-26 12:19:07 +00:00
|
|
|
|
2007-09-23 12:30:28 +00:00
|
|
|
sfmin = sensors_get_subfeature(name, feature,
|
|
|
|
SENSORS_SUBFEATURE_IN_MIN);
|
|
|
|
sfmax = sensors_get_subfeature(name, feature,
|
|
|
|
SENSORS_SUBFEATURE_IN_MAX);
|
|
|
|
if (sfmin && sfmax)
|
2007-08-26 12:19:07 +00:00
|
|
|
printf(" (min = %+6.2f V, max = %+6.2f V)",
|
2007-09-29 18:11:38 +00:00
|
|
|
get_value(name, sfmin),
|
|
|
|
get_value(name, sfmax));
|
2007-09-23 12:30:28 +00:00
|
|
|
else if (sfmin)
|
2007-08-26 12:19:07 +00:00
|
|
|
printf(" (min = %+6.2f V)",
|
2007-09-29 18:11:38 +00:00
|
|
|
get_value(name, sfmin));
|
2007-09-23 12:30:28 +00:00
|
|
|
else if (sfmax)
|
2007-08-26 12:19:07 +00:00
|
|
|
printf(" (max = %+6.2f V)",
|
2007-09-29 18:11:38 +00:00
|
|
|
get_value(name, sfmax));
|
2007-09-23 12:30:28 +00:00
|
|
|
|
|
|
|
sf = sensors_get_subfeature(name, feature,
|
|
|
|
SENSORS_SUBFEATURE_IN_ALARM);
|
|
|
|
sfmin = sensors_get_subfeature(name, feature,
|
|
|
|
SENSORS_SUBFEATURE_IN_MIN_ALARM);
|
|
|
|
sfmax = sensors_get_subfeature(name, feature,
|
|
|
|
SENSORS_SUBFEATURE_IN_MAX_ALARM);
|
|
|
|
if (sfmin || sfmax) {
|
2007-09-29 18:11:38 +00:00
|
|
|
alarm_max = sfmax ? get_value(name, sfmax) : 0;
|
|
|
|
alarm_min = sfmin ? get_value(name, sfmin) : 0;
|
2007-08-26 12:19:07 +00:00
|
|
|
|
|
|
|
if (alarm_min || alarm_max) {
|
|
|
|
printf(" ALARM (");
|
|
|
|
|
|
|
|
if (alarm_min)
|
|
|
|
printf("MIN");
|
|
|
|
if (alarm_max)
|
|
|
|
printf("%sMAX", (alarm_min) ? ", " : "");
|
|
|
|
|
|
|
|
printf(")");
|
|
|
|
}
|
2007-09-23 12:30:28 +00:00
|
|
|
} else if (sf) {
|
2007-08-26 12:19:07 +00:00
|
|
|
printf(" %s",
|
2007-09-29 18:11:38 +00:00
|
|
|
get_value(name, sf) ? "ALARM" : "");
|
2007-08-26 12:19:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
2007-08-26 21:26:20 +00:00
|
|
|
static void print_chip_fan(const sensors_chip_name *name,
|
2007-09-23 12:05:16 +00:00
|
|
|
const sensors_feature *feature,
|
2007-08-26 21:26:20 +00:00
|
|
|
int label_size)
|
2007-08-26 12:19:07 +00:00
|
|
|
{
|
2007-09-23 12:30:28 +00:00
|
|
|
const sensors_subfeature *sf, *sfmin, *sfdiv;
|
2010-05-23 09:04:13 +00:00
|
|
|
double val;
|
2007-08-26 12:19:07 +00:00
|
|
|
char *label;
|
|
|
|
|
2007-09-23 12:05:16 +00:00
|
|
|
if (!(label = sensors_get_label(name, feature))) {
|
2007-09-29 18:11:38 +00:00
|
|
|
fprintf(stderr, "ERROR: Can't get label of feature %s!\n",
|
|
|
|
feature->name);
|
2007-08-26 12:19:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
print_label(label, label_size);
|
|
|
|
free(label);
|
|
|
|
|
2007-09-23 12:30:28 +00:00
|
|
|
sf = sensors_get_subfeature(name, feature,
|
|
|
|
SENSORS_SUBFEATURE_FAN_FAULT);
|
2007-09-29 18:11:38 +00:00
|
|
|
if (sf && get_value(name, sf))
|
2007-08-26 12:19:07 +00:00
|
|
|
printf(" FAULT");
|
2007-09-30 17:56:19 +00:00
|
|
|
else {
|
|
|
|
sf = sensors_get_subfeature(name, feature,
|
|
|
|
SENSORS_SUBFEATURE_FAN_INPUT);
|
2010-05-23 09:04:13 +00:00
|
|
|
if (sf && get_input_value(name, sf, &val) == 0)
|
|
|
|
printf("%4.0f RPM", val);
|
2007-09-30 17:56:19 +00:00
|
|
|
else
|
|
|
|
printf(" N/A");
|
|
|
|
}
|
2007-08-26 12:19:07 +00:00
|
|
|
|
2007-09-23 12:30:28 +00:00
|
|
|
sfmin = sensors_get_subfeature(name, feature,
|
|
|
|
SENSORS_SUBFEATURE_FAN_MIN);
|
|
|
|
sfdiv = sensors_get_subfeature(name, feature,
|
|
|
|
SENSORS_SUBFEATURE_FAN_DIV);
|
|
|
|
if (sfmin && sfdiv)
|
2007-08-26 12:19:07 +00:00
|
|
|
printf(" (min = %4.0f RPM, div = %1.0f)",
|
2007-09-29 18:11:38 +00:00
|
|
|
get_value(name, sfmin),
|
|
|
|
get_value(name, sfdiv));
|
2007-09-23 12:30:28 +00:00
|
|
|
else if (sfmin)
|
2007-08-26 12:19:07 +00:00
|
|
|
printf(" (min = %4.0f RPM)",
|
2007-09-29 18:11:38 +00:00
|
|
|
get_value(name, sfmin));
|
2007-09-23 12:30:28 +00:00
|
|
|
else if (sfdiv)
|
2007-08-26 12:19:07 +00:00
|
|
|
printf(" (div = %1.0f)",
|
2007-09-29 18:11:38 +00:00
|
|
|
get_value(name, sfdiv));
|
2007-08-26 12:19:07 +00:00
|
|
|
|
2007-09-23 12:30:28 +00:00
|
|
|
sf = sensors_get_subfeature(name, feature,
|
|
|
|
SENSORS_SUBFEATURE_FAN_ALARM);
|
2007-09-29 18:11:38 +00:00
|
|
|
if (sf && get_value(name, sf)) {
|
2007-08-26 12:19:07 +00:00
|
|
|
printf(" ALARM");
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
2008-04-17 01:30:37 +00:00
|
|
|
struct scale_table {
|
|
|
|
double upper_bound;
|
|
|
|
const char *unit;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void scale_value(double *value, const char **prefixstr)
|
|
|
|
{
|
|
|
|
double abs_value = fabs(*value);
|
|
|
|
double divisor = 1e-9;
|
|
|
|
static struct scale_table prefix_scales[] = {
|
|
|
|
{1e-6, "n"},
|
|
|
|
{1e-3, "u"},
|
|
|
|
{1, "m"},
|
|
|
|
{1e3, ""},
|
|
|
|
{1e6, "k"},
|
|
|
|
{1e9, "M"},
|
|
|
|
{0, "G"}, /* no upper bound */
|
|
|
|
};
|
|
|
|
struct scale_table *scale = prefix_scales;
|
|
|
|
|
|
|
|
while (scale->upper_bound && abs_value > scale->upper_bound) {
|
|
|
|
divisor = scale->upper_bound;
|
|
|
|
scale++;
|
|
|
|
}
|
|
|
|
|
|
|
|
*value /= divisor;
|
|
|
|
*prefixstr = scale->unit;
|
|
|
|
}
|
|
|
|
|
2008-04-17 01:28:51 +00:00
|
|
|
static void print_chip_power(const sensors_chip_name *name,
|
|
|
|
const sensors_feature *feature,
|
|
|
|
int label_size)
|
|
|
|
{
|
2008-04-17 01:30:37 +00:00
|
|
|
double val;
|
2008-04-17 01:28:51 +00:00
|
|
|
int need_space = 0;
|
|
|
|
const sensors_subfeature *sf, *sfmin, *sfmax, *sfint;
|
|
|
|
char *label;
|
2008-04-17 01:30:37 +00:00
|
|
|
const char *unit;
|
2008-04-17 01:28:51 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2008-10-24 09:03:18 +00:00
|
|
|
/* Power sensors come in 2 flavors: instantaneous and averaged.
|
|
|
|
To keep things simple, we assume that each sensor only implements
|
|
|
|
one flavor. */
|
2008-04-17 01:28:51 +00:00
|
|
|
sf = sensors_get_subfeature(name, feature,
|
2008-10-24 09:03:18 +00:00
|
|
|
SENSORS_SUBFEATURE_POWER_INPUT);
|
|
|
|
if (sf) {
|
|
|
|
sfmin = sensors_get_subfeature(name, feature,
|
|
|
|
SENSORS_SUBFEATURE_POWER_INPUT_HIGHEST);
|
|
|
|
sfmax = sensors_get_subfeature(name, feature,
|
|
|
|
SENSORS_SUBFEATURE_POWER_INPUT_LOWEST);
|
|
|
|
sfint = NULL;
|
|
|
|
} else {
|
|
|
|
sf = sensors_get_subfeature(name, feature,
|
|
|
|
SENSORS_SUBFEATURE_POWER_AVERAGE);
|
|
|
|
sfmin = sensors_get_subfeature(name, feature,
|
|
|
|
SENSORS_SUBFEATURE_POWER_AVERAGE_HIGHEST);
|
|
|
|
sfmax = sensors_get_subfeature(name, feature,
|
|
|
|
SENSORS_SUBFEATURE_POWER_AVERAGE_LOWEST);
|
|
|
|
sfint = sensors_get_subfeature(name, feature,
|
|
|
|
SENSORS_SUBFEATURE_POWER_AVERAGE_INTERVAL);
|
|
|
|
}
|
|
|
|
|
2010-05-23 09:04:13 +00:00
|
|
|
if (sf && get_input_value(name, sf, &val) == 0) {
|
2008-04-17 01:30:37 +00:00
|
|
|
scale_value(&val, &unit);
|
|
|
|
printf("%6.2f %sW", val, unit);
|
|
|
|
} else
|
2008-04-17 01:28:51 +00:00
|
|
|
printf(" N/A");
|
|
|
|
|
|
|
|
if (sfmin || sfmax || sfint) {
|
|
|
|
printf(" (");
|
|
|
|
|
|
|
|
if (sfmin) {
|
2008-04-17 01:30:37 +00:00
|
|
|
val = get_value(name, sfmin);
|
|
|
|
scale_value(&val, &unit);
|
|
|
|
printf("min = %6.2f %sW", val, unit);
|
2008-04-17 01:28:51 +00:00
|
|
|
need_space = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sfmax) {
|
2008-04-17 01:30:37 +00:00
|
|
|
val = get_value(name, sfmax);
|
|
|
|
scale_value(&val, &unit);
|
|
|
|
printf("%smax = %6.2f %sW", (need_space ? ", " : ""),
|
|
|
|
val, unit);
|
2008-04-17 01:28:51 +00:00
|
|
|
need_space = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sfint) {
|
|
|
|
printf("%sinterval = %6.2f s", (need_space ? ", " : ""),
|
|
|
|
get_value(name, sfint));
|
|
|
|
need_space = 1;
|
|
|
|
}
|
|
|
|
printf(")");
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void print_chip_energy(const sensors_chip_name *name,
|
|
|
|
const sensors_feature *feature,
|
|
|
|
int label_size)
|
|
|
|
{
|
2008-04-17 01:30:37 +00:00
|
|
|
double val;
|
2008-04-17 01:28:51 +00:00
|
|
|
const sensors_subfeature *sf;
|
|
|
|
char *label;
|
2008-04-17 01:30:37 +00:00
|
|
|
const char *unit;
|
2008-04-17 01:28:51 +00:00
|
|
|
|
|
|
|
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);
|
2010-05-23 09:04:13 +00:00
|
|
|
if (sf && get_input_value(name, sf, &val) == 0) {
|
2008-04-17 01:30:37 +00:00
|
|
|
scale_value(&val, &unit);
|
|
|
|
printf("%6.2f %sJ", val, unit);
|
|
|
|
} else
|
2008-04-17 01:28:51 +00:00
|
|
|
printf(" N/A");
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
2007-09-23 12:05:16 +00:00
|
|
|
static void print_chip_vid(const sensors_chip_name *name,
|
|
|
|
const sensors_feature *feature,
|
2007-08-26 21:26:20 +00:00
|
|
|
int label_size)
|
|
|
|
{
|
|
|
|
char *label;
|
2007-09-23 12:05:16 +00:00
|
|
|
const sensors_subfeature *subfeature;
|
2007-08-26 21:26:20 +00:00
|
|
|
double vid;
|
2007-09-23 12:05:16 +00:00
|
|
|
|
2007-09-23 12:30:28 +00:00
|
|
|
subfeature = sensors_get_subfeature(name, feature,
|
|
|
|
SENSORS_SUBFEATURE_VID);
|
2007-09-23 12:05:16 +00:00
|
|
|
if (!subfeature)
|
|
|
|
return;
|
2007-08-26 21:26:20 +00:00
|
|
|
|
2007-09-23 12:05:16 +00:00
|
|
|
if ((label = sensors_get_label(name, feature))
|
|
|
|
&& !sensors_get_value(name, subfeature->number, &vid)) {
|
2007-08-26 21:26:20 +00:00
|
|
|
print_label(label, label_size);
|
|
|
|
printf("%+6.3f V\n", vid);
|
|
|
|
}
|
|
|
|
free(label);
|
|
|
|
}
|
|
|
|
|
2007-09-23 12:05:16 +00:00
|
|
|
static void print_chip_beep_enable(const sensors_chip_name *name,
|
|
|
|
const sensors_feature *feature,
|
2007-09-05 12:28:31 +00:00
|
|
|
int label_size)
|
|
|
|
{
|
|
|
|
char *label;
|
2007-09-23 12:05:16 +00:00
|
|
|
const sensors_subfeature *subfeature;
|
2007-09-05 12:28:31 +00:00
|
|
|
double beep_enable;
|
2007-09-23 12:05:16 +00:00
|
|
|
|
2007-09-23 12:30:28 +00:00
|
|
|
subfeature = sensors_get_subfeature(name, feature,
|
|
|
|
SENSORS_SUBFEATURE_BEEP_ENABLE);
|
2007-09-23 12:05:16 +00:00
|
|
|
if (!subfeature)
|
|
|
|
return;
|
2007-09-05 12:28:31 +00:00
|
|
|
|
2007-09-23 12:05:16 +00:00
|
|
|
if ((label = sensors_get_label(name, feature))
|
|
|
|
&& !sensors_get_value(name, subfeature->number, &beep_enable)) {
|
2007-09-05 12:28:31 +00:00
|
|
|
print_label(label, label_size);
|
|
|
|
printf("%s\n", beep_enable ? "enabled" : "disabled");
|
|
|
|
}
|
|
|
|
free(label);
|
|
|
|
}
|
|
|
|
|
2008-10-24 09:04:26 +00:00
|
|
|
static void print_chip_curr(const sensors_chip_name *name,
|
|
|
|
const sensors_feature *feature,
|
|
|
|
int label_size)
|
|
|
|
{
|
|
|
|
const sensors_subfeature *sf, *sfmin, *sfmax;
|
2010-05-23 09:04:13 +00:00
|
|
|
double alarm_max, alarm_min, val;
|
2008-10-24 09:04:26 +00:00
|
|
|
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_CURR_INPUT);
|
2010-05-23 09:04:13 +00:00
|
|
|
if (sf && get_input_value(name, sf, &val) == 0)
|
|
|
|
printf("%+6.2f A", val);
|
2008-10-24 09:04:26 +00:00
|
|
|
else
|
|
|
|
printf(" N/A");
|
|
|
|
|
|
|
|
sfmin = sensors_get_subfeature(name, feature,
|
|
|
|
SENSORS_SUBFEATURE_CURR_MIN);
|
|
|
|
sfmax = sensors_get_subfeature(name, feature,
|
|
|
|
SENSORS_SUBFEATURE_CURR_MAX);
|
|
|
|
if (sfmin && sfmax)
|
|
|
|
printf(" (min = %+6.2f A, max = %+6.2f A)",
|
|
|
|
get_value(name, sfmin),
|
|
|
|
get_value(name, sfmax));
|
|
|
|
else if (sfmin)
|
|
|
|
printf(" (min = %+6.2f A)",
|
|
|
|
get_value(name, sfmin));
|
|
|
|
else if (sfmax)
|
|
|
|
printf(" (max = %+6.2f A)",
|
|
|
|
get_value(name, sfmax));
|
|
|
|
|
|
|
|
sf = sensors_get_subfeature(name, feature,
|
|
|
|
SENSORS_SUBFEATURE_CURR_ALARM);
|
|
|
|
sfmin = sensors_get_subfeature(name, feature,
|
|
|
|
SENSORS_SUBFEATURE_CURR_MIN_ALARM);
|
|
|
|
sfmax = sensors_get_subfeature(name, feature,
|
|
|
|
SENSORS_SUBFEATURE_CURR_MAX_ALARM);
|
|
|
|
if (sfmin || sfmax) {
|
|
|
|
alarm_max = sfmax ? get_value(name, sfmax) : 0;
|
|
|
|
alarm_min = sfmin ? get_value(name, sfmin) : 0;
|
|
|
|
|
|
|
|
if (alarm_min || alarm_max) {
|
|
|
|
printf(" ALARM (");
|
|
|
|
|
|
|
|
if (alarm_min)
|
|
|
|
printf("MIN");
|
|
|
|
if (alarm_max)
|
|
|
|
printf("%sMAX", (alarm_min) ? ", " : "");
|
|
|
|
|
|
|
|
printf(")");
|
|
|
|
}
|
|
|
|
} else if (sf) {
|
|
|
|
printf(" %s",
|
|
|
|
get_value(name, sf) ? "ALARM" : "");
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
2010-11-03 13:01:38 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2007-08-26 21:26:20 +00:00
|
|
|
void print_chip(const sensors_chip_name *name)
|
2007-08-26 12:19:07 +00:00
|
|
|
{
|
2007-09-23 12:05:16 +00:00
|
|
|
const sensors_feature *feature;
|
2007-08-26 12:19:07 +00:00
|
|
|
int i, label_size;
|
|
|
|
|
2007-09-23 12:33:12 +00:00
|
|
|
label_size = get_label_size(name);
|
2007-08-26 12:19:07 +00:00
|
|
|
|
|
|
|
i = 0;
|
2007-09-23 12:00:59 +00:00
|
|
|
while ((feature = sensors_get_features(name, &i))) {
|
2007-08-26 12:19:07 +00:00
|
|
|
switch (feature->type) {
|
2007-09-23 12:16:50 +00:00
|
|
|
case SENSORS_FEATURE_TEMP:
|
2007-09-23 12:00:59 +00:00
|
|
|
print_chip_temp(name, feature, label_size);
|
2007-08-26 12:19:07 +00:00
|
|
|
break;
|
2007-09-23 12:16:50 +00:00
|
|
|
case SENSORS_FEATURE_IN:
|
2007-09-23 12:00:59 +00:00
|
|
|
print_chip_in(name, feature, label_size);
|
2007-08-26 12:19:07 +00:00
|
|
|
break;
|
2007-09-23 12:16:50 +00:00
|
|
|
case SENSORS_FEATURE_FAN:
|
2007-09-23 12:00:59 +00:00
|
|
|
print_chip_fan(name, feature, label_size);
|
2007-08-26 12:19:07 +00:00
|
|
|
break;
|
2007-09-23 12:16:50 +00:00
|
|
|
case SENSORS_FEATURE_VID:
|
2007-09-23 12:05:16 +00:00
|
|
|
print_chip_vid(name, feature, label_size);
|
2007-08-26 12:19:07 +00:00
|
|
|
break;
|
2007-09-23 12:16:50 +00:00
|
|
|
case SENSORS_FEATURE_BEEP_ENABLE:
|
2007-09-23 12:05:16 +00:00
|
|
|
print_chip_beep_enable(name, feature, label_size);
|
2007-09-05 12:28:31 +00:00
|
|
|
break;
|
2008-04-17 01:28:51 +00:00
|
|
|
case SENSORS_FEATURE_POWER:
|
|
|
|
print_chip_power(name, feature, label_size);
|
|
|
|
break;
|
|
|
|
case SENSORS_FEATURE_ENERGY:
|
|
|
|
print_chip_energy(name, feature, label_size);
|
|
|
|
break;
|
2008-10-24 09:04:26 +00:00
|
|
|
case SENSORS_FEATURE_CURR:
|
|
|
|
print_chip_curr(name, feature, label_size);
|
|
|
|
break;
|
2010-11-03 13:01:38 +00:00
|
|
|
case SENSORS_FEATURE_INTRUSION:
|
|
|
|
print_chip_intrusion(name, feature, label_size);
|
|
|
|
break;
|
2007-08-26 12:19:07 +00:00
|
|
|
default:
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|