From d7c2edb43e73bc440c0adc6c1c445570b2aae698 Mon Sep 17 00:00:00 2001 From: reinelt <> Date: Mon, 19 Feb 2001 00:15:46 +0000 Subject: [lcd4linux @ 2001-02-19 00:15:46 by reinelt] integrated mail and seti client major rewrite of parser and tokenizer to support double-byte tokens --- Makefile.am | 1 + Makefile.in | 11 ++--- lcd4linux.conf.sample | 23 ++++++---- mail.c | 9 +++- parser.c | 67 ++++++++++++++++++---------- parser.h | 19 +++++--- processor.c | 121 +++++++++++++++++++++++++++++++------------------- seti.c | 11 +++-- seti.h | 9 +++- 9 files changed, 175 insertions(+), 96 deletions(-) diff --git a/Makefile.am b/Makefile.am index e57454b..9cfac63 100644 --- a/Makefile.am +++ b/Makefile.am @@ -20,6 +20,7 @@ parser.c parser.h \ processor.c processor.h \ system.c system.h \ isdn.c isdn.h \ +mail.c mail.h \ seti.c seti.h \ filter.c filter.h \ udelay.c udelay.h \ diff --git a/Makefile.in b/Makefile.in index 9556e85..3adfe2e 100644 --- a/Makefile.in +++ b/Makefile.in @@ -73,7 +73,7 @@ AM_CFLAGS = $(X_CFLAGS) -D_GNU_SOURCE -Wall lcd4linux_LDFLAGS = $(X_LIBS) @WITH_X_TRUE@lcd4linux_LDADD = -lX11 -lcd4linux_SOURCES = lcd4linux.c debug.c debug.h cfg.c cfg.h lock.c lock.h parser.c parser.h processor.c processor.h system.c system.h isdn.c isdn.h seti.c seti.h filter.c filter.h udelay.c udelay.h display.c display.h pixmap.c pixmap.h fontmap.c fontmap.h Skeleton.c MatrixOrbital.c BeckmannEgle.c HD44780.c Crystalfontz.c Crystalfontz.h SIN.c PalmPilot.c Raster.c XWindow.c +lcd4linux_SOURCES = lcd4linux.c debug.c debug.h cfg.c cfg.h lock.c lock.h parser.c parser.h processor.c processor.h system.c system.h isdn.c isdn.h mail.c mail.h seti.c seti.h filter.c filter.h udelay.c udelay.h display.c display.h pixmap.c pixmap.h fontmap.c fontmap.h Skeleton.c MatrixOrbital.c BeckmannEgle.c HD44780.c Crystalfontz.c Crystalfontz.h SIN.c PalmPilot.c Raster.c XWindow.c EXTRA_DIST = lcd4linux.conf.sample lcd4kde.conf lcd4linux.kdelnk lcd4linux.xpm lcd4linux.lsm CREDITS FAQ TODO README.Drivers README.MatrixOrbital README.HD44780 README.Crystalfontz README.X11 README.KDE README.Raster @@ -93,8 +93,8 @@ X_LIBS = @X_LIBS@ X_EXTRA_LIBS = @X_EXTRA_LIBS@ X_PRE_LIBS = @X_PRE_LIBS@ lcd4linux_OBJECTS = lcd4linux.o debug.o cfg.o lock.o parser.o \ -processor.o system.o isdn.o seti.o filter.o udelay.o display.o pixmap.o \ -fontmap.o Skeleton.o MatrixOrbital.o BeckmannEgle.o HD44780.o \ +processor.o system.o isdn.o mail.o seti.o filter.o udelay.o display.o \ +pixmap.o fontmap.o Skeleton.o MatrixOrbital.o BeckmannEgle.o HD44780.o \ Crystalfontz.o SIN.o PalmPilot.o Raster.o XWindow.o @WITH_X_TRUE@lcd4linux_DEPENDENCIES = CFLAGS = @CFLAGS@ @@ -113,8 +113,9 @@ DEP_FILES = .deps/BeckmannEgle.P .deps/Crystalfontz.P .deps/HD44780.P \ .deps/MatrixOrbital.P .deps/PalmPilot.P .deps/Raster.P .deps/SIN.P \ .deps/Skeleton.P .deps/XWindow.P .deps/cfg.P .deps/debug.P \ .deps/display.P .deps/filter.P .deps/fontmap.P .deps/isdn.P \ -.deps/lcd4linux.P .deps/lock.P .deps/parser.P .deps/pixmap.P \ -.deps/processor.P .deps/seti.P .deps/system.P .deps/udelay.P +.deps/lcd4linux.P .deps/lock.P .deps/mail.P .deps/parser.P \ +.deps/pixmap.P .deps/processor.P .deps/seti.P .deps/system.P \ +.deps/udelay.P SOURCES = $(lcd4linux_SOURCES) OBJECTS = $(lcd4linux_OBJECTS) diff --git a/lcd4linux.conf.sample b/lcd4linux.conf.sample index fac0770..f4166b4 100644 --- a/lcd4linux.conf.sample +++ b/lcd4linux.conf.sample @@ -1,7 +1,7 @@ -#Display LCD2041 -#Port /dev/ttyS2 -#Speed 19200 -#Contrast 160 +Display LCD2041 +Port /dev/ttyS2 +Speed 19200 +Contrast 160 #Display HD44780 #Port 0x378 @@ -41,11 +41,13 @@ #halfground \#90c000 #background \#a0d000 -Display SIN -Port /dev/tty9 +#Display SIN +#Port /dev/tty9 Row1 "Disk%dm $R10dr+dw" Row2 "Net %nm $R10nr+nw" +Row3 "%s1 %s2 %s3" +Row4 "%hc %ht %e1" #Row1 "*** %o %v ***" #Row2 "%p CPU %r MB RAM" @@ -70,14 +72,17 @@ Tau 500 Overload 2.0 -Sensor1 /proc/sys/dev/sensors/w83781d-isa-0290/temp1 +SetiDir /etc/setiathome +Mailbox1 /var/spool/mail/michii + +Sensor1 /proc/sys/dev/sensors/as99127f-i2c-0-2d/temp1 Sensor1_min 30 Sensor1_max 50 -Sensor2 /proc/sys/dev/sensors/w83781d-isa-0290/temp2 +Sensor2 /proc/sys/dev/sensors/as99127f-i2c-0-2d/temp2 Sensor2_min 30 Sensor2_max 50 -Sensor3 /proc/sys/dev/sensors/w83781d-isa-0290/temp3 +Sensor3 /proc/sys/dev/sensors/as99127f-i2c-0-2d/temp3 Sensor3_min 30 Sensor3_max 50 diff --git a/mail.c b/mail.c index 87bb4cc..408398c 100644 --- a/mail.c +++ b/mail.c @@ -1,4 +1,4 @@ -/* $Id: mail.c,v 1.1 2001/02/18 22:11:34 reinelt Exp $ +/* $Id: mail.c,v 1.2 2001/02/19 00:15:46 reinelt Exp $ * * email specific functions * @@ -20,6 +20,11 @@ * * * $Log: mail.c,v $ + * Revision 1.2 2001/02/19 00:15:46 reinelt + * + * integrated mail and seti client + * major rewrite of parser and tokenizer to support double-byte tokens + * * Revision 1.1 2001/02/18 22:11:34 reinelt * *** empty log message *** * @@ -138,7 +143,7 @@ int Mail (int index, int *num) } fclose (fstr); } - *cnt=v1; + *num=v1; return (0); } diff --git a/parser.c b/parser.c index 9bf856e..2275923 100644 --- a/parser.c +++ b/parser.c @@ -1,4 +1,4 @@ -/* $Id: parser.c,v 1.9 2001/02/16 08:23:09 reinelt Exp $ +/* $Id: parser.c,v 1.10 2001/02/19 00:15:46 reinelt Exp $ * * row definition parser * @@ -20,6 +20,11 @@ * * * $Log: parser.c,v $ + * Revision 1.10 2001/02/19 00:15:46 reinelt + * + * integrated mail and seti client + * major rewrite of parser and tokenizer to support double-byte tokens + * * Revision 1.9 2001/02/16 08:23:09 reinelt * * new token 'ic' (ISDN connected) by Carsten Nau @@ -129,24 +134,19 @@ static SYMTAB Symtab[] = {{ "%", T_PERCENT, C_GENERIC, 0 }, { "nw", T_ETH_TX, C_ETH, 1 }, { "nt", T_ETH_TOTAL, C_ETH, 1 }, { "nm", T_ETH_MAX, C_ETH, 1 }, + { "ic", T_ISDN_USED, C_ISDN, 0 }, { "ii", T_ISDN_IN, C_ISDN, 1 }, { "io", T_ISDN_OUT, C_ISDN, 1 }, { "it", T_ISDN_TOTAL, C_ISDN, 1 }, { "im", T_ISDN_MAX, C_ISDN, 1 }, - { "ic", T_ISDN_CONNECT, C_ISDN, 0 }, { "ti", T_PPP_RX, C_PPP, 1 }, { "to", T_PPP_TX, C_PPP, 1 }, { "tt", T_PPP_TOTAL, C_PPP, 1 }, { "tm", T_PPP_MAX, C_PPP, 1 }, - { "s1", T_SENSOR_1, C_SENSOR, 1 }, - { "s2", T_SENSOR_2, C_SENSOR, 1 }, - { "s3", T_SENSOR_3, C_SENSOR, 1 }, - { "s4", T_SENSOR_4, C_SENSOR, 1 }, - { "s5", T_SENSOR_5, C_SENSOR, 1 }, - { "s6", T_SENSOR_6, C_SENSOR, 1 }, - { "s7", T_SENSOR_7, C_SENSOR, 1 }, - { "s8", T_SENSOR_8, C_SENSOR, 1 }, - { "s9", T_SENSOR_9, C_SENSOR, 1 }, + { "hc", T_SETI_PRC, C_SETI, 1 }, + { "ht", T_SETI_CPU, C_SETI, 0 }, + { "e*", T_MAIL, C_MAIL, 0 }, + { "s*", T_SENSOR, C_SENSOR, 1 }, { "", -1, 0 }}; static int bar_type (char tag) @@ -165,16 +165,30 @@ static int bar_type (char tag) } } -static TOKEN get_token (char *s, char **p, int bar, int usage[]) +static int get_token (char *s, char **p, int bar, int usage[]) { - int i; + char c; + int i, l; + for (i=0; Symtab[i].token!=-1; i++) { - int l=strlen(Symtab[i].symbol); if (bar && !Symtab[i].bar) continue; - if (strncmp(Symtab[i].symbol, s, l)==0) { + l=strlen(Symtab[i].symbol); + if (Symtab[i].symbol[l-1]=='*') { + if (Symtab[i].token='1' && c<='9') { + *p=s+l; + usage[Symtab[i].token]|=(1<<(c-'0')); + usage[Symtab[i].class]=1; + return Symtab[i].token+(c<<8); + } + } else if (strncmp(Symtab[i].symbol, s, l)==0) { *p=s+l; - usage[Symtab[i].token]++; - usage[Symtab[i].class]++; + usage[Symtab[i].token]=1; + usage[Symtab[i].class]=1; return Symtab[i].token; } } @@ -186,7 +200,7 @@ char *parse_row (char *string, int supported_bars, int usage[]) static char buffer[256]; char *s=string; char *p=buffer; - TOKEN token, token2; + int token, token2; int type, len; do { @@ -197,7 +211,8 @@ char *parse_row (char *string, int supported_bars, int usage[]) error ("WARNING: unknown token <%%%c> in <%s>", *s, string); } else { *p++='%'; - *p++=token; + *p++=token&255; + if (token>256) *p++=token>>8; } break; @@ -239,8 +254,12 @@ char *parse_row (char *string, int supported_bars, int usage[]) *p++='$'; *p++=type; *p++=len; - *p++=token; - if (token2!=-1) *p++=token2; + *p++=token&255; + if (token>256) *p++=token>>8; + if (token2!=-1) { + *p++=token2&255; + if (token>256) *p++=token2>>8; + } break; case '\\': @@ -269,10 +288,10 @@ char *parse_row (char *string, int supported_bars, int usage[]) return buffer; } -char parse_gpo (char *string, int usage[]) +int parse_gpo (char *string, int usage[]) { char *s=string; - TOKEN token=-1; + int token=-1; if (*s=='%') { if ((token=get_token (++s, &s, 0, usage))==-1) { @@ -283,6 +302,6 @@ char parse_gpo (char *string, int usage[]) if (*s!='\0') { error ("WARNING: error while parsing <%s>", string); } - + return token; } diff --git a/parser.h b/parser.h index 8a0072c..1d0e1d3 100644 --- a/parser.h +++ b/parser.h @@ -1,4 +1,4 @@ -/* $Id: parser.h,v 1.7 2001/02/16 08:23:09 reinelt Exp $ +/* $Id: parser.h,v 1.8 2001/02/19 00:15:46 reinelt Exp $ * * row definition parser * @@ -20,6 +20,11 @@ * * * $Log: parser.h,v $ + * Revision 1.8 2001/02/19 00:15:46 reinelt + * + * integrated mail and seti client + * major rewrite of parser and tokenizer to support double-byte tokens + * * Revision 1.7 2001/02/16 08:23:09 reinelt * * new token 'ic' (ISDN connected) by Carsten Nau @@ -69,16 +74,18 @@ typedef enum { T_DISK_READ, T_DISK_WRITE, T_DISK_TOTAL, T_DISK_MAX, T_ETH_RX, T_ETH_TX, T_ETH_TOTAL, T_ETH_MAX, T_PPP_RX, T_PPP_TX, T_PPP_TOTAL, T_PPP_MAX, - T_ISDN_IN, T_ISDN_OUT, T_ISDN_TOTAL, T_ISDN_MAX, T_ISDN_CONNECT, - T_SENSOR_1, T_SENSOR_2, T_SENSOR_3, T_SENSOR_4, T_SENSOR_5, - T_SENSOR_6, T_SENSOR_7, T_SENSOR_8, T_SENSOR_9 + T_ISDN_USED, T_ISDN_IN, T_ISDN_OUT, T_ISDN_TOTAL, T_ISDN_MAX, + T_SETI_PRC, T_SETI_CPU, + T_EXTENDED, + T_MAIL, + T_SENSOR } TOKEN; typedef enum { - C_GENERIC, C_MEM, C_LOAD, C_CPU, C_DISK, C_ETH, C_PPP, C_ISDN, C_SENSOR + C_GENERIC, C_MEM, C_LOAD, C_CPU, C_DISK, C_ETH, C_PPP, C_ISDN, C_SETI, C_MAIL, C_SENSOR } CLASS; char *parse_row (char *string, int supported_bars, int usage[]); -char parse_gpo (char *string, int usage[]); +int parse_gpo (char *string, int usage[]); #endif diff --git a/processor.c b/processor.c index 396ec41..0687fc6 100644 --- a/processor.c +++ b/processor.c @@ -1,4 +1,4 @@ -/* $Id: processor.c,v 1.13 2001/02/16 14:15:11 reinelt Exp $ +/* $Id: processor.c,v 1.14 2001/02/19 00:15:46 reinelt Exp $ * * main data processing * @@ -20,6 +20,11 @@ * * * $Log: processor.c,v $ + * Revision 1.14 2001/02/19 00:15:46 reinelt + * + * integrated mail and seti client + * major rewrite of parser and tokenizer to support double-byte tokens + * * Revision 1.13 2001/02/16 14:15:11 reinelt * * fixed type in processor.c @@ -107,7 +112,8 @@ #include "parser.h" #include "display.h" #include "processor.h" - +#include "mail.h" +#include "seti.h" #define ROWS 16 #define GPOS 16 @@ -124,12 +130,14 @@ struct { int read, write, total, max, peak; } disk; struct { int rx, tx, total, max, peak, bytes; } net; struct { int usage, in, out, total, max, peak; } isdn; struct { int rx, tx, total, max, peak; } ppp; +struct { double perc, cput; } seti; +struct { int num; } mail[MAILBOXES]; struct { double val, min, max; } sensor[SENSORS]; static double query (int token) { - switch (token) { + switch (token&255) { case T_MEM_TOTAL: return ram.total; @@ -190,7 +198,7 @@ static double query (int token) return isdn.total; case T_ISDN_MAX: return isdn.max; - case T_ISDN_CONNECT: + case T_ISDN_USED: return isdn.usage; case T_PPP_RX: @@ -202,16 +210,16 @@ static double query (int token) case T_PPP_MAX: return ppp.max; - case T_SENSOR_1: - case T_SENSOR_2: - case T_SENSOR_3: - case T_SENSOR_4: - case T_SENSOR_5: - case T_SENSOR_6: - case T_SENSOR_7: - case T_SENSOR_8: - case T_SENSOR_9: - return sensor[token-T_SENSOR_1+1].val; + case T_SETI_PRC: + return seti.perc; + case T_SETI_CPU: + return seti.cput; + + case T_MAIL: + return mail[(token>>8)-'0'].num; + + case T_SENSOR: + return sensor[(token>>8)-'0'].val; } return 0.0; } @@ -265,16 +273,11 @@ static double query_bar (int token) case T_PPP_TOTAL: return value/ppp.peak/2.0; - case T_SENSOR_1: - case T_SENSOR_2: - case T_SENSOR_3: - case T_SENSOR_4: - case T_SENSOR_5: - case T_SENSOR_6: - case T_SENSOR_7: - case T_SENSOR_8: - case T_SENSOR_9: - i=token-T_SENSOR_1+1; + case T_SETI_PRC: + return value; + + case T_SENSOR: + i=(token>>8)-'0'; return (value-sensor[i].min)/(sensor[i].max-sensor[i].min); } return value; @@ -318,15 +321,7 @@ static void print_token (int token, char **p) case T_LOAD_1: case T_LOAD_2: case T_LOAD_3: - case T_SENSOR_1: - case T_SENSOR_2: - case T_SENSOR_3: - case T_SENSOR_4: - case T_SENSOR_5: - case T_SENSOR_6: - case T_SENSOR_7: - case T_SENSOR_8: - case T_SENSOR_9: + case T_SENSOR: val=query(token); if (val<10.0) *p+=sprintf (*p, "%5.2f", val); @@ -360,14 +355,31 @@ static void print_token (int token, char **p) else *p+=sprintf (*p, " ----"); break; - case T_ISDN_CONNECT: + case T_ISDN_USED: if (isdn.usage) *p+=sprintf (*p, "*"); else *p+=sprintf (*p, " "); break; + case T_SETI_PRC: + val=100.0*query(token); + if (val<100.0) + *p+=sprintf (*p, "%4.1f", val); + else + *p+=sprintf (*p, " 100"); + break; + case T_SETI_CPU: + val=query(token); + *p+=sprintf (*p, "%2d.%2.2d:%2.2d", (int)val/86400, + (int)((int)val%86400)/3600, + (int)(((int)val%86400)%3600)/60 ); + break; + case T_MAIL: + val=query(token); + *p+=sprintf (*p, "%3.0f", val); + break; default: - *p+=sprintf (*p, "%5.0f", query(token)); + *p+=sprintf (*p, "%5.0f", query(token)); } } @@ -417,8 +429,18 @@ static void collect_data (void) if (ppp.max>ppp.peak) ppp.peak=ppp.max; } + if (token_usage[C_SETI]) { + Seti (&seti.perc, &seti.cput); + } + + for (i=1; i<=MAILBOXES; i++) { + if (token_usage[T_MAIL]&(1<T_EXTENDED) token += (*(unsigned char*)++s)<<8; + print_token (token, &p); } else if (*s=='$') { - int i; - int type=*++s; - int len=*++s; - double val1=query_bar(*(unsigned char*)++s); - double val2=val1; - if (type & (BAR_H2 | BAR_V2)) - val2=query_bar(*(unsigned char*)++s); + double val1, val2; + int i, type, len; + type=*++s; + len=*++s; + token = *(unsigned char*)++s; + if (token>T_EXTENDED) token += (*(unsigned char*)++s)<<8; + val1=query_bar(token); + val2=val1; + if (type & (BAR_H2 | BAR_V2)) { + token = *(unsigned char*)++s; + if (token>T_EXTENDED) token += (*(unsigned char*)++s)<<8; + val2=query_bar(token); + } if (type & BAR_H) lcd_bar (type, r, p-buffer+1, len*xres, val1*len*xres, val2*len*xres); else @@ -468,7 +499,7 @@ static int process_gpo (int r) int token; double val; - token=(unsigned char)gpo[r]; + token=gpo[r]; val=query(token); return (val > 0.0); diff --git a/seti.c b/seti.c index 83ce79c..875787d 100644 --- a/seti.c +++ b/seti.c @@ -1,4 +1,4 @@ -/* $Id: seti.c,v 1.2 2001/02/18 21:16:06 reinelt Exp $ +/* $Id: seti.c,v 1.3 2001/02/19 00:15:46 reinelt Exp $ * * seti@home specific functions * @@ -20,6 +20,11 @@ * * * $Log: seti.c,v $ + * Revision 1.3 2001/02/19 00:15:46 reinelt + * + * integrated mail and seti client + * major rewrite of parser and tokenizer to support double-byte tokens + * * Revision 1.2 2001/02/18 21:16:06 reinelt * *** empty log message *** * @@ -58,7 +63,7 @@ #include "debug.h" #include "seti.h" -int Seti (int *perc, int *cput) +int oldSeti (int *perc, int *cput) { FILE *fstr; static int err_marker=0; // Was there an erro before -> -2 @@ -182,7 +187,7 @@ int Seti (int *perc, int *cput) } -int newSeti (double *perc, double *cput) +int Seti (double *perc, double *cput) { static char fn[256]; static time_t now=0; diff --git a/seti.h b/seti.h index 5855aa4..965c0de 100644 --- a/seti.h +++ b/seti.h @@ -1,4 +1,4 @@ -/* $Id: seti.h,v 1.1 2001/02/18 21:15:15 reinelt Exp $ +/* $Id: seti.h,v 1.2 2001/02/19 00:15:46 reinelt Exp $ * * seti@home specific functions * @@ -20,6 +20,11 @@ * * * $Log: seti.h,v $ + * Revision 1.2 2001/02/19 00:15:46 reinelt + * + * integrated mail and seti client + * major rewrite of parser and tokenizer to support double-byte tokens + * * Revision 1.1 2001/02/18 21:15:15 reinelt * * added setiathome client @@ -31,6 +36,6 @@ #define DEFSETIPOLLEXT 10 -int Seti (int *perc, int *cput); +int Seti (double *perc, double *cput); #endif -- cgit v1.2.3