#include #include #include #ifdef IRIX #include #endif #include #include #include #include #include "../../shared/sockets.h" #include "../../shared/LL.h" #include "main.h" #include "mode.h" #include "mem.h" //the kewl utilisation info struct struct utilinfo { //utilisation unsigned long llUp; unsigned long llDown; unsigned long llUpSpeed; unsigned long llDownSpeed; }; int utilinfo_fd = 0; static char device[10]; //some boring function.. long tvdiff(struct timeval a,struct timeval b) { return (((b.tv_sec-a.tv_sec)*1000000)+(b.tv_usec-a.tv_usec)); } //TODO: ugly function - know what a codingstandard is?? :-) static void get_util_info(struct utilinfo *result) { // int i, res; char *bufptr; static struct timeval tv,tvprev; static unsigned long long UpPrev,DownPrev; char intf[10]; unsigned long rbyt,rpac,rerr,rdrop,rfifo,rframe,rcom,rmulti=0; unsigned long tbyt,tpac,terr,tdrop,tfifo,tcolls,tcarr,tcom=0; char bagger[5000]; char *start; unsigned long diff; reread(utilinfo_fd, "get_utilinfo:"); start=NULL; if (buffer) start=strstr(buffer,device); if (start) { sscanf(start,"%s %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu\n",intf,&rbyt,&rpac,&rerr,&rdrop,&rfifo,&rframe,&rcom,&rmulti, &tbyt,&tpac,&terr,&tdrop,&tfifo,&tcolls,&tcarr,&tcom); printf(" net=(%s,%lu,%lu)\n",intf,rbyt,tbyt); } gettimeofday(&tv,NULL); diff=tvdiff(tvprev,tv); result->llUp=tbyt; result->llDown=rbyt; result->llUpSpeed=((tbyt-UpPrev)*1000000)/(diff); result->llDownSpeed=((rbyt-DownPrev)*1000000)/(diff); //debug info: printf(" net=(%s %lu %lu %lu %lu )\n",intf,result->llUp,result->llDown,result->llUpSpeed,result->llDownSpeed); tvprev=tv; UpPrev=tbyt; DownPrev=rbyt; /* result[0].total = getentry("MemTotal:", buffer); //result[0].free = getentry("MemFree:", buffer); re/sult[0].shared = getentry("MemShared:", buffer); result[0].buffers = getentry("Buffers:", buffer); result[0].cache = getentry("Cached:", buffer); result[1].total = getentry("SwapTotal:", buffer); result[1].free = getentry("SwapFree:", buffer); */ } int net_init() { if(!utilinfo_fd) { utilinfo_fd = open("/proc/net/dev",O_RDONLY); } strcpy(device,"eth0:"); return 0; } int net_close() { //i//f(uinfo_fd) // meminfo_fd = open("/proc/meminfo",O_RDONLY); close(utilinfo_fd); utilinfo_fd = 0; return 0; } ///////////////////////////////////////////////////////////////////////// // Mem Screen displays info about memory and swap usage... // int net_screen(int rep, int display) { int n; struct utilinfo util; static int first = 1; static int which_title=0; float value; if(first) { first = 0; sock_send_string(sock, "screen_add M\n"); sprintf(buffer, "screen_set M name {Memory & Swap: %s}\n", host); sock_send_string(sock, buffer); if(lcd_hgt >= 4) { sock_send_string(sock, "widget_add M title title\n"); sock_send_string(sock, "widget_set M title { MEM -==- SWAP}\n"); sock_send_string(sock, "widget_add M totl string\n"); sock_send_string(sock, "widget_add M used string\n"); sock_send_string(sock, "widget_set M totl 9 2 Totl\n"); sock_send_string(sock, "widget_set M used 9 3 Free\n"); sock_send_string(sock, "widget_add M EF string\n"); sock_send_string(sock, "widget_set M EF 1 4 {E F E F}\n"); sock_send_string(sock, "widget_add M memused string\n"); sock_send_string(sock, "widget_add M swapused string\n"); //sock_send_string(sock, "widget_set M memgauge 2 4 0\n"); //sock_send_string(sock, "widget_set M swapgauge 13 4 0\n"); } else { sock_send_string(sock, "widget_add M m string\n"); sock_send_string(sock, "widget_add M s string\n"); if(lcd_wid >= 20) { sock_send_string(sock, "widget_set M m 1 1 {M [ ]}\n"); sock_send_string(sock, "widget_set M s 1 2 {S [ ]}\n"); } else { sock_send_string(sock, "widget_set M m 1 1 {M [ ]}\n"); sock_send_string(sock, "widget_set M s 1 2 {S [ ]}\n"); } sock_send_string(sock, "widget_add M mem% string\n"); sock_send_string(sock, "widget_add M swap% string\n"); sock_send_string(sock, "widget_set M mem% 16 1 { 0.0%}\n"); sock_send_string(sock, "widget_set M swap% 16 2 { 0.0%}\n"); //sock_send_string(sock, "widget_set M memgauge 8 1 0\n"); //sock_send_string(sock, "widget_set M swapgauge 8 2 0\n"); } sock_send_string(sock, "widget_add M memtotl string\n"); sock_send_string(sock, "widget_add M swaptotl string\n"); sock_send_string(sock, "widget_add M memgauge hbar\n"); sock_send_string(sock, "widget_add M swapgauge hbar\n"); //sock_send_string(sock, "\n"); } //first get_util_info(&util); // flip the title back and forth... if(which_title & 4) { sprintf(buffer, "widget_set M title {%s}\n", host); sock_send_string(sock, buffer); } else sock_send_string(sock, "widget_set M title { MEM -==- SWAP}\n"); which_title = (which_title + 1)&7; // Total memory //sprintf(tmp, "widget_set M memtotl 1 2 {%6dk}\n", mem[0].total); if(display) sock_send_string(sock, tmp); return 0; } // End mem_screen()