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.

EthernetClient.h 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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. * Based on Arduino ethernet library, Copyright (c) 2010 Arduino LLC. All right reserved.
  20. */
  21. #ifndef EthernetClient_h
  22. #define EthernetClient_h
  23. #include "Client.h"
  24. #include "IPAddress.h"
  25. // State codes from W5100 library
  26. #define ETHERNETCLIENT_W5100_CLOSED 0x00
  27. #define ETHERNETCLIENT_W5100_LISTEN 0x14
  28. #define ETHERNETCLIENT_W5100_SYNSENT 0x15
  29. #define ETHERNETCLIENT_W5100_SYNRECV 0x16
  30. #define ETHERNETCLIENT_W5100_ESTABLISHED 0x17
  31. #define ETHERNETCLIENT_W5100_FIN_WAIT 0x18
  32. #define ETHERNETCLIENT_W5100_CLOSING 0x1A
  33. #define ETHERNETCLIENT_W5100_TIME_WAIT 0x1B
  34. #define ETHERNETCLIENT_W5100_CLOSE_WAIT 0x1C
  35. #define ETHERNETCLIENT_W5100_LAST_ACK 0x1D
  36. /**
  37. * EthernetClient class
  38. */
  39. class EthernetClient : public Client
  40. {
  41. public:
  42. /**
  43. * @brief EthernetClient constructor.
  44. */
  45. EthernetClient();
  46. /**
  47. * @brief EthernetClient constructor.
  48. *
  49. * @param sock Network socket.
  50. */
  51. explicit EthernetClient(int sock);
  52. /**
  53. * @brief Initiate a connection with host:port.
  54. *
  55. * @param host name to resolve or a stringified dotted IP address.
  56. * @param port to connect to.
  57. * @return 1 if SUCCESS or -1 if FAILURE.
  58. */
  59. virtual int connect(const char *host, uint16_t port);
  60. /**
  61. * @brief Initiate a connection with ip:port.
  62. *
  63. * @param ip to connect to.
  64. * @param port to connect to.
  65. * @return 1 if SUCCESS or -1 if FAILURE.
  66. */
  67. virtual int connect(IPAddress ip, uint16_t port);
  68. /**
  69. * @brief Write a byte.
  70. *
  71. * @param b byte to write.
  72. * @return 0 if FAILURE or 1 if SUCCESS.
  73. */
  74. virtual size_t write(uint8_t b);
  75. /**
  76. * @brief Write at most 'size' bytes.
  77. *
  78. * @param buf Buffer to read from.
  79. * @param size of the buffer.
  80. * @return 0 if FAILURE or the number of bytes sent.
  81. */
  82. virtual size_t write(const uint8_t *buf, size_t size);
  83. /**
  84. * @brief Write a null-terminated string.
  85. *
  86. * @param str String to write.
  87. * @return 0 if FAILURE or number of characters sent.
  88. */
  89. size_t write(const char *str);
  90. /**
  91. * @brief Write at most 'size' characters.
  92. *
  93. * @param buffer to read from.
  94. * @param size of the buffer.
  95. * @return 0 if FAILURE or the number of characters sent.
  96. */
  97. size_t write(const char *buffer, size_t size);
  98. /**
  99. * @brief Returns the number of bytes available for reading.
  100. *
  101. * @return number of bytes available.
  102. */
  103. virtual int available();
  104. /**
  105. * @brief Read a byte.
  106. *
  107. * @return -1 if no data, else the first byte available.
  108. */
  109. virtual int read();
  110. /**
  111. * @brief Read a number of bytes and store in a buffer.
  112. *
  113. * @param buf buffer to write to.
  114. * @param bytes number of bytes to read.
  115. * @return -1 if no data or number of read bytes.
  116. */
  117. virtual int read(uint8_t *buf, size_t bytes);
  118. /**
  119. * @brief Returns the next byte of the read queue without removing it from the queue.
  120. *
  121. * @return -1 if no data, else the first byte of incoming data available.
  122. */
  123. virtual int peek();
  124. /**
  125. * @brief Waits until all outgoing bytes in buffer have been sent.
  126. */
  127. virtual void flush();
  128. /**
  129. * @brief Close the connection gracefully.
  130. *
  131. * Send a FIN and wait 1s for a response. If no response close it forcefully.
  132. */
  133. virtual void stop();
  134. /**
  135. * @brief Connection status.
  136. *
  137. * @return state according to W5100 library codes.
  138. */
  139. uint8_t status();
  140. /**
  141. * @brief Whether or not the client is connected.
  142. *
  143. * Note that a client is considered connected if the connection has been closed but
  144. * there is still unread data.
  145. *
  146. * @return 1 if the client is connected, 0 if not.
  147. */
  148. virtual uint8_t connected();
  149. /**
  150. * @brief Close the connection.
  151. */
  152. void close();
  153. /**
  154. * @brief Bind the conection to the specified local ip.
  155. */
  156. void bind(IPAddress ip);
  157. /**
  158. * @brief Get the internal socket file descriptor.
  159. *
  160. * @return an integer, that is the socket number.
  161. */
  162. int getSocketNumber();
  163. /**
  164. * @brief Overloaded cast operators.
  165. *
  166. * Allow EthernetClient objects to be used where a bool is expected.
  167. */
  168. virtual operator bool();
  169. /**
  170. * @brief Overloaded cast operators.
  171. *
  172. */
  173. virtual bool operator==(const bool value)
  174. {
  175. return bool() == value;
  176. }
  177. /**
  178. * @brief Overloaded cast operators.
  179. *
  180. */
  181. virtual bool operator!=(const bool value)
  182. {
  183. return bool() != value;
  184. }
  185. /**
  186. * @brief Overloaded cast operators.
  187. *
  188. */
  189. virtual bool operator==(const EthernetClient& rhs);
  190. /**
  191. * @brief Overloaded cast operators.
  192. *
  193. */
  194. virtual bool operator!=(const EthernetClient& rhs)
  195. {
  196. return !this->operator==(rhs);
  197. };
  198. friend class EthernetServer;
  199. private:
  200. int _sock; //!< @brief Network socket file descriptor.
  201. IPAddress _srcip; //!< @brief Local ip to bind to.
  202. };
  203. #endif