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.

EthernetServer.h 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 EthernetServer_h
  22. #define EthernetServer_h
  23. #include <list>
  24. #include <vector>
  25. #include "Server.h"
  26. #include "IPAddress.h"
  27. #ifdef ETHERNETSERVER_MAX_CLIENTS
  28. #define ETHERNETSERVER_BACKLOG ETHERNETSERVER_MAX_CLIENTS //!< Maximum length to which the queue of pending connections may grow.
  29. #else
  30. #define ETHERNETSERVER_MAX_CLIENTS 10 //!< Default value for max_clients.
  31. #define ETHERNETSERVER_BACKLOG 10 //!< Maximum length to which the queue of pending connections may grow.
  32. #endif
  33. class EthernetClient;
  34. /**
  35. * @brief EthernetServer class
  36. */
  37. class EthernetServer : public Server
  38. {
  39. public:
  40. /**
  41. * @brief EthernetServer constructor.
  42. *
  43. * @param port number for the socket addresses.
  44. * @param max_clients The maximum number allowed for connected clients.
  45. */
  46. EthernetServer(uint16_t port, uint16_t max_clients = ETHERNETSERVER_MAX_CLIENTS);
  47. /**
  48. * @brief Listen for inbound connection request.
  49. *
  50. */
  51. virtual void begin();
  52. /**
  53. * @brief Listen on the specified ip for inbound connection request.
  54. *
  55. * @param addr IP address to bind to.
  56. */
  57. void begin(IPAddress addr);
  58. /**
  59. * @brief Verifies if a new client has connected.
  60. *
  61. * @return @c true if a new client has connected, else @c false.
  62. */
  63. bool hasClient();
  64. /**
  65. * @brief Get the new connected client.
  66. *
  67. * @return a EthernetClient object; if no new client has connected, this object will evaluate to false.
  68. */
  69. EthernetClient available();
  70. /**
  71. * @brief Write a byte to all clients.
  72. *
  73. * @param b byte to send.
  74. * @return 0 if FAILURE or 1 if SUCCESS.
  75. */
  76. virtual size_t write(uint8_t b);
  77. /**
  78. * @brief Write at most 'size' bytes to all clients.
  79. *
  80. * @param buffer to read from.
  81. * @param size of the buffer.
  82. * @return 0 if FAILURE else number of bytes sent.
  83. */
  84. virtual size_t write(const uint8_t *buffer, size_t size);
  85. /**
  86. * @brief Write a null-terminated string to all clients.
  87. *
  88. * @param str String to write.
  89. * @return 0 if FAILURE else number of characters sent.
  90. */
  91. size_t write(const char *str);
  92. /**
  93. * @brief Write at most 'size' characters to all clients.
  94. *
  95. * @param buffer to read from.
  96. * @param size of the buffer.
  97. * @return 0 if FAILURE else the number of characters sent.
  98. */
  99. size_t write(const char *buffer, size_t size);
  100. private:
  101. uint16_t port; //!< @brief Port number for the network socket.
  102. std::list<int> new_clients; //!< Socket list of new connected clients.
  103. std::vector<int> clients; //!< @brief Socket list of connected clients.
  104. uint16_t max_clients; //!< @brief The maximum number of allowed clients.
  105. int sockfd; //!< @brief Network socket used to accept connections.
  106. /**
  107. * @brief Accept new clients if the total of connected clients is below max_clients.
  108. *
  109. */
  110. void _accept();
  111. };
  112. #endif