/* $Id: system.c,v 1.12 2000/05/21 06:20:35 reinelt Exp $ * * system status retreivement * * 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: system.c,v $ * Revision 1.12 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.11 2000/04/15 11:56:35 reinelt * * more debug messages * * Revision 1.10 2000/04/13 06:09:52 reinelt * * added BogoMips() to system.c (not used by now, maybe sometimes we can * calibrate our delay loop with this value) * * added delay loop to HD44780 driver. It seems to be quite fast now. Hopefully * no compiler will optimize away the delay loop! * * Revision 1.9 2000/03/28 07:22:15 reinelt * * version 0.95 released * X11 driver up and running * minor bugs fixed * * Revision 1.8 2000/03/23 07:24:48 reinelt * * PPM driver up and running (but slow!) * * Revision 1.7 2000/03/18 08:07:04 reinelt * * vertical bars implemented * bar compaction improved * memory information implemented * * Revision 1.6 2000/03/17 09:21:42 reinelt * * various memory statistics added * * Revision 1.5 2000/03/10 17:36:02 reinelt * * first unstable but running release * * Revision 1.4 2000/03/10 10:49:53 reinelt * * MatrixOrbital driver finished * * Revision 1.3 2000/03/07 11:01:34 reinelt * * system.c cleanup * * Revision 1.2 2000/03/06 06:04:06 reinelt * * minor cleanups * * */ /* * exported functions: * * char *System (void); * returns OS name ('Linux') * * char *Release (void); * returns OS release ('2.0.38') * * char *Processor (void); * returns processor type ('i686') * * double BogoMips (void); * returns BogoMips from /proc/cpuinfo * * int Memory (void); * returns main memory (Megabytes) * * int Ram (int *total, int *free, int *shared, int *buffer, int *cached) * sets various usage of ram * retuns 0 if ok, -1 on error * * int Load (double *load1, double *load2, double *load3) * sets load average during thwe last 1, 5 and 15 minutes * retuns 0 if ok, -1 on error * * int Busy (double *user, double *nice, double *system, double *idle) * sets percentage of CPU time spent in user processes, nice'd processes * system calls and idle state * returns 0 if ok, -1 on error * * int Disk (int *r, int *w); * sets number of read and write accesses to all disks * returns 0 if ok, -1 on error * * int Net (int *rx, int *tx); * sets number of packets received and transmitted * returns 0 if ok, -1 on error * * int PPP (int unit, int *rx, int *tx); * sets number of packets received and transmitted * returns 0 if ok, -1 on error * * int Sensor (int index, double *val, double *min, double *max) * sets the current value of the index'th sensor and * the minimum and maximum values from the config file * returns 0 if ok, -1 on error * */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "debug.h" #include "cfg.h" #include "system.h" #include "filter.h" static int parse_
# Channel table for Santa Albertina - SP - Brazil
# Source: http://www.portalbsd.com.br/terrestres_channels.php?channels=3509

# Physical channel 32
[Rede Vida]
	DELIVERY_SYSTEM = ISDBT
	BANDWIDTH_HZ = 6000000
	FREQUENCY = 581142857
	INVERSION = AUTO
	GUARD_INTERVAL = AUTO
	TRANSMISSION_MODE = AUTO
	INVERSION = AUTO
	GUARD_INTERVAL = AUTO
	TRANSMISSION_MODE = AUTO
	ISDBT_LAYER_ENABLED = 7
	ISDBT_SOUND_BROADCASTING = 0
	ISDBT_SB_SUBCHANNEL_ID = 0
	ISDBT_SB_SEGMENT_IDX = 0
	ISDBT_SB_SEGMENT_COUNT = 0
	ISDBT_LAYERA_FEC = AUTO
	ISDBT_LAYERA_MODULATION = QAM/AUTO
	ISDBT_LAYERA_SEGMENT_COUNT = 0
	ISDBT_LAYERA_TIME_INTERLEAVING = 0
	ISDBT_LAYERB_FEC = AUTO
	ISDBT_LAYERB_MODULATION = QAM/AUTO
	ISDBT_LAYERB_SEGMENT_COUNT = 0
	ISDBT_LAYERB_TIME_INTERLEAVING = 0
	ISDBT_LAYERC_FEC = AUTO
	ISDBT_LAYERC_MODULATION = QAM/AUTO
	ISDBT_LAYERC_SEGMENT_COUNT = 0
	ISDBT_LAYERC_TIME_INTERLEAVING = 0
; return -1; } p=strstr(buffer, "disk_rblk"); if (p==NULL) { fprintf (stderr, "parse(/proc/stat) failed: no 'disk_rblk' line\n"); fd=-1; return -1; } if (sscanf(p+9, "%lu %lu %lu %lu\n", &r1, &r2, &r3, &r4)<4) { fprintf (stderr, "scanf(/proc/stat) failed\n"); fd=-1; return -1; } p=strstr(buffer, "disk_wblk"); if (p==NULL) { fprintf (stderr, "parse(/proc/stat) failed: no 'disk_wblk' line\n"); fd=-1; return -1; } if (sscanf(p+9, "%lu %lu %lu %lu\n", &w1, &w2, &w3, &w4)<4) { fprintf (stderr, "scanf(/proc/stat) failed\n"); fd=-1; return -1; } *r=smooth ("disk_r", 500, r1+r2+r3+r4); *w=smooth ("disk_w", 500, w1+w2+w3+w4); return 0; } int Net (int *rx, int *tx) { char buffer[4096], *p, *s; static int fd=-2; unsigned long pkg_rx, pkg_tx; *rx=0; *tx=0; if (fd==-1) return -1; if (fd==-2) { fd = open("/proc/net/dev", O_RDONLY | O_NDELAY); if (fd==-1) { perror ("open(/proc/net/dev) failed"); return -1; } debug ("open (/proc/net/dev)=%d\n", fd); } if (lseek(fd, 0L, SEEK_SET)!=0) { perror ("lseek(/proc/net/dev) failed"); fd=-1; return -1; } if (read (fd, &buffer, sizeof(buffer)-1)==-1) { perror ("read(/proc/net/dev) failed"); fd=-1; return -1; } pkg_rx=0; pkg_tx=0; p=buffer; while ((s=strsep(&p, "\n"))) { unsigned long r, t; if (sscanf (s, " eth%*d:%*d: %ld %*d %*d %*d %*d %ld", &r, &t)==2 || sscanf (s, " eth%*d: %ld %*d %*d %*d %*d %ld", &r, &t)==2) { pkg_rx+=r; pkg_tx+=t; } } *rx=smooth("net_rx", 500, pkg_rx); *tx=smooth("net_tx", 500, pkg_tx); return 0; } int PPP (int unit, int *rx, int *tx) { static int fd=-2; struct ifpppstatsreq req; char buffer[16]; *rx=0; *tx=0; if (fd==-1) return -1; if (fd==-2) { fd = socket(AF_INET, SOCK_DGRAM, 0); if (fd==-1) { perror ("socket() failed"); return -1; } debug ("socket()=%d\n", fd); } memset (&req, 0, sizeof (req)); req.stats_ptr = (caddr_t) &req.stats; snprintf (req.ifr__name, sizeof(req.ifr__name), "ppp%d", unit); if (ioctl(fd, SIOCGPPPSTATS, &req) < 0) return 0; snprintf (buffer, sizeof(buffer), "ppp%d_rx", unit); *rx=smooth(buffer, 500, req.stats.p.ppp_ibytes); snprintf (buffer, sizeof(buffer), "ppp%d_tx", unit); *tx=smooth(buffer, 500, req.stats.p.ppp_obytes); return 0; } int Sensor (int index, double *val, double *min, double *max) { char buffer[32]; double value; static int fd[SENSORS]={[0 ... SENSORS-1]=-2,}; static char *sensor[SENSORS]={NULL,}; static double val_buf[SENSORS]={0.0,}; static double min_buf[SENSORS]={0.0,}; static double max_buf[SENSORS]={0.0,}; static time_t now[SENSORS]={0,}; if (index<1 || index>=SENSORS) return -1; *val=val_buf[index]; *min=min_buf[index]; *max=max_buf[index]; if (fd[index]==-1) return -1; if (time(NULL)==now[index]) return 0; time(&now[index]); if (fd[index]==-2) { snprintf(buffer, 32, "Sensor%d", index); sensor[index]=cfg_get(buffer); if (sensor[index]==NULL || *sensor[index]=='\0') { fprintf (stderr, "%s: no entry for '%s'\n", cfg_file(), buffer); fd[index]=-1; return -1; } snprintf(buffer, 32, "Sensor%d_min", index); min_buf[index]=atof(cfg_get(buffer)?:"0"); snprintf(buffer, 32, "Sensor%d_max", index); max_buf[index]=atof(cfg_get(buffer)?:"100"); fd[index]=open(sensor[index], O_RDONLY); if (fd[index]==-1) { fprintf (stderr, "open(%s) failed: %s\n", sensor[index], strerror(errno)); return -1; } debug ("open (%s)=%d\n", sensor[index], fd[index]); } if (lseek(fd[index], 0L, SEEK_SET)!=0) { fprintf (stderr, "lseek(%s) failed: %s\n", sensor[index], strerror(errno)); fd[index]=-1; return -1; } if (read (fd[index], &buffer, sizeof(buffer)-1)==-1) { fprintf (stderr, "read(%s) failed: %s\n", sensor[index], strerror(errno)); fd[index]=-1; return -1; } if (sscanf(buffer, "%*f %*f %lf", &value)<1) { fprintf (stderr, "scanf(%s) failed\n", sensor[index]); fd[index]=-1; return -1; } val_buf[index]=value; *val=value; return 0; }