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 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * essais de gadgets UI
  3. */
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <unistd.h>
  7. #include <ncurses.h>
  8. #include "../serial/serial.h"
  9. #include "terminal.h"
  10. int verbosity;
  11. /* ---------------------------------------------------------------- */
  12. int special_dumper(FILE *fp, unsigned char octet)
  13. {
  14. static int idx = 0;
  15. static unsigned char buffer[16];
  16. int foo, c;
  17. #if DEBUG_LEVEL > 1
  18. fprintf(stderr, "%s $%x %c\n", __func__, octet, octet);
  19. #endif
  20. buffer[idx++] = octet;
  21. if (idx==16) {
  22. fprintf(fp, "dmp : ");
  23. for (foo=0; foo<16; foo++) {
  24. fprintf(fp, "%02x ", buffer[foo]);
  25. if (7==foo) fprintf(fp, " ");
  26. }
  27. fprintf(fp, " - |");
  28. for (foo=0; foo<16; foo++) {
  29. c = buffer[foo];
  30. fprintf(fp, "%c", isprint(c) ? c : ' ');
  31. }
  32. fprintf(fp, "|\n"); fflush(fp);
  33. idx = 0;
  34. }
  35. return 0;
  36. }
  37. /* ---------------------------------------------------------------- */
  38. void help(int k)
  39. {
  40. puts("options : ");
  41. puts("\t-d\tserial device to read.");
  42. puts("\t-K\tset the K parameter.");
  43. puts("\t-v\tincrease verbosity.");
  44. exit(0);
  45. }
  46. /* ---------------------------------------------------------------- */
  47. int main(int argc, char *argv[])
  48. {
  49. int opt, foo;
  50. int serial_in;
  51. char *device = "/dev/ttyS0";
  52. int K = 0;
  53. // char ligne[100];
  54. while ((opt = getopt(argc, argv, "d:hv")) != -1) {
  55. switch (opt) {
  56. case 'd': device = optarg; break;
  57. case 'h': help(0); break;
  58. case 'K': K = atoi(optarg); break;
  59. case 'v': verbosity++; break;
  60. default: break;
  61. }
  62. }
  63. printf("\n*** compiled %s %s\n", __DATE__, __TIME__);
  64. printf("*** device: %s\n", device);
  65. serial_in = prepare_UART(device, 9600);
  66. if (serial_in < 0) {
  67. fprintf(stderr, "err open %s : %d\n", device, serial_in);
  68. exit(1);
  69. }
  70. sleep(1);
  71. foo = essai_terminal(serial_in, device, K);
  72. fprintf(stderr, "essai terminal -> %d\n", foo);
  73. return 0;
  74. }
  75. /* ---------------------------------------------------------------- */