Monitoring du Phytotron
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

essai.c 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * essai.c
  3. */
  4. #include <stdio.h>
  5. #include <unistd.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include <curses.h>
  9. #include <time.h>
  10. #include "core/utils.h"
  11. #include "core/sysmetrics.h"
  12. #include "serial/serial.h"
  13. #include "viz/curses/ecran.h"
  14. int verbosity;
  15. /* --------------------------------------------------------------- */
  16. int affiche_valeurs(int sfd, int nbloops)
  17. {
  18. int idx, foo;
  19. char ligne[200];
  20. int Idatas[4];
  21. float Fdatas[4];
  22. FILE *fp;
  23. time_t temps,
  24. old_temps = (time_t)0L;
  25. /* XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX */
  26. fp = fopen("serial/foo.dat", "a");
  27. if (NULL==fp) {
  28. fprintf(stderr, "***** error fopen datafile *****\n");
  29. return -1;
  30. }
  31. /* XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX */
  32. for (idx=0; idx<nbloops; idx++) {
  33. foo = getline_to(sfd, ligne, 100, 0);
  34. if (verbosity) message(ligne);
  35. #if DEBUG_LEVEL
  36. if (foo) fprintf(stderr, "get values -> %d\n", foo);
  37. #endif
  38. foo = parse4_Ivalues(ligne, 'T', Idatas);
  39. #if DEBUG_LEVEL
  40. if (foo) fprintf(stderr, "parse I val -> %d\n", foo);
  41. #endif
  42. values2temperature(Idatas, Fdatas);
  43. for (foo=0; foo<3; foo++) {
  44. sprintf(ligne, "%4d", Idatas[foo]);
  45. minidigit_affstr(stdscr, 12+(12*foo), 8, ligne);
  46. aff7segs_float(stdscr, 8+(12*foo), 55, Fdatas[foo]);
  47. }
  48. /* here we are trying to log all that temps values */
  49. if (NULL!=fp) {
  50. temps = time(NULL);
  51. if ((temps-old_temps) > 50) {
  52. fprintf(fp, "%ld %f %f %f %f\n", temps,
  53. Fdatas[0], Fdatas[1], Fdatas[2], Fdatas[3]);
  54. fflush(fp);
  55. old_temps = temps;
  56. }
  57. }
  58. }
  59. fclose(fp);
  60. return 0;
  61. }
  62. /* --------------------------------------------------------------- */
  63. static void finish(int signal)
  64. {
  65. endwin();
  66. fprintf(stderr, "end of pid %d\n", getpid());
  67. exit(0);
  68. }
  69. /* --------------------------------------------------------------- */
  70. void help(int k)
  71. {
  72. puts("options : ");
  73. puts("\t-d\tserial device to read.");
  74. puts("\t-v\tincrease verbosity.");
  75. exit(0);
  76. }
  77. /* --------------------------------------------------------------- */
  78. int main(int argc, char *argv[])
  79. {
  80. int opt, foo;
  81. int serial_in;
  82. char *device = "/dev/ttyACM0";
  83. while ((opt = getopt(argc, argv, "d:hv")) != -1) {
  84. switch (opt) {
  85. case 'd': device = optarg; break;
  86. case 'h': help(0); break;
  87. case 'v': verbosity++; break;
  88. default: break;
  89. }
  90. }
  91. serial_in = prepare_UART(device, 9600);
  92. if (serial_in < 0) {
  93. fprintf(stderr, "%s : open device : error %d on %s\n",
  94. argv[0], serial_in, device);
  95. exit(1);
  96. }
  97. initscr();
  98. nonl(); cbreak(); noecho();
  99. keypad(stdscr, TRUE); /* acces aux touches 'curseur' */
  100. fond_ecran(" Demonstrator ");
  101. affiche_valeurs(serial_in, 5000000);
  102. /*
  103. * plop, on a fini, il faut restaurer la console
  104. */
  105. finish(0);
  106. return 0;
  107. }
  108. /* --------------------------------------------------------------- */