aboutsummaryrefslogtreecommitdiffstats
path: root/hash.c (follow)
AgeCommit message (Expand)AuthorFilesLines
2007-09-09email address changedmichael1-1/+1
2007-01-14removed all tagsmichael1-112/+0
2007-01-14svn properties fixedmichael1-1/+2
2005-05-08[lcd4linux @ 2005-05-08 04:32:43 by reinelt]reinelt1-287/+312
2005-01-18[lcd4linux @ 2005-01-18 06:30:21 by reinelt]reinelt1-3/+6
2004-06-26[lcd4linux @ 2004-06-26 12:04:59 by reinelt]reinelt1-2/+6
2004-06-26[lcd4linux @ 2004-06-26 09:27:20 by reinelt]reinelt1-64/+71
2004-06-20[lcd4linux @ 2004-06-20 10:09:52 by reinelt]reinelt1-7/+11
2004-06-17[lcd4linux @ 2004-06-17 06:23:39 by reinelt]reinelt1-158/+283
2004-06-13[lcd4linux @ 2004-06-13 01:12:52 by reinelt]reinelt1-2/+5
2004-06-01[lcd4linux @ 2004-06-01 06:45:28 by reinelt]reinelt1-3/+26
2004-05-31[lcd4linux @ 2004-05-31 16:39:05 by reinelt]reinelt1-2/+11
2004-03-11[lcd4linux @ 2004-03-11 06:39:58 by reinelt]reinelt1-17/+35
2004-03-03[lcd4linux @ 2004-03-03 08:40:07 by hejl]hejl1-1/+6
2004-03-03[lcd4linux @ 2004-03-03 04:44:16 by reinelt]reinelt1-24/+8
2004-03-03[lcd4linux @ 2004-03-03 03:47:04 by reinelt]reinelt1-4/+31
2004-02-27[lcd4linux @ 2004-02-27 06:07:55 by reinelt]reinelt1-19/+35
2004-01-30[lcd4linux @ 2004-01-30 20:57:55 by reinelt]reinelt1-1/+9
2004-01-29[lcd4linux @ 2004-01-29 04:40:02 by reinelt]reinelt1-1/+6
2004-01-27[lcd4linux @ 2004-01-27 04:48:57 by reinelt]reinelt1-3/+6
2004-01-22[lcd4linux @ 2004-01-22 07:57:45 by reinelt]reinelt1-4/+5
2004-01-21[lcd4linux @ 2004-01-21 14:29:03 by reinelt]reinelt1-13/+54
2004-01-21[lcd4linux @ 2004-01-21 10:48:17 by reinelt]reinelt1-3/+41
2004-01-20[lcd4linux @ 2004-01-20 05:36:59 by reinelt]reinelt1-1/+6
2004-01-18[lcd4linux @ 2004-01-18 09:01:45 by reinelt]reinelt1-21/+118
2004-01-18[lcd4linux @ 2004-01-18 06:54:08 by reinelt]reinelt1-13/+38
2004-01-16[lcd4linux @ 2004-01-16 07:26:25 by reinelt]reinelt1-88/+5
2004-01-16[lcd4linux @ 2004-01-16 05:04:53 by reinelt]reinelt1-3/+97
2004-01-13[lcd4linux @ 2004-01-13 10:03:01 by reinelt]reinelt1-0/+129
/* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
/* $Id: isdn.c,v 1.12 2003/11/24 11:34:54 reinelt Exp $
 *
 * ISDN specific functions
 *
 * Copyright 1999, 2000 Michael Reinelt <reinelt@eunet.at>
 *
 * 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: isdn.c,v $
 * Revision 1.12  2003/11/24 11:34:54  reinelt
 *
 * 'Fixed' Rows which do not scroll by Lars Kempe
 * temporary workaround for debian kernel-header bug
 *
 * Revision 1.11  2003/10/05 17:58:50  reinelt
 * libtool junk; copyright messages cleaned up
 *
 * Revision 1.10  2003/06/21 05:46:18  reinelt
 * DVB client integrated
 *
 * Revision 1.9  2001/05/27 07:19:28  reinelt
 *
 * fixed a warning in pixmap.c
 * temporarily fixed a bug in isdn.c (ISDN_MAX_CHANNELS is no longer defined?)
 * fixed a bug in configure.in (--with-drivers=xyz did not work)
 *
 * Revision 1.8  2000/08/10 18:42:20  reinelt
 *
 * fixed some bugs with the new syslog code
 *
 * Revision 1.7  2000/08/10 09:44:09  reinelt
 *
 * new debugging scheme: error(), info(), debug()
 * uses syslog if in daemon mode
 *
 * Revision 1.6  2000/04/15 11:56:35  reinelt
 *
 * more debug messages
 *
 * Revision 1.5  2000/03/13 15:58:24  reinelt
 *
 * release 0.9
 * moved row parsing to parser.c
 * all basic work finished
 *
 * Revision 1.4  2000/03/10 17:36:02  reinelt
 *
 * first unstable but running release
 *
 * 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:
 *
 * Isdn (int *rx, int *tx, int *usage)
 *   returns 0 if ok, -1 if error
 *   sets *usage to all channels USAGE or'ed together
 *   sets received/transmitted bytes in *rx, *tx
 *
 */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/types.h>

// Fixme: my debian has some bugs with kernel headers
#if 0
#include <linux/isdn.h>
#else
#define IIOCGETCPS  _IO('I',21)
#endif

// Fixme: ISDN_MAX_CHANNELS seems undefined in recent kernels
#ifndef ISDN_MAX_CHANNELS
#define ISDN_MAX_CHANNELS 64
#endif

#include "debug.h"
#include "isdn.h"
#include "filter.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) {
    error ("open(/dev/isdninfo) failed: %s", strerror(errno));
    return 0;
  }
  
  if (read (fd, buffer, sizeof(buffer))==-1) {
    error ("read(/dev/isdninfo) failed: %s", strerror(errno));
    fd=-1;
    return 0;
  }

  if (close(fd)==-1) {
    error ("close(/dev/isdninfo) failed: %s", strerror(errno));
    fd=-1;
    return 0;
  }

  p=strstr(buffer, "usage:");
  if (p==NULL) {
    error ("parse(/dev/isdninfo) failed: no usage line");
    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, int *usage)
{
  static int fd=-2;
  CPS cps[ISDN_MAX_CHANNELS];
  double cps_i, cps_o;
  int i;

  *usage=0;
  *rx=0;
  *tx=0;

  if (fd==-1) return -1;
  
  if (fd==-2) {
    fd = open("/dev/isdninfo", O_RDONLY | O_NDELAY);
    if (fd==-1) {
      error ("open(/dev/isdninfo) failed: %s", strerror(errno));
      return -1;
    }
    debug ("open (/dev/isdninfo)=%d", fd);
  }

  if (ioctl(fd, IIOCGETCPS, &cps)) {
    error("ioctl(IIOCGETCPS) failed: %s", strerror(errno));
    fd=-1;
    return -1;
  }

  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);
  *usage=Usage();

  return 0;
}