print.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. voltlogger_analyzer
  3. Copyright (C) 2015 Dmitry Yu Okunev <dyokunev@ut.mephi.ru> 0x8E30679C
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. #define _GNU_SOURCE
  16. #include "configuration.h"
  17. #include "macros.h"
  18. #include <stdio.h> /* getline() */
  19. #include <stdlib.h> /* atof() */
  20. #include <unistd.h> /* getopt() */
  21. #include <math.h>
  22. #include <assert.h>
  23. #include "error.h"
  24. #include "binary.h"
  25. #include "analyzer.h"
  26. int main(int argc, char *argv[]) {
  27. char realtime = 0;
  28. FILE *i_f = stdin, *o_f = stdout;
  29. int channelsNum = 1;
  30. // Initializing output subsystem
  31. {
  32. int output_method = OM_STDERR;
  33. int output_quiet = 0;
  34. int output_verbosity = 9;
  35. int output_debuglevel = 9;
  36. error_init(&output_method, &output_quiet, &output_verbosity, &output_debuglevel);
  37. }
  38. // Parsing arguments
  39. char c;
  40. while ((c = getopt (argc, argv, "ri:N:")) != -1) {
  41. char *arg;
  42. arg = optarg;
  43. switch (c)
  44. {
  45. case 'r':
  46. realtime = 1;
  47. break;
  48. case 'i':
  49. assert ((i_f = fopen(arg, "r")) != NULL);
  50. break;
  51. case 'N':
  52. channelsNum = atoi(optarg);
  53. break;
  54. default:
  55. abort ();
  56. }
  57. }
  58. history_item_t history_item;
  59. static uint64_t unixTSNano_prev;
  60. while (!feof(i_f)) {
  61. while(1) {
  62. long pos = ftell(i_f);
  63. history_item.row.unixTSNano = get_uint64(i_f, realtime);
  64. if (unixTSNano_prev != 0 && llabs((int64_t)history_item.row.unixTSNano - (int64_t)unixTSNano_prev) > 1E9*1E8) {
  65. fprintf(stderr, "Wrong unixTSNano\n");
  66. if (i_f != stdin)
  67. fseek(i_f, pos+1, SEEK_SET);
  68. continue;
  69. }
  70. unixTSNano_prev = history_item.row.unixTSNano;
  71. break;
  72. }
  73. history_item.row.sensorTS = get_uint64(i_f, realtime);
  74. {
  75. int i = 0;
  76. while (i < channelsNum)
  77. history_item.row.value[i++] = get_uint32(i_f, realtime);
  78. }
  79. fprintf(o_f, "%lu\t%lu", history_item.row.unixTSNano, history_item.row.sensorTS);
  80. {
  81. int i = 0;
  82. while (i < channelsNum) {
  83. fprintf(o_f, "\t%u", history_item.row.value[i++]);
  84. }
  85. }
  86. fprintf(o_f, "\n");
  87. }
  88. return 0;
  89. }