summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 8cc583b)
raw | patch | inline | side by side (parent: 8cc583b)
author | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Sat, 15 Sep 2007 09:58:52 +0000 (11:58 +0200) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Sat, 15 Sep 2007 09:58:52 +0000 (11:58 +0200) |
ChangeLog | patch | blob | history | |
src/wireless.c | patch | blob | history |
diff --git a/ChangeLog b/ChangeLog
index 49e5983c885ef4d09db832f86ff63cc20923dca0..12e508d4fe2fce31574c8ed4b6dda522306f7f00 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
+yyyy-mm-dd, Version 3.11.7
+ * wireless plugin: Correct the handling of cards returning signal and
+ noise quality as percentage.
+
2007-08-31, Version 3.11.6
* processes plugin: Fix a potential segmentation fault.
diff --git a/src/wireless.c b/src/wireless.c
index f0b9b01ae1e18d1f7147b63d68eaddd9daf5aab5..c771b9abb0f70580d7899be87b008ce84d586e55 100644 (file)
--- a/src/wireless.c
+++ b/src/wireless.c
plugin_submit (MODULE_NAME, device, buf);
}
+#define POWER_MIN -90.0
+#define POWER_MAX -50.0
+static double wireless_percent_to_power (double quality)
+{
+ assert ((quality >= 0.0) && (quality <= 100.0));
+
+ return ((quality * (POWER_MAX - POWER_MIN)) + POWER_MIN);
+} /* double wireless_percent_to_power */
+
static void wireless_read (void)
{
#ifdef KERNEL_LINUX
while (fgets (buffer, BUFSIZE, fh) != NULL)
{
+ char *endptr;
+
numfields = strsplit (buffer, fields, 8);
if (numfields < 5)
fields[0][len] = '\0';
device = fields[0];
- quality = atof (fields[2]);
- power = atof (fields[3]);
- noise = atof (fields[4]);
-
- /* Fill in invalid values when conversion failed.. */
- if (quality == 0.0)
- quality = -1.0; /* quality >= 0 */
-
- if (power == 0.0)
- power = 1.0; /* power <= 0 */
- if (noise == 0.0)
- noise = 1.0; /* noise <= 0 */
+ quality = strtod (fields[2], &endptr);
+ if (fields[2] == endptr)
+ quality = -1.0; /* invalid */
+
+ /* power [dBm] < 0.0 */
+ power = strtod (fields[3], &endptr);
+ if (fields[3] == endptr)
+ power = 1.0; /* invalid */
+ else if ((power >= 0.0) && (power <= 100.0))
+ power = wireless_percent_to_power (power);
+ else if (power > 100.0)
+ power = 1.0; /* invalid */
+
+ /* noise [dBm] < 0.0 */
+ noise = strtod (fields[3], &endptr);
+ if (fields[3] == endptr)
+ noise = 1.0; /* invalid */
+ else if ((noise >= 0.0) && (noise <= 100.0))
+ noise = wireless_percent_to_power (noise);
+ else if (noise > 100.0)
+ noise = 1.0; /* invalid */
wireless_submit (device, quality, power, noise);
}