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.

t.c 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Experiments with the serial input
  3. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. */
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <strings.h>
  8. #include <ctype.h>
  9. #include <time.h>
  10. #include <unistd.h> //Used for UART
  11. #include <fcntl.h> //Used for UART
  12. #include <errno.h>
  13. #include <termios.h> //Used for UART
  14. #include <getopt.h>
  15. #include "serial.h"
  16. int verbosity;
  17. /* ---------------------------------------------------------------- */
  18. int loop(int sfd, int iters)
  19. {
  20. int count, foo;
  21. long temps;
  22. char ligne[200];
  23. float datas[4];
  24. for (count=0; count<iters; count++) {
  25. foo = getline_to(sfd, ligne, 100, 0);
  26. //
  27. if (verbosity) {
  28. /* fprintf(stderr, "getline #%d on %d -> %d\n",
  29. count, iters, foo); */
  30. fprintf(stderr, "%s\n", ligne);
  31. }
  32. foo = parse4values(ligne, 'T', datas);
  33. //
  34. if (foo >= 0) {
  35. temps = time(NULL);
  36. values2temperature(datas);
  37. printf("%ld %f %f %f %f\n", temps,
  38. datas[0], datas[1], datas[2], datas[3]);
  39. fflush(stdout);
  40. }
  41. else {
  42. fprintf(stderr, "%s: parse -> %d\n", __func__, foo);
  43. }
  44. if (verbosity > 1) fprintf(stderr, "\n");
  45. }
  46. return 0;
  47. }
  48. /* ---------------------------------------------------------------- */
  49. int main (int argc, char *argv[])
  50. {
  51. int serial_in;
  52. char *device = "/dev/ttyACM0";
  53. int nbre, speed, opt;
  54. /* set some default values */
  55. verbosity = 0;
  56. nbre = 25;
  57. speed = 9600;
  58. while ((opt = getopt(argc, argv, "d:n:v")) != -1) {
  59. switch (opt) {
  60. case 'v': verbosity++; break;
  61. case 'n': nbre = atoi(optarg); break;
  62. case 'd': device = optarg; break;
  63. default:
  64. fprintf(stderr, "%s : uh ?", argv[0]);
  65. exit(1);
  66. break;
  67. }
  68. }
  69. if (verbosity) {
  70. fprintf(stderr, "Testing Serial Software - compiled " \
  71. __DATE__ " " __TIME__ "\n");
  72. }
  73. serial_in = prepare_UART(device, speed);
  74. if (serial_in < 0) {
  75. fprintf(stderr, "%s : open device : error %d on %s\n",
  76. argv[0], serial_in, device);
  77. exit(1);
  78. }
  79. fprintf(stderr, "going to listen on %d\n", serial_in);
  80. (void)loop(serial_in, nbre);
  81. return 0;
  82. }
  83. /* ---------------------------------------------------------------- */