[Goodies-commits] r2323 - in xfce4-wavelan-plugin/trunk: . panel-plugin
James Westby
jamesw at xfce.org
Tue Jan 9 01:07:48 CET 2007
Author: jamesw
Date: 2007-01-09 00:07:48 +0000 (Tue, 09 Jan 2007)
New Revision: 2323
Modified:
xfce4-wavelan-plugin/trunk/ChangeLog
xfce4-wavelan-plugin/trunk/panel-plugin/wi_linux.c
Log:
* Fix a bug in which the signal strength was incorrectly calculated, due to
a max value being assumed that is not correct and usually too small.
This change will probably reduce the signal strength reported, but that is
because it was incorrect before. Bug 1499.
* Add config.h to panel-plugin/wi_linux.c to enable the trace debugging
Modified: xfce4-wavelan-plugin/trunk/ChangeLog
===================================================================
--- xfce4-wavelan-plugin/trunk/ChangeLog 2007-01-08 23:47:16 UTC (rev 2322)
+++ xfce4-wavelan-plugin/trunk/ChangeLog 2007-01-09 00:07:48 UTC (rev 2323)
@@ -1,3 +1,12 @@
+2007-01-09 00:04 james
+
+ * Fix a bug in which the signal strength was incorrectly calculated, due to
+ a max value being assumed that is not correct and usually too small.
+ This change will probably reduce the signal strength reported, but that is
+ because it was incorrect before. Bug 1499.
+ * Add config.h to panel-plugin/wi_linux.c to enable the trace debugging
+ properly.
+
2007-01-07 23:28 james
* Remove an unused variable that caused a failure with -Werror.
Modified: xfce4-wavelan-plugin/trunk/panel-plugin/wi_linux.c
===================================================================
--- xfce4-wavelan-plugin/trunk/panel-plugin/wi_linux.c 2007-01-08 23:47:16 UTC (rev 2322)
+++ xfce4-wavelan-plugin/trunk/panel-plugin/wi_linux.c 2007-01-09 00:07:48 UTC (rev 2323)
@@ -27,6 +27,10 @@
#if defined(__linux__)
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
#include <libxfce4util/libxfce4util.h>
#include <math.h>
@@ -86,6 +90,37 @@
g_free(device);
}
+static double
+wi_get_max_quality(struct wi_device *device)
+{
+ struct iwreq wreq;
+ double max_qual = 92.0;
+ char range_buf[sizeof(struct iw_range) * 2]; // wireless tools says it is
+ // large enough.
+ int result;
+
+ /* Set interface name */
+ strncpy(wreq.ifr_name, device->interface, IFNAMSIZ);
+
+ memset(range_buf, 0, sizeof(range_buf));
+
+ wreq.u.data.pointer = (caddr_t) range_buf;
+ wreq.u.data.length = sizeof(range_buf);
+ wreq.u.data.flags = 0;
+ if ((result = ioctl(device->socket, SIOCGIWRANGE, &wreq)) < 0) {
+ TRACE ("Couldn't get range information, taking default.");
+ } else {
+ struct iw_range *range = (struct iw_range *) range_buf;
+ max_qual = range->max_qual.qual;
+ if (max_qual <= 0) {
+ TRACE ("Got a negative value for max_qual, returning to default.");
+ max_qual = 92.0;
+ }
+ }
+
+ return max_qual;
+}
+
int
wi_query(struct wi_device *device, struct wi_stats *stats)
{
@@ -97,6 +132,7 @@
double link;
long level;
int result;
+ double max_qual = 92.0;
struct iwreq wreq;
struct iw_statistics wstats;
@@ -145,6 +181,9 @@
}
level = wstats.qual.level;
link = wstats.qual.qual;
+
+ max_qual = wi_get_max_quality(device);
+
#else /* WIRELESS_EXT <= 11 */
/* Get interface stats through /proc/net/wireless */
if ((fp = fopen("/proc/net/wireless", "r")) == NULL) {
@@ -181,8 +220,9 @@
if (link <= 0)
stats->ws_quality = 0;
else {
- /* thanks to google for this hint */
- stats->ws_quality = (int)rint(log(link) / log(92.0) * 100.0);
+ /* thanks to google and wireless tools for this hint */
+ stats->ws_quality = (int)rint(log(link) / log(max_qual) * 100.0);
+ TRACE ("Quality: %2f, max quality: %2f", link, max_qual);
}
return(WI_OK);
More information about the Goodies-commits
mailing list