mirror of
https://github.com/lm-sensors/lm-sensors.git
synced 2026-10-18 11:09:32 +00:00
Define a separate structure to represent main features. This allows
for faster main features lookup. One side effect of this change is that subfeatures can no longer have labels nor be ignored. I do not think that this is a problem in practice, and actually this makes a lot of sense. git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4834 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
1 parent
bfe337fe76
commit
96c914bfda
11 files changed
+160
-126
No files matched your search
+28
-36
@@ -141,30 +141,27 @@ int sensors_chip_name_has_wildcards(const sensors_chip_name *chip)
|
||||
contain wildcard values! The returned string is newly allocated (free it
|
||||
yourself). On failure, NULL is returned.
|
||||
If no label exists for this feature, its name is returned itself. */
|
||||
char *sensors_get_label(const sensors_chip_name *name, int feature)
|
||||
char *sensors_get_label(const sensors_chip_name *name,
|
||||
const sensors_feature *feature)
|
||||
{
|
||||
char *label;
|
||||
const sensors_chip *chip;
|
||||
const sensors_subfeature *featureptr;
|
||||
char buf[128], path[PATH_MAX];
|
||||
FILE *f;
|
||||
int i;
|
||||
|
||||
if (sensors_chip_name_has_wildcards(name))
|
||||
return NULL;
|
||||
if (!(featureptr = sensors_lookup_feature_nr(name, feature)))
|
||||
return NULL;
|
||||
|
||||
for (chip = NULL; (chip = sensors_for_all_config_chips(name, chip));)
|
||||
for (i = 0; i < chip->labels_count; i++)
|
||||
if (!strcmp(featureptr->name, chip->labels[i].name)) {
|
||||
if (!strcmp(feature->name, chip->labels[i].name)) {
|
||||
label = strdup(chip->labels[i].value);
|
||||
goto sensors_get_label_exit;
|
||||
}
|
||||
|
||||
/* No user specified label, check for a _label sysfs file */
|
||||
snprintf(path, PATH_MAX, "%s/%s_label", name->path,
|
||||
featureptr->name);
|
||||
snprintf(path, PATH_MAX, "%s/%s_label", name->path, feature->name);
|
||||
|
||||
if ((f = fopen(path, "r"))) {
|
||||
i = fread(buf, 1, sizeof(buf) - 1, f);
|
||||
@@ -178,7 +175,7 @@ char *sensors_get_label(const sensors_chip_name *name, int feature)
|
||||
}
|
||||
|
||||
/* No label, return the feature name instead */
|
||||
label = strdup(featureptr->name);
|
||||
label = strdup(feature->name);
|
||||
|
||||
sensors_get_label_exit:
|
||||
if (!label)
|
||||
@@ -188,26 +185,16 @@ sensors_get_label_exit:
|
||||
}
|
||||
|
||||
/* Looks up whether a feature should be ignored. Returns
|
||||
1 if it should be ignored, 0 if not. This function takes
|
||||
mappings into account. */
|
||||
1 if it should be ignored, 0 if not. */
|
||||
static int sensors_get_ignored(const sensors_chip_name *name,
|
||||
const sensors_subfeature *feature)
|
||||
const sensors_feature *feature)
|
||||
{
|
||||
const sensors_chip *chip;
|
||||
const char *main_feature_name;
|
||||
int i;
|
||||
|
||||
if (feature->mapping == SENSORS_NO_MAPPING)
|
||||
main_feature_name = NULL;
|
||||
else
|
||||
main_feature_name = sensors_lookup_feature_nr(name,
|
||||
feature->mapping)->name;
|
||||
|
||||
for (chip = NULL; (chip = sensors_for_all_config_chips(name, chip));)
|
||||
for (i = 0; i < chip->ignores_count; i++)
|
||||
if (!strcmp(feature->name, chip->ignores[i].name) ||
|
||||
(main_feature_name &&
|
||||
!strcmp(main_feature_name, chip->ignores[i].name)))
|
||||
if (!strcmp(feature->name, chip->ignores[i].name))
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
@@ -352,42 +339,47 @@ sensors_get_all_features(const sensors_chip_name *name, int *nr)
|
||||
for (i = 0; i < sensors_proc_chips_count; i++)
|
||||
if (sensors_match_chip(&sensors_proc_chips[i].chip, name)) {
|
||||
subfeature_list = sensors_proc_chips[i].subfeature;
|
||||
while (*nr < sensors_proc_chips[i].subfeature_count
|
||||
&& sensors_get_ignored(name, &subfeature_list[*nr]))
|
||||
(*nr)++;
|
||||
if (*nr == sensors_proc_chips[i].subfeature_count)
|
||||
if (*nr >= sensors_proc_chips[i].subfeature_count)
|
||||
return NULL;
|
||||
return &subfeature_list[(*nr)++];
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const sensors_subfeature *
|
||||
const sensors_feature *
|
||||
sensors_get_features(const sensors_chip_name *name, int *nr)
|
||||
{
|
||||
const sensors_subfeature *feature;
|
||||
const sensors_feature *feature_list;
|
||||
int i;
|
||||
|
||||
while ((feature = sensors_get_all_features(name, nr))) {
|
||||
if (feature->mapping == SENSORS_NO_MAPPING)
|
||||
return feature;
|
||||
}
|
||||
for (i = 0; i < sensors_proc_chips_count; i++)
|
||||
if (sensors_match_chip(&sensors_proc_chips[i].chip, name)) {
|
||||
feature_list = sensors_proc_chips[i].feature;
|
||||
while (*nr < sensors_proc_chips[i].feature_count
|
||||
&& sensors_get_ignored(name, &feature_list[*nr]))
|
||||
(*nr)++;
|
||||
if (*nr >= sensors_proc_chips[i].feature_count)
|
||||
return NULL;
|
||||
return &feature_list[(*nr)++];
|
||||
}
|
||||
return NULL; /* end of list */
|
||||
}
|
||||
|
||||
const sensors_subfeature *
|
||||
sensors_get_all_subfeatures(const sensors_chip_name *name, int feature, int *nr)
|
||||
sensors_get_all_subfeatures(const sensors_chip_name *name,
|
||||
const sensors_feature *feature, int *nr)
|
||||
{
|
||||
const sensors_subfeature *subfeature;
|
||||
|
||||
/* Seek directly to the first subfeature */
|
||||
if (*nr < feature)
|
||||
*nr = feature;
|
||||
if (*nr < feature->first_subfeature)
|
||||
*nr = feature->first_subfeature;
|
||||
|
||||
subfeature = sensors_get_all_features(name, nr);
|
||||
if (!subfeature)
|
||||
return NULL; /* end of list */
|
||||
if (subfeature->number == feature ||
|
||||
subfeature->mapping == feature)
|
||||
if (subfeature->number == feature->first_subfeature ||
|
||||
subfeature->mapping == feature->first_subfeature)
|
||||
return subfeature;
|
||||
return NULL; /* end of subfeature list */
|
||||
}
|
||||
|
||||
@@ -123,7 +123,9 @@ typedef struct sensors_bus {
|
||||
/* Internal data about all features of a type of chip */
|
||||
typedef struct sensors_chip_features {
|
||||
struct sensors_chip_name chip;
|
||||
struct sensors_feature *feature;
|
||||
struct sensors_subfeature *subfeature;
|
||||
int feature_count;
|
||||
int subfeature_count;
|
||||
} sensors_chip_features;
|
||||
|
||||
|
||||
@@ -59,6 +59,9 @@ static void free_chip_features(sensors_chip_features *features)
|
||||
for (i = 0; i < features->subfeature_count; i++)
|
||||
free(features->subfeature[i].name);
|
||||
free(features->subfeature);
|
||||
for (i = 0; i < features->feature_count; i++)
|
||||
free(features->feature[i].name);
|
||||
free(features->feature);
|
||||
}
|
||||
|
||||
static void free_bus(sensors_bus *bus)
|
||||
|
||||
+7
-9
@@ -36,7 +36,7 @@ libsensors \- publicly accessible functions provided by the sensors library
|
||||
.B int sensors_parse_chip_name(const char *orig_name,
|
||||
\fBsensors_chip_name *res);\fP
|
||||
.B const char *sensors_get_adapter_name(int bus_nr);
|
||||
.B char *sensors_get_label(const sensors_chip_name *name, int feature);\fP
|
||||
.B char *sensors_get_label(const sensors_chip_name *name, const sensors_feature *feature);\fP
|
||||
.B int sensors_get_value(const sensors_chip_name *name, int feature,
|
||||
\fBdouble *value);\fP
|
||||
.B int sensors_set_value(const sensors_chip_name *name, int feature,
|
||||
@@ -44,10 +44,8 @@ libsensors \- publicly accessible functions provided by the sensors library
|
||||
.B int sensors_do_chip_sets(const sensors_chip_name *name);
|
||||
.B const sensors_chip_name *sensors_get_detected_chips(const sensors_chip_name
|
||||
\fB*match, int *nr);\fP
|
||||
.B const sensors_feature_data *sensors_get_features
|
||||
\fB(const sensors_chip_name *name, int *nr);\fP
|
||||
.B const sensors_feature_data *sensors_get_all_subfeatures
|
||||
\fB(const sensors_chip_name *name, int feature, int *nr);\fP
|
||||
.B const sensors_feature *sensors_get_features(const sensors_chip_name *name, int *nr);\fP
|
||||
.B const sensors_subfeature *sensors_get_all_subfeatures(const sensors_chip_name *name, const sensors_feature *feature, int *nr);\fP
|
||||
.B const char *libsensors_version;
|
||||
.fi
|
||||
.SH DESCRIPTION
|
||||
@@ -73,7 +71,7 @@ Parse a chip name to the internal representation. Return 0 on succes, <0 on erro
|
||||
This function returns the adapter name of a bus number, as used within the
|
||||
sensors_chip_name structure. If it could not be found, it returns NULL.
|
||||
|
||||
\fBchar *sensors_get_label(const sensors_chip_name *name, int feature);\fP
|
||||
\fBchar *sensors_get_label(const sensors_chip_name *name, const sensors_feature *feature);\fP
|
||||
.br
|
||||
Look up the label which belongs to this chip. Note that chip should not
|
||||
contain wildcard values! The returned string is newly allocated (free it
|
||||
@@ -124,7 +122,7 @@ The flags field is a bitfield, its value is a combination of
|
||||
SENSORS_MODE_R (readable), SENSORS_MODE_W (writable) and SENSORS_COMPUTE_MAPPING
|
||||
(affected by the computation rules of the main feature).
|
||||
|
||||
\fBconst sensors_feature_data *sensors_get_features(const sensors_chip_name *name, int *nr);\fP
|
||||
\fBconst sensors_feature *sensors_get_features(const sensors_chip_name *name, int *nr);\fP
|
||||
.br
|
||||
This returns all main features of a specific chip. nr is an internally
|
||||
used variable. Set it to zero to start at the begin of the list. If no
|
||||
@@ -132,12 +130,12 @@ more features are found NULL is returned.
|
||||
Do not try to change the returned structure; you will corrupt internal
|
||||
data structures.
|
||||
|
||||
\fBconst sensors_feature_data *sensors_get_all_subfeatures(const sensors_chip_name *name, int feature, int *nr);\fP
|
||||
\fBconst sensors_subfeature *sensors_get_all_subfeatures(const sensors_chip_name *name, const sensors_feature *feature, int *nr);\fP
|
||||
.br
|
||||
This returns all subfeatures of a given main feature (including that
|
||||
main feature itself, in first position.) nr is an internally used
|
||||
variable. Set it to zero to start at the begin of the list. If no more
|
||||
features are found NULL is returned.
|
||||
subfeatures are found NULL is returned.
|
||||
Do not try to change the returned structure; you will corrupt internal
|
||||
data structures.
|
||||
|
||||
|
||||
+14
-3
@@ -82,11 +82,14 @@ int sensors_snprintf_chip_name(char *str, size_t size,
|
||||
it returns NULL */
|
||||
const char *sensors_get_adapter_name(const sensors_bus_id *bus);
|
||||
|
||||
typedef struct sensors_feature sensors_feature;
|
||||
|
||||
/* Look up the label which belongs to this chip. Note that chip should not
|
||||
contain wildcard values! The returned string is newly allocated (free it
|
||||
yourself). On failure, NULL is returned.
|
||||
If no label exists for this feature, its name is returned itself. */
|
||||
char *sensors_get_label(const sensors_chip_name *name, int feature);
|
||||
char *sensors_get_label(const sensors_chip_name *name,
|
||||
const sensors_feature *feature);
|
||||
|
||||
/* Read the value of a feature of a certain chip. Note that chip should not
|
||||
contain wildcard values! This function will return 0 on success, and <0
|
||||
@@ -163,6 +166,13 @@ typedef enum sensors_feature_type {
|
||||
SENSORS_FEATURE_UNKNOWN = INT_MAX,
|
||||
} sensors_feature_type;
|
||||
|
||||
/* Data about a single chip feature (or category leader) */
|
||||
struct sensors_feature {
|
||||
char *name;
|
||||
int first_subfeature;
|
||||
sensors_feature_type type;
|
||||
};
|
||||
|
||||
/* Data about a single chip subfeature:
|
||||
name is the string name used to refer to this subfeature (in config files)
|
||||
number is the internal subfeature number, used in many functions to refer
|
||||
@@ -188,7 +198,7 @@ typedef struct sensors_subfeature {
|
||||
more features are found NULL is returned.
|
||||
Do not try to change the returned structure; you will corrupt internal
|
||||
data structures. */
|
||||
const sensors_subfeature *
|
||||
const sensors_feature *
|
||||
sensors_get_features(const sensors_chip_name *name, int *nr);
|
||||
|
||||
/* This returns all subfeatures of a given main feature (including that
|
||||
@@ -198,7 +208,8 @@ sensors_get_features(const sensors_chip_name *name, int *nr);
|
||||
Do not try to change the returned structure; you will corrupt internal
|
||||
data structures. */
|
||||
const sensors_subfeature *
|
||||
sensors_get_all_subfeatures(const sensors_chip_name *name, int feature, int *nr);
|
||||
sensors_get_all_subfeatures(const sensors_chip_name *name,
|
||||
const sensors_feature *feature, int *nr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
+26
@@ -163,6 +163,7 @@ static int sensors_read_dynamic_chip(sensors_chip_features *chip,
|
||||
struct dlist *attrs;
|
||||
sensors_subfeature *features;
|
||||
sensors_subfeature *dyn_subfeatures;
|
||||
sensors_feature *dyn_features;
|
||||
|
||||
attrs = sysfs_get_device_attributes(sysdir);
|
||||
|
||||
@@ -289,6 +290,31 @@ static int sensors_read_dynamic_chip(sensors_chip_features *chip,
|
||||
chip->subfeature = dyn_subfeatures;
|
||||
chip->subfeature_count = fnum;
|
||||
|
||||
/* And now the main features */
|
||||
fnum = 0;
|
||||
for (i = 0; i < chip->subfeature_count; i++) {
|
||||
if (chip->subfeature[i].mapping == SENSORS_NO_MAPPING)
|
||||
fnum++;
|
||||
}
|
||||
|
||||
dyn_features = calloc(fnum, sizeof(sensors_feature));
|
||||
if (dyn_features == NULL) {
|
||||
sensors_fatal_error(__FUNCTION__, "Out of memory");
|
||||
}
|
||||
|
||||
fnum = 0;
|
||||
for (i = 0; i < chip->subfeature_count; i++) {
|
||||
if (chip->subfeature[i].mapping == SENSORS_NO_MAPPING) {
|
||||
dyn_features[fnum].name = strdup(chip->subfeature[i].name);
|
||||
dyn_features[fnum].first_subfeature = i;
|
||||
dyn_features[fnum].type = chip->subfeature[i].type;
|
||||
fnum++;
|
||||
}
|
||||
}
|
||||
|
||||
chip->feature = dyn_features;
|
||||
chip->feature_count = fnum;
|
||||
|
||||
exit_free:
|
||||
free(features);
|
||||
return 0;
|
||||
|
||||
+29
-12
@@ -141,7 +141,7 @@ rrdF3
|
||||
}
|
||||
|
||||
static void getAvailableFeatures (const sensors_chip_name *name,
|
||||
const sensors_subfeature *feature,
|
||||
const sensors_feature *feature,
|
||||
short *has_features,
|
||||
int *feature_nrs, int size,
|
||||
int first_val)
|
||||
@@ -149,7 +149,7 @@ static void getAvailableFeatures (const sensors_chip_name *name,
|
||||
const sensors_subfeature *iter;
|
||||
int i = 0;
|
||||
|
||||
while ((iter = sensors_get_all_subfeatures(name, feature->number, &i))) {
|
||||
while ((iter = sensors_get_all_subfeatures(name, feature, &i))) {
|
||||
int index0;
|
||||
|
||||
index0 = iter->type - first_val;
|
||||
@@ -166,7 +166,7 @@ static void getAvailableFeatures (const sensors_chip_name *name,
|
||||
#define IN_FEATURE_NR(x) feature_nrs[x - SENSORS_FEATURE_IN]
|
||||
static void fillChipVoltage (FeatureDescriptor *voltage,
|
||||
const sensors_chip_name *name,
|
||||
const sensors_subfeature *feature)
|
||||
const sensors_feature *feature)
|
||||
{
|
||||
const int size = SENSORS_FEATURE_IN_BEEP - SENSORS_FEATURE_IN + 1;
|
||||
short has_features[SENSORS_FEATURE_IN_BEEP - SENSORS_FEATURE_IN + 1] = { 0, };
|
||||
@@ -215,7 +215,7 @@ static void fillChipVoltage (FeatureDescriptor *voltage,
|
||||
#define TEMP_FEATURE_NR(x) feature_nrs[x - SENSORS_FEATURE_TEMP]
|
||||
static void fillChipTemperature (FeatureDescriptor *temperature,
|
||||
const sensors_chip_name *name,
|
||||
const sensors_subfeature *feature)
|
||||
const sensors_feature *feature)
|
||||
{
|
||||
const int size = SENSORS_FEATURE_TEMP_BEEP - SENSORS_FEATURE_TEMP + 1;
|
||||
short has_features[SENSORS_FEATURE_TEMP_BEEP - SENSORS_FEATURE_TEMP + 1] = { 0, };
|
||||
@@ -267,7 +267,7 @@ static void fillChipTemperature (FeatureDescriptor *temperature,
|
||||
#define FAN_FEATURE_NR(x) feature_nrs[x - SENSORS_FEATURE_FAN]
|
||||
static void fillChipFan (FeatureDescriptor *fan,
|
||||
const sensors_chip_name *name,
|
||||
const sensors_subfeature *feature)
|
||||
const sensors_feature *feature)
|
||||
{
|
||||
const int size = SENSORS_FEATURE_FAN_BEEP - SENSORS_FEATURE_FAN + 1;
|
||||
short has_features[SENSORS_FEATURE_FAN_BEEP - SENSORS_FEATURE_FAN + 1] = { 0, };
|
||||
@@ -312,26 +312,42 @@ static void fillChipFan (FeatureDescriptor *fan,
|
||||
}
|
||||
|
||||
static void fillChipVid (FeatureDescriptor *vid,
|
||||
const sensors_subfeature *feature)
|
||||
const sensors_chip_name *name,
|
||||
const sensors_feature *feature)
|
||||
{
|
||||
int i = 0;
|
||||
const sensors_subfeature *sub;
|
||||
|
||||
sub = sensors_get_all_subfeatures(name, feature, &i);
|
||||
if (!sub)
|
||||
return;
|
||||
|
||||
vid->format = fmtVolt_3;
|
||||
vid->rrd = rrdF3;
|
||||
vid->type = DataType_voltage;
|
||||
vid->alarmNumber = -1;
|
||||
vid->beepNumber = -1;
|
||||
vid->dataNumbers[0] = feature->number;
|
||||
vid->dataNumbers[0] = sub->number;
|
||||
vid->dataNumbers[1] = -1;
|
||||
}
|
||||
|
||||
static void fillChipBeepEnable (FeatureDescriptor *beepen,
|
||||
const sensors_subfeature *feature)
|
||||
const sensors_chip_name *name,
|
||||
const sensors_feature *feature)
|
||||
{
|
||||
int i = 0;
|
||||
const sensors_subfeature *sub;
|
||||
|
||||
sub = sensors_get_all_subfeatures(name, feature, &i);
|
||||
if (!sub)
|
||||
return;
|
||||
|
||||
beepen->format = fmtSoundAlarm;
|
||||
beepen->rrd = rrdF0;
|
||||
beepen->type = DataType_other;
|
||||
beepen->alarmNumber = -1;
|
||||
beepen->beepNumber = -1;
|
||||
beepen->dataNumbers[0] = feature->number;
|
||||
beepen->dataNumbers[0] = sub->number;
|
||||
beepen->dataNumbers[1] = -1;
|
||||
}
|
||||
|
||||
@@ -339,7 +355,7 @@ static
|
||||
FeatureDescriptor * generateChipFeatures (const sensors_chip_name *chip)
|
||||
{
|
||||
int nr, count = 1;
|
||||
const sensors_subfeature *sensor;
|
||||
const sensors_feature *sensor;
|
||||
FeatureDescriptor *features;
|
||||
|
||||
/* How many main features do we have? */
|
||||
@@ -367,15 +383,16 @@ FeatureDescriptor * generateChipFeatures (const sensors_chip_name *chip)
|
||||
fillChipFan(&features[count], chip, sensor);
|
||||
break;
|
||||
case SENSORS_FEATURE_VID:
|
||||
fillChipVid(&features[count], sensor);
|
||||
fillChipVid(&features[count], chip, sensor);
|
||||
break;
|
||||
case SENSORS_FEATURE_BEEP_ENABLE:
|
||||
fillChipBeepEnable(&features[count], sensor);
|
||||
fillChipBeepEnable(&features[count], chip, sensor);
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
|
||||
features[count].feature = sensor;
|
||||
count++;
|
||||
}
|
||||
|
||||
|
||||
+3
-7
@@ -156,15 +156,11 @@ applyToFeatures
|
||||
|
||||
for (index0 = 0; (ret == 0) && (num < MAX_RRD_SENSORS) && features[index0].format; ++ index0) {
|
||||
const FeatureDescriptor *feature = features + index0;
|
||||
int labelNumber = feature->dataNumbers[0];
|
||||
const char *rawLabel = NULL;
|
||||
const char *rawLabel = features->feature->name;
|
||||
char *label = NULL;
|
||||
|
||||
if (getRawLabel (chip, labelNumber, &rawLabel)) {
|
||||
sensorLog (LOG_ERR, "Error getting raw sensor label: %s/#%d", chip->prefix, labelNumber);
|
||||
ret = -1;
|
||||
} else if (!(label = sensors_get_label (chip, labelNumber))) {
|
||||
sensorLog (LOG_ERR, "Error getting sensor label: %s/#%d", chip->prefix, labelNumber);
|
||||
if (!(label = sensors_get_label (chip, features->feature))) {
|
||||
sensorLog (LOG_ERR, "Error getting sensor label: %s/%s", chip->prefix, rawLabel);
|
||||
ret = -1;
|
||||
} else {
|
||||
rrdCheckLabel (rawLabel, num);
|
||||
|
||||
+2
-23
@@ -33,26 +33,6 @@
|
||||
#define DO_SET 2
|
||||
#define DO_RRD 3
|
||||
|
||||
int
|
||||
getRawLabel
|
||||
(const sensors_chip_name *name, int feature, const char **label) {
|
||||
const sensors_subfeature *mainfeat, *sub;
|
||||
int a, b;
|
||||
|
||||
a = 0;
|
||||
while ((mainfeat = sensors_get_features(name, &a))) {
|
||||
b = 0;
|
||||
while ((sub = sensors_get_all_subfeatures(name, mainfeat->number, &b))) {
|
||||
if (sub->number == feature) {
|
||||
*label = sub->name;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* TODO: Ensure labels match RRD construct and are not repeated! */
|
||||
return -1;
|
||||
}
|
||||
|
||||
static const char *
|
||||
chipName
|
||||
(const sensors_chip_name *chip) {
|
||||
@@ -87,12 +67,11 @@ doKnownChip
|
||||
ret = idChip (chip);
|
||||
for (index0 = 0; (ret == 0) && features[index0].format; ++ index0) {
|
||||
const FeatureDescriptor *feature = features + index0;
|
||||
int labelNumber = feature->dataNumbers[0];
|
||||
int alarm, beep;
|
||||
char *label = NULL;
|
||||
|
||||
if (!(label = sensors_get_label (chip, labelNumber))) {
|
||||
sensorLog (LOG_ERR, "Error getting sensor label: %s/#%d", chip->prefix, labelNumber);
|
||||
if (!(label = sensors_get_label (chip, feature->feature))) {
|
||||
sensorLog (LOG_ERR, "Error getting sensor label: %s/%s", chip->prefix, feature->feature->name);
|
||||
ret = 22;
|
||||
} else {
|
||||
double values[MAX_DATA];
|
||||
|
||||
@@ -56,8 +56,6 @@ extern int unloadLib (void);
|
||||
|
||||
/* from sense.c */
|
||||
|
||||
extern int getRawLabel (const sensors_chip_name *name, int feature, const char **label);
|
||||
|
||||
extern int readChips (void);
|
||||
extern int scanChips (void);
|
||||
extern int setChips (void);
|
||||
@@ -91,7 +89,8 @@ typedef struct {
|
||||
DataType type;
|
||||
int alarmNumber;
|
||||
int beepNumber;
|
||||
int dataNumbers[MAX_DATA + 1]; /* First entry is used for the label */
|
||||
const sensors_feature *feature;
|
||||
int dataNumbers[MAX_DATA + 1];
|
||||
} FeatureDescriptor;
|
||||
|
||||
typedef struct {
|
||||
|
||||
+44
-33
@@ -31,32 +31,30 @@
|
||||
void print_chip_raw(const sensors_chip_name *name)
|
||||
{
|
||||
int a, b;
|
||||
const sensors_subfeature *feature, *sub;
|
||||
const sensors_feature *feature;
|
||||
const sensors_subfeature *sub;
|
||||
char *label;
|
||||
double val;
|
||||
|
||||
a = 0;
|
||||
while ((feature = sensors_get_features(name, &a))) {
|
||||
if (!(label = sensors_get_label(name, feature))) {
|
||||
printf("ERROR: Can't get feature label!\n");
|
||||
continue;
|
||||
}
|
||||
printf("%s:\n", label);
|
||||
free(label);
|
||||
|
||||
b = 0;
|
||||
while ((sub = sensors_get_all_subfeatures(name, feature->number,
|
||||
&b))) {
|
||||
if (!(label = sensors_get_label(name, sub->number))) {
|
||||
printf("ERROR: Can't get feature `%s' label!\n",
|
||||
sub->name);
|
||||
continue;
|
||||
}
|
||||
while ((sub = sensors_get_all_subfeatures(name, feature, &b))) {
|
||||
if (sub->flags & SENSORS_MODE_R) {
|
||||
if (sensors_get_value(name, sub->number, &val))
|
||||
printf("ERROR: Can't get feature `%s' "
|
||||
"data!\n", sub->name);
|
||||
else if (sub->mapping != SENSORS_NO_MAPPING)
|
||||
printf(" %s: %.2f\n", label, val);
|
||||
else
|
||||
printf("%s: %.2f (%s)\n", label, val,
|
||||
sub->name);
|
||||
printf(" %s: %.2f\n", sub->name, val);
|
||||
} else
|
||||
printf("(%s)\n", label);
|
||||
free(label);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -73,7 +71,7 @@ static void print_label(const char *label, int space)
|
||||
}
|
||||
|
||||
static void sensors_get_available_features(const sensors_chip_name *name,
|
||||
const sensors_subfeature *feature,
|
||||
const sensors_feature *feature,
|
||||
short *has_features,
|
||||
double *feature_vals, int size,
|
||||
int first_val)
|
||||
@@ -81,7 +79,7 @@ static void sensors_get_available_features(const sensors_chip_name *name,
|
||||
const sensors_subfeature *iter;
|
||||
int i = 0;
|
||||
|
||||
while ((iter = sensors_get_all_subfeatures(name, feature->number, &i))) {
|
||||
while ((iter = sensors_get_all_subfeatures(name, feature, &i))) {
|
||||
int indx, err;
|
||||
|
||||
indx = iter->type - first_val;
|
||||
@@ -103,13 +101,13 @@ static void sensors_get_available_features(const sensors_chip_name *name,
|
||||
static int sensors_get_label_size(const sensors_chip_name *name)
|
||||
{
|
||||
int i;
|
||||
const sensors_subfeature *iter;
|
||||
const sensors_feature *iter;
|
||||
char *label;
|
||||
unsigned int max_size = 11; /* 11 as minumum label width */
|
||||
|
||||
i = 0;
|
||||
while ((iter = sensors_get_features(name, &i))) {
|
||||
if ((label = sensors_get_label(name, iter->number)) &&
|
||||
if ((label = sensors_get_label(name, iter)) &&
|
||||
strlen(label) > max_size)
|
||||
max_size = strlen(label);
|
||||
free(label);
|
||||
@@ -143,7 +141,7 @@ static void print_temp_limits(double limit1, double limit2,
|
||||
#define TEMP_FEATURE(x) has_features[x - SENSORS_FEATURE_TEMP]
|
||||
#define TEMP_FEATURE_VAL(x) feature_vals[x - SENSORS_FEATURE_TEMP]
|
||||
static void print_chip_temp(const sensors_chip_name *name,
|
||||
const sensors_subfeature *feature,
|
||||
const sensors_feature *feature,
|
||||
int label_size)
|
||||
{
|
||||
double val, limit1, limit2;
|
||||
@@ -154,7 +152,7 @@ static void print_chip_temp(const sensors_chip_name *name,
|
||||
short has_features[SENSORS_FEATURE_TEMP_TYPE - SENSORS_FEATURE_TEMP + 1] = { 0, };
|
||||
double feature_vals[SENSORS_FEATURE_TEMP_TYPE - SENSORS_FEATURE_TEMP + 1] = { 0.0, };
|
||||
|
||||
if (!(label = sensors_get_label(name, feature->number))) {
|
||||
if (!(label = sensors_get_label(name, feature))) {
|
||||
printf("ERROR: Can't get temperature label!\n");
|
||||
return;
|
||||
}
|
||||
@@ -276,7 +274,7 @@ static void print_chip_temp(const sensors_chip_name *name,
|
||||
#define IN_FEATURE(x) has_features[x - SENSORS_FEATURE_IN]
|
||||
#define IN_FEATURE_VAL(x) feature_vals[x - SENSORS_FEATURE_IN]
|
||||
static void print_chip_in(const sensors_chip_name *name,
|
||||
const sensors_subfeature *feature,
|
||||
const sensors_feature *feature,
|
||||
int label_size)
|
||||
{
|
||||
const int size = SENSORS_FEATURE_IN_MAX_ALARM - SENSORS_FEATURE_IN + 1;
|
||||
@@ -285,7 +283,7 @@ static void print_chip_in(const sensors_chip_name *name,
|
||||
double val, alarm_max, alarm_min;
|
||||
char *label;
|
||||
|
||||
if (!(label = sensors_get_label(name, feature->number))) {
|
||||
if (!(label = sensors_get_label(name, feature))) {
|
||||
printf("ERROR: Can't get in label!\n");
|
||||
return;
|
||||
}
|
||||
@@ -336,7 +334,7 @@ static void print_chip_in(const sensors_chip_name *name,
|
||||
#define FAN_FEATURE(x) has_features[x - SENSORS_FEATURE_FAN]
|
||||
#define FAN_FEATURE_VAL(x) feature_vals[x - SENSORS_FEATURE_FAN]
|
||||
static void print_chip_fan(const sensors_chip_name *name,
|
||||
const sensors_subfeature *feature,
|
||||
const sensors_feature *feature,
|
||||
int label_size)
|
||||
{
|
||||
char *label;
|
||||
@@ -345,7 +343,7 @@ static void print_chip_fan(const sensors_chip_name *name,
|
||||
double feature_vals[SENSORS_FEATURE_FAN_DIV - SENSORS_FEATURE_FAN + 1] = { 0.0, };
|
||||
double val;
|
||||
|
||||
if (!(label = sensors_get_label(name, feature->number))) {
|
||||
if (!(label = sensors_get_label(name, feature))) {
|
||||
printf("ERROR: Can't get fan label!\n");
|
||||
return;
|
||||
}
|
||||
@@ -383,28 +381,42 @@ static void print_chip_fan(const sensors_chip_name *name,
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
static void print_chip_vid(const sensors_chip_name *name, int f_vid,
|
||||
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;
|
||||
int i = 0;
|
||||
|
||||
if ((label = sensors_get_label(name, f_vid))
|
||||
&& !sensors_get_value(name, f_vid, &vid)) {
|
||||
subfeature = sensors_get_all_subfeatures(name, feature, &i);
|
||||
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);
|
||||
}
|
||||
|
||||
static void print_chip_beep_enable(const sensors_chip_name *name, int f_beep,
|
||||
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;
|
||||
int i = 0;
|
||||
|
||||
if ((label = sensors_get_label(name, f_beep))
|
||||
&& !sensors_get_value(name, f_beep, &beep_enable)) {
|
||||
subfeature = sensors_get_all_subfeatures(name, feature, &i);
|
||||
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");
|
||||
}
|
||||
@@ -413,7 +425,7 @@ static void print_chip_beep_enable(const sensors_chip_name *name, int f_beep,
|
||||
|
||||
void print_chip(const sensors_chip_name *name)
|
||||
{
|
||||
const sensors_subfeature *feature;
|
||||
const sensors_feature *feature;
|
||||
int i, label_size;
|
||||
|
||||
label_size = sensors_get_label_size(name);
|
||||
@@ -431,11 +443,10 @@ void print_chip(const sensors_chip_name *name)
|
||||
print_chip_fan(name, feature, label_size);
|
||||
break;
|
||||
case SENSORS_FEATURE_VID:
|
||||
print_chip_vid(name, feature->number, label_size);
|
||||
print_chip_vid(name, feature, label_size);
|
||||
break;
|
||||
case SENSORS_FEATURE_BEEP_ENABLE:
|
||||
print_chip_beep_enable(name, feature->number,
|
||||
label_size);
|
||||
print_chip_beep_enable(name, feature, label_size);
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
|
||||
Reference in new issue
Block a user