2
0
mirror of https://github.com/lm-sensors/lm-sensors synced 2025-08-30 05:48:07 +00:00

Add generic chip support to sensord, much like sensors has.

Alarm and beep mask support is still missing.


git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4817 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
Jean Delvare 2007-09-19 15:11:34 +00:00
parent d3b00b0a86
commit 2e773670b8
4 changed files with 224 additions and 25 deletions

View File

@ -71,9 +71,9 @@ fmtTemps_1
}
static const char *
fmtTemps_minmax_0
fmtTemps_minmax_1
(const double values[], int alarm, int beep) {
sprintf (buff, "%.0f C (min = %.0f C, max = %.0f C)", values[0], values[1], values[2]);
sprintf (buff, "%.1f C (min = %.1f C, max = %.1f C)", values[0], values[1], values[2]);
return fmtExtra (alarm, beep);
}
@ -119,6 +119,13 @@ fmtFans_nodiv_0
return fmtExtra (alarm, beep);
}
static const char *
fmtFan_only
(const double values[], int alarm, int beep) {
sprintf (buff, "%.0f RPM", values[0]);
return fmtExtra (alarm, beep);
}
static const char *
fmtMHz_2
(const double values[], int alarm, int beep) {
@ -175,8 +182,203 @@ rrdF3
return buff;
}
/** ALL **/
static void getAvailableFeatures (const sensors_chip_name *name,
const sensors_feature_data *feature,
int i, short *has_features,
int *feature_nrs, int size,
int first_val)
{
const sensors_feature_data *iter;
const ChipDescriptor * const knownChips[] = {
NULL
};
while ((iter = sensors_get_all_features (name, &i)) &&
iter->mapping == feature->number) {
int index0;
index0 = iter->type - first_val - 1;
if (index0 < 0 || index0 >= size)
/* New feature in libsensors? Ignore. */
continue;
has_features[index0] = 1;
feature_nrs[index0] = iter->number;
}
}
#define IN_FEATURE(x) has_features[x - SENSORS_FEATURE_IN - 1]
#define IN_FEATURE_NR(x) feature_nrs[x - SENSORS_FEATURE_IN - 1]
static void fillChipVoltage (FeatureDescriptor *voltage,
const sensors_chip_name *name,
const sensors_feature_data *feature, int i)
{
const int size = SENSORS_FEATURE_IN_MAX_ALARM - SENSORS_FEATURE_IN;
short has_features[SENSORS_FEATURE_IN_MAX_ALARM - SENSORS_FEATURE_IN] = { 0, };
int feature_nrs[SENSORS_FEATURE_IN_MAX_ALARM - SENSORS_FEATURE_IN];
int pos = 0;
voltage->rrd = rrdF2;
voltage->type = DataType_voltage;
voltage->dataNumbers[pos++] = feature->number;
getAvailableFeatures (name, feature, i, has_features,
feature_nrs, size, SENSORS_FEATURE_IN);
if (IN_FEATURE(SENSORS_FEATURE_IN_MIN) &&
IN_FEATURE(SENSORS_FEATURE_IN_MAX)) {
voltage->format = fmtVolts_2;
voltage->dataNumbers[pos++] = IN_FEATURE_NR(SENSORS_FEATURE_IN_MIN);
voltage->dataNumbers[pos++] = IN_FEATURE_NR(SENSORS_FEATURE_IN_MAX);
} else {
voltage->format = fmtVolt_2;
}
/* terminate the list */
voltage->dataNumbers[pos] = -1;
}
#define TEMP_FEATURE(x) has_features[x - SENSORS_FEATURE_TEMP - 1]
#define TEMP_FEATURE_NR(x) feature_nrs[x - SENSORS_FEATURE_TEMP - 1]
static void fillChipTemperature (FeatureDescriptor *temperature,
const sensors_chip_name *name,
const sensors_feature_data *feature, int i)
{
const int size = SENSORS_FEATURE_TEMP_TYPE - SENSORS_FEATURE_TEMP;
short has_features[SENSORS_FEATURE_TEMP_TYPE - SENSORS_FEATURE_TEMP] = { 0, };
int feature_nrs[SENSORS_FEATURE_TEMP_TYPE - SENSORS_FEATURE_TEMP];
int pos = 0;
temperature->rrd = rrdF1;
temperature->type = DataType_temperature;
temperature->dataNumbers[pos++] = feature->number;
getAvailableFeatures (name, feature, i, has_features,
feature_nrs, size, SENSORS_FEATURE_TEMP);
if (TEMP_FEATURE(SENSORS_FEATURE_TEMP_MIN) &&
TEMP_FEATURE(SENSORS_FEATURE_TEMP_MAX)) {
temperature->format = fmtTemps_minmax_1;
temperature->dataNumbers[pos++] = TEMP_FEATURE_NR(SENSORS_FEATURE_TEMP_MIN);
temperature->dataNumbers[pos++] = TEMP_FEATURE_NR(SENSORS_FEATURE_TEMP_MAX);
} else if (TEMP_FEATURE(SENSORS_FEATURE_TEMP_MAX) &&
TEMP_FEATURE(SENSORS_FEATURE_TEMP_MAX_HYST)) {
temperature->format = fmtTemps_1;
temperature->dataNumbers[pos++] = TEMP_FEATURE_NR(SENSORS_FEATURE_TEMP_MAX);
temperature->dataNumbers[pos++] = TEMP_FEATURE_NR(SENSORS_FEATURE_TEMP_MAX_HYST);
} else {
temperature->format = fmtTemp_only;
}
/* terminate the list */
temperature->dataNumbers[pos] = -1;
}
#define FAN_FEATURE(x) has_features[x - SENSORS_FEATURE_FAN - 1]
#define FAN_FEATURE_NR(x) feature_nrs[x - SENSORS_FEATURE_FAN - 1]
static void fillChipFan (FeatureDescriptor *fan,
const sensors_chip_name *name,
const sensors_feature_data *feature, int i)
{
const int size = SENSORS_FEATURE_FAN_DIV - SENSORS_FEATURE_FAN;
short has_features[SENSORS_FEATURE_FAN_DIV - SENSORS_FEATURE_FAN] = { 0, };
int feature_nrs[SENSORS_FEATURE_FAN_DIV - SENSORS_FEATURE_FAN];
int pos = 0;
fan->rrd = rrdF0;
fan->type = DataType_rpm;
fan->dataNumbers[pos++] = feature->number;
getAvailableFeatures (name, feature, i, has_features,
feature_nrs, size, SENSORS_FEATURE_FAN);
if (FAN_FEATURE(SENSORS_FEATURE_FAN_MIN)) {
fan->dataNumbers[pos++] = FAN_FEATURE_NR(SENSORS_FEATURE_FAN_MIN);
if (FAN_FEATURE(SENSORS_FEATURE_FAN_DIV)) {
fan->format = fmtFans_0;
fan->dataNumbers[pos++] = FAN_FEATURE_NR(SENSORS_FEATURE_FAN_DIV);
} else {
fan->format = fmtFans_nodiv_0;
}
} else {
fan->format = fmtFan_only;
}
/* terminate the list */
fan->dataNumbers[pos] = -1;
}
static void fillChipVid (FeatureDescriptor *voltage,
const sensors_feature_data *feature)
{
voltage->format = fmtVolt_3;
voltage->rrd = rrdF3;
voltage->type = DataType_voltage;
voltage->dataNumbers[0] = feature->number;
voltage->dataNumbers[1] = -1;
}
static void fillChipBeepEnable (FeatureDescriptor *voltage,
const sensors_feature_data *feature)
{
voltage->format = fmtSoundAlarm;
voltage->rrd = rrdF0;
voltage->type = DataType_other;
voltage->dataNumbers[0] = feature->number;
voltage->dataNumbers[1] = -1;
}
/* Note that alarms and beeps are no longer (or not yet) supported */
ChipDescriptor * generateChipDescriptor (const sensors_chip_name *chip)
{
int nr, count = 1;
const sensors_feature_data *sensor;
ChipDescriptor *descriptor;
FeatureDescriptor *features;
/* How many main features do we have? */
nr = 0;
while ((sensor = sensors_get_all_features(chip, &nr))) {
if (sensor->mapping == SENSORS_NO_MAPPING)
count++;
}
/* Allocate the memory we need */
descriptor = calloc(1, sizeof(ChipDescriptor));
features = calloc(count, sizeof(FeatureDescriptor));
if (!descriptor || !features) {
free(descriptor);
free(features);
return NULL;
}
descriptor->features = features;
/* Fill in the data structures */
count = 0;
nr = 0;
while ((sensor = sensors_get_all_features(chip, &nr))) {
if (sensor->mapping != SENSORS_NO_MAPPING)
continue;
switch (sensor->type) {
case SENSORS_FEATURE_TEMP:
fillChipTemperature(&features[count], chip, sensor, nr);
break;
case SENSORS_FEATURE_IN:
fillChipVoltage(&features[count], chip, sensor, nr);
break;
case SENSORS_FEATURE_FAN:
fillChipFan(&features[count], chip, sensor, nr);
break;
case SENSORS_FEATURE_VID:
fillChipVid(&features[count], sensor);
break;
case SENSORS_FEATURE_BEEP_ENABLE:
fillChipBeepEnable(&features[count], sensor);
break;
default:
continue;
}
count++;
}
return descriptor;
}

View File

@ -141,14 +141,11 @@ applyToFeatures
for (j = 0; (ret == 0) && (j < numChipNames); ++ j) {
while ((ret == 0) && ((chip = sensors_get_detected_chips (&chipNames[j], &i)) != NULL)) {
int index0, subindex, chipindex = -1;
for (index0 = 0; knownChips[index0]; ++ index0)
for (subindex = 0; knownChips[index0]->names[subindex]; ++ subindex)
if (!strcmp (chip->prefix, knownChips[index0]->names[subindex]))
chipindex = index0;
if (chipindex >= 0) {
const ChipDescriptor *descriptor = knownChips[chipindex];
ChipDescriptor *descriptor;
descriptor = generateChipDescriptor (chip);
if (descriptor) {
const FeatureDescriptor *features = descriptor->features;
int index0;
for (index0 = 0; (ret == 0) && (num < MAX_RRD_SENSORS) && features[index0].format; ++ index0) {
const FeatureDescriptor *feature = features + index0;
@ -170,6 +167,8 @@ applyToFeatures
if (label)
free (label);
}
free (descriptor->features);
free (descriptor);
}
}
}

View File

@ -197,14 +197,13 @@ doChip
if (action == DO_SET) {
ret = setChip (chip);
} else {
int index0, subindex, chipindex = -1;
for (index0 = 0; knownChips[index0]; ++ index0)
for (subindex = 0; knownChips[index0]->names[subindex]; ++ subindex)
if (!strcmp (chip->prefix, knownChips[index0]->names[subindex]))
chipindex = index0;
if (chipindex >= 0)
ret = doKnownChip (chip, knownChips[chipindex], action);
else if (action == DO_READ)
ChipDescriptor *descriptor;
descriptor = generateChipDescriptor (chip);
if (descriptor) {
ret = doKnownChip (chip, descriptor, action);
free (descriptor->features);
free (descriptor);
} else if (action == DO_READ)
ret = readUnknownChip (chip);
}
return ret;

View File

@ -91,14 +91,13 @@ typedef struct {
DataType type;
int alarmMask;
int beepMask;
const int dataNumbers[MAX_DATA + 1]; /* First entry is used for the label */
int dataNumbers[MAX_DATA + 1]; /* First entry is used for the label */
} FeatureDescriptor;
typedef struct {
const char * const *names;
const FeatureDescriptor *features;
FeatureDescriptor *features;
int alarmNumber;
int beepNumber;
} ChipDescriptor;
extern const ChipDescriptor * const knownChips[];
extern ChipDescriptor * generateChipDescriptor (const sensors_chip_name *chip);