Mac OS X gamepad emulator for serial RC transmitters
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

serial.h 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. * ----------------------------------------------------------------------------
  3. * "THE BEER-WARE LICENSE" (Revision 42):
  4. * <xythobuz@xythobuz.de> wrote this file. As long as you retain this notice
  5. * you can do whatever you want with this stuff. If we meet some day, and you
  6. * think this stuff is worth it, you can buy me a beer in return. Thomas Buck
  7. * ----------------------------------------------------------------------------
  8. */
  9. #ifndef _SERIAL_H_
  10. #define _SERIAL_H_
  11. /*
  12. * Configuration
  13. */
  14. /*!
  15. * \brief Enable XON/XOFF flow control.
  16. *
  17. * If you uncomment this definition, the serial port code will
  18. * stop sending when a XOFF was received, and start again upon
  19. * receiving XON. However, you need to use the blocking
  20. * read/write functions!
  21. */
  22. //#define XONXOFF
  23. #define XON 0x11 //!< XON flow control character
  24. #define XOFF 0x13 //!< XOFF flow control character
  25. /*!
  26. * \brief Search term to filter the list of available ports.
  27. *
  28. * If you define SEARCH, instead of simply returning a list of
  29. * files in /dev/, getSerialPorts() will only return items that
  30. * contain the string defined to SEARCH.
  31. */
  32. #define SEARCH "tty"
  33. /*!
  34. * \brief Only list real serial ports.
  35. *
  36. * If you uncomment this definition, getSerialPorts() will try to
  37. * open every port, only returning the name if it is a real serial
  38. * port. This could cause a big delay, if eg. your system tries to
  39. * open non-existing bluetooth devices, waiting for their timeout.
  40. * Also, if your console tty is probed, it might change it's settings.
  41. */
  42. //#define TRY_TO_OPEN_PORTS
  43. /*!
  44. * \brief The timeout in seconds for raw reading/writing.
  45. *
  46. * If this amount of time passes without being able to write/read
  47. * a character, the raw I/O functions will return 0.
  48. */
  49. #define TIMEOUT 2
  50. /*
  51. * Setup
  52. */
  53. /*!
  54. * \brief open a serial port
  55. * \param port name of port
  56. * \param baud baudrate
  57. * \returns file handle or -1 on error
  58. */
  59. int serialOpen(const char *port, unsigned int baud);
  60. /*!
  61. * \brief close an open serial port
  62. * \param fd file handle of port to close
  63. */
  64. void serialClose(int fd);
  65. /*!
  66. * \brief query available serial ports
  67. * \returns string array with serial port names.
  68. * Last element is NULL. Don't forget to free()
  69. * after using it!
  70. */
  71. char **getSerialPorts(void);
  72. /*
  73. * Raw, non-blocking I/O
  74. */
  75. /*!
  76. * \brief read from an open serial port
  77. * \param fd file handle of port to read from
  78. * \param data buffer big enough to fit all read data
  79. * \param length maximum number of bytes to read
  80. * \returns number of bytes really read
  81. */
  82. unsigned int serialReadRaw(int fd, char *data, int length);
  83. /*!
  84. * \brief write to an open serial port
  85. * \param fd file handle of port to write to
  86. * \param data buffer containing data to write
  87. * \param length number of bytes to write
  88. * \returns number of bytes really written
  89. */
  90. unsigned int serialWriteRaw(int fd, const char *data, int length);
  91. /*!
  92. * \brief wait until data is sent
  93. * \param fd file handle of port to wait for
  94. */
  95. void serialWaitUntilSent(int fd);
  96. /*
  97. * Blocking I/O
  98. */
  99. /*!
  100. * \brief check if a character has arrived and can be read
  101. * \param fd file handle of port to check
  102. * \returns 1 if a character is available, 0 if not
  103. */
  104. int serialHasChar(int fd);
  105. /*!
  106. * \brief read a single character
  107. * \param fd file handle of port to read from
  108. * \param c where read character will be stored
  109. */
  110. void serialReadChar(int fd, char *c);
  111. /*!
  112. * \brief write a single character
  113. * \param fd file handle to write to
  114. * \param c character to write
  115. */
  116. void serialWriteChar(int fd, char c);
  117. /*!
  118. * \brief write a string
  119. * \param fd file handle to write to
  120. * \param s C string to be written
  121. */
  122. void serialWriteString(int fd, const char *s);
  123. #endif