main.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 "analyzer.h"
  25. enum functype {
  26. FT_SIN
  27. };
  28. typedef enum functype functype_t;
  29. static char *const functypes[] = {
  30. [FT_SIN] = "sin",
  31. NULL
  32. };
  33. int main(int argc, char *argv[]) {
  34. functype_t functype = FT_SIN;
  35. char realtime = 0;
  36. float frequency = 50;
  37. double errorthreshold = 1;
  38. int concurrency = 1;
  39. char *checkpointpath = NULL;
  40. FILE *input = stdin;
  41. int channelsNum = 1;
  42. int channelId = 0;
  43. // Initializing output subsystem
  44. {
  45. int output_method = OM_STDERR;
  46. int output_quiet = 0;
  47. int output_verbosity = 9;
  48. int output_debuglevel = 9;
  49. error_init(&output_method, &output_quiet, &output_verbosity, &output_debuglevel);
  50. }
  51. // Parsing arguments
  52. char c;
  53. while ((c = getopt (argc, argv, "ri:f:F:c:C:e:N:n:")) != -1) {
  54. char *arg;
  55. arg = optarg;
  56. switch (c)
  57. {
  58. case 'f': {
  59. char *value;
  60. functype = getsubopt(&arg, functypes, &value);
  61. break;
  62. }
  63. case 'F':
  64. frequency = atof(optarg);
  65. break;
  66. case 'r':
  67. realtime = 1;
  68. break;
  69. case 'c':
  70. concurrency = atoi(optarg);
  71. break;
  72. case 'C':
  73. checkpointpath = arg;
  74. break;
  75. case 'i':
  76. assert ((input = fopen(arg, "r")) != NULL);
  77. break;
  78. case 'e':
  79. errorthreshold = atof(optarg);
  80. break;
  81. case 'N':
  82. channelsNum = atoi(optarg);
  83. break;
  84. case 'n':
  85. channelId = atoi(optarg);
  86. break;
  87. default:
  88. abort ();
  89. }
  90. }
  91. assert (channelsNum > 0);
  92. assert (channelId < channelsNum);
  93. switch (functype) {
  94. case FT_SIN:
  95. vl_analyze_sin(input, stdout, channelsNum, channelId, checkpointpath, concurrency, frequency, errorthreshold, realtime);
  96. break;
  97. default:
  98. fprintf(stderr, "Unknown approximation function\n");
  99. abort ();
  100. }
  101. return 0;
  102. }