Skip to content
Browse files

Remove struct, use int

  • Loading branch information...
1 parent 14e36d4 commit 0a9c4b8a5ff52115f6650538d6f1804c8cfc1d95 @moetunes committed
Showing with 27 additions and 37 deletions.
  1. +5 −11 status.c
  2. +22 −26 updown.c
View
16 status.c
@@ -23,10 +23,6 @@ typedef struct {
char out[6];
} CPUS;
-struct net_speed {
- unsigned int recv;
-};
-
#define OUT_TO_CONSOLE 1 // Zero to print in terminal, One to set root windows name
#define WIFI "wlan0"
#define CPUFILE "/proc/stat"
@@ -58,11 +54,9 @@ static char temps_ret[15];
static char time_ret[25];
static char daydate_ret[7];
static char uptime_ret[15];
-
-#include "fuzzy-time.c"
-
static double ti, tj;
-static struct net_speed ns[2];
+static unsigned int recd;
+#include "fuzzy-time.c"
// Make sure this value is at least the number of cpus
static CPUS cpus[4];
@@ -163,7 +157,7 @@ void update_speed() {
vals = strchr(line, ':');
++vals;
- last_recv = ns->recv;
+ last_recv = recd;
/* bytes packets errs drop fifo frame compressed multicast|bytes ... */
sscanf(vals, "%d %*d %*d %*d %*d %*d %*d %*d %*d",
@@ -171,10 +165,10 @@ void update_speed() {
/* if recv is less than last time, an overflow happened */
if (down < last_recv) last_recv = 0;
- else ns->recv = down;
+ else recd = down;
/* calculate speeds */
- down_speed = (ns->recv - last_recv) / delta;
+ down_speed = (recd - last_recv) / delta;
if(down_speed > 1000000.0)
sprintf(speed_ret, "%.2f MB/s", down_speed/1000000.0);
else if(down_speed > 1000)
View
48 updown.c
@@ -10,16 +10,12 @@
#define DEVICE "wlan0"
#define NETSPEEDFILE "/proc/net/dev"
-struct net_speed {
- unsigned int recv, trans;
-};
-
static void update_speed();
static void update_speed2();
static char speed_ret[50];
-static double ti, tj;
-static struct net_speed ns[2];
+static double tj;
+static unsigned int recd, sent;
double time_so_far() {
struct timeval tp;
@@ -47,45 +43,45 @@ void update_speed() {
fclose(f1);
char *vals;
- unsigned int last_recv, last_trans;
+ unsigned int last_recd, last_trans;
unsigned int down, up;
double delta, down_speed, up_speed, current;
/* get delta */
current = time_so_far();
- delta = current - ti;
+ delta = current - tj;
if (delta <= 0.0001) {
sprintf(speed_ret, "NET FAIL T");
return;
}
- ti = current;
+ tj = current;
vals = strchr(line, ':');
++vals;
- last_recv = ns->recv;
- //last_trans = ns->trans;
+ last_recd = recd;
+ //last_trans = sent;
/* bytes packets errs drop fifo frame compressed multicast|bytes ... */
sscanf(vals, "%d %*d %*d %*d %*d %*d %*d %*d %d",
&down, &up);
- /* if recv or trans is less than last time, an overflow happened */
- if (down < last_recv) {
- last_recv = 0;
+ /* if recd or trans is less than last time, an overflow happened */
+ if (down < last_recd) {
+ last_recd = 0;
} else {
- ns->recv = down;
+ recd = down;
}
if (up < last_trans) {
last_trans = 0;
} else {
- ns->trans = up;
+ sent = up;
}
/* calculate speeds */
- down_speed = (ns->recv - last_recv) / delta;
- //up_speed = (ns->trans - last_trans) / delta;
+ down_speed = (recd - last_recd) / delta;
+ //up_speed = (sent - last_trans) / delta;
if(down_speed > 1000000)
sprintf(speed_ret, "%.2f MB/s %.2f MB/s", down_speed/1000000, up_speed/1000000);
else if(down_speed > 1000)
@@ -112,7 +108,7 @@ void update_speed2() {
fclose(f1);
char *vals;
- unsigned int last_recv;
+ unsigned int last_recd;
int down;
double delta, down_speed, current;
@@ -128,22 +124,22 @@ void update_speed2() {
vals = strchr(line, ':');
++vals;
- last_recv = ns->recv;
+ last_recd = recd;
/* bytes packets errs drop fifo frame compressed multicast|bytes ... */
sscanf(vals, "%d %*d %*d %*d %*d %*d %*d %*d %*d",
&down);
- /* if recv is less than last time, an overflow happened */
- if (down < last_recv) {
- last_recv = 0;
+ /* if recd is less than last time, an overflow happened */
+ if (down < last_recd) {
+ last_recd = 0;
} else {
- ns->recv = down;
+ recd = down;
}
/* calculate speeds */
- down_speed = (ns->recv - last_recv) / delta;
- //printf("DOWN= %d, lr= %d, nsr= %d\n", down, last_recv, ns->recv);
+ down_speed = (recd - last_recd) / delta;
+ //printf("DOWN= %d, lr= %d, nsr= %d\n", down, last_recd, recd);
if(down_speed > 1000000.0)
sprintf(speed_ret, "%.2f MB/s", down_speed/1000000.0);
else if(down_speed > 1000)

0 comments on commit 0a9c4b8

Please sign in to comment.
Something went wrong with that request. Please try again.