1
0

Return actual percentage for wifi_perc()

Implement basic percentage calculation for wifi_perc. With this
commit, the function returns correct percentage, since the max
of what /proc/net/wireless returns is 70.
This commit is contained in:
parazyd 2017-10-24 11:03:17 +02:00 committed by Aaron Marcher
parent 7246dc4381
commit d2988c72e3
No known key found for this signature in database
GPG Key ID: 74B048E5C2474F9A

View File

@ -14,7 +14,9 @@
const char * const char *
wifi_perc(const char *iface) wifi_perc(const char *iface)
{ {
int i, perc; int i, cur;
float perc;
int total = 70; /* the max of /proc/net/wireless */
char *p, *datastart; char *p, *datastart;
char path[PATH_MAX]; char path[PATH_MAX];
char status[5]; char status[5];
@ -50,9 +52,11 @@ wifi_perc(const char *iface)
return NULL; return NULL;
datastart = (datastart+(strlen(iface)+1)); datastart = (datastart+(strlen(iface)+1));
sscanf(datastart + 1, " %*d %d %*d %*d %*d %*d %*d %*d %*d %*d", &perc); sscanf(datastart + 1, " %*d %d %*d %*d %*d %*d %*d %*d %*d %*d", &cur);
return bprintf("%d", perc); perc = (float)cur / total * 100.0;
return bprintf("%.0f", perc);
} }
const char * const char *