/* geiger.c */ #include #include #include #include #include #include int main(int argc, char *argv[]) { int fd, flags, prevcts, count, events; if ((fd = open("/dev/cua0", O_RDONLY)) < 0) return 1; prevcts = -1; count = events = 0; while (ioctl(fd, TIOCMGET, &flags) == 0) { int cts = (flags & TIOCM_CTS); time_t t = time(0); struct tm *lt = localtime(&t); if (prevcts == -1) { prevcts = cts; } else if (cts != prevcts) { events++; prevcts = cts; } if (++count > 3000 && lt->tm_sec == 0 && lt->tm_min % 10 == 0) { FILE *f = fopen("/usr/local/apache/htdocs/geiger.dat", "a"); if (f != NULL) { fprintf(f, "%04d-%02d-%02d %02d:%02d %d\n", lt->tm_year + 1900, lt->tm_mon + 1, lt->tm_mday, lt->tm_hour, lt->tm_min, events); fclose(f); } count = events = 0; } usleep(100000); } close(fd); return 0; }