From 366a4ce8b7361eb0155514d2d55bb5201c357a12 Mon Sep 17 00:00:00 2001 From: Shibby Date: Mon, 20 Apr 2015 19:28:01 +0200 Subject: [PATCH] GUI: add Wireless Temperature on Status page feature cherry-picked from Hyzoom (BWQ) sources - THX --- release/src-rt-6.x.4708/router/httpd/misc.c | 8 +- release/src-rt-6.x.4708/router/httpd/tomato.h | 1 + release/src-rt-6.x.4708/router/httpd/wl.c | 97 ++++++++++++++++++++++ release/src-rt-6.x.4708/router/www/status-data.jsx | 1 + .../src-rt-6.x.4708/router/www/status-overview.asp | 4 +- 5 files changed, 108 insertions(+), 3 deletions(-) diff --git a/release/src-rt-6.x.4708/router/httpd/misc.c b/release/src-rt-6.x.4708/router/httpd/misc.c index 3c6ddbb7de..d157262830 100644 --- a/release/src-rt-6.x.4708/router/httpd/misc.c +++ b/release/src-rt-6.x.4708/router/httpd/misc.c @@ -517,7 +517,9 @@ void asp_sysinfo(int argc, char **argv) char cpu_model[64]; char bogomips[8]; char cpuclk[8]; + char wl_tempsense[128]; + get_wl_tempsense(wl_tempsense); get_cpuinfo(system_type, cpu_model, bogomips, cpuclk); web_puts("\nsysinfo = {\n"); @@ -544,7 +546,8 @@ void asp_sysinfo(int argc, char **argv) "\tsystemtype: '%s',\n" "\tcpumodel: '%s',\n" "\tbogomips: '%s',\n" - "\tcpuclk: '%s'", + "\tcpuclk: '%s',\n" + "\twlsense: '%s'", si.uptime, reltime(s, si.uptime), si.loads[0], si.loads[1], si.loads[2], @@ -557,7 +560,8 @@ void asp_sysinfo(int argc, char **argv) system_type, cpu_model, bogomips, - cpuclk); + cpuclk, + wl_tempsense); if ((a = fopen(procstat, "r")) != NULL) { fgets(sa, sizeof(sa), a); diff --git a/release/src-rt-6.x.4708/router/httpd/tomato.h b/release/src-rt-6.x.4708/router/httpd/tomato.h index 2b6ab3d7fe..ac68ce795a 100644 --- a/release/src-rt-6.x.4708/router/httpd/tomato.h +++ b/release/src-rt-6.x.4708/router/httpd/tomato.h @@ -37,6 +37,7 @@ extern int rboot; extern void exec_service(const char *action); extern void wi_generic(char *url, int len, char *boundary); extern void common_redirect(void); +extern char* get_wl_tempsense(char *); extern const char *resmsg_get(void); extern void resmsg_set(const char *msg); diff --git a/release/src-rt-6.x.4708/router/httpd/wl.c b/release/src-rt-6.x.4708/router/httpd/wl.c index ed98561a7c..71444dabd7 100644 --- a/release/src-rt-6.x.4708/router/httpd/wl.c +++ b/release/src-rt-6.x.4708/router/httpd/wl.c @@ -759,3 +759,100 @@ void asp_wlcountries(int argc, char **argv) } web_puts("];\n"); } + +/* + Get temperature of wireless chip + bwq518. Copyright 2013 +*/ +char* get_wl_tempsense(char *buf) +{ + char *lan_ifnames; + char *p; + char *ifname; + char tmpfile[32], s[WLC_IOCTL_SMLEN],temp[128], band[WLC_IOCTL_SMLEN]; + int b5G, b2G; + unsigned *cur_temp; + int ret = 0, len, i, n; + + strcpy(buf,""); + if ((lan_ifnames = strdup(nvram_safe_get("lan_ifnames"))) != NULL) { + p = lan_ifnames; + while ((ifname = strsep(&p, " ")) != NULL) { + while (*ifname == ' ') ++ifname; + trimstr(ifname); + if ((*ifname == 0) || (strncasecmp(ifname, "eth",3) != 0)) continue; + + bzero(s, sizeof(s)); + bzero(temp, sizeof(temp)); + strcpy(s, "phy_tempsense"); + if ((ret = wl_ioctl(ifname, WLC_GET_VAR, s, sizeof(s))) == 0) + { + cur_temp = (unsigned int*) s; + sprintf(temp, "%d",*cur_temp / 2 + 20); + if ((atoi(temp) <=0) || (atoi(temp)>= 120)) + strcpy(temp, "--"); + } + else strcpy(temp, "--"); + //syslog(LOG_INFO, "wl tempsense:|%s|", temp); + + //get band of ifname + bzero(s, sizeof(s)); + bzero(band, sizeof(band)); + int bandlist[WLC_BAND_ALL]; + if (wl_ioctl(ifname, WLC_GET_BANDLIST, bandlist, sizeof(bandlist)) == 0) + { + //syslog(LOG_INFO, "wl ifname:|%s|, bandlist[0]:|%d|", ifname, bandlist[0]); + if (bandlist[0] == 0) strcpy(band, "--"); + else + { + b5G = 0; + b2G = 0; + for (i = 1; i <= bandlist[0]; i++) + { + switch (bandlist[i]) + { + case WLC_BAND_5G: + b5G = 1; + break; + case WLC_BAND_2G: + b2G = 1; + break; + default: + break; + } + } + if (b5G == 1 && b2G == 1) + strcpy(band,"2.4G/5G"); + else if ( b5G == 0 && b2G == 1) + strcpy(band,"2.4G"); + else if ( b5G == 1 && b2G == 0) + strcpy(band,"5G"); + else // b5G == 0 && b2G == 0 + strcpy(band,"--"); + } // for + } + else strcpy(band,"--"); + //syslog(LOG_INFO, "wl ifname:|%s|, band:|%s|", ifname, band); + if ((strlen(temp) > 0) && (strlen(band) > 0)) + { + if((strcmp(temp,"--") != 0) || (strcmp(band,"--") != 0)) + { + strcat(buf, ifname); + strcat(buf, ": "); + strcat(buf, band); + strcat(buf, " - "); + strcat(buf, temp); + strcat(buf, "°C    "); + } + } + } + free(lan_ifnames); + } + // remove spaces from end + len = strlen(buf); + if(len >= 24) buf[len - 24] = '\0'; + if(len == 0) strcpy(buf,"--"); + else trimstr(buf); + //syslog(LOG_INFO, "wl full info:|%s|", buf); + return buf; +} diff --git a/release/src-rt-6.x.4708/router/www/status-data.jsx b/release/src-rt-6.x.4708/router/www/status-data.jsx index 2acff58882..d8bf6703a9 100644 --- a/release/src-rt-6.x.4708/router/www/status-data.jsx +++ b/release/src-rt-6.x.4708/router/www/status-data.jsx @@ -51,6 +51,7 @@ do { lastjiffiesidle = jiffylist[3]; stats.cpupercent = lastjiffiesusage.toFixed(2) + '%'; + stats.wlsense = sysinfo.wlsense; a = sysinfo.totalram; b = sysinfo.totalfreeram; diff --git a/release/src-rt-6.x.4708/router/www/status-overview.asp b/release/src-rt-6.x.4708/router/www/status-overview.asp index d116340831..8a76e5973c 100644 --- a/release/src-rt-6.x.4708/router/www/status-overview.asp +++ b/release/src-rt-6.x.4708/router/www/status-overview.asp @@ -237,6 +237,7 @@ function show() { c('cpu', stats.cpuload); c('cpupercent', stats.cpupercent); + c('wlsense', stats.wlsense); c('uptime', stats.uptime); c('time', stats.time); c('wanip', stats.wanip); @@ -378,7 +379,8 @@ createFieldTable('', [ { title: 'CPU Load (1 / 5 / 15 mins)', rid: 'cpu', text: stats.cpuload }, { title: 'Total / Free Memory', rid: 'memory', text: stats.memory }, { title: 'Total / Free Swap', rid: 'swap', text: stats.swap, hidden: (stats.swap == '') }, - { title: 'Total / Free NVRAM', text: scaleSize(nvstat.size) + ' / ' + scaleSize(nvstat.free) + ' (' + (a).toFixed(2) + '%)' } + { title: 'Total / Free NVRAM', text: scaleSize(nvstat.size) + ' / ' + scaleSize(nvstat.free) + ' (' + (a).toFixed(2) + '%)' }, + { title: 'Wireless Temperature', rid: 'wlsense', text: stats.wlsense } ]); -- 2.11.4.GIT