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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. }
  26. fprintf(fp, " - |");
  27. for (foo=0; foo<16; foo++) {
  28. c = buffer[foo];
  29. fprintf(fp, "%c", isprint(c) ? c : ' ');
  30. }
  31. fprintf(fp, "|\n"); fflush(fp);
  32. idx = 0;
  33. }
  34. return 0;
  35. }
  36. /* ---------------------------------------------------------------- */
  37. void help(int k)
  38. {
  39. puts("options : ");
  40. puts("\t-d\tserial device to read.");
  41. puts("\t-K\tset the K parameter.");
  42. puts("\t-v\tincrease verbosity.");
  43. exit(0);
  44. }
  45. /* ---------------------------------------------------------------- */
  46. int main(int argc, char *argv[])
  47. {
  48. int opt, foo;
  49. int serial_in;
  50. char *device = "/dev/ttyS0";
  51. int K = 0;
  52. // char ligne[100];
  53. while ((opt = getopt(argc, argv, "d:hv")) != -1) {
  54. switch (opt) {
  55. case 'd': device = optarg; break;
  56. case 'h': help(0); break;
  57. case 'K': K = atoi(optarg); break;
  58. case 'v': verbosity++; break;
  59. default: break;
  60. }
  61. }
  62. printf("\n*** compiled %s %s\n", __DATE__, __TIME__);
  63. printf("*** device: %s\n", device);
  64. serial_in = prepare_UART(device, 9600);
  65. if (serial_in < 0) {
  66. fprintf(stderr, "err open %s : %d\n", device, serial_in);
  67. exit(1);
  68. }
  69. sleep(1);
  70. foo = essai_terminal(serial_in, device, K);
  71. fprintf(stderr, "essai terminal -> %d\n", foo);
  72. return 0;
  73. }
  74. /* ---------------------------------------------------------------- */