X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fwireless.c;h=f7ba735d37687356d16d3d7bd5b3ff230736563d;hb=9c98fa31ef50a6ff849d36cac4f5297faa6f7909;hp=106754996c962518bc66e7348e36b2661a211562;hpb=bd66a09b35da21dcb405650ae4587bf2ca811438;p=collectd.git diff --git a/src/wireless.c b/src/wireless.c index 10675499..f7ba735d 100644 --- a/src/wireless.c +++ b/src/wireless.c @@ -23,15 +23,12 @@ #include "common.h" #include "plugin.h" -#if defined(KERNEL_LINUX) -# define WIRELESS_HAVE_READ 1 -#else -# define WIRELESS_HAVE_READ 0 +#if !KERNEL_LINUX +# error "No applicable input method." #endif #define WIRELESS_PROC_FILE "/proc/net/wireless" -#if WIRELESS_HAVE_READ #if 0 static double wireless_dbm_to_watt (double dbm) { @@ -58,13 +55,13 @@ static void wireless_submit (const char *plugin_instance, const char *type, vl.values = values; vl.values_len = 1; - vl.time = time (NULL); - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "wireless"); - strncpy (vl.plugin_instance, plugin_instance, + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "wireless", sizeof (vl.plugin)); + sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); + sstrncpy (vl.type, type, sizeof (vl.type)); - plugin_dispatch_values (type, &vl); + plugin_dispatch_values (&vl); } /* void wireless_submit */ #define POWER_MIN -90.0 @@ -131,16 +128,20 @@ static int wireless_read (void) power = 1.0; /* invalid */ else if ((power >= 0.0) && (power <= 100.0)) power = wireless_percent_to_power (power); - else if (power > 100.0) + else if ((power > 100.0) && (power <= 256.0)) + power = power - 256.0; + else if (power > 0.0) power = 1.0; /* invalid */ /* noise [dBm] < 0.0 */ - noise = strtod (fields[3], &endptr); - if (fields[3] == endptr) + noise = strtod (fields[4], &endptr); + if (fields[4] == endptr) noise = 1.0; /* invalid */ else if ((noise >= 0.0) && (noise <= 100.0)) noise = wireless_percent_to_power (noise); - else if (noise > 100.0) + else if ((noise > 100.0) && (noise <= 256.0)) + noise = noise - 256.0; + else if (noise > 0.0) noise = 1.0; /* invalid */ wireless_submit (device, "signal_quality", quality); @@ -160,11 +161,8 @@ static int wireless_read (void) return (0); } /* int wireless_read */ -#endif /* WIRELESS_HAVE_READ */ void module_register (void) { -#if WIRELESS_HAVE_READ plugin_register_read ("wireless", wireless_read); -#endif /* WIRELESS_HAVE_READ */ } /* void module_register */