--- geiger.c 2003-08-04 22:55:14.000000000 +0200 +++ geiger_usb.c 2007-09-08 19:54:48.000000000 +0200 @@ -59,7 +59,6 @@ #include #include #include -#include #define GAVERAGE 5 /* Number of minutes to average over */ #define GWAIT 60 /* Number of seconds to wait (for testing) */ @@ -73,22 +72,23 @@ static double click[GAVERAGE]; static int currentClick, maxClick; static gDataT d0, d1; -static const char *logfile; +static const char *logfile = NULL; static char filename[2048]; static FILE *str; - +static int count = 0; +static int divide = 1; static void gLog(gDataT *d0, gDataT *d1) { double current, average, total; int i; - double factor = 1000.0 / 1050.0; /* RM-60 */ + double factor = 1000.0 / 1490.0; /* RM-70 */ /* Compute uR/hr for previous minute. * Note that, for the RM-60, * counts/minute * 1000/1050 = uR/hr * (see http://www.aw-el.com/specs.htm) */ time_t seconds = d1->t - d0->t; - current = (double)(d1->count - d0->count) * factor * 60.0 / seconds; + current = (double)(d1->count - d0->count) / divide * factor * 60.0 / seconds; /* Maintain table for computing average */ click[currentClick++] = current; @@ -121,11 +121,8 @@ static void gRead(gDataT *data) { - struct serial_icounter_struct icount; - time(&data->t); - ioctl(fd, TIOCGICOUNT, &icount); - data->count = icount.rng; + data->count = count; } static void gHandler(int sig) @@ -133,6 +130,7 @@ gRead(&d1); gLog(&d0, &d1); d0 = d1; + count--; /* SIGALRM causes the ioctl to return */ alarm(GWAIT); } @@ -190,6 +188,7 @@ "-t specify tty (default = " DEFAULT_TTY ")", "-d increase debugging level", "-l logfile name in strftime(3) format", + "-u divide counts by two (needed for most USB to serial adapters)", "-h give this help", 0 }; const char **p = help_msg; @@ -206,11 +205,12 @@ int c; struct sigaction sa; - while ((c = getopt( argc, argv, "t:dl:")) != EOF) + while ((c = getopt( argc, argv, "t:dl:u")) != EOF) switch (c) { case 't': tty = optarg; break; case 'd': ++debug; break; case 'l': logfile = optarg; break; + case 'u': divide = 2; break; default: help(); exit(0); } @@ -236,7 +236,8 @@ * you're timing events, be sure to check that an event actually * happened. Note that the delivery of SIGALRM causes the ioctl * to return. */ - ioctl(fd, TIOCMIWAIT, debug ? TIOCM_RNG : 0); + ioctl(fd, TIOCMIWAIT, TIOCM_RNG); + count++; if (debug) { time_t t; time(&t);