Smart-Home am Beispiel der Präsenzerkennung im Raum Projektarbeit Lennart Heimbs, Johannes Krug, Sebastian Dohle und Kevin Holzschuh bei Prof. Oliver Hofmann SS2019
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.

SerialPort.h 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * The MySensors Arduino library handles the wireless radio link and protocol
  3. * between your home built sensors/actuators and HA controller of choice.
  4. * The sensors forms a self healing radio network with optional repeaters. Each
  5. * repeater and gateway builds a routing tables in EEPROM which keeps track of the
  6. * network topology allowing messages to be routed to nodes.
  7. *
  8. * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
  9. * Copyright (C) 2013-2018 Sensnology AB
  10. * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors
  11. *
  12. * Documentation: http://www.mysensors.org
  13. * Support Forum: http://forum.mysensors.org
  14. *
  15. * This program is free software; you can redistribute it and/or
  16. * modify it under the terms of the GNU General Public License
  17. * version 2 as published by the Free Software Foundation.
  18. */
  19. #ifndef SerialPort_h
  20. #define SerialPort_h
  21. #include <string>
  22. #include <stdbool.h>
  23. #include "Stream.h"
  24. /**
  25. * SerialPort Class
  26. * Class that provides the functionality of arduino Serial library
  27. */
  28. class SerialPort : public Stream
  29. {
  30. private:
  31. int sd; //!< @brief file descriptor number.
  32. std::string serialPort; //!< @brief tty name.
  33. bool isPty; //!< @brief true if serial is pseudo terminal.
  34. public:
  35. /**
  36. * @brief SerialPort constructor.
  37. */
  38. SerialPort(const char *port, bool isPty = false);
  39. /**
  40. * @brief Open the serial port and set the data rate in bits per second (baud).
  41. *
  42. * This function will terminate the program on an error.
  43. *
  44. * @param bauds bits per second.
  45. */
  46. void begin(int bauds);
  47. /**
  48. * @brief Open the serial port and set the data rate in bits per second (baud).
  49. *
  50. * @param bauds bits per second.
  51. * @return @c true if no errors, else @c false.
  52. */
  53. bool open(int bauds = 115200);
  54. /**
  55. * @brief Grant access to the specified system group for the serial device.
  56. *
  57. * @param groupName system group name.
  58. */
  59. bool setGroupPerm(const char *groupName);
  60. /**
  61. * @brief Get the number of bytes available.
  62. *
  63. * Get the numberof bytes (characters) available for reading from
  64. * the serial port.
  65. *
  66. * @return number of bytes avalable to read.
  67. */
  68. int available();
  69. /**
  70. * @brief Reads 1 byte of incoming serial data.
  71. *
  72. * @return first byte of incoming serial data available.
  73. */
  74. int read();
  75. /**
  76. * @brief Writes a single byte to the serial port.
  77. *
  78. * @param b byte to write.
  79. * @return number of bytes written.
  80. */
  81. size_t write(uint8_t b);
  82. /**
  83. * @brief Writes binary data to the serial port.
  84. *
  85. * @param buffer to write.
  86. * @param size of the buffer.
  87. * @return number of bytes written.
  88. */
  89. size_t write(const uint8_t *buffer, size_t size);
  90. /**
  91. * @brief
  92. *
  93. * Returns the next byte (character) of incoming serial data without removing it from
  94. * the internal serial buffer.
  95. *
  96. * @return -1 if no data else character in the buffer.
  97. */
  98. int peek();
  99. /**
  100. * @brief Remove any data remaining on the serial buffer.
  101. */
  102. void flush();
  103. /**
  104. * @brief Disables serial communication.
  105. */
  106. void end();
  107. };
  108. #endif