X-Git-Url: http://sigaev.ru/git/gitweb.cgi?p=trinked.git;a=blobdiff_plain;f=main.c;h=0fb4f1a1294917b8e41f60600661d3b43bbaeb3a;hp=7b2ab8f973cb2f65d6e9649aed39bd2f17d58cf8;hb=8cbe60be9b46ed1bd7aa695ed1be732524994d7d;hpb=767d08d38964048ea000c3d7700e9765c83dd87f diff --git a/main.c b/main.c index 7b2ab8f..0fb4f1a 100644 --- a/main.c +++ b/main.c @@ -7,10 +7,10 @@ * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE @@ -42,6 +42,7 @@ static int period = (300); /* in seconds */ static char* pidfile = NULL; static char* logfile = NULL; static bool daemonize = false; +static bool workaround = false; static char tfile[MAXPATHLEN], ofile[MAXPATHLEN]; @@ -51,7 +52,7 @@ static void usage(const char *errmsg) { puts("trinketd - collecting info from AtomPro"); puts("Copyright (c) 2016, Teodor Sigaev "); - puts("trinketd [-d] [-l logfile] [-p pidfile] [-P period] [-D datadir]"); + puts("trinketd [-d] [-l logfile] [-p pidfile] [-P period] [-D datadir] [-w]"); if (errmsg) { puts(""); @@ -75,7 +76,10 @@ restart: goto restart; } - while(42 && stopRequest == false) { + while(42) { + if (workaround) + trinketPing(); + if (trinketGetCumDose(&curDose) != ERR_OK) { fprintf(stderr, "trinketGetCumDose fails\n"); trinketClose(); @@ -85,7 +89,7 @@ restart: if (prevDose >= 0.0) { double counts = curDose - prevDose; - double radlevel = coefficient * counts * 3600.0 / (double)period; + double radlevel = 1e6 * coefficient * counts * 3600.0 / (double)period; FILE *fh = stdout; bool successOpen = true; @@ -99,7 +103,7 @@ 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); + fprintf(fh, "radlevel: %.02f\n", radlevel); } if (fh && fh != stdout) { @@ -127,7 +131,7 @@ main(int argn, char* argv[]) { logfd; opterr = 0; - while((i=getopt(argn,argv,"dD:p:P:h")) != EOF) { + while((i=getopt(argn,argv,"dD:l:p:P:wh")) != EOF) { switch(i) { case 'd': daemonize = true; @@ -135,12 +139,18 @@ main(int argn, char* argv[]) { case 'D': dbdir = strdup(optarg); break; + case 'l': + logfile = strdup(optarg); + break; case 'p': pidfile = strdup(optarg); break; case 'P': period = atoi(optarg); break; + case 'w': + workaround = true; + break; case 'h': default: usage(NULL);