tweak counting
authorTeodor Sigaev <teodor@sigaev.ru>
Mon, 4 Apr 2016 06:52:42 +0000 (09:52 +0300)
committerTeodor Sigaev <teodor@sigaev.ru>
Mon, 4 Apr 2016 06:52:42 +0000 (09:52 +0300)
main.c

diff --git a/main.c b/main.c
index 4b2aab5..7b2ab8f 100644 (file)
--- a/main.c
+++ b/main.c
@@ -27,7 +27,6 @@
  */
 
 #include <fcntl.h>
-#include <signal.h>
 #include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <trinket.h>
 
 static char*   dbdir = NULL;
-static int             period = (150);
+static int             period = (300); /* in seconds */
 static char*   pidfile = NULL;
 static char*   logfile = NULL;
 static bool            daemonize = false;
 static char            tfile[MAXPATHLEN],
                                ofile[MAXPATHLEN];
 
-static const double coefficient = 1.0;
-
-static bool                    stopRequest = false;
-
-static void
-sig_int(int sig) {
-       stopRequest = true;
-}
+static const double coefficient = (248e-6 / 2637.0);
 
 static void
 usage(const char *errmsg) {
@@ -93,7 +85,7 @@ restart:
 
                if (prevDose >= 0.0) {
                        double  counts = curDose - prevDose;
-                       double  radlevel = coefficient * counts / (double)period;
+                       double  radlevel = coefficient * counts * 3600.0 / (double)period;
                        FILE    *fh = stdout;
                        bool    successOpen = true;
 
@@ -105,11 +97,12 @@ restart:
                        }
 
                        if (successOpen) {
+                               fprintf(fh, "total: %lld\n", (long long)curDose);
                                fprintf(fh, "counts: %lld\n", (long long)counts);
                                fprintf(fh, "radlevel: %e\n", radlevel);
                        }
 
-                       if (fh != stdout) {
+                       if (fh && fh != stdout) {
                                fflush(fh);
                                fclose(fh);
                                rename(tfile, ofile);
@@ -132,7 +125,6 @@ main(int argn, char* argv[]) {
        int i;
        int     pidfd,
                logfd;
-       struct sigaction sa;
 
        opterr = 0;
        while((i=getopt(argn,argv,"dD:p:P:h")) != EOF) {
@@ -208,13 +200,6 @@ main(int argn, char* argv[]) {
                snprintf(ofile, MAXPATHLEN, "%s/trinket.dat", dbdir);
        }
 
-       memset(&sa, 0, sizeof(sa));
-       sigemptyset(&sa.sa_mask);
-       sa.sa_handler = sig_int;
-       sigaction(SIGINT, &sa, 0);
-       sigaction(SIGTERM, &sa, 0);
-       sigaction(SIGHUP, &sa, 0);
-
        main_loop();
 
        hid_exit();