Author: felix
Date: Mon Apr 27 06:51:37 2009
New Revision: 5490
URL: http://svn.slimdevices.com/jive?rev=5490&view=rev
Log:
Bug: 11192
Description: Get SNR from wireless driver using ioctl instead of running a
shell command.
Modified:
7.3/trunk/squeezeplay/src/squeezeplay_jive/share/jive/net/Wireless.lua
7.3/trunk/squeezeplay/src/squeezeplay_jive/src/jive_wireless.c
Modified: 7.3/trunk/squeezeplay/src/squeezeplay_jive/share/jive/net/Wireless.lua
URL:
http://svn.slimdevices.com/jive/7.3/trunk/squeezeplay/src/squeezeplay_jive/share/jive/net/Wireless.lua?rev=5490&r1=5489&r2=5490&view=diff
==============================================================================
--- 7.3/trunk/squeezeplay/src/squeezeplay_jive/share/jive/net/Wireless.lua
(original)
+++ 7.3/trunk/squeezeplay/src/squeezeplay_jive/share/jive/net/Wireless.lua Mon
Apr 27 06:51:37 2009
@@ -551,15 +551,21 @@
function getSNR(self)
- local f = io.popen("/sbin/iwpriv " .. self.interface .. " getSNR 1")
- if f == nil then
+ if not self.t_sock then
return 0
end
- local t = f:read("*all")
- f:close()
-
- return tonumber(string.match(t, ":(%d+)"))
+ local t = self.t_sock:getSNR()
+ if t == nil then
+ log:error("getSNR() failed")
+ return 0
+ end
+
+ -- t[1] : Beacon non-average
+ -- t[2] : Beacon average
+ -- t[3] : Data non-average
+ -- t[4] : Data average
+ return t[2]
end
Modified: 7.3/trunk/squeezeplay/src/squeezeplay_jive/src/jive_wireless.c
URL:
http://svn.slimdevices.com/jive/7.3/trunk/squeezeplay/src/squeezeplay_jive/src/jive_wireless.c?rev=5490&r1=5489&r2=5490&view=diff
==============================================================================
--- 7.3/trunk/squeezeplay/src/squeezeplay_jive/src/jive_wireless.c (original)
+++ 7.3/trunk/squeezeplay/src/squeezeplay_jive/src/jive_wireless.c Mon Apr 27
06:51:37 2009
@@ -241,6 +241,54 @@
};
+static int jive_net_wlan_get_snr( lua_State *L) {
+ struct wlan_data *data;
+ struct iwreq wrq;
+
+ int buf[4];
+
+ // These two values work with Marvell wireless drivers
+ // They might be different for other wireless drivers
+ int ioctl_val = 0x8BFD;
+ int subioctl_val = 0xA;
+
+ data = (struct wlan_data *) lua_touserdata( L, 1);
+
+ if( !data->fd) {
+ lua_pushnil( L);
+ lua_pushstring( L, "wlan closed");
+ return 2;
+ }
+
+ strncpy( wrq.ifr_ifrn.ifrn_name, "eth0", IFNAMSIZ);
+
+ memset( buf, 0, sizeof(buf));
+
+ wrq.u.data.pointer = buf;
+ wrq.u.data.length = 0; // We want all four values
+ wrq.u.data.flags = subioctl_val;
+
+ if( ioctl( data->fd, ioctl_val, &wrq) < 0) {
+ lua_pushnil( L);
+ lua_pushfstring( L, "ioctl error: %s", strerror( errno));
+ return 2;
+ }
+
+ lua_newtable( L);
+
+ lua_pushinteger( L, buf[0]);
+ lua_rawseti( L, -2, 1);
+ lua_pushinteger( L, buf[1]);
+ lua_rawseti( L, -2, 2);
+ lua_pushinteger( L, buf[2]);
+ lua_rawseti( L, -2, 3);
+ lua_pushinteger( L, buf[3]);
+ lua_rawseti( L, -2, 4);
+
+ return 1;
+}
+
+
static const struct luaL_Reg jive_net_wpa_ctrl_lib[] = {
{ "open", jive_net_wpa_ctrl_open },
{ NULL, NULL }
@@ -271,6 +319,9 @@
lua_pushcfunction(L, jive_net_wlan_set_power);
lua_setfield(L, -2, "setPower");
+ lua_pushcfunction(L, jive_net_wlan_get_snr);
+ lua_setfield(L, -2, "getSNR");
+
lua_pushvalue(L, -1);
lua_setfield(L, -2, "__index");
_______________________________________________
Jive-checkins mailing list
[email protected]
http://lists.slimdevices.com/mailman/listinfo/jive-checkins