diff options
author | reinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f> | 2000-01-16 12:17:59 +0000 |
---|---|---|
committer | reinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f> | 2000-01-16 12:17:59 +0000 |
commit | dfc5239aecb7e421afd26a4599bc4600d21e12c4 (patch) | |
tree | e884a890843544c3039c1af4c58e43e45b642018 /isdn.c | |
parent | fba83a8ef0ad2b95cbe55035441c9ad9435ae6c9 (diff) | |
download | lcd4linux-dfc5239aecb7e421afd26a4599bc4600d21e12c4.tar.gz |
[lcd4linux @ 2000-01-16 12:17:59 by reinelt]
Initial revision
git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@2 3ae390bd-cb1e-0410-b409-cd5a39f66f1f
Diffstat (limited to '')
-rw-r--r-- | isdn.c | 98 |
1 files changed, 98 insertions, 0 deletions
@@ -0,0 +1,98 @@ +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <unistd.h> +#include <fcntl.h> +#include <sys/ioctl.h> +#include <sys/types.h> +#include <linux/isdn.h> + +#include "isdn.h" +#include "filter.h" +#include "lcd4linux.h" + +typedef struct { + unsigned long in; + unsigned long out; +} CPS; + + +static int Usage (void) +{ + static int fd=0; + char buffer[4096], *p; + int i, usage; + + if (fd==-1) return 0; + + fd=open ("/dev/isdninfo", O_RDONLY | O_NDELAY); + if (fd==-1) { + perror ("open(/dev/isdninfo) failed"); + return 0; + } + + if (read (fd, buffer, sizeof(buffer))==-1) { + perror ("read(/dev/isdninfo) failed"); + fd=-1; + return 0; + } + + if (close(fd)==-1) { + perror ("close(/dev/isdninfo) failed"); + fd=-1; + return 0; + } + + p=strstr(buffer, "usage:"); + if (p==NULL) { + fprintf (stderr, "parse(/dev/isdninfo) failed: no usage line\n"); + fd=-1; + return 0; + } + p+=6; + + usage=0; + for (i=0; i<ISDN_MAX_CHANNELS; i++) { + usage|=strtol(p, &p, 10); + } + + return usage; +} + +int Isdn (int *rx, int *tx) +{ + static int fd=-2; + CPS cps[ISDN_MAX_CHANNELS]; + double cps_i, cps_o; + int i; + + *rx=0; + *tx=0; + + if (fd==-1) return 0; + + if (fd==-2) { + fd = open("/dev/isdninfo", O_RDONLY | O_NDELAY); + if (fd==-1) { + perror ("open(/dev/isdninfo) failed"); + return 0; + } + } + if (ioctl(fd, IIOCGETCPS, &cps)) { + perror("ioctl(IIOCGETCPS) failed"); + fd=-1; + return 0; + } + cps_i=0; + cps_o=0; + for (i=0; i<ISDN_MAX_CHANNELS; i++) { + cps_i+=cps[i].in; + cps_o+=cps[i].out; + } + + *rx=(int)smooth("isdn_rx", 1000, cps_i); + *tx=(int)smooth("isdn_tx", 1000, cps_o); + + return Usage(); +} + |