From 36ded1b5fcaef657dc20c8caa97d6c04d3eeffd5 Mon Sep 17 00:00:00 2001 From: Jean Delvare Date: Thu, 20 Sep 2007 21:22:42 +0000 Subject: [PATCH] Restore support for alarms. git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4825 7894878c-1315-0410-8ee3-d5d059ff63e0 --- prog/sensord/chips.c | 37 +++++++++++++++++++++++++++++++++ prog/sensord/sense.c | 46 ++++++++++++++++++++++-------------------- prog/sensord/sensord.h | 6 ++---- 3 files changed, 63 insertions(+), 26 deletions(-) diff --git a/prog/sensord/chips.c b/prog/sensord/chips.c index 3c9bc540..421e5c5e 100644 --- a/prog/sensord/chips.c +++ b/prog/sensord/chips.c @@ -191,6 +191,19 @@ static void fillChipVoltage (FeatureDescriptor *voltage, /* terminate the list */ voltage->dataNumbers[pos] = -1; + + /* alarm if applicable */ + if (IN_FEATURE(SENSORS_FEATURE_IN_ALARM)) { + voltage->alarmNumber = IN_FEATURE_NR(SENSORS_FEATURE_IN_ALARM); + } else if (IN_FEATURE(SENSORS_FEATURE_IN_MIN_ALARM)) { + voltage->alarmNumber = IN_FEATURE_NR(SENSORS_FEATURE_IN_MIN_ALARM); + } else if (IN_FEATURE(SENSORS_FEATURE_IN_MAX_ALARM)) { + voltage->alarmNumber = IN_FEATURE_NR(SENSORS_FEATURE_IN_MAX_ALARM); + } else { + voltage->alarmNumber = -1; + } + /* beep support missing for now */ + voltage->beepNumber = -1; } #define TEMP_FEATURE(x) has_features[x - SENSORS_FEATURE_TEMP - 1] @@ -227,6 +240,17 @@ static void fillChipTemperature (FeatureDescriptor *temperature, /* terminate the list */ temperature->dataNumbers[pos] = -1; + + /* alarm if applicable */ + if (TEMP_FEATURE(SENSORS_FEATURE_TEMP_ALARM)) { + temperature->alarmNumber = TEMP_FEATURE_NR(SENSORS_FEATURE_TEMP_ALARM); + } else if (TEMP_FEATURE(SENSORS_FEATURE_TEMP_MAX_ALARM)) { + temperature->alarmNumber = TEMP_FEATURE_NR(SENSORS_FEATURE_TEMP_MAX_ALARM); + } else { + temperature->alarmNumber = -1; + } + /* beep support missing for now */ + temperature->beepNumber = -1; } #define FAN_FEATURE(x) has_features[x - SENSORS_FEATURE_FAN - 1] @@ -261,6 +285,15 @@ static void fillChipFan (FeatureDescriptor *fan, /* terminate the list */ fan->dataNumbers[pos] = -1; + + /* alarm if applicable */ + if (FAN_FEATURE(SENSORS_FEATURE_FAN_ALARM)) { + fan->alarmNumber = FAN_FEATURE_NR(SENSORS_FEATURE_FAN_ALARM); + } else { + fan->alarmNumber = -1; + } + /* beep support missing for now */ + fan->beepNumber = -1; } static void fillChipVid (FeatureDescriptor *vid, @@ -269,6 +302,8 @@ static void fillChipVid (FeatureDescriptor *vid, vid->format = fmtVolt_3; vid->rrd = rrdF3; vid->type = DataType_voltage; + vid->alarmNumber = -1; + vid->beepNumber = -1; vid->dataNumbers[0] = feature->number; vid->dataNumbers[1] = -1; } @@ -279,6 +314,8 @@ static void fillChipBeepEnable (FeatureDescriptor *beepen, beepen->format = fmtSoundAlarm; beepen->rrd = rrdF0; beepen->type = DataType_other; + beepen->alarmNumber = -1; + beepen->beepNumber = -1; beepen->dataNumbers[0] = feature->number; beepen->dataNumbers[1] = -1; } diff --git a/prog/sensord/sense.c b/prog/sensord/sense.c index 5f569447..14a816d6 100644 --- a/prog/sensord/sense.c +++ b/prog/sensord/sense.c @@ -76,44 +76,46 @@ static int doKnownChip (const sensors_chip_name *chip, const ChipDescriptor *descriptor, int action) { const FeatureDescriptor *features = descriptor->features; - int alarms = 0, beeps = 0; int index0, subindex; int ret = 0; double tmp; if (action == DO_READ) ret = idChip (chip); - if (!ret && descriptor->alarmNumber) { - if ((ret = sensors_get_value (chip, descriptor->alarmNumber, &tmp))) { - sensorLog (LOG_ERR, "Error getting sensor data: %s/#%d: %s", chip->prefix, descriptor->alarmNumber, sensors_strerror (ret)); - ret = 20; - } else { - alarms = (int) (tmp + 0.5); - } - } - if (!ret && descriptor->beepNumber) { - if ((ret = sensors_get_value (chip, descriptor->beepNumber, &tmp))) { - sensorLog (LOG_ERR, "Error getting sensor data: %s/#%d: %s", chip->prefix, descriptor->beepNumber, sensors_strerror (ret)); - ret = 21; - } else { - beeps = (int) (tmp + 0.5); - } - } for (index0 = 0; (ret == 0) && features[index0].format; ++ index0) { const FeatureDescriptor *feature = features + index0; int labelNumber = feature->dataNumbers[0]; - int alarm = alarms & feature->alarmMask; - int beep = beeps & feature->beepMask; + int alarm, beep; char *label = NULL; - if ((action == DO_SCAN) && !alarm) { - continue; - } else if (!(label = sensors_get_label (chip, labelNumber))) { + if (!(label = sensors_get_label (chip, labelNumber))) { sensorLog (LOG_ERR, "Error getting sensor label: %s/#%d", chip->prefix, labelNumber); ret = 22; } else { double values[MAX_DATA]; + alarm = 0; + if (!ret && feature->alarmNumber != -1) { + if ((ret = sensors_get_value (chip, feature->alarmNumber, &tmp))) { + sensorLog (LOG_ERR, "Error getting sensor data: %s/#%d: %s", chip->prefix, feature->alarmNumber, sensors_strerror (ret)); + ret = 20; + } else { + alarm = (int) (tmp + 0.5); + } + } + if ((action == DO_SCAN) && !alarm) + continue; + + beep = 0; + if (!ret && feature->beepNumber != -1) { + if ((ret = sensors_get_value (chip, feature->beepNumber, &tmp))) { + sensorLog (LOG_ERR, "Error getting sensor data: %s/#%d: %s", chip->prefix, feature->beepNumber, sensors_strerror (ret)); + ret = 21; + } else { + beep = (int) (tmp + 0.5); + } + } + for (subindex = 0; !ret && (feature->dataNumbers[subindex] >= 0); ++ subindex) { if ((ret = sensors_get_value (chip, feature->dataNumbers[subindex], values + subindex))) { sensorLog (LOG_ERR, "Error getting sensor data: %s/#%d: %s", chip->prefix, feature->dataNumbers[subindex], sensors_strerror (ret)); diff --git a/prog/sensord/sensord.h b/prog/sensord/sensord.h index fa81ebd4..93bbbbe5 100644 --- a/prog/sensord/sensord.h +++ b/prog/sensord/sensord.h @@ -89,15 +89,13 @@ typedef struct { FormatterFN format; RRDFN rrd; DataType type; - int alarmMask; - int beepMask; + int alarmNumber; + int beepNumber; int dataNumbers[MAX_DATA + 1]; /* First entry is used for the label */ } FeatureDescriptor; typedef struct { FeatureDescriptor *features; - int alarmNumber; - int beepNumber; } ChipDescriptor; extern ChipDescriptor * generateChipDescriptor (const sensors_chip_name *chip);