From 1f0791dbac416903409b420ce5bdd73a1944c3d4 Mon Sep 17 00:00:00 2001 From: reinelt Date: Mon, 13 Mar 2000 15:58:24 +0000 Subject: [lcd4linux @ 2000-03-13 15:58:24 by reinelt] release 0.9 moved row parsing to parser.c all basic work finished git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@10 3ae390bd-cb1e-0410-b409-cd5a39f66f1f --- Makefile.am | 12 +- Makefile.in | 13 +- MatrixOrbital.c | 127 ++++++++---- configure | 2 +- configure.in | 2 +- display.c | 15 +- display.h | 23 +- isdn.c | 10 +- isdn.h | 10 +- lcd4linux.c | 565 ++++++++++++++++++-------------------------------- lcd4linux.conf.sample | 14 +- lcd4linux.h | 0 parser.c | 208 +++++++++++++++++++ parser.h | 48 +++++ 14 files changed, 629 insertions(+), 420 deletions(-) delete mode 100644 lcd4linux.h create mode 100644 parser.c create mode 100644 parser.h diff --git a/Makefile.am b/Makefile.am index f75d8b5..38b15bf 100644 --- a/Makefile.am +++ b/Makefile.am @@ -3,9 +3,17 @@ AUTOMAKE_OPTIONS = foreign CLEANFILES = *~ -CFLAGS = -Wall -O2 +AM_CFLAGS = -Wall bin_PROGRAMS = lcd4linux -lcd4linux_SOURCES = lcd4linux.c cfg.c display.c filter.c system.c isdn.c MatrixOrbital.c +lcd4linux_SOURCES = \ + lcd4linux.c \ + cfg.c cfg.h \ + parser.c parser.h \ + system.c system.h \ + isdn.c isdn.h \ + filter.c filter.h \ + display.c display.h \ + MatrixOrbital.c diff --git a/Makefile.in b/Makefile.in index 080f5bb..a500dd9 100644 --- a/Makefile.in +++ b/Makefile.in @@ -65,10 +65,11 @@ VERSION = @VERSION@ AUTOMAKE_OPTIONS = foreign CLEANFILES = *~ -CFLAGS = -Wall -O2 +AM_CFLAGS = -Wall bin_PROGRAMS = lcd4linux -lcd4linux_SOURCES = lcd4linux.c cfg.c display.c filter.c system.c isdn.c MatrixOrbital.c +lcd4linux_SOURCES = lcd4linux.c cfg.c cfg.h parser.c parser.h system.c system.h isdn.c isdn.h filter.c filter.h display.c display.h MatrixOrbital.c + ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs CONFIG_CLEAN_FILES = @@ -79,11 +80,12 @@ DEFS = @DEFS@ -I. -I$(srcdir) CPPFLAGS = @CPPFLAGS@ LDFLAGS = @LDFLAGS@ LIBS = @LIBS@ -lcd4linux_OBJECTS = lcd4linux.o cfg.o display.o filter.o system.o \ -isdn.o MatrixOrbital.o +lcd4linux_OBJECTS = lcd4linux.o cfg.o parser.o system.o isdn.o filter.o \ +display.o MatrixOrbital.o lcd4linux_LDADD = $(LDADD) lcd4linux_DEPENDENCIES = lcd4linux_LDFLAGS = +CFLAGS = @CFLAGS@ COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) CCLD = $(CC) LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ @@ -96,7 +98,8 @@ DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST) TAR = tar GZIP_ENV = --best DEP_FILES = .deps/MatrixOrbital.P .deps/cfg.P .deps/display.P \ -.deps/filter.P .deps/isdn.P .deps/lcd4linux.P .deps/system.P +.deps/filter.P .deps/isdn.P .deps/lcd4linux.P .deps/parser.P \ +.deps/system.P SOURCES = $(lcd4linux_SOURCES) OBJECTS = $(lcd4linux_OBJECTS) diff --git a/MatrixOrbital.c b/MatrixOrbital.c index f59a81e..510ae26 100644 --- a/MatrixOrbital.c +++ b/MatrixOrbital.c @@ -1,4 +1,4 @@ -/* $Id: MatrixOrbital.c,v 1.4 2000/03/10 17:36:02 reinelt Exp $ +/* $Id: MatrixOrbital.c,v 1.5 2000/03/13 15:58:24 reinelt Exp $ * * driver for Matrix Orbital serial display modules * @@ -20,6 +20,12 @@ * * * $Log: MatrixOrbital.c,v $ + * Revision 1.5 2000/03/13 15:58:24 reinelt + * + * release 0.9 + * moved row parsing to parser.c + * all basic work finished + * * Revision 1.4 2000/03/10 17:36:02 reinelt * * first unstable but running release @@ -46,12 +52,16 @@ #include "cfg.h" #include "display.h" +#define SPEED 19200 #define XRES 5 #define YRES 8 #define CHARS 8 +#define BARS ( BAR_L | BAR_R | BAR_H2 ) +// Fixme: BAR_U, BAR_D static DISPLAY Display; static char *Port=NULL; +static speed_t Speed; static int Device=-1; typedef struct { @@ -92,7 +102,7 @@ static int MO_open (void) return -1; } cfmakeraw(&portset); - cfsetospeed(&portset, B19200); + cfsetospeed(&portset, Speed); if (tcsetattr(fd, TCSANOW, &portset)==-1) { fprintf (stderr, "MatrixOrbital: tcsetattr(%s) failed: %s\n", Port, strerror(errno)); return -1; @@ -117,7 +127,7 @@ static int MO_contrast (void) char buffer[4]; int contrast; - contrast=atoi(cfg_get("contrast")); + contrast=atoi(cfg_get("Contrast")); if (contrast==0) contrast=160; snprintf (buffer, 4, "\376P%c", contrast); MO_write (buffer, 3); @@ -222,10 +232,9 @@ static void MO_compact_bars (void) static void MO_define_chars (void) { - int i, j, c; + int c, i, j; char buffer[12]="\376N"; - char Pixel[] = {0, 16, 24, 28, 30, 31}; - + for (i=2; imax) len1=max; if (len2<1) len2=1; else if (len2>max) len2=max; - while (max>0 && col<=Display.cols) { - Bar[row][col].type=type; - Bar[row][col].segment=-1; - if (len1>=XRES) { - Bar[row][col].len1=XRES; - len1-=XRES; - } else { - Bar[row][col].len1=len1; - len1=0; - } - if (len2>=XRES) { - Bar[row][col].len2=XRES; - len2-=XRES; - } else { - Bar[row][col].len2=len2; - len2=0; + switch (type & (BAR_L | BAR_R | BAR_U | BAR_D)) { + case BAR_L: + len1=max-len1; + len2=max-len2; + rev=1; + + case BAR_R: + while (max>0 && col<=Display.cols) { + Bar[row][col].type=type; + Bar[row][col].segment=-1; + if (len1>=XRES) { + Bar[row][col].len1=rev?0:XRES; + len1-=XRES; + } else { + Bar[row][col].len1=rev?XRES-len1:len1; + len1=0; + } + if (len2>=XRES) { + Bar[row][col].len2=rev?0:XRES; + len2-=XRES; + } else { + Bar[row][col].len2=rev?XRES-len2:len2; + len2=0; + } + max-=XRES; + col++; } - max-=XRES; - col++; + break; + + case BAR_U: + break; + + case BAR_D: + break; + } return 0; } @@ -379,8 +436,6 @@ int MO_flush (void) } -#define BARS ( BAR_L | BAR_R | BAR_U | BAR_D | BAR_S ) - DISPLAY MatrixOrbital[] = { { "LCD0821", 2, 8, XRES, YRES, BARS, MO_init, MO_clear, MO_put, MO_bar, MO_flush }, { "LCD1621", 2, 16, XRES, YRES, BARS, MO_init, MO_clear, MO_put, MO_bar, MO_flush }, diff --git a/configure b/configure index 75dae57..482de95 100755 --- a/configure +++ b/configure @@ -691,7 +691,7 @@ fi PACKAGE=lcd4linux -VERSION=0.8 +VERSION=0.9 if test "`cd $srcdir && pwd`" != "`pwd`" && test -f $srcdir/config.status; then { echo "configure: error: source directory already configured; run "make distclean" there first" 1>&2; exit 1; } diff --git a/configure.in b/configure.in index 9c7ea3c..487344a 100644 --- a/configure.in +++ b/configure.in @@ -1,6 +1,6 @@ dnl Process this file with autoconf to produce a configure script. AC_INIT(lcd4linux.c) -AM_INIT_AUTOMAKE(lcd4linux, 0.8) +AM_INIT_AUTOMAKE(lcd4linux, 0.9) dnl Checks for programs. AC_PROG_CC diff --git a/display.c b/display.c index e3f6aee..e00f791 100644 --- a/display.c +++ b/display.c @@ -1,4 +1,4 @@ -/* $Id: display.c,v 1.4 2000/03/10 17:36:02 reinelt Exp $ +/* $Id: display.c,v 1.5 2000/03/13 15:58:24 reinelt Exp $ * * framework for device drivers * @@ -20,6 +20,12 @@ * * * $Log: display.c,v $ + * Revision 1.5 2000/03/13 15:58:24 reinelt + * + * release 0.9 + * moved row parsing to parser.c + * all basic work finished + * * Revision 1.4 2000/03/10 17:36:02 reinelt * * first unstable but running release @@ -59,6 +65,7 @@ #include #include +#include #include "cfg.h" #include "display.h" @@ -118,6 +125,12 @@ int lcd_bar (int type, int row, int col, int max, int len1, int len2) { if (row<1 || row>Display->rows) return -1; if (col<1 || col>Display->cols) return -1; + if (!(type & (BAR_H2 | BAR_V2))) len2=len1; + if (type & BAR_LOG) { + type &= ~BAR_LOG; + len1=(double)max*log(len1+1)/log(max); + len2=(double)max*log(len2+1)/log(max); + } return Display->bar(type, row-1, col-1, max, len1, len2); } diff --git a/display.h b/display.h index 0a2bb95..988389a 100644 --- a/display.h +++ b/display.h @@ -1,4 +1,4 @@ -/* $Id: display.h,v 1.5 2000/03/10 17:36:02 reinelt Exp $ +/* $Id: display.h,v 1.6 2000/03/13 15:58:24 reinelt Exp $ * * framework for device drivers * @@ -20,6 +20,12 @@ * * * $Log: display.h,v $ + * Revision 1.6 2000/03/13 15:58:24 reinelt + * + * release 0.9 + * moved row parsing to parser.c + * all basic work finished + * * Revision 1.5 2000/03/10 17:36:02 reinelt * * first unstable but running release @@ -40,11 +46,16 @@ #ifndef _DISPLAY_H_ #define _DISPLAY_H_ -#define BAR_L 1 -#define BAR_R 2 -#define BAR_U 4 -#define BAR_D 8 -#define BAR_S 16 +#define BAR_L (1<<0) +#define BAR_R (1<<1) +#define BAR_U (1<<2) +#define BAR_D (1<<3) +#define BAR_H2 (1<<4) +#define BAR_V2 (1<<5) +#define BAR_LOG (1<<6) + +#define BAR_H (BAR_L | BAR_R) +#define BAR_V (BAR_U | BAR_D) typedef struct DISPLAY { char name[16]; diff --git a/isdn.c b/isdn.c index f6dfc4b..a77b15b 100644 --- a/isdn.c +++ b/isdn.c @@ -1,4 +1,4 @@ -/* $Id: isdn.c,v 1.4 2000/03/10 17:36:02 reinelt Exp $ +/* $Id: isdn.c,v 1.5 2000/03/13 15:58:24 reinelt Exp $ * * ISDN specific functions * @@ -20,6 +20,12 @@ * * * $Log: isdn.c,v $ + * Revision 1.5 2000/03/13 15:58:24 reinelt + * + * release 0.9 + * moved row parsing to parser.c + * all basic work finished + * * Revision 1.4 2000/03/10 17:36:02 reinelt * * first unstable but running release @@ -32,7 +38,6 @@ * * minor cleanups * - * */ /* @@ -56,7 +61,6 @@ #include "isdn.h" #include "filter.h" -#include "lcd4linux.h" typedef struct { unsigned long in; diff --git a/isdn.h b/isdn.h index bfb15c5..233c141 100644 --- a/isdn.h +++ b/isdn.h @@ -1,4 +1,4 @@ -/* $Id: isdn.h,v 1.4 2000/03/10 17:36:02 reinelt Exp $ +/* $Id: isdn.h,v 1.5 2000/03/13 15:58:24 reinelt Exp $ * * ISDN specific functions * @@ -20,6 +20,12 @@ * * * $Log: isdn.h,v $ + * Revision 1.5 2000/03/13 15:58:24 reinelt + * + * release 0.9 + * moved row parsing to parser.c + * all basic work finished + * * Revision 1.4 2000/03/10 17:36:02 reinelt * * first unstable but running release @@ -37,6 +43,6 @@ #ifndef _ISDN_H_ #define _ISDN_H_ -int Isdn (int *rx, int *tx,int *usage); +int Isdn (int *rx, int *tx, int *usage); #endif diff --git a/lcd4linux.c b/lcd4linux.c index dc43064..383dc45 100644 --- a/lcd4linux.c +++ b/lcd4linux.c @@ -1,4 +1,4 @@ -/* $Id: lcd4linux.c,v 1.2 2000/03/10 17:36:02 reinelt Exp $ +/* $Id: lcd4linux.c,v 1.3 2000/03/13 15:58:24 reinelt Exp $ * * LCD4Linux * @@ -20,6 +20,12 @@ * * * $Log: lcd4linux.c,v $ + * Revision 1.3 2000/03/13 15:58:24 reinelt + * + * release 0.9 + * moved row parsing to parser.c + * all basic work finished + * * Revision 1.2 2000/03/10 17:36:02 reinelt * * first unstable but running release @@ -32,10 +38,10 @@ #include #include #include -#include #include "cfg.h" #include "display.h" +#include "parser.h" #include "system.h" #include "isdn.h" @@ -43,380 +49,214 @@ double overload; int tick, tack, tau; -int rows, cols, xres, yres, bars; -char *row[ROWS]; +int rows, cols, xres, yres, supported_bars; -void usage(void) +struct { double load1, load2, load3, overload; } load; +struct { double user, nice, system, idle; } busy; +struct { int read, write, total, max, peak; } disk; +struct { int rx, tx, total, max, peak; } net; +struct { int usage, in, out, total, max, peak; } isdn; + +static void usage(void) { - printf ("LCD4Linux " VERSION " (c) 2000 Michael Reinelt "); - printf ("usage: lcd4linux [configuration]\n"); + printf ("LCD4Linux V" VERSION " (c) 2000 Michael Reinelt "); + printf ("usage: lcd4linux [config file]\n"); } -int bar_type (char tag) +static void collect_data (void) { - switch (tag) { - case 'l': - return BAR_L; - case 'r': - return BAR_R; - case 'u': - return BAR_U; - case 'd': - return BAR_D; - default: - return 0; - } + Busy (&busy.user, &busy.nice, &busy.system, &busy.idle); + Load (&load.load1, &load.load2, &load.load3); + + Disk (&disk.read, &disk.write); + disk.total=disk.read+disk.write; + disk.max=disk.read>disk.write?disk.read:disk.write; + if (disk.max>disk.peak) disk.peak=disk.max; + + Net (&net.rx, &net.tx); + net.total=net.rx+net.tx; + net.max=net.rx>net.tx?net.rx:net.tx; + if (net.max>net.peak) net.peak=net.max; + + Isdn (&isdn.in, &isdn.out, &isdn.usage); + isdn.total=isdn.in+isdn.out; + isdn.max=isdn.in>isdn.out?isdn.in:isdn.out; + if (isdn.max>isdn.peak) isdn.peak=isdn.max; } -int strpos (char *s, int c) +static double query (int token) { - int i; - char *p; - for (p=s, i=0; *p; p++, i++) { - if (*p==c) return i; + switch (token) { + + case T_LOAD_1: + return load.load1; + case T_LOAD_2: + return load.load2; + case T_LOAD_3: + return load.load3; + + case T_CPU_USER: + return busy.user; + case T_CPU_NICE: + return busy.nice; + case T_CPU_SYSTEM: + return busy.system; + case T_CPU_BUSY: + return 1.0-busy.idle; + case T_CPU_IDLE: + return busy.idle; + + case T_DISK_READ: + return disk.read; + case T_DISK_WRITE: + return disk.write; + case T_DISK_TOTAL: + return disk.total; + case T_DISK_MAX: + return disk.max; + + case T_NET_RX: + return net.rx; + case T_NET_TX: + return net.tx; + case T_NET_TOTAL: + return net.total; + case T_NET_MAX: + return net.max; + + case T_ISDN_IN: + return isdn.in; + case T_ISDN_OUT: + return isdn.out; + case T_ISDN_TOTAL: + return isdn.total; + case T_ISDN_MAX: + return isdn.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 -1; + return 0.0; } + +static double query_bar (int token) +{ + double value=query(token); -int print4f (char *p, double val) + switch (token) { + case T_LOAD_1: + case T_LOAD_2: + case T_LOAD_3: + return value/load.overload; + + case T_DISK_READ: + case T_DISK_WRITE: + case T_DISK_MAX: + return value/disk.peak; + case T_DISK_TOTAL: + return value/disk.peak/2.0; + + case T_NET_RX: + case T_NET_TX: + case T_NET_MAX: + return value/net.peak; + case T_NET_TOTAL: + return value/net.peak/2.0; + + case T_ISDN_IN: + case T_ISDN_OUT: + case T_ISDN_MAX: + return value/isdn.peak; + case T_ISDN_TOTAL: + return value/isdn.peak/2.0; + + } + return value; +} + +void print_token (int token, char **p) { - if (val<10.0) { - return sprintf (p, "%4.2f", val); - } else if (val<100.0) { - return sprintf (p, "%4.1f", val); - } else { - return sprintf (p, "%4.0f", val); + double val; + + switch (token) { + case T_PERCENT: + *(*p)++='%'; + break; + case T_DOLLAR: + *(*p)++='$'; + break; + case T_OS: + *p+=sprintf (*p, "%s", System()); + break; + case T_RELEASE: + *p+=sprintf (*p, "%s", Release()); + break; + case T_CPU: + *p+=sprintf (*p, "%s", Processor()); + break; + case T_RAM: + *p+=sprintf (*p, "%d", Memory()); + break; + case T_OVERLOAD: + *(*p)++=load.load1>load.overload?'!':' '; + break; + case T_CPU_USER: + case T_CPU_NICE: + case T_CPU_SYSTEM: + case T_CPU_BUSY: + case T_CPU_IDLE: + *p+=sprintf (*p, "%3.0f", 100.0*query(token)); + break; + default: + val=query(token); + if (val<10.0) { + *p+=sprintf (*p, "%4.2f", val); + } else if (val<100.0) { + *p+=sprintf (*p, "%4.1f", val); + } else { + *p+=sprintf (*p, "%4.0f", val); + } } } -char *parse (char *string) +char *process_row (int r, char *s) { - int pos; static char buffer[256]; - char *s=string; char *p=buffer; - + do { if (*s=='%') { - if (strchr("orpmlLcdDnNiIs%", *++s)==NULL) { - fprintf (stderr, "WARNING: unknown format <%%%c> in <%s>\n", *s, string); - continue; - } - *p='%'; - *(p+1)=*s; - switch (*s) { - case 'l': - pos=strpos("123", *++s); - if (pos<0) { - fprintf (stderr, "WARNING: unknown Load tag <%%l%c> in <%s>\n", *s, string); - continue; - } - *(p+2)=pos+1; - p+=3; - break; - case 'c': - pos=strpos("unsi", *++s); - if (pos<0) { - fprintf (stderr, "WARNING: unknown CPU tag <%%c%c> in <%s>\n", *s, string); - continue; - } - *(p+2)=pos+1; - p+=3; - break; - case 'd': - pos=strpos("rwtm", *++s); - if (pos<0) { - fprintf (stderr, "WARNING: unknown disk tag <%%d%c> in <%s>\n", *s, string); - continue; - } - *(p+2)=pos+1; - p+=3; - break; - case 'n': - pos=strpos("iotm", *++s); - if (pos<0) { - fprintf (stderr, "WARNING: unknown net tag <%%n%c> in <%s>\n", *s, string); - continue; - } - *(p+2)=pos+1; - p+=3; - break; - case 'i': - pos=strpos("iotm", *++s); - if (pos<0) { - fprintf (stderr, "WARNING: unknown ISDN tag <%%i%c> in <%s>\n", *s, string); - continue; - } - *(p+2)=pos+1; - p+=3; - break; - case 's': - pos=strpos("123456789", *++s); - if (pos<0) { - fprintf (stderr, "WARNING: unknown sensor <%%s%c> in <%s>\n", *s, string); - continue; - } - *(p+2)=pos+1; - p+=3; - break; - default: - p+=2; - } - + print_token (*(unsigned char*)++s, &p); + } else if (*s=='$') { - char dir; - int type; - int len=0; - dir=*++s; - if (dir=='$') { - *p++='$'; - *p++='$'; - continue; - } - if (strchr("lrud", tolower(dir))==NULL) { - fprintf (stderr, "invalid bar direction '%c' in <%s>\n", dir, string); - continue; - } - type=bar_type(tolower(dir)); - if (type==0) { - fprintf (stderr, "driver does not support bar type '%c'\n", dir); - continue; - } - if (isdigit(*++s)) len=strtol(s, &s, 10); - if (len<1 || len>255) { - fprintf (stderr, "invalid bar length in <%s>\n", string); - continue; - } - *p='$'; - *(p+1)=isupper(dir)?-type:type; - *(p+2)=len; - *(p+3)=*s; - switch (*s) { - case 'l': - pos=strpos("123", *++s); - if (pos<0) { - fprintf (stderr, "WARNING: unknown Load tag <$l%c> in <%s>\n", *s, string); - continue; - } - *(p+4)=pos+1; - p+=5; - break; - case 'c': - pos=strpos("unsi", *++s); - if (pos<0) { - fprintf (stderr, "WARNING: unknown CPU tag <$d%c> in <%s>\n", *s, string); - continue; - } - *(p+4)=pos+1; - p+=5; - break; - case 'd': - pos=strpos("rwm", *++s); - if (pos<0) { - fprintf (stderr, "WARNING: unknown disk tag <$d%c> in <%s>\n", *s, string); - continue; - } - *(p+4)=pos+1; - p+=5; - break; - case 'n': - pos=strpos("iom", *++s); - if (pos<0) { - fprintf (stderr, "WARNING: unknown net tag <$n%c> in <%s>\n", *s, string); - continue; - } - *(p+4)=pos+1; - p+=5; - break; - case 'i': - pos=strpos("iom", *++s); - if (pos<0) { - fprintf (stderr, "WARNING: unknown ISDN tag <$i%c> in <%s>\n", *s, string); - continue; - } - *(p+4)=pos+1; - p+=5; - break; - case 's': - pos=strpos("123456789", *++s); - if (pos<0) { - fprintf (stderr, "WARNING: unknown sensor <$s%c> in <%s>\n", *s, string); - continue; - } - *(p+4)=pos+1; - p+=5; - break; - default: - fprintf (stderr, "WARNING: unknown bar format <$%c> in <%s>\n", *s, string); - p+=4; - } - - } else if (*s=='\\') { - unsigned int c=0; int n; - if (*(s+1)=='\\') { - *p++='\\'; - s+=2; - } else { - sscanf (s+1, "%3o%n", &c, &n); - if (c==0 || c>255) { - fprintf (stderr, "WARNING: illegal '\\' in <%s> <%s>\n", string, s); - continue; - } - *p++=c; - s+=n; - } - + int i; + int type=*++s; + int len=*++s; + double val1=query_bar(*(unsigned char*)++s); + double val2; + if (type & (BAR_H2 | BAR_V2)) + val2=query_bar(*(unsigned char*)++s); + else + val2=val1; + lcd_bar (type, r, p-buffer+1, len*xres, val1*len*xres, val2*len*xres); + + for (i=0; idisk[1]?disk[0]:disk[1]; - if (disk[3]>disk_peak) disk_peak=disk[3]; - - Net (&net[0], &net[1]); - net[2]=net[0]+net[1]; - net[3]=net[0]>net[1]?net[0]:net[1]; - if (net[3]>net_peak) net_peak=net[3]; - - Isdn (&isdn[0], &isdn[1], &isdn_usage); - isdn[2]=isdn[0]+isdn[1]; - isdn[3]=isdn[0]>isdn[1]?isdn[0]:isdn[1]; - if (isdn[3]>isdn_peak) isdn_peak=isdn[3]; - - for (r=1; r<=rows; r++) { - char *s=row[r]; - char *p=buffer; - do { - if (*s=='%') { - switch (*++s) { - case '%': - *p++='%'; - break; - case 'o': - p+=sprintf (p, "%s", System()); - break; - case 'r': - p+=sprintf (p, "%s", Release()); - break; - case 'p': - p+=sprintf (p, "%s", Processor()); - break; - case 'm': - p+=sprintf (p, "%d", Memory()); - break; - case 'l': - p+=print4f (p, load[*++s-1]); - break; - case 'L': - *p++=load[0]>overload?'!':' '; - break; - case 'c': - p+=sprintf (p, "%3.0f", 100.0*busy[*++s-1]); - break; - case 'd': - p+=print4f (p, disk[*++s-1]); - break; - case 'D': - if (disk[0]+disk[1]==0) - *p++=' '; - else - *p++=disk[0]>disk[1]?'\176':'\177'; - break; - case 'n': - p+=print4f (p, net[*++s-1]/1024.0); - break; - case 'N': - if (net[0]+net[1]==0) - *p++=' '; - else - *p++=net[0]>net[1]?'\176':'\177'; - break; - case 'i': - if (isdn_usage) { - p+=print4f (p, isdn[*++s-1]/1024.0); - } else { - p+=sprintf (p, "----"); - s++; - } - break; - case 'I': - if (isdn[0]+isdn[1]==0) - *p++=' '; - else - *p++=isdn[0]>isdn[1]?'\176':'\177'; - break; - } - - } else if (*s=='$') { - int dir, len; - if ((dir=*++s)=='$') { - *p++='$'; - continue; - } - len=*++s; - switch (*++s) { - case 'l': - val=load[*++s-1]/overload; - break; - case 'c': - val=busy[*++s-1]; - break; - case 'd': - val=disk[*++s-1]/disk_peak; - break; - case 'n': - val=net[*++s-1]/net_peak; - break; - case 'i': - val=isdn[*++s-1]/8000.0; - break; - default: - val=0.0; - } - - if (dir>0) { - int bar=val*len*xres; - lcd_bar (dir, r, p-buffer+1, len*xres, bar, bar); - } else { - double bar=len*xres*log(val*len*xres+1)/log(len*xres); - lcd_bar (-dir, r, p-buffer+1, len*xres, bar, bar); - } - - for (i=0; i2) { usage(); @@ -458,31 +298,38 @@ void main (int argc, char *argv[]) if (lcd_init(display)==-1) { exit (1); } - lcd_query (&rows, &cols, &xres, &yres, &bars); + lcd_query (&rows, &cols, &xres, &yres, &supported_bars); tick=atoi(cfg_get("tick")); tack=atoi(cfg_get("tack")); tau=atoi(cfg_get("tau")); - overload=atof(cfg_get("overload")); + + load.overload=atof(cfg_get("overload")); for (i=1; i<=rows; i++) { char buffer[8]; snprintf (buffer, sizeof(buffer), "row%d", i); - row[i]=strdup(parse(cfg_get(buffer))); + row[i]=strdup(parse(cfg_get(buffer), supported_bars)); } lcd_clear(); - lcd_put (1, 1, "** LCD4Linux V" VERSION " **"); - lcd_put (rows-1,1, "(c) 2000 M. Reinelt"); + lcd_put (1, 1, "** LCD4Linux V" VERSION " **"); + lcd_put (2, 1, " (c) 2000 M.Reinelt"); lcd_flush(); - sleep (2); + sleep (3); lcd_clear(); smooth=0; while (1) { - draw(smooth); + collect_data(); + for (i=1; i<=rows; i++) { + row[0]=process_row (i, row[i]); + if (smooth==0) + lcd_put (i, 1, row[0]); + } + lcd_flush(); smooth+=tick; if (smooth>tack) smooth=0; usleep(1000*tick); diff --git a/lcd4linux.conf.sample b/lcd4linux.conf.sample index 990a2d5..4970c9b 100644 --- a/lcd4linux.conf.sample +++ b/lcd4linux.conf.sample @@ -1,11 +1,17 @@ Display LCD2041 Port /dev/ttyS2 +Speed 19200 Contrast 160 -Row1 "*** %o %r ***" -Row2 "%p CPU %m MB RAM" -Row3 "Busy %cu%% $r10cu" -Row4 "L$$D %l1%L$r10l1" +#Row1 "*** %o %r ***" +#Row2 "%p CPU %m MB RAM" +#Row3 "Busy %cu%% $r10cs" +#Row4 "Load %l1%L$r10l1" + +Row1 "Busy %cb%% $r10cs+cb" +Row2 "Disk %dm $R10dr+dw" +Row3 "Net %nm $R10nr+nw" +Row4 "ISDN %im $r10ii+io" Tick 100 Tack 400 diff --git a/lcd4linux.h b/lcd4linux.h deleted file mode 100644 index e69de29..0000000 diff --git a/parser.c b/parser.c new file mode 100644 index 0000000..a3ebddb --- /dev/null +++ b/parser.c @@ -0,0 +1,208 @@ +/* $Id: parser.c,v 1.1 2000/03/13 15:58:24 reinelt Exp $ + * + * row definition parser + * + * Copyright 1999, 2000 by Michael Reinelt (reinelt@eunet.at) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * + * $Log: parser.c,v $ + * Revision 1.1 2000/03/13 15:58:24 reinelt + * + * release 0.9 + * moved row parsing to parser.c + * all basic work finished + * + */ + +/* + * exported functions: + * + * char *parse (char *string, int supported_bars) + * converts a row definition from the config file + * into the internal form using tokens + */ + +#include +#include +#include +#include + +#include "display.h" +#include "parser.h" + +typedef struct { + char *symbol; + TOKEN token; + int bar; +} SYMTAB; + +static SYMTAB Symtab[] = {{ "%", T_PERCENT, 0 }, + { "$", T_DOLLAR, 0 }, + { "o", T_OS, 0 }, + { "r", T_RELEASE, 0 }, + { "p", T_CPU, 0 }, + { "m", T_RAM, 0 }, + { "l1", T_LOAD_1, 1 }, + { "l2", T_LOAD_2, 1 }, + { "l3", T_LOAD_3, 1 }, + { "L", T_OVERLOAD, 0 }, + { "cu", T_CPU_USER, 1 }, + { "cn", T_CPU_NICE, 1 }, + { "cs", T_CPU_SYSTEM, 1 }, + { "cb", T_CPU_BUSY, 1 }, + { "ci", T_CPU_IDLE, 1 }, + { "dr", T_DISK_READ, 1 }, + { "dw", T_DISK_WRITE, 1 }, + { "dt", T_DISK_TOTAL, 1 }, + { "dm", T_DISK_MAX, 1 }, + { "nr", T_NET_RX, 1 }, + { "nw", T_NET_TX, 1 }, + { "nt", T_NET_TOTAL, 1 }, + { "nm", T_NET_MAX, 1 }, + { "ii", T_ISDN_IN, 1 }, + { "io", T_ISDN_OUT, 1 }, + { "it", T_ISDN_TOTAL, 1 }, + { "im", T_ISDN_MAX, 1 }, + { "s1", T_SENSOR_1, 1 }, + { "s1", T_SENSOR_2, 1 }, + { "s2", T_SENSOR_3, 1 }, + { "s3", T_SENSOR_4, 1 }, + { "s4", T_SENSOR_5, 1 }, + { "s5", T_SENSOR_6, 1 }, + { "s6", T_SENSOR_7, 1 }, + { "s7", T_SENSOR_8, 1 }, + { "s8", T_SENSOR_9, 1 }, + { "", -1 }}; + + +static int bar_type (char tag) +{ + switch (tag) { + case 'l': + return BAR_L; + case 'r': + return BAR_R; + case 'u': + return BAR_U; + case 'd': + return BAR_D; + default: + return 0; + } +} + +static TOKEN get_token (char *s, char **p, int bar) +{ + int i; + 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) { + *p=s+l; + return Symtab[i].token; + } + } + return -1; +} + +char *parse (char *string, int supported_bars) +{ + static char buffer[256]; + char *s=string; + char *p=buffer; + int token, token2, type, len; + + do { + switch (*s) { + + case '%': + if ((token=get_token (s+1, &s, 0))==-1) { + s++; + fprintf (stderr, "WARNING: unknown token <%%%c> in <%s>\n", *s, string); + } else { + *p++='%'; + *p++=token; + } + break; + + case '$': + type=bar_type(tolower(*++s)); + if (type==0) { + fprintf (stderr, "WARNING: invalid bar type <$%c> in <%s>\n", *s, string); + break; + } + if (!(type & supported_bars)) { + fprintf (stderr, "WARNING: driver does not support bar type '%c'\n", *s); + break; + } + if (isupper(*s)) type |= BAR_LOG; + len=strtol(++s, &s, 10); + if (len<1 || len>127) { + fprintf (stderr, "WARNING: invalid bar length in <%s>\n", string); + break; + } + if ((token=get_token (s, &s, 0))==-1) { + fprintf (stderr, "WARNING: unknown token <$%c> in <%s>\n", *s, string); + break; + } + token2=-1; + if (*s=='+') { + if ((type & BAR_H) && (supported_bars & BAR_H2)) { + type |= BAR_H2; + } else if ((type & BAR_V) && (supported_bars & BAR_V2)) { + type |= BAR_V2; + } else { + fprintf (stderr, "WARNING: driver does not support double bars\n"); + break; + } + if ((token2=get_token (s+1, &s, 0))==-1) { + fprintf (stderr, "WARNING: unknown token <$%c> in <%s>\n", *s, string); + break; + } + } + *p++='$'; + *p++=type; + *p++=len; + *p++=token; + if (token2!=-1) *p++=token2; + break; + + case '\\': + if (*(s+1)=='\\') { + *p++='\\'; + s++; + } else { + unsigned int c=0; int n; + sscanf (s+1, "%3o%n", &c, &n); + if (c==0 || c>255) { + fprintf (stderr, "WARNING: illegal '\\' in <%s>\n", string); + } else { + *p++=c; + s+=n; + } + } + break; + + default: + *p++=*s++; + } + + } while (*s); + + return buffer; +} + diff --git a/parser.h b/parser.h new file mode 100644 index 0000000..959eb4d --- /dev/null +++ b/parser.h @@ -0,0 +1,48 @@ +/* $Id: parser.h,v 1.1 2000/03/13 15:58:24 reinelt Exp $ + * + * row definition parser + * + * Copyright 1999, 2000 by Michael Reinelt (reinelt@eunet.at) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * + * $Log: parser.h,v $ + * Revision 1.1 2000/03/13 15:58:24 reinelt + * + * release 0.9 + * moved row parsing to parser.c + * all basic work finished + * + */ + +#ifndef _PARSER_H_ +#define _PARSER_H_ + +typedef enum { + T_PERCENT=128, T_DOLLAR, + T_OS, T_RELEASE, T_CPU, T_RAM, + T_LOAD_1, T_LOAD_2, T_LOAD_3, T_OVERLOAD, + T_CPU_USER, T_CPU_NICE, T_CPU_SYSTEM, T_CPU_BUSY, T_CPU_IDLE, + T_DISK_READ, T_DISK_WRITE, T_DISK_TOTAL, T_DISK_MAX, + T_NET_RX, T_NET_TX, T_NET_TOTAL, T_NET_MAX, + T_ISDN_IN, T_ISDN_OUT, T_ISDN_TOTAL, T_ISDN_MAX, + 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, +} TOKEN; + +char *parse (char *string, int supported_bars); + +#endif -- cgit v1.2.3