]> git.webhop.me Git - lcd4linux.git/commitdiff
[lcd4linux @ 2000-03-22 07:33:50 by reinelt]
authorreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>
Wed, 22 Mar 2000 07:33:50 +0000 (07:33 +0000)
committerreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>
Wed, 22 Mar 2000 07:33:50 +0000 (07:33 +0000)
FAQ added
new modules 'processor.c' contains all data processing

git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@15 3ae390bd-cb1e-0410-b409-cd5a39f66f1f

13 files changed:
FAQ [new file with mode: 0644]
Makefile.am
Makefile.in
MatrixOrbital.c
README.MatrixOrbital
Skeleton.c
configure
configure.in
filter.c
lcd4linux.c
lcd4linux.conf.sample
processor.c [new file with mode: 0644]
processor.h [new file with mode: 0644]

diff --git a/FAQ b/FAQ
new file mode 100644 (file)
index 0000000..cdd72a7
--- /dev/null
+++ b/FAQ
@@ -0,0 +1,10 @@
+#
+# $Id: FAQ,v 1.1 2000/03/22 07:33:50 reinelt Exp $
+#
+
+lcd4linux Frequently Asked Questions
+
+Q: Where can I buy LCD's from Matrox Orbital in Germany or Austria?
+
+A: Germany: Elektronikladen (http://www.elektronikladen.de/seriallcd.html)
+   Austria: MEGATON (http://www.elektronikladen.de/ela-oesterreich.html)
\ No newline at end of file
index 8500ce569b6a63062ad8a9b52a52a3b2053bd972..86e6be138996503a8f30dff70ed5e7e4b6591e11 100644 (file)
@@ -10,6 +10,7 @@ lcd4linux_SOURCES = \
        lcd4linux.c \
        cfg.c cfg.h \
        parser.c parser.h \
+       processor.c processor.h \
        system.c system.h \
        isdn.c isdn.h \
        filter.c filter.h \
index 508d87f6a1ebc5fed8be32a263f3c73c37fc3996..9231301e6629f2c9b348a8d27942d1f6330488ed 100644 (file)
@@ -68,7 +68,7 @@ CLEANFILES = *~
 AM_CFLAGS = -Wall
 
 bin_PROGRAMS = lcd4linux
-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     Skeleton.c      MatrixOrbital.c
+lcd4linux_SOURCES =    lcd4linux.c     cfg.c cfg.h     parser.c parser.h       processor.c processor.h         system.c system.h       isdn.c isdn.h   filter.c filter.h       display.c display.h     Skeleton.c      MatrixOrbital.c
 
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
 mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
@@ -80,8 +80,8 @@ DEFS = @DEFS@ -I. -I$(srcdir)
 CPPFLAGS = @CPPFLAGS@
 LDFLAGS = @LDFLAGS@
 LIBS = @LIBS@
-lcd4linux_OBJECTS =  lcd4linux.o cfg.o parser.o system.o isdn.o filter.o \
-display.o Skeleton.o MatrixOrbital.o
+lcd4linux_OBJECTS =  lcd4linux.o cfg.o parser.o processor.o system.o \
+isdn.o filter.o display.o Skeleton.o MatrixOrbital.o
 lcd4linux_LDADD = $(LDADD)
 lcd4linux_DEPENDENCIES = 
 lcd4linux_LDFLAGS = 
@@ -99,7 +99,7 @@ TAR = tar
 GZIP_ENV = --best
 DEP_FILES =  .deps/MatrixOrbital.P .deps/Skeleton.P .deps/cfg.P \
 .deps/display.P .deps/filter.P .deps/isdn.P .deps/lcd4linux.P \
-.deps/parser.P .deps/system.P
+.deps/parser.P .deps/processor.P .deps/system.P
 SOURCES = $(lcd4linux_SOURCES)
 OBJECTS = $(lcd4linux_OBJECTS)
 
index 3ecefe40a81817988f47ce91e0907381b041b0c3..e4618589029ae3f2da01cbe4e655b955da3b6b01 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: MatrixOrbital.c,v 1.8 2000/03/19 08:41:28 reinelt Exp $
+/* $Id: MatrixOrbital.c,v 1.9 2000/03/22 07:33:50 reinelt Exp $
  *
  * driver for Matrix Orbital serial display modules
  *
  *
  *
  * $Log: MatrixOrbital.c,v $
+ * Revision 1.9  2000/03/22 07:33:50  reinelt
+ *
+ * FAQ added
+ * new modules 'processor.c' contains all data processing
+ *
  * Revision 1.8  2000/03/19 08:41:28  reinelt
  *
  * documentation available! README, README.MatrixOrbital, README.Drivers
@@ -96,7 +101,7 @@ static char Txt[4][40];
 static BAR  Bar[4][40];
 
 static int nSegment=2;
-static SEGMENT Segment[256] = {{ len1:0,   len2:0,   type:255, used:0, ascii:32 },
+static SEGMENT Segment[128] = {{ len1:0,   len2:0,   type:255, used:0, ascii:32 },
                               { len1:255, len2:255, type:255, used:0, ascii:255 }};
 
 
index 1138b49389d4270f56f3b87d4f5bf76c4fc05191..a8e889cb24f3a5e7536019a20f90fa0d216bf6b7 100644 (file)
@@ -1,5 +1,5 @@
 #
-# $Id: README.MatrixOrbital,v 1.1 2000/03/19 08:41:28 reinelt Exp $
+# $Id: README.MatrixOrbital,v 1.2 2000/03/22 07:33:50 reinelt Exp $
 #
 
 This is the README file for the MatrixOrbital display driver for lcd4linux
@@ -38,3 +38,16 @@ fails, this characters will be redefined, too.
 
 The displays have a GPO (general purpose output), where you can connect a LED or something. 
 The driver supports controlling this GPO, but this function is unused by now.
+
+
+Configuration:
+
+The driver needs/supports the following entries in lcd4linux.conf:
+
+Display: a valid Matrix Orbital Display name (e.g. "LCD2041")
+Port: serial device the display is attached to (e.g. /dev/ttyS2)
+Speed: the baud rate from the display (configured via jumpers) must match 
+       this value. Possible values are 1200, 2400, 9600 and 19200
+Contrast: sets the LCD display contrast to a level between 0 (light) 
+          and 256 (dark). Default value: 160
+
index 6522f343ff491b996c858ddb50f5d185c4167a1b..566ce428dcf446977bcb85f4bdf3760820ac77b9 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: Skeleton.c,v 1.1 2000/03/19 08:41:28 reinelt Exp $
+/* $Id: Skeleton.c,v 1.2 2000/03/22 07:33:50 reinelt Exp $
  *
  * skeleton driver for new display modules
  *
  *
  *
  * $Log: Skeleton.c,v $
+ * Revision 1.2  2000/03/22 07:33:50  reinelt
+ *
+ * FAQ added
+ * new modules 'processor.c' contains all data processing
+ *
  * Revision 1.1  2000/03/19 08:41:28  reinelt
  *
  * documentation available! README, README.MatrixOrbital, README.Drivers
@@ -52,6 +57,9 @@ int Skel_init (DISPLAY *Self)
 {
   Display=*Self;
 
+  fprintf (stderr, "Skeleton: This driver does not drive anything!");
+  return -1;
+
   Skel_clear();
   return 0;
 }
index 89cc8dedb48aed443d428e6d13cc66c2b955079a..e5fbb4bd276255398867e2e4e8b253a9c6549028 100755 (executable)
--- a/configure
+++ b/configure
@@ -691,7 +691,7 @@ fi
 
 PACKAGE=lcd4linux
 
-VERSION=0.92
+VERSION=0.94
 
 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; }
index b195cb64a1c98041ca53f963f2da0ceda8962378..b960e10fa5f61b461d7631970acf479f9c6d7543 100644 (file)
@@ -1,6 +1,6 @@
 dnl Process this file with autoconf to produce a configure script.
 AC_INIT(lcd4linux.c)
-AM_INIT_AUTOMAKE(lcd4linux, 0.92)
+AM_INIT_AUTOMAKE(lcd4linux, 0.94)
 
 dnl Checks for programs.
 AC_PROG_CC
index 74ae3fdfda8ec16c6a933a2b506a131c7b34a038..1fbf9c2a73b068cb13fc938b9df2edb572316bcf 100644 (file)
--- a/filter.c
+++ b/filter.c
@@ -1,4 +1,4 @@
-/* $Id: filter.c,v 1.2 2000/03/06 06:04:06 reinelt Exp $
+/* $Id: filter.c,v 1.3 2000/03/22 07:33:50 reinelt Exp $
  *
  *  smooth and damp functions
  *
  *
  *
  * $Log: filter.c,v $
+ * Revision 1.3  2000/03/22 07:33:50  reinelt
+ *
+ * FAQ added
+ * new modules 'processor.c' contains all data processing
+ *
  * Revision 1.2  2000/03/06 06:04:06  reinelt
  *
  * minor cleanups
  *
- *
  */
 
 /* 
@@ -37,7 +41,6 @@
  *
  * damp (name, value)
  *   damps a value with exp(-t/tau) 
- *   uses global variable "tau"
  *
  */
 
 #include <math.h>
 #include <sys/time.h>
 
+#include "cfg.h"
 #include "filter.h"
 
 extern int tick;
-extern int tau;
 
 #define SLOTS 64
 #define SECONDS(x) (x.tv_sec+x.tv_usec/1000000.0)
@@ -116,12 +119,16 @@ double smooth(char *name, int period, double value)
 
 double damp(char *name, double value)
 {
+  static int tau=-1;
   static FILTER *Filter=NULL;
   static int nFilter=0;
   struct timeval now;
   double max;
   int i, j;
   
+  if (tau==-1)
+    tau=atoi(cfg_get("tau"));
+
   if (tau==0.0)
     return value;
   
index f065022393234eb095031c62bf1f3b8ab536a6b5..cdd03706dfd5de0ac9c07b933970f31568e34fc1 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: lcd4linux.c,v 1.7 2000/03/19 08:41:28 reinelt Exp $
+/* $Id: lcd4linux.c,v 1.8 2000/03/22 07:33:50 reinelt Exp $
  *
  * LCD4Linux
  *
  *
  *
  * $Log: lcd4linux.c,v $
+ * Revision 1.8  2000/03/22 07:33:50  reinelt
+ *
+ * FAQ added
+ * new modules 'processor.c' contains all data processing
+ *
  * Revision 1.7  2000/03/19 08:41:28  reinelt
  *
  * documentation available! README, README.MatrixOrbital, README.Drivers
 
 #include <stdlib.h>
 #include <stdio.h>
-#include <string.h>
-#include <ctype.h>
 #include <unistd.h>
 
 #include "cfg.h"
 #include "display.h"
-#include "parser.h"
-#include "system.h"
-#include "isdn.h"
-
-#define ROWS 16
-
-double overload;
-int tick, tack, tau;
-int rows, cols, xres, yres, supported_bars;
+#include "processor.h"
 
-int token_usage[256]={0,};
-
-struct { int total, used, free, shared, buffer, cache, avail; } ram;
-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;
-struct { double val, min, max; } sensor[SENSORS];
+int tick, tack;
 
 static void usage(void)
 {
-  printf ("LCD4Linux V" VERSION " (c) 2000 Michael Reinelt <reinelt@eunet.at>");
-  printf ("usage: lcd4linux [config file]\n");
-}
-
-static void collect_data (void) 
-{
-  int i;
-
-  if (token_usage[C_MEM]) {
-    Ram (&ram.total, &ram.free, &ram.shared, &ram.buffer, &ram.cache); 
-    ram.used=ram.total-ram.free;
-    ram.avail=ram.free+ram.buffer+ram.cache;
-  }
-  
-  if (token_usage[C_LOAD]) {
-    Load (&load.load1, &load.load2, &load.load3);
-  }
-  
-  if (token_usage[C_CPU]) {
-    Busy (&busy.user, &busy.nice, &busy.system, &busy.idle);
-  }
-  
-  if (token_usage[C_DISK]) {
-    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;
-  }
-  
-  if (token_usage[C_NET]) {
-    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;
-  }
-
-  if (token_usage[C_ISDN]) {
-    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;
-  }
-
-  for (i=1; i<SENSORS; i++) {
-    if (token_usage[T_SENSOR_1+i-1]) {
-      Sensor (i, &sensor[i].val, &sensor[i].min, &sensor[i].max);
-    }
-  }
+  printf ("LCD4Linux V" VERSION " (c) 2000 Michael Reinelt <reinelt@eunet.at>\n");
+  printf ("usage: lcd4linux [-h] [-l] [-f config-file]\n");
 }
 
-static double query (int token)
-{
-  switch (token) {
-    
-  case T_MEM_TOTAL:
-    return ram.total;
-  case T_MEM_USED:
-    return ram.used;
-  case T_MEM_FREE:
-    return ram.free;
-  case T_MEM_SHARED:
-    return ram.shared;
-  case T_MEM_BUFFER:
-    return ram.buffer;
-  case T_MEM_CACHE:
-    return ram.cache;
-  case T_MEM_AVAIL:
-    return ram.avail;
-
-  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 sensor[token-T_SENSOR_1+1].val;
-  }
-  return 0.0;
-}
-
-static double query_bar (int token)
-{
-  int i;
-  double value=query(token);
-  
-  switch (token) {
-
-  case T_MEM_TOTAL:
-  case T_MEM_USED:
-  case T_MEM_FREE:
-  case T_MEM_SHARED:
-  case T_MEM_BUFFER:
-  case T_MEM_CACHE:
-  case T_MEM_AVAIL:
-    return value/ram.total;
-
-  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;
-
-  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;
-    return (value-sensor[i].min)/(sensor[i].max-sensor[i].min);
-  }
-  return value;
-}
-
-void print_token (int token, char **p)
-{
-  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_MEM_TOTAL:
-  case T_MEM_USED:
-  case T_MEM_FREE:
-  case T_MEM_SHARED:
-  case T_MEM_BUFFER:
-  case T_MEM_CACHE:
-  case T_MEM_AVAIL:
-    *p+=sprintf (*p, "%6.0f", query(token));
-    break;
-  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:
-    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);
-    }
-    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;
-  case T_ISDN_IN:
-  case T_ISDN_OUT:
-  case T_ISDN_MAX:
-  case T_ISDN_TOTAL:
-    if (isdn.usage)
-      *p+=sprintf (*p, "%4.0f", query(token));
-    else
-      *p+=sprintf (*p, "----");
-    break;
-  default:
-      *p+=sprintf (*p, "%4.0f", query(token));
-  }
-}
-
-char *process_row (int r, char *s)
-{
-  static char buffer[256];
-  char *p=buffer;
-  
-  do {
-    if (*s=='%') {
-      print_token (*(unsigned char*)++s, &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);
-      if (type & BAR_H)
-       lcd_bar (type, r, p-buffer+1, len*xres, val1*len*xres, val2*len*xres);
-      else
-       lcd_bar (type, r, p-buffer+1, len*yres, val1*len*yres, val2*len*yres);
-      
-      if (type & BAR_H) {
-       for (i=0; i<len && p-buffer<cols; i++)
-         *p++='\t';
-      } else {
-       *p++='\t';
-      }
-      
-    } else {
-      *p++=*s;
-    }
-    
-  } while (*s++); 
-    
-  return buffer;
-}
-
-
 void main (int argc, char *argv[])
 {
   char *cfg="/etc/lcd4linux.conf";
   char *display;
-  char *row[ROWS];
-  int i, smooth;
-
-  if (argc>2) {
-    usage();
-    exit (2);
+  int c, smooth;
+
+  while ((c=getopt (argc, argv, "hlf:"))!=EOF) {
+    switch (c) {
+    case 'h':
+      usage();
+      exit(0);
+    case 'l':
+      usage();
+      exit(0);
+    case 'f':
+      cfg=optarg;
+      break;
+    default:
+      exit(2);
+    }
   }
-  if (argc==2) {
-    cfg=argv[1];
+
+  if (optind < argc) {
+    fprintf (stderr, "%s: illegal option %s\n", argv[0], argv[optind]);
+    exit(2);
   }
 
+  // set default values
   cfg_set ("row1", "*** %o %v ***");
   cfg_set ("row2", "%p CPU  %r MB RAM");
   cfg_set ("row3", "Busy %cu%% $r10cu");
@@ -423,19 +127,11 @@ void main (int argc, char *argv[])
   if (lcd_init(display)==-1) {
     exit (1);
   }
-  lcd_query (&rows, &cols, &xres, &yres, &supported_bars);
 
   tick=atoi(cfg_get("tick"));
   tack=atoi(cfg_get("tack"));
-  tau=atoi(cfg_get("tau"));
 
-  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), supported_bars, token_usage));
-  }
+  process_init();
 
   lcd_clear();
   lcd_put (1, 1, "** LCD4Linux V" VERSION " **");
@@ -447,13 +143,7 @@ void main (int argc, char *argv[])
 
   smooth=0;
   while (1) {
-    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();
+    process (smooth);
     smooth+=tick;
     if (smooth>tack) smooth=0;
     usleep(tick*1000);
index 688cc2373c2708acf3a430cbe3a11b78205739e1..783ea8b57e304306eadde6491bfc1ba660448bc1 100644 (file)
@@ -8,15 +8,11 @@ Contrast 160
 #Row3 "Busy %cu%% $r10cs+cb"
 #Row4 "Load %l1%L$r10l1"
 
-#Row1 "Load %l1%L$r10cs+cb"
-#Row2 "Disk %dm $R10dr+dw"
-#Row3 "Net  %nm $R10nr+nw"
-#Row4 "ISDN %im $r10ii+io"
-
 Row1 "Load %l1%L$r10cs+cb"
-Row2 "Temp %s2\337$r10s1+s2"
-Row3 "Disk %dm $R10dr+dw"
-Row4 "Net  %nm $R10nr+nw"
+Row2 "Disk %dm $R10dr+dw"
+Row3 "Net  %nm $R10nr+nw"
+Row4 "ISDN %im $r10ii+io"
+Row5 "Temp %s2\337$r10s1+s2"
 
 #Row1 "$u3l1$u3cb$u3cs $u3mu$u3ma$u3ms $u3dr$u3dw $u3nr$u3nw $u3ii$u3io"
 #Row2 " "
diff --git a/processor.c b/processor.c
new file mode 100644 (file)
index 0000000..6c95208
--- /dev/null
@@ -0,0 +1,393 @@
+/* $Id: processor.c,v 1.1 2000/03/22 07:33:50 reinelt Exp $
+ *
+ * main data processing
+ *
+ * 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: processor.c,v $
+ * Revision 1.1  2000/03/22 07:33:50  reinelt
+ *
+ * FAQ added
+ * new modules 'processor.c' contains all data processing
+ *
+ */
+
+/* 
+ * exported functions:
+ *
+ * void process_init (void);
+ *   does all necessary initializations
+ *
+ * void process (int smooth);
+ *   processes a whole screen
+ *   bars will always be processed
+ *   texts only if smooth=0
+ *
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "cfg.h"
+#include "system.h"
+#include "isdn.h"
+#include "parser.h"
+#include "display.h"
+#include "processor.h"
+
+
+#define ROWS 16
+
+char *row[ROWS];
+int   rows, cols, xres, yres, supported_bars;
+int   token_usage[256]={0,};
+
+struct { int total, used, free, shared, buffer, cache, avail; } ram;
+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;
+struct { double val, min, max; } sensor[SENSORS];
+
+
+static double query (int token)
+{
+  switch (token) {
+    
+  case T_MEM_TOTAL:
+    return ram.total;
+  case T_MEM_USED:
+    return ram.used;
+  case T_MEM_FREE:
+    return ram.free;
+  case T_MEM_SHARED:
+    return ram.shared;
+  case T_MEM_BUFFER:
+    return ram.buffer;
+  case T_MEM_CACHE:
+    return ram.cache;
+  case T_MEM_AVAIL:
+    return ram.avail;
+
+  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 sensor[token-T_SENSOR_1+1].val;
+  }
+  return 0.0;
+}
+
+static double query_bar (int token)
+{
+  int i;
+  double value=query(token);
+  
+  switch (token) {
+
+  case T_MEM_TOTAL:
+  case T_MEM_USED:
+  case T_MEM_FREE:
+  case T_MEM_SHARED:
+  case T_MEM_BUFFER:
+  case T_MEM_CACHE:
+  case T_MEM_AVAIL:
+    return value/ram.total;
+
+  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;
+
+  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;
+    return (value-sensor[i].min)/(sensor[i].max-sensor[i].min);
+  }
+  return value;
+}
+
+static void print_token (int token, char **p)
+{
+  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_MEM_TOTAL:
+  case T_MEM_USED:
+  case T_MEM_FREE:
+  case T_MEM_SHARED:
+  case T_MEM_BUFFER:
+  case T_MEM_CACHE:
+  case T_MEM_AVAIL:
+    *p+=sprintf (*p, "%6.0f", query(token));
+    break;
+  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:
+    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);
+    }
+    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;
+  case T_ISDN_IN:
+  case T_ISDN_OUT:
+  case T_ISDN_MAX:
+  case T_ISDN_TOTAL:
+    if (isdn.usage)
+      *p+=sprintf (*p, "%4.0f", query(token));
+    else
+      *p+=sprintf (*p, "----");
+    break;
+  default:
+      *p+=sprintf (*p, "%4.0f", query(token));
+  }
+}
+
+static void collect_data (void) 
+{
+  int i;
+
+  if (token_usage[C_MEM]) {
+    Ram (&ram.total, &ram.free, &ram.shared, &ram.buffer, &ram.cache); 
+    ram.used=ram.total-ram.free;
+    ram.avail=ram.free+ram.buffer+ram.cache;
+  }
+  
+  if (token_usage[C_LOAD]) {
+    Load (&load.load1, &load.load2, &load.load3);
+  }
+  
+  if (token_usage[C_CPU]) {
+    Busy (&busy.user, &busy.nice, &busy.system, &busy.idle);
+  }
+  
+  if (token_usage[C_DISK]) {
+    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;
+  }
+  
+  if (token_usage[C_NET]) {
+    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;
+  }
+
+  if (token_usage[C_ISDN]) {
+    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;
+  }
+
+  for (i=1; i<SENSORS; i++) {
+    if (token_usage[T_SENSOR_1+i-1]) {
+      Sensor (i, &sensor[i].val, &sensor[i].min, &sensor[i].max);
+    }
+  }
+}
+
+static char *process_row (int r)
+{
+  static char buffer[256];
+  char *s=row[r];
+  char *p=buffer;
+  
+  do {
+    if (*s=='%') {
+      print_token (*(unsigned char*)++s, &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);
+      if (type & BAR_H)
+       lcd_bar (type, r, p-buffer+1, len*xres, val1*len*xres, val2*len*xres);
+      else
+       lcd_bar (type, r, p-buffer+1, len*yres, val1*len*yres, val2*len*yres);
+      
+      if (type & BAR_H) {
+       for (i=0; i<len && p-buffer<cols; i++)
+         *p++='\t';
+      } else {
+       *p++='\t';
+      }
+      
+    } else {
+      *p++=*s;
+    }
+    
+  } while (*s++); 
+    
+  return buffer;
+}
+
+void process_init (void)
+{
+  int i;
+  char buffer[8];
+
+  load.overload=atof(cfg_get("overload"));
+  lcd_query (&rows, &cols, &xres, &yres, &supported_bars);
+
+  for (i=1; i<=rows; i++) {
+    snprintf (buffer, sizeof(buffer), "row%d", i);
+    row[i]=strdup(parse(cfg_get(buffer), supported_bars, token_usage));
+  }
+}
+
+void process (int smooth)
+{
+  int i;
+  char *txt;
+
+  collect_data();
+  for (i=1; i<=rows; i++) {
+    txt=process_row (i);
+    if (smooth==0)
+      lcd_put (i, 1, txt);
+  }
+  lcd_flush();
+}
diff --git a/processor.h b/processor.h
new file mode 100644 (file)
index 0000000..eb489a4
--- /dev/null
@@ -0,0 +1,36 @@
+/* $Id: processor.h,v 1.1 2000/03/22 07:33:50 reinelt Exp $
+ *
+ * main data processing
+ *
+ * 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: processor.h,v $
+ * Revision 1.1  2000/03/22 07:33:50  reinelt
+ *
+ * FAQ added
+ * new modules 'processor.c' contains all data processing
+ *
+ */
+
+#ifndef _PROCESSOR_H_
+#define _PROCESSOR_H_
+
+void process_init (void);
+void process (int smooth);
+
+#endif