123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- /*
- voltlogger_analyzer
-
- Copyright (C) 2015 Dmitry Yu Okunev <dyokunev@ut.mephi.ru> 0x8E30679C
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- #define _GNU_SOURCE
- #include "configuration.h"
- #include "macros.h"
- #include <stdio.h> /* getline() */
- #include <stdlib.h> /* atof() */
- #include <unistd.h> /* getopt() */
- #include <math.h>
- #include <assert.h>
- #include "error.h"
- #include "binary.h"
- #include "analyzer.h"
- int main(int argc, char *argv[]) {
- char realtime = 0;
- double clockscale = 1;
- double padding = 0;
- FILE *i_f = stdin, *o_f = stdout;
- int channelsNum = 1;
- // Initializing output subsystem
- {
- int output_method = OM_STDERR;
- int output_quiet = 0;
- int output_verbosity = 9;
- int output_debuglevel = 9;
- error_init(&output_method, &output_quiet, &output_verbosity, &output_debuglevel);
- }
- // Parsing arguments
- char c;
- while ((c = getopt (argc, argv, "ri:N:s:p:")) != -1) {
- char *arg;
- arg = optarg;
- switch (c)
- {
- case 'r':
- realtime = 1;
- break;
- case 'i':
- assert ((i_f = fopen(arg, "r")) != NULL);
- break;
- case 's':
- clockscale = atof(optarg);
- break;
- case 'N':
- channelsNum = atoi(optarg);
- break;
- case 'p':
- padding = atof(optarg);
- break;
- default:
- abort ();
- }
- }
- history_item_t history_item;
- static uint64_t sensorTS_prev = 0, sensorTS_prev_prev = 0, unixTSNano_prev;
- double sensorTSdeviation = 0;
- while (!feof(i_f)) {
- while(1) {
- long pos = ftell(i_f);
- history_item.row.unixTSNano = get_uint64(i_f, realtime);
- if (unixTSNano_prev != 0 && llabs((int64_t)history_item.row.unixTSNano - (int64_t)unixTSNano_prev) > 1E9*1E8) {
- //fprintf(stderr, "Wrong unixTSNano\n");
- exit(-1);
- fseek(i_f, pos+1, SEEK_SET);
- continue;
- }
- unixTSNano_prev = history_item.row.unixTSNano;
- break;
- }
- history_item.row.sensorTS = get_uint64(i_f, realtime);
-
- {
- int i = 0;
- while (i < channelsNum)
- history_item.row.value[i++] = get_uint32(i_f, realtime);
- }
- if (sensorTS_prev - sensorTS_prev_prev > 0)
- if ((history_item.row.sensorTS - sensorTS_prev) / (sensorTS_prev - sensorTS_prev_prev) > 10) {
- sensorTSdeviation += padding;
- sensorTSdeviation -= history_item.row.sensorTS - sensorTS_prev;
- }
- sensorTS_prev_prev = sensorTS_prev;
- sensorTS_prev = history_item.row.sensorTS;
- history_item.row.sensorTS += sensorTSdeviation;
- history_item.row.unixTSNano = 1E9*1E8 + (double)history_item.row.sensorTS * clockscale;
- out_uint64(o_f, history_item.row.unixTSNano);
- out_uint64(o_f, history_item.row.sensorTS);
- {
- int i = 0;
- while (i < channelsNum) {
- out_uint32(o_f, history_item.row.value[i++]);
- }
- }
- }
- return 0;
- }
|