Logiciels divers autour du protocole « Open Sound Control » aka OSC
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.

75 lines
1.7 KiB

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <termios.h> /* serial things */
  4. #include <unistd.h>
  5. #include <fcntl.h>
  6. #include "serial.h"
  7. /* ----------------------------------------------------------------- */
  8. /*
  9. * this variable must be declared/initialised in your
  10. * main program.
  11. */
  12. extern int verbosity;
  13. /* ----------------------------------------------------------------- */
  14. /* values for 'bauds' can be found in /usr/include/bits/termios.h
  15. */
  16. int open_serial(char *dev, int bauds, int unused)
  17. {
  18. int fd;
  19. #if DEBUG_LEVEL
  20. fprintf(stderr, "opening %s (b/s code : 0%06o)\n", dev, bauds);
  21. #endif
  22. fd = open(dev, O_RDWR, O_NOCTTY);
  23. if (fd < 0) {
  24. perror(dev);
  25. return -1;
  26. }
  27. return fd;
  28. }
  29. /* ----------------------------------------------------------------- */
  30. /*
  31. * from the manpage
  32. The zero baud rate, B0, is used to terminate the connection. If B0 is
  33. specified, the modem control lines shall no longer be asserted. Normally,
  34. this will disconnect the line.
  35. */
  36. int bauds_str_to_B(char *strb, int unused)
  37. {
  38. long value;
  39. #if DEBUG_LEVEL
  40. fprintf(stderr, "--> %s ( '%s' 0x%x )\n", __func__, strb, unused);
  41. #endif
  42. if (1 != sscanf(strb, "%ld", &value)) {
  43. return B0;
  44. }
  45. #if DEBUG_LEVEL
  46. fprintf(stderr, " computed baudrate = %ld\n", value);
  47. #endif
  48. switch (value) {
  49. case 50: return B50;
  50. case 75: return B75;
  51. case 110: return B110;
  52. case 300: return B300;
  53. case 1200: return B1200;
  54. case 2400: return B2400;
  55. case 4800: return B4800;
  56. case 9600: return B9600;
  57. case 19200: return B19200;
  58. }
  59. return B0;
  60. }
  61. /* ----------------------------------------------------------------- */
  62. /* ----------------------------------------------------------------- */
  63. /* ----------------------------------------------------------------- */