projects
/
trinked.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
munin plugin
[trinked.git]
/
main.c
diff --git
a/main.c
b/main.c
index
4b2aab5
..
0fb4f1a
100644
(file)
--- 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
* 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
* 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
*
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@@
-27,7
+27,6
@@
*/
#include <fcntl.h>
*/
#include <fcntl.h>
-#include <signal.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
@@
-39,27
+38,21
@@
#include <trinket.h>
static char* dbdir = NULL;
#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* pidfile = NULL;
static char* logfile = NULL;
static bool daemonize = false;
+static bool workaround = false;
static char tfile[MAXPATHLEN],
ofile[MAXPATHLEN];
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) {
puts("trinketd - collecting info from AtomPro");
puts("Copyright (c) 2016, Teodor Sigaev <teodor@sigaev.ru>");
static void
usage(const char *errmsg) {
puts("trinketd - collecting info from AtomPro");
puts("Copyright (c) 2016, Teodor Sigaev <teodor@sigaev.ru>");
- 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("");
if (errmsg) {
puts("");
@@
-83,7
+76,10
@@
restart:
goto restart;
}
goto restart;
}
- while(42 && stopRequest == false) {
+ while(42) {
+ if (workaround)
+ trinketPing();
+
if (trinketGetCumDose(&curDose) != ERR_OK) {
fprintf(stderr, "trinketGetCumDose fails\n");
trinketClose();
if (trinketGetCumDose(&curDose) != ERR_OK) {
fprintf(stderr, "trinketGetCumDose fails\n");
trinketClose();
@@
-93,7
+89,7
@@
restart:
if (prevDose >= 0.0) {
double counts = curDose - prevDose;
if (prevDose >= 0.0) {
double counts = curDose - prevDose;
- double radlevel =
coefficient * counts
/ (double)period;
+ double radlevel =
1e6 * coefficient * counts * 3600.0
/ (double)period;
FILE *fh = stdout;
bool successOpen = true;
FILE *fh = stdout;
bool successOpen = true;
@@
-105,11
+101,12
@@
restart:
}
if (successOpen) {
}
if (successOpen) {
+ fprintf(fh, "total: %lld\n", (long long)curDose);
fprintf(fh, "counts: %lld\n", (long long)counts);
fprintf(fh, "counts: %lld\n", (long long)counts);
- fprintf(fh, "radlevel: %
e
\n", radlevel);
+ fprintf(fh, "radlevel: %
.02f
\n", radlevel);
}
}
- if (fh != stdout) {
+ if (fh
&& fh
!= stdout) {
fflush(fh);
fclose(fh);
rename(tfile, ofile);
fflush(fh);
fclose(fh);
rename(tfile, ofile);
@@
-132,10
+129,9
@@
main(int argn, char* argv[]) {
int i;
int pidfd,
logfd;
int i;
int pidfd,
logfd;
- struct sigaction sa;
opterr = 0;
opterr = 0;
- while((i=getopt(argn,argv,"dD:
p:P:
h")) != EOF) {
+ while((i=getopt(argn,argv,"dD:
l:p:P:w
h")) != EOF) {
switch(i) {
case 'd':
daemonize = true;
switch(i) {
case 'd':
daemonize = true;
@@
-143,12
+139,18
@@
main(int argn, char* argv[]) {
case 'D':
dbdir = strdup(optarg);
break;
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 'p':
pidfile = strdup(optarg);
break;
case 'P':
period = atoi(optarg);
break;
+ case 'w':
+ workaround = true;
+ break;
case 'h':
default:
usage(NULL);
case 'h':
default:
usage(NULL);
@@
-208,13
+210,6
@@
main(int argn, char* argv[]) {
snprintf(ofile, MAXPATHLEN, "%s/trinket.dat", dbdir);
}
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();
main_loop();
hid_exit();