From 870fec3b7b48712b88c2c8b3ebb05613b186cdd3 Mon Sep 17 00:00:00 2001 From: reinelt Date: Sun, 25 Jan 2004 05:30:09 +0000 Subject: [lcd4linux @ 2004-01-25 05:30:08 by reinelt] plugin_netdev for parsing /proc/net/dev added git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@338 3ae390bd-cb1e-0410-b409-cd5a39f66f1f --- Makefile.am | 1 + Makefile.in | 30 +++++----- drv_Crystalfontz.c | 39 ++++++++++--- drv_generic_serial.c | 21 ++++--- lcd4linux.conf.sample | 11 +++- plugin.c | 7 ++- plugin_meminfo.c | 11 ++-- plugin_netdev.c | 148 ++++++++++++++++++++++++++++++++++++++++++++++++++ plugin_proc_stat.c | 8 ++- 9 files changed, 235 insertions(+), 41 deletions(-) create mode 100644 plugin_netdev.c diff --git a/Makefile.am b/Makefile.am index 199575e..07c6ebb 100644 --- a/Makefile.am +++ b/Makefile.am @@ -37,6 +37,7 @@ plugin_loadavg.c \ plugin_proc_stat.c \ plugin_cpuinfo.c \ plugin_meminfo.c \ +plugin_netdev.c \ plugin_i2c_sensors.c \ plugin_xmms.c \ system.c system.h \ diff --git a/Makefile.in b/Makefile.in index d2b0024..e9caa48 100644 --- a/Makefile.in +++ b/Makefile.in @@ -106,7 +106,7 @@ lcd4linux_LDADD = @DRIVERS@ @DRVLIBS@ #remove next line for liblcd4linux lcd4linux_DEPENDENCIES = @DRIVERS@ -lcd4linux_SOURCES = lcd4linux.c pid.c pid.h hash.c hash.h parser.c parser.h processor.c processor.h layout.c layout.h timer.c timer.h evaluator.c evaluator.h widget.c widget.h widget_text.c widget_text.h widget_bar.c widget_bar.h widget_icon.c widget_icon.h plugin.c plugin.h plugin_math.c plugin_string.c plugin_cfg.c plugin_uname.c plugin_loadavg.c plugin_proc_stat.c plugin_cpuinfo.c plugin_meminfo.c plugin_i2c_sensors.c plugin_xmms.c system.c system.h isdn.c isdn.h wifi.c wifi.h mail.c mail.h seti.c seti.h battery.c battery.h dvb.c dvb.h filter.c filter.h exec.c exec.h expr.c expr.h mail2.c socket.c socket.h imon.c imon.h display.c display.h drv.c drv.h drv_generic_serial.c drv_generic_serial.h drv_generic_parport.c drv_generic_parport.h drv_generic_text.c drv_generic_text.h debug.c debug.h cfg.c cfg.h lock.c lock.h pixmap.c pixmap.h bar.c bar.h icon.c icon.h fontmap.c fontmap.h udelay.c udelay.h +lcd4linux_SOURCES = lcd4linux.c pid.c pid.h hash.c hash.h parser.c parser.h processor.c processor.h layout.c layout.h timer.c timer.h evaluator.c evaluator.h widget.c widget.h widget_text.c widget_text.h widget_bar.c widget_bar.h widget_icon.c widget_icon.h plugin.c plugin.h plugin_math.c plugin_string.c plugin_cfg.c plugin_uname.c plugin_loadavg.c plugin_proc_stat.c plugin_cpuinfo.c plugin_meminfo.c plugin_netdev.c plugin_i2c_sensors.c plugin_xmms.c system.c system.h isdn.c isdn.h wifi.c wifi.h mail.c mail.h seti.c seti.h battery.c battery.h dvb.c dvb.h filter.c filter.h exec.c exec.h expr.c expr.h mail2.c socket.c socket.h imon.c imon.h display.c display.h drv.c drv.h drv_generic_serial.c drv_generic_serial.h drv_generic_parport.c drv_generic_parport.h drv_generic_text.c drv_generic_text.h debug.c debug.h cfg.c cfg.h lock.c lock.h pixmap.c pixmap.h bar.c bar.h icon.c icon.h fontmap.c fontmap.h udelay.c udelay.h #liblcd4linux_la_DEPENDENCIES = @DRIVERS@ @@ -153,15 +153,15 @@ widget_bar.$(OBJEXT) widget_icon.$(OBJEXT) plugin.$(OBJEXT) \ plugin_math.$(OBJEXT) plugin_string.$(OBJEXT) plugin_cfg.$(OBJEXT) \ plugin_uname.$(OBJEXT) plugin_loadavg.$(OBJEXT) \ plugin_proc_stat.$(OBJEXT) plugin_cpuinfo.$(OBJEXT) \ -plugin_meminfo.$(OBJEXT) plugin_i2c_sensors.$(OBJEXT) \ -plugin_xmms.$(OBJEXT) system.$(OBJEXT) isdn.$(OBJEXT) wifi.$(OBJEXT) \ -mail.$(OBJEXT) seti.$(OBJEXT) battery.$(OBJEXT) dvb.$(OBJEXT) \ -filter.$(OBJEXT) exec.$(OBJEXT) expr.$(OBJEXT) mail2.$(OBJEXT) \ -socket.$(OBJEXT) imon.$(OBJEXT) display.$(OBJEXT) drv.$(OBJEXT) \ -drv_generic_serial.$(OBJEXT) drv_generic_parport.$(OBJEXT) \ -drv_generic_text.$(OBJEXT) debug.$(OBJEXT) cfg.$(OBJEXT) lock.$(OBJEXT) \ -pixmap.$(OBJEXT) bar.$(OBJEXT) icon.$(OBJEXT) fontmap.$(OBJEXT) \ -udelay.$(OBJEXT) +plugin_meminfo.$(OBJEXT) plugin_netdev.$(OBJEXT) \ +plugin_i2c_sensors.$(OBJEXT) plugin_xmms.$(OBJEXT) system.$(OBJEXT) \ +isdn.$(OBJEXT) wifi.$(OBJEXT) mail.$(OBJEXT) seti.$(OBJEXT) \ +battery.$(OBJEXT) dvb.$(OBJEXT) filter.$(OBJEXT) exec.$(OBJEXT) \ +expr.$(OBJEXT) mail2.$(OBJEXT) socket.$(OBJEXT) imon.$(OBJEXT) \ +display.$(OBJEXT) drv.$(OBJEXT) drv_generic_serial.$(OBJEXT) \ +drv_generic_parport.$(OBJEXT) drv_generic_text.$(OBJEXT) \ +debug.$(OBJEXT) cfg.$(OBJEXT) lock.$(OBJEXT) pixmap.$(OBJEXT) \ +bar.$(OBJEXT) icon.$(OBJEXT) fontmap.$(OBJEXT) udelay.$(OBJEXT) CFLAGS = @CFLAGS@ COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) @@ -190,11 +190,11 @@ DEP_FILES = .deps/BeckmannEgle.P .deps/Crystalfontz.P .deps/Cwlinux.P \ .deps/mail.P .deps/mail2.P .deps/parport.P .deps/parser.P .deps/pid.P \ .deps/pixmap.P .deps/plugin.P .deps/plugin_cfg.P .deps/plugin_cpuinfo.P \ .deps/plugin_i2c_sensors.P .deps/plugin_loadavg.P .deps/plugin_math.P \ -.deps/plugin_meminfo.P .deps/plugin_proc_stat.P .deps/plugin_string.P \ -.deps/plugin_uname.P .deps/plugin_xmms.P .deps/processor.P .deps/seti.P \ -.deps/socket.P .deps/system.P .deps/timer.P .deps/udelay.P \ -.deps/widget.P .deps/widget_bar.P .deps/widget_icon.P \ -.deps/widget_text.P .deps/wifi.P +.deps/plugin_meminfo.P .deps/plugin_netdev.P .deps/plugin_proc_stat.P \ +.deps/plugin_string.P .deps/plugin_uname.P .deps/plugin_xmms.P \ +.deps/processor.P .deps/seti.P .deps/socket.P .deps/system.P \ +.deps/timer.P .deps/udelay.P .deps/widget.P .deps/widget_bar.P \ +.deps/widget_icon.P .deps/widget_text.P .deps/wifi.P SOURCES = $(lcd4linux_SOURCES) $(EXTRA_lcd4linux_SOURCES) OBJECTS = $(lcd4linux_OBJECTS) diff --git a/drv_Crystalfontz.c b/drv_Crystalfontz.c index c4a856f..62723bc 100644 --- a/drv_Crystalfontz.c +++ b/drv_Crystalfontz.c @@ -1,4 +1,4 @@ -/* $Id: drv_Crystalfontz.c,v 1.4 2004/01/23 07:04:03 reinelt Exp $ +/* $Id: drv_Crystalfontz.c,v 1.5 2004/01/25 05:30:09 reinelt Exp $ * * new style driver for Crystalfontz display modules * @@ -23,6 +23,9 @@ * * * $Log: drv_Crystalfontz.c,v $ + * Revision 1.5 2004/01/25 05:30:09 reinelt + * plugin_netdev for parsing /proc/net/dev added + * * Revision 1.4 2004/01/23 07:04:03 reinelt * icons finished! * @@ -88,7 +91,9 @@ typedef struct { static MODEL Models[] = { { 0x26, "626", 2, 16, 0, 1 }, + { 0x31, "631", 2, 16, 0, 2 }, { 0x32, "632", 2, 16, 0, 1 }, + { 0x33, "633", 2, 16, 0, 2 }, { 0x34, "634", 4, 20, 0, 1 }, { 0x36, "636", 2, 16, 0, 1 }, { 0xff, "Unknown", -1, -1, 0, 0 } @@ -128,6 +133,7 @@ static int drv_CF_start (char *section) { int i; char *model; + char buffer[17]; model=cfg_get(section, "Model", NULL); if (model!=NULL && *model!='\0') { @@ -141,22 +147,37 @@ static int drv_CF_start (char *section) Model=i; info ("%s: using model '%s'", Name, Models[Model].name); } else { - error ("%s: no '%s.Model' entry from %s", Name, section, cfg_source()); - return -1; + info ("%s: no '%s.Model' entry from %s, auto-dedecting", Name, section, cfg_source()); + Model=-1; } - // initialize global variables - DROWS = Models[Model].rows; - DCOLS = Models[Model].cols; - GPOS = Models[Model].gpos; - Protocol = Models[Model].protocol; - // open serial port if (drv_generic_serial_open(section, Name)<0) return -1; // MR: why such a large delay? usleep(350*1000); + // read display type + memset(buffer, 0, sizeof(buffer)); + drv_generic_serial_write ("\1", 2); + usleep(250*1000); +#if 1 + { + int len=drv_generic_serial_read (buffer, 16); + debug ("Michi: len=<%d> buffer=<%s>", len, buffer); + } +#else + if (drv_generic_serial_read (buffer, 16)==16) { + info ("%s: display reports serial number 0x%x", Name, *(short*)buffer); + } +#endif + + // initialize global variables + DROWS = Models[Model].rows; + DCOLS = Models[Model].cols; + GPOS = Models[Model].gpos; + Protocol = Models[Model].protocol; + drv_generic_serial_write ("\014", 1); // Form Feed (Clear Display) drv_generic_serial_write ("\004", 1); // hide cursor drv_generic_serial_write ("\024", 1); // scroll off diff --git a/drv_generic_serial.c b/drv_generic_serial.c index 4eb9bff..39e993d 100644 --- a/drv_generic_serial.c +++ b/drv_generic_serial.c @@ -1,4 +1,4 @@ -/* $Id: drv_generic_serial.c,v 1.1 2004/01/20 14:26:09 reinelt Exp $ +/* $Id: drv_generic_serial.c,v 1.2 2004/01/25 05:30:09 reinelt Exp $ * * generic driver helper for serial and usbserial displays * @@ -23,6 +23,9 @@ * * * $Log: drv_generic_serial.c,v $ + * Revision 1.2 2004/01/25 05:30:09 reinelt + * plugin_netdev for parsing /proc/net/dev added + * * Revision 1.1 2004/01/20 14:26:09 reinelt * moved drv_generic to drv_generic_serial * @@ -219,14 +222,16 @@ int drv_generic_serial_open (char *section, char *driver) return -1; } - if (cfg_number(section, "Speed", 19200, 1200, 38400, &i)<0) return -1; + if (cfg_number(section, "Speed", 19200, 1200, 115200, &i)<0) return -1; switch (i) { - case 1200: Speed = B1200; break; - case 2400: Speed = B2400; break; - case 4800: Speed = B4800; break; - case 9600: Speed = B9600; break; - case 19200: Speed = B19200; break; - case 38400: Speed = B38400; break; + case 1200: Speed = B1200; break; + case 2400: Speed = B2400; break; + case 4800: Speed = B4800; break; + case 9600: Speed = B9600; break; + case 19200: Speed = B19200; break; + case 38400: Speed = B38400; break; + case 57600: Speed = B57600; break; + case 115200: Speed = B115200; break; default: error ("%s: unsupported speed '%d' from %s", Driver, i, cfg_source()); return -1; diff --git a/lcd4linux.conf.sample b/lcd4linux.conf.sample index 76a55d1..94797f9 100644 --- a/lcd4linux.conf.sample +++ b/lcd4linux.conf.sample @@ -8,6 +8,14 @@ Display LK204 { } +Display CF631 { + Icons 2 + Driver 'Crystalfontz' + Model '631' + Port '/dev/usb/tts/0' + Speed 115200 +} + Display CF632 { Icons 7 Driver 'Crystalfontz' @@ -239,7 +247,8 @@ Layout L16x2 { #Display 'LK204' #Display 'HD44780-20x4' -Display 'CF632' +#Display 'CF632' +Display 'CF631' #Layout 'Default' Layout 'L16x2' diff --git a/plugin.c b/plugin.c index 2d381ba..0418f6c 100644 --- a/plugin.c +++ b/plugin.c @@ -1,4 +1,4 @@ -/* $Id: plugin.c,v 1.13 2004/01/16 05:04:53 reinelt Exp $ +/* $Id: plugin.c,v 1.14 2004/01/25 05:30:09 reinelt Exp $ * * plugin handler for the Evaluator * @@ -22,6 +22,9 @@ * * * $Log: plugin.c,v $ + * Revision 1.14 2004/01/25 05:30:09 reinelt + * plugin_netdev for parsing /proc/net/dev added + * * Revision 1.13 2004/01/16 05:04:53 reinelt * started plugin proc_stat which should parse /proc/stat * which again is a paint in the a** @@ -123,6 +126,7 @@ int plugin_init_loadavg (void); int plugin_init_proc_stat (void); int plugin_init_cpuinfo (void); int plugin_init_meminfo (void); +int plugin_init_netdev (void); int plugin_init_i2c_sensors (void); int plugin_init_xmms (void); @@ -137,6 +141,7 @@ int plugin_init (void) plugin_init_proc_stat(); plugin_init_cpuinfo(); plugin_init_meminfo(); + plugin_init_netdev(); // MR: segfaults here // plugin_init_i2c_sensors(); plugin_init_xmms(); diff --git a/plugin_meminfo.c b/plugin_meminfo.c index b455f71..4091648 100644 --- a/plugin_meminfo.c +++ b/plugin_meminfo.c @@ -1,4 +1,4 @@ -/* $Id: plugin_meminfo.c,v 1.3 2004/01/21 10:48:17 reinelt Exp $ +/* $Id: plugin_meminfo.c,v 1.4 2004/01/25 05:30:09 reinelt Exp $ * * plugin for /proc/meminfo parsing * @@ -23,6 +23,9 @@ * * * $Log: plugin_meminfo.c,v $ + * Revision 1.4 2004/01/25 05:30:09 reinelt + * plugin_netdev for parsing /proc/net/dev added + * * Revision 1.3 2004/01/21 10:48:17 reinelt * hash_age function added * @@ -65,12 +68,11 @@ static HASH MemInfo = { 0, }; static int parse_meminfo (void) { int age; - int line; FILE *stream; - // reread every 100 msec only + // reread every 10 msec only age=hash_age(&MemInfo, NULL, NULL); - if (age>0 && age<=100) return 0; + if (age>0 && age<=10) return 0; stream=fopen("/proc/meminfo", "r"); if (stream==NULL) { @@ -78,7 +80,6 @@ static int parse_meminfo (void) return -1; } - line=0; while (!feof(stream)) { char buffer[256]; char *c, *key, *val; diff --git a/plugin_netdev.c b/plugin_netdev.c new file mode 100644 index 0000000..2c1b8b9 --- /dev/null +++ b/plugin_netdev.c @@ -0,0 +1,148 @@ +/* $Id: plugin_netdev.c,v 1.1 2004/01/25 05:30:09 reinelt Exp $ + * + * plugin for /proc/net/dev parsing + * + * Copyright 2003 Michael Reinelt + * Copyright 2004 The LCD4Linux Team + * + * This file is part of LCD4Linux. + * + * LCD4Linux 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. + * + * LCD4Linux 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: plugin_netdev.c,v $ + * Revision 1.1 2004/01/25 05:30:09 reinelt + * plugin_netdev for parsing /proc/net/dev added + * + */ + +/* + * exported functions: + * + * int plugin_init_netdev (void) + * adds functions to access /proc/net/dev + * + */ + + +#include +#include +#include +#include +#include + +#include "debug.h" +#include "plugin.h" + +#include "hash.h" + + +static HASH NetDev = { 0, }; + + +static void hash_set3 (char *key1, char *key2, char *key3, char *val) +{ + char key[32]; + + snprintf (key, sizeof(key), "%s.%s.%s", key1, key2, key3); + hash_set_delta (&NetDev, key, val); +} + + +static int parse_netdev (void) +{ + int age; + int line; + int RxTx=0; // position of Receive/Transmit switch + FILE *stream; + + // reread every 10 msec only + age=hash_age(&NetDev, NULL, NULL); + if (age>0 && age<=10) return 0; + + stream=fopen("/proc/net/dev", "r"); + if (stream==NULL) { + error ("fopen(/proc/net/dev) failed: %s", strerror(errno)); + return -1; + } + + line=0; + while (!feof(stream)) { + char buffer[256]; + char header[256]; + char *head[32]; + int col; + + if (fgets (buffer, sizeof(buffer), stream) == NULL) break; + + // skip line 1 + if (++line<2) continue; + + // line 2 used for headers + if (line==2) { + char *h; + strncpy(header, buffer, sizeof(header)); + RxTx=(strrchr(header, '|') - header); + col=0; + h=strtok(header, "| \t\n"); + while (h!=NULL) { + head[col++]=h; + h=strtok(NULL, "| \t\n"); + } + } else { + char *h, *iface=NULL; + col=0; + h=strtok(buffer, ":| \t\n"); + while (h!=NULL) { + if (col==0) { + iface=h; + } else { + hash_set3 (iface, (h-buffer) < RxTx ? "Rx" : "Tx", head[col], h); + } + h=strtok(NULL, "| \t\n"); + col++; + } + } + } + fclose (stream); + return 0; +} + +static void my_netdev (RESULT *result, RESULT *arg1, RESULT *arg2) +{ + char *key; + int delay; + double value; + + if (parse_netdev()<0) { + SetResult(&result, R_STRING, ""); + return; + } + + key = R2S(arg1); + delay = R2N(arg2); + + value = hash_get_regex(&NetDev, key, delay); + + SetResult(&result, R_NUMBER, &value); +} + + +int plugin_init_netdev (void) +{ + AddFunction ("netdev", 2, my_netdev); + return 0; +} + diff --git a/plugin_proc_stat.c b/plugin_proc_stat.c index 26cc8a9..37d7c85 100644 --- a/plugin_proc_stat.c +++ b/plugin_proc_stat.c @@ -1,4 +1,4 @@ -/* $Id: plugin_proc_stat.c,v 1.10 2004/01/22 08:55:30 reinelt Exp $ +/* $Id: plugin_proc_stat.c,v 1.11 2004/01/25 05:30:09 reinelt Exp $ * * plugin for /proc/stat parsing * @@ -23,6 +23,9 @@ * * * $Log: plugin_proc_stat.c,v $ + * Revision 1.11 2004/01/25 05:30:09 reinelt + * plugin_netdev for parsing /proc/net/dev added + * * Revision 1.10 2004/01/22 08:55:30 reinelt * fixed unhandled kernel-2.6 entries in /prco/stat * @@ -125,7 +128,8 @@ static int parse_proc_stat (void) while (!feof(stream)) { char buffer[1024]; - if (fgets (buffer, sizeof(buffer), stream) ==NULL) break; + if (fgets (buffer, sizeof(buffer), stream) == NULL) break; + if (strncmp(buffer, "cpu", 3)==0) { char *cpu; cpu=strtok(buffer, " \t\n"); -- cgit v1.2.3