📄 processor.c
字号:
/* $Id: processor.c,v 1.45 2003/09/11 04:09:53 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.45 2003/09/11 04:09:53 reinelt * minor cleanups * * Revision 1.44 2003/09/10 15:59:39 reinelt * minor cleanups * * Revision 1.43 2003/09/10 14:01:53 reinelt * icons nearly finished\! * * Revision 1.42 2003/09/10 08:37:09 reinelt * icons: reorganized tick_* again... * * Revision 1.41 2003/09/10 03:48:23 reinelt * Icons for M50530, new processing scheme (Ticks.Text...) * * Revision 1.40 2003/09/09 06:54:43 reinelt * new function 'cfg_number()' * * Revision 1.39 2003/09/09 05:30:34 reinelt * even more icons stuff * * Revision 1.38 2003/09/01 04:09:35 reinelt * icons nearly finished, but MatrixOrbital only * * Revision 1.37 2003/08/24 05:17:58 reinelt * liblcd4linux patch from Patrick Schemitz * * Revision 1.36 2003/08/17 16:37:39 reinelt * more icon framework * * Revision 1.35 2003/07/24 04:48:09 reinelt * 'soft clear' needed for virtual rows * * Revision 1.34 2003/07/21 06:34:14 reinelt * bars on virtual rows fixed * * Revision 1.33 2003/07/21 06:10:11 reinelt * removed maxlen parameter from process_row() * * Revision 1.32 2003/06/21 05:46:18 reinelt * DVB client integrated * * Revision 1.31 2003/06/13 06:35:56 reinelt * added scrolling capability * * Revision 1.30 2003/02/22 07:53:10 reinelt * cfg_get(key,defval) * * Revision 1.29 2003/02/05 04:31:38 reinelt * * T_EXEC: remove trailing CR/LF * T_EXEC: deactivated maxlen calculation (for I don't understand what it is for :-) * * Revision 1.28 2002/12/05 19:23:01 reinelt * fixed undefined operations found by gcc3 * * Revision 1.27 2002/08/19 04:41:20 reinelt * introduced bar.c, moved bar stuff from display.h to bar.h * * Revision 1.26 2001/05/06 10:01:27 reinelt * * fixed a bug which prevented extendet tokens to be used for GPO's * many thanks to Carsten Nau! * * Revision 1.25 2001/03/17 11:11:31 ltoetsch * bugfix: max for BAR_T * * Revision 1.24 2001/03/16 16:40:17 ltoetsch * implemented time bar * * Revision 1.23 2001/03/16 09:28:08 ltoetsch * bugfixes * * Revision 1.22 2001/03/15 15:49:23 ltoetsch * fixed compile HD44780.c, cosmetics * * Revision 1.21 2001/03/15 09:47:13 reinelt * * some fixes to ppdef * off-by-one bug in processor.c fixed * * Revision 1.20 2001/03/14 13:19:29 ltoetsch * Added pop3/imap4 mail support * * Revision 1.19 2001/03/13 08:34:15 reinelt * * corrected a off-by-one bug with sensors * * Revision 1.18 2001/03/08 15:25:38 ltoetsch * improved exec * * Revision 1.17 2001/03/08 08:39:55 reinelt * * fixed two typos * * Revision 1.16 2001/03/07 18:10:21 ltoetsch * added e(x)ec commands * * Revision 1.15 2001/03/02 10:18:03 ltoetsch * added /proc/apm battery stat * * 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 * GPO documentation update from Carsten * * Revision 1.12 2001/02/16 08:23:09 reinelt * * new token 'ic' (ISDN connected) by Carsten Nau <info@cnau.de> * * Revision 1.11 2001/02/14 07:40:16 reinelt * * first (incomplete) GPO implementation * * Revision 1.10 2001/02/13 09:00:13 reinelt * * prepared framework for GPO's (general purpose outputs) * * Revision 1.9 2001/02/11 23:34:07 reinelt * * fixed a small bug where the throughput of an offline ISDN connection * is displayed as '----', but the online value is 5 chars long. * corrected to ' ----'. Thanks to Carsten Nau <info@cnau.de> * * Revision 1.8 2000/08/10 09:44:09 reinelt * * new debugging scheme: error(), info(), debug() * uses syslog if in daemon mode * * Revision 1.7 2000/07/31 10:43:44 reinelt * * some changes to support kernel-2.4 (different layout of various files in /proc) * * Revision 1.6 2000/05/21 06:20:35 reinelt * * added ppp throughput * token is '%t[iomt]' at the moment, but this will change in the near future * * Revision 1.5 2000/04/15 11:56:35 reinelt * * more debug messages * * Revision 1.4 2000/04/15 11:13:54 reinelt * * added '-d' (debugging) switch * added several debugging messages * removed config entry 'Delay' for HD44780 driver * delay loop for HD44780 will be calibrated automatically * * Revision 1.3 2000/04/01 16:22:38 reinelt * * bug that caused a segfault in processor.c fixed (thanks to herp) * * Revision 1.2 2000/03/23 07:24:48 reinelt * * PPM driver up and running (but slow!) * * 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 (); * processes a whole screen * */#include <stdlib.h>#include <stdio.h>#include <string.h>#include <ctype.h>#include <sys/time.h>#include "debug.h"#include "cfg.h"#include "system.h"#include "isdn.h"#include "parser.h"#include "display.h"#include "bar.h"#include "processor.h"#include "mail.h"#include "battery.h"#include "dvb.h"#include "seti.h"#include "exec.h"#define ROWS 64#define ICONS 8#define GPOS 16static char *row[ROWS+1];static int gpo[GPOS+1];static int rows, cols, xres, yres, supported_bars, icons, gpos;static int lines, scroll, turn;static int token_usage[256]={0,};static struct { int total, used, free, shared, buffer, cache, avail; } ram;static struct { double load1, load2, load3, overload; } load;static struct { double user, nice, system, idle; } busy;static struct { int read, write, total, max, peak; } disk;static struct { int rx, tx, total, max, peak, bytes; } net;static struct { int usage, in, out, total, max, peak; } isdn;static struct { int rx, tx, total, max, peak; } ppp;static struct { int perc, stat; double dur; } batt;static struct { double perc, cput; } seti;static struct { int num, unseen;} mail[MAILBOXES+1];static struct { double val, min, max; } sensor[SENSORS+1];static struct { double strength, snr; } dvb;extern int tick, tack;static int tick_text, tick_bar, tick_icon, tick_gpo;static double query (int token){ switch (token&255) { 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_ETH_RX: return net.rx; case T_ETH_TX: return net.tx; case T_ETH_TOTAL: return net.total; case T_ETH_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_ISDN_USED: return isdn.usage; case T_PPP_RX: return ppp.rx; case T_PPP_TX: return ppp.tx; case T_PPP_TOTAL: return ppp.total; case T_PPP_MAX: return ppp.max; case T_SETI_PRC: return seti.perc; case T_SETI_CPU: return seti.cput; case T_BATT_PERC: return batt.perc; case T_BATT_STAT: return batt.stat; case T_BATT_DUR: return batt.dur; case T_DVB_STRENGTH: return dvb.strength; case T_DVB_SNR: return dvb.snr; case T_MAIL: return mail[(token>>8)-'0'].num; case T_MAIL_UNSEEN: return mail[(token>>8)-'0'].unseen; case T_SENSOR: return sensor[(token>>8)-'0'].val; case T_EXEC: return exec[(token>>8)-'0'].val; } return 0.0;}/* return a value 0..1 */static double query_bar (int token){ int i; double value=query(token); switch (token & 255) { 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_ETH_RX: case T_ETH_TX: case T_ETH_MAX: return value/net.peak; case T_ETH_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_PPP_RX: case T_PPP_TX: case T_PPP_MAX: return value/ppp.peak; case T_PPP_TOTAL: return value/ppp.peak/2.0; case T_SETI_PRC: return value; case T_BATT_PERC: { static int alarm; alarm=((alarm+1) % 3); if(value < atoi(cfg_get("battwarning","10")) && !alarm) /* flash bar */ value = 0; return value/100; } case T_SENSOR: i=(token>>8)-'0'; return (value-sensor[i].min)/(sensor[i].max-sensor[i].min); } return value;}static void print_token (int token, char **p, char *start){ double val; int i; switch (token & 255) { 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:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -