1 #include "jDockApp/jDockApp.h"
2 #include "jDockApp/colors.h"
19 printf("wmjiface version %s was built on %s.\n\n", VERSION
, BDATE
);
20 printf("-s <sec>: Seconds between executions of ifacechk\n");
21 printf("-o : Show the traffic headed out instead.\n");
22 printf("-D : Doommaker's Show-Both (in&out traf simultaneously).\n");
23 printf("-A : Use approximate exponential averaging.\n");
24 printf("-a <num>: Alpha for the exp. avg. {default %f}.\n", alpha
);
25 printf("-b <num>: Beta: subst for alpha if bps==0 {default %f}.\n", beta
);
26 printf("-l <num>: Skip <num> lines before showing the first device.\n");
27 printf("-1 <num>: High-water-mark 1 (red color) {default %i B/s}.\n",hw1
);
28 printf("-2 <num>: High-water-mark 2 (red color) {default %i B/s}.\n",hw2
);
33 void setup(int argc
, char** argv
) {
35 int c
; // thanx to a PowerPC user named Carine Bournez
38 while( -1 != (c
= getopt(argc
, argv
, "hoADua:b:s:l:1:2:"))) {
41 case 'h': show_help();
43 case 'o': out
= 1; break;
44 case 'A': use_expavg
= 1; break;
45 case 'D': showboth
= 1; break;
47 case 'a': alpha
=atof(optarg
); break;
48 case 'b': beta
=atof(optarg
); break;
50 case 's': i
=atoi(optarg
); break;
51 case 'l': skip
=atoi(optarg
); break;
53 case '1': hw1
=atoi(optarg
); break;
54 case '2': hw2
=atoi(optarg
); break;
58 set_update_delay(delay
); /* seconds */
59 set_loop_delay(1000); /* mu seconds */
70 void do_print_one_dev(char iface
[5], char io
, int bps_
, int row
) {
75 jpprintf(0, row
, GREEN
, "%c", io
);
76 if(iface
[0] >= '0' && iface
[0] <= '9') {
77 jprintf(RED
, "%s", "unkn");
79 jprintf(BLUE
, "%s", iface
);
81 jprintf(CYAN
, ":", io
);
84 if(bps_
> 1000) { display
= (bps_
)/1024.0; letter
= 'k'; }
85 else { display
= bps_
; letter
= ' '; }
87 display
+= 0.5; /* Round Up */
89 if(!bps_
) { color
= BLUE
; }
90 else if(bps_
< hw1
) { /* 2000 default */ color
= GREEN
; }
91 else if(bps_
< hw2
) { /* 4000 default */ color
= YELLOW
; }
94 if(letter
=='k' && display
<100) {
95 jpprintf(6, row
, color
, "%.1f", display
);
97 jpprintf(6, row
, color
, "%.0f", display
);
100 jprintf(ORANGE
, "%c", letter
);
110 #define Fal0d(X) ((X) ? alpha : beta)
113 FILE *f
= popen("ifacechk", "r");
118 int toshow_in
, toshow_out
;
121 jpprintf(0, 0, YELLOW
, " J-Iface"); /* title */
122 jpprintf(0, 1, PINK
, "Dev:"); /* desc line */
123 jpprintf(5, 1, PINK
, "bits/s");
125 while(1 + fscanf(f
, "%s%i%i", iface
, &bps_in
, &bps_out
)) {
128 (Fal0d(bps_in
)*bps_in
) + (1-Fal0d(bps_in
))*exp_avg
[IN
][c
];
130 (Fal0d(bps_out
)*bps_out
) + (1-Fal0d(bps_out
))*exp_avg
[OUT
][c
];
131 toshow_in
= exp_avg
[IN
][c
];
132 toshow_out
= exp_avg
[OUT
][c
];
135 toshow_out
= bps_out
;
140 do_print_one_dev(iface
, 'i', toshow_in
, row
++);
141 do_print_one_dev(iface
, 'o', toshow_out
, row
++);
147 (out
) ? toshow_out
: toshow_in
,
161 void do_button_release() {