Reem M
/
http-server-example1
http
easy-connect/esp8266-driver/ESP8266Interface.h@1:ce6ccd14af4c, 2019-04-15 (annotated)
- Committer:
- reeml3
- Date:
- Mon Apr 15 18:12:24 2019 +0000
- Revision:
- 1:ce6ccd14af4c
- Parent:
- 0:a49e37a83a7a
http
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
DuaaAbusharkh | 0:a49e37a83a7a | 1 | /* ESP8266 implementation of NetworkInterfaceAPI |
DuaaAbusharkh | 0:a49e37a83a7a | 2 | * Copyright (c) 2015 ARM Limited |
DuaaAbusharkh | 0:a49e37a83a7a | 3 | * |
DuaaAbusharkh | 0:a49e37a83a7a | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
DuaaAbusharkh | 0:a49e37a83a7a | 5 | * you may not use this file except in compliance with the License. |
DuaaAbusharkh | 0:a49e37a83a7a | 6 | * You may obtain a copy of the License at |
DuaaAbusharkh | 0:a49e37a83a7a | 7 | * |
DuaaAbusharkh | 0:a49e37a83a7a | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
DuaaAbusharkh | 0:a49e37a83a7a | 9 | * |
DuaaAbusharkh | 0:a49e37a83a7a | 10 | * Unless required by applicable law or agreed to in writing, software |
DuaaAbusharkh | 0:a49e37a83a7a | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
DuaaAbusharkh | 0:a49e37a83a7a | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
DuaaAbusharkh | 0:a49e37a83a7a | 13 | * See the License for the specific language governing permissions and |
DuaaAbusharkh | 0:a49e37a83a7a | 14 | * limitations under the License. |
DuaaAbusharkh | 0:a49e37a83a7a | 15 | */ |
DuaaAbusharkh | 0:a49e37a83a7a | 16 | |
DuaaAbusharkh | 0:a49e37a83a7a | 17 | #ifndef ESP8266_INTERFACE_H |
DuaaAbusharkh | 0:a49e37a83a7a | 18 | #define ESP8266_INTERFACE_H |
DuaaAbusharkh | 0:a49e37a83a7a | 19 | |
DuaaAbusharkh | 0:a49e37a83a7a | 20 | #include "mbed.h" |
DuaaAbusharkh | 0:a49e37a83a7a | 21 | #include "ESP8266.h" |
DuaaAbusharkh | 0:a49e37a83a7a | 22 | |
DuaaAbusharkh | 0:a49e37a83a7a | 23 | |
DuaaAbusharkh | 0:a49e37a83a7a | 24 | #define ESP8266_SOCKET_COUNT 5 |
DuaaAbusharkh | 0:a49e37a83a7a | 25 | |
DuaaAbusharkh | 0:a49e37a83a7a | 26 | /** ESP8266Interface class |
DuaaAbusharkh | 0:a49e37a83a7a | 27 | * Implementation of the NetworkStack for the ESP8266 |
DuaaAbusharkh | 0:a49e37a83a7a | 28 | */ |
DuaaAbusharkh | 0:a49e37a83a7a | 29 | class ESP8266Interface : public NetworkStack, public WiFiInterface |
DuaaAbusharkh | 0:a49e37a83a7a | 30 | { |
DuaaAbusharkh | 0:a49e37a83a7a | 31 | public: |
DuaaAbusharkh | 0:a49e37a83a7a | 32 | /** ESP8266Interface lifetime |
DuaaAbusharkh | 0:a49e37a83a7a | 33 | * @param tx TX pin |
DuaaAbusharkh | 0:a49e37a83a7a | 34 | * @param rx RX pin |
DuaaAbusharkh | 0:a49e37a83a7a | 35 | * @param debug Enable debugging |
DuaaAbusharkh | 0:a49e37a83a7a | 36 | */ |
DuaaAbusharkh | 0:a49e37a83a7a | 37 | ESP8266Interface(PinName tx, PinName rx, bool debug = false); |
DuaaAbusharkh | 0:a49e37a83a7a | 38 | |
DuaaAbusharkh | 0:a49e37a83a7a | 39 | /** Start the interface |
DuaaAbusharkh | 0:a49e37a83a7a | 40 | * |
DuaaAbusharkh | 0:a49e37a83a7a | 41 | * Attempts to connect to a WiFi network. Requires ssid and passphrase to be set. |
DuaaAbusharkh | 0:a49e37a83a7a | 42 | * If passphrase is invalid, NSAPI_ERROR_AUTH_ERROR is returned. |
DuaaAbusharkh | 0:a49e37a83a7a | 43 | * |
DuaaAbusharkh | 0:a49e37a83a7a | 44 | * @return 0 on success, negative error code on failure |
DuaaAbusharkh | 0:a49e37a83a7a | 45 | */ |
DuaaAbusharkh | 0:a49e37a83a7a | 46 | virtual int connect(); |
DuaaAbusharkh | 0:a49e37a83a7a | 47 | |
DuaaAbusharkh | 0:a49e37a83a7a | 48 | /** Start the interface |
DuaaAbusharkh | 0:a49e37a83a7a | 49 | * |
DuaaAbusharkh | 0:a49e37a83a7a | 50 | * Attempts to connect to a WiFi network. |
DuaaAbusharkh | 0:a49e37a83a7a | 51 | * |
DuaaAbusharkh | 0:a49e37a83a7a | 52 | * @param ssid Name of the network to connect to |
DuaaAbusharkh | 0:a49e37a83a7a | 53 | * @param pass Security passphrase to connect to the network |
DuaaAbusharkh | 0:a49e37a83a7a | 54 | * @param security Type of encryption for connection (Default: NSAPI_SECURITY_NONE) |
DuaaAbusharkh | 0:a49e37a83a7a | 55 | * @param channel This parameter is not supported, setting it to anything else than 0 will result in NSAPI_ERROR_UNSUPPORTED |
DuaaAbusharkh | 0:a49e37a83a7a | 56 | * @return 0 on success, or error code on failure |
DuaaAbusharkh | 0:a49e37a83a7a | 57 | */ |
DuaaAbusharkh | 0:a49e37a83a7a | 58 | virtual int connect(const char *ssid, const char *pass, nsapi_security_t security = NSAPI_SECURITY_NONE, |
DuaaAbusharkh | 0:a49e37a83a7a | 59 | uint8_t channel = 0); |
DuaaAbusharkh | 0:a49e37a83a7a | 60 | |
DuaaAbusharkh | 0:a49e37a83a7a | 61 | /** Set the WiFi network credentials |
DuaaAbusharkh | 0:a49e37a83a7a | 62 | * |
DuaaAbusharkh | 0:a49e37a83a7a | 63 | * @param ssid Name of the network to connect to |
DuaaAbusharkh | 0:a49e37a83a7a | 64 | * @param pass Security passphrase to connect to the network |
DuaaAbusharkh | 0:a49e37a83a7a | 65 | * @param security Type of encryption for connection |
DuaaAbusharkh | 0:a49e37a83a7a | 66 | * (defaults to NSAPI_SECURITY_NONE) |
DuaaAbusharkh | 0:a49e37a83a7a | 67 | * @return 0 on success, or error code on failure |
DuaaAbusharkh | 0:a49e37a83a7a | 68 | */ |
DuaaAbusharkh | 0:a49e37a83a7a | 69 | virtual int set_credentials(const char *ssid, const char *pass, nsapi_security_t security = NSAPI_SECURITY_NONE); |
DuaaAbusharkh | 0:a49e37a83a7a | 70 | |
DuaaAbusharkh | 0:a49e37a83a7a | 71 | /** Set the WiFi network channel - NOT SUPPORTED |
DuaaAbusharkh | 0:a49e37a83a7a | 72 | * |
DuaaAbusharkh | 0:a49e37a83a7a | 73 | * This function is not supported and will return NSAPI_ERROR_UNSUPPORTED |
DuaaAbusharkh | 0:a49e37a83a7a | 74 | * |
DuaaAbusharkh | 0:a49e37a83a7a | 75 | * @param channel Channel on which the connection is to be made, or 0 for any (Default: 0) |
DuaaAbusharkh | 0:a49e37a83a7a | 76 | * @return Not supported, returns NSAPI_ERROR_UNSUPPORTED |
DuaaAbusharkh | 0:a49e37a83a7a | 77 | */ |
DuaaAbusharkh | 0:a49e37a83a7a | 78 | virtual int set_channel(uint8_t channel); |
DuaaAbusharkh | 0:a49e37a83a7a | 79 | |
DuaaAbusharkh | 0:a49e37a83a7a | 80 | /** Stop the interface |
DuaaAbusharkh | 0:a49e37a83a7a | 81 | * @return 0 on success, negative on failure |
DuaaAbusharkh | 0:a49e37a83a7a | 82 | */ |
DuaaAbusharkh | 0:a49e37a83a7a | 83 | virtual int disconnect(); |
DuaaAbusharkh | 0:a49e37a83a7a | 84 | |
DuaaAbusharkh | 0:a49e37a83a7a | 85 | /** Get the internally stored IP address |
DuaaAbusharkh | 0:a49e37a83a7a | 86 | * @return IP address of the interface or null if not yet connected |
DuaaAbusharkh | 0:a49e37a83a7a | 87 | */ |
DuaaAbusharkh | 0:a49e37a83a7a | 88 | virtual const char *get_ip_address(); |
DuaaAbusharkh | 0:a49e37a83a7a | 89 | |
DuaaAbusharkh | 0:a49e37a83a7a | 90 | /** Get the internally stored MAC address |
DuaaAbusharkh | 0:a49e37a83a7a | 91 | * @return MAC address of the interface |
DuaaAbusharkh | 0:a49e37a83a7a | 92 | */ |
DuaaAbusharkh | 0:a49e37a83a7a | 93 | virtual const char *get_mac_address(); |
DuaaAbusharkh | 0:a49e37a83a7a | 94 | |
DuaaAbusharkh | 0:a49e37a83a7a | 95 | /** Get the local gateway |
DuaaAbusharkh | 0:a49e37a83a7a | 96 | * |
DuaaAbusharkh | 0:a49e37a83a7a | 97 | * @return Null-terminated representation of the local gateway |
DuaaAbusharkh | 0:a49e37a83a7a | 98 | * or null if no network mask has been recieved |
DuaaAbusharkh | 0:a49e37a83a7a | 99 | */ |
DuaaAbusharkh | 0:a49e37a83a7a | 100 | virtual const char *get_gateway(); |
DuaaAbusharkh | 0:a49e37a83a7a | 101 | |
DuaaAbusharkh | 0:a49e37a83a7a | 102 | /** Get the local network mask |
DuaaAbusharkh | 0:a49e37a83a7a | 103 | * |
DuaaAbusharkh | 0:a49e37a83a7a | 104 | * @return Null-terminated representation of the local network mask |
DuaaAbusharkh | 0:a49e37a83a7a | 105 | * or null if no network mask has been recieved |
DuaaAbusharkh | 0:a49e37a83a7a | 106 | */ |
DuaaAbusharkh | 0:a49e37a83a7a | 107 | virtual const char *get_netmask(); |
DuaaAbusharkh | 0:a49e37a83a7a | 108 | |
DuaaAbusharkh | 0:a49e37a83a7a | 109 | /** Gets the current radio signal strength for active connection |
DuaaAbusharkh | 0:a49e37a83a7a | 110 | * |
DuaaAbusharkh | 0:a49e37a83a7a | 111 | * @return Connection strength in dBm (negative value) |
DuaaAbusharkh | 0:a49e37a83a7a | 112 | */ |
DuaaAbusharkh | 0:a49e37a83a7a | 113 | virtual int8_t get_rssi(); |
DuaaAbusharkh | 0:a49e37a83a7a | 114 | |
DuaaAbusharkh | 0:a49e37a83a7a | 115 | /** Scan for available networks |
DuaaAbusharkh | 0:a49e37a83a7a | 116 | * |
DuaaAbusharkh | 0:a49e37a83a7a | 117 | * This function will block. |
DuaaAbusharkh | 0:a49e37a83a7a | 118 | * |
DuaaAbusharkh | 0:a49e37a83a7a | 119 | * @param ap Pointer to allocated array to store discovered AP |
DuaaAbusharkh | 0:a49e37a83a7a | 120 | * @param count Size of allocated @a res array, or 0 to only count available AP |
DuaaAbusharkh | 0:a49e37a83a7a | 121 | * @param timeout Timeout in milliseconds; 0 for no timeout (Default: 0) |
DuaaAbusharkh | 0:a49e37a83a7a | 122 | * @return Number of entries in @a, or if @a count was 0 number of available networks, negative on error |
DuaaAbusharkh | 0:a49e37a83a7a | 123 | * see @a nsapi_error |
DuaaAbusharkh | 0:a49e37a83a7a | 124 | */ |
DuaaAbusharkh | 0:a49e37a83a7a | 125 | virtual int scan(WiFiAccessPoint *res, unsigned count); |
DuaaAbusharkh | 0:a49e37a83a7a | 126 | |
DuaaAbusharkh | 0:a49e37a83a7a | 127 | /** Translates a hostname to an IP address with specific version |
DuaaAbusharkh | 0:a49e37a83a7a | 128 | * |
DuaaAbusharkh | 0:a49e37a83a7a | 129 | * The hostname may be either a domain name or an IP address. If the |
DuaaAbusharkh | 0:a49e37a83a7a | 130 | * hostname is an IP address, no network transactions will be performed. |
DuaaAbusharkh | 0:a49e37a83a7a | 131 | * |
DuaaAbusharkh | 0:a49e37a83a7a | 132 | * If no stack-specific DNS resolution is provided, the hostname |
DuaaAbusharkh | 0:a49e37a83a7a | 133 | * will be resolve using a UDP socket on the stack. |
DuaaAbusharkh | 0:a49e37a83a7a | 134 | * |
DuaaAbusharkh | 0:a49e37a83a7a | 135 | * @param address Destination for the host SocketAddress |
DuaaAbusharkh | 0:a49e37a83a7a | 136 | * @param host Hostname to resolve |
DuaaAbusharkh | 0:a49e37a83a7a | 137 | * @param version IP version of address to resolve, NSAPI_UNSPEC indicates |
DuaaAbusharkh | 0:a49e37a83a7a | 138 | * version is chosen by the stack (defaults to NSAPI_UNSPEC) |
DuaaAbusharkh | 0:a49e37a83a7a | 139 | * @return 0 on success, negative error code on failure |
DuaaAbusharkh | 0:a49e37a83a7a | 140 | */ |
DuaaAbusharkh | 0:a49e37a83a7a | 141 | using NetworkInterface::gethostbyname; |
DuaaAbusharkh | 0:a49e37a83a7a | 142 | |
DuaaAbusharkh | 0:a49e37a83a7a | 143 | /** Add a domain name server to list of servers to query |
DuaaAbusharkh | 0:a49e37a83a7a | 144 | * |
DuaaAbusharkh | 0:a49e37a83a7a | 145 | * @param addr Destination for the host address |
DuaaAbusharkh | 0:a49e37a83a7a | 146 | * @return 0 on success, negative error code on failure |
DuaaAbusharkh | 0:a49e37a83a7a | 147 | */ |
DuaaAbusharkh | 0:a49e37a83a7a | 148 | using NetworkInterface::add_dns_server; |
DuaaAbusharkh | 0:a49e37a83a7a | 149 | |
DuaaAbusharkh | 0:a49e37a83a7a | 150 | protected: |
DuaaAbusharkh | 0:a49e37a83a7a | 151 | /** Open a socket |
DuaaAbusharkh | 0:a49e37a83a7a | 152 | * @param handle Handle in which to store new socket |
DuaaAbusharkh | 0:a49e37a83a7a | 153 | * @param proto Type of socket to open, NSAPI_TCP or NSAPI_UDP |
DuaaAbusharkh | 0:a49e37a83a7a | 154 | * @return 0 on success, negative on failure |
DuaaAbusharkh | 0:a49e37a83a7a | 155 | */ |
DuaaAbusharkh | 0:a49e37a83a7a | 156 | virtual int socket_open(void **handle, nsapi_protocol_t proto); |
DuaaAbusharkh | 0:a49e37a83a7a | 157 | |
DuaaAbusharkh | 0:a49e37a83a7a | 158 | /** Close the socket |
DuaaAbusharkh | 0:a49e37a83a7a | 159 | * @param handle Socket handle |
DuaaAbusharkh | 0:a49e37a83a7a | 160 | * @return 0 on success, negative on failure |
DuaaAbusharkh | 0:a49e37a83a7a | 161 | * @note On failure, any memory associated with the socket must still |
DuaaAbusharkh | 0:a49e37a83a7a | 162 | * be cleaned up |
DuaaAbusharkh | 0:a49e37a83a7a | 163 | */ |
DuaaAbusharkh | 0:a49e37a83a7a | 164 | virtual int socket_close(void *handle); |
DuaaAbusharkh | 0:a49e37a83a7a | 165 | |
DuaaAbusharkh | 0:a49e37a83a7a | 166 | /** Bind a server socket to a specific port |
DuaaAbusharkh | 0:a49e37a83a7a | 167 | * @param handle Socket handle |
DuaaAbusharkh | 0:a49e37a83a7a | 168 | * @param address Local address to listen for incoming connections on |
DuaaAbusharkh | 0:a49e37a83a7a | 169 | * @return 0 on success, negative on failure. |
DuaaAbusharkh | 0:a49e37a83a7a | 170 | */ |
DuaaAbusharkh | 0:a49e37a83a7a | 171 | virtual int socket_bind(void *handle, const SocketAddress &address); |
DuaaAbusharkh | 0:a49e37a83a7a | 172 | |
DuaaAbusharkh | 0:a49e37a83a7a | 173 | /** Start listening for incoming connections |
DuaaAbusharkh | 0:a49e37a83a7a | 174 | * @param handle Socket handle |
DuaaAbusharkh | 0:a49e37a83a7a | 175 | * @param backlog Number of pending connections that can be queued up at any |
DuaaAbusharkh | 0:a49e37a83a7a | 176 | * one time [Default: 1] |
DuaaAbusharkh | 0:a49e37a83a7a | 177 | * @return 0 on success, negative on failure |
DuaaAbusharkh | 0:a49e37a83a7a | 178 | */ |
DuaaAbusharkh | 0:a49e37a83a7a | 179 | virtual int socket_listen(void *handle, int backlog); |
DuaaAbusharkh | 0:a49e37a83a7a | 180 | |
DuaaAbusharkh | 0:a49e37a83a7a | 181 | /** Connects this TCP socket to the server |
DuaaAbusharkh | 0:a49e37a83a7a | 182 | * @param handle Socket handle |
DuaaAbusharkh | 0:a49e37a83a7a | 183 | * @param address SocketAddress to connect to |
DuaaAbusharkh | 0:a49e37a83a7a | 184 | * @return 0 on success, negative on failure |
DuaaAbusharkh | 0:a49e37a83a7a | 185 | */ |
DuaaAbusharkh | 0:a49e37a83a7a | 186 | virtual int socket_connect(void *handle, const SocketAddress &address); |
DuaaAbusharkh | 0:a49e37a83a7a | 187 | |
DuaaAbusharkh | 0:a49e37a83a7a | 188 | /** Accept a new connection. |
DuaaAbusharkh | 0:a49e37a83a7a | 189 | * @param handle Handle in which to store new socket |
DuaaAbusharkh | 0:a49e37a83a7a | 190 | * @param server Socket handle to server to accept from |
DuaaAbusharkh | 0:a49e37a83a7a | 191 | * @return 0 on success, negative on failure |
DuaaAbusharkh | 0:a49e37a83a7a | 192 | * @note This call is not-blocking, if this call would block, must |
DuaaAbusharkh | 0:a49e37a83a7a | 193 | * immediately return NSAPI_ERROR_WOULD_WAIT |
DuaaAbusharkh | 0:a49e37a83a7a | 194 | */ |
DuaaAbusharkh | 0:a49e37a83a7a | 195 | virtual int socket_accept(void *handle, void **socket, SocketAddress *address); |
DuaaAbusharkh | 0:a49e37a83a7a | 196 | |
DuaaAbusharkh | 0:a49e37a83a7a | 197 | /** Send data to the remote host |
DuaaAbusharkh | 0:a49e37a83a7a | 198 | * @param handle Socket handle |
DuaaAbusharkh | 0:a49e37a83a7a | 199 | * @param data The buffer to send to the host |
DuaaAbusharkh | 0:a49e37a83a7a | 200 | * @param size The length of the buffer to send |
DuaaAbusharkh | 0:a49e37a83a7a | 201 | * @return Number of written bytes on success, negative on failure |
DuaaAbusharkh | 0:a49e37a83a7a | 202 | * @note This call is not-blocking, if this call would block, must |
DuaaAbusharkh | 0:a49e37a83a7a | 203 | * immediately return NSAPI_ERROR_WOULD_WAIT |
DuaaAbusharkh | 0:a49e37a83a7a | 204 | */ |
DuaaAbusharkh | 0:a49e37a83a7a | 205 | virtual int socket_send(void *handle, const void *data, unsigned size); |
DuaaAbusharkh | 0:a49e37a83a7a | 206 | |
DuaaAbusharkh | 0:a49e37a83a7a | 207 | /** Receive data from the remote host |
DuaaAbusharkh | 0:a49e37a83a7a | 208 | * @param handle Socket handle |
DuaaAbusharkh | 0:a49e37a83a7a | 209 | * @param data The buffer in which to store the data received from the host |
DuaaAbusharkh | 0:a49e37a83a7a | 210 | * @param size The maximum length of the buffer |
DuaaAbusharkh | 0:a49e37a83a7a | 211 | * @return Number of received bytes on success, negative on failure |
DuaaAbusharkh | 0:a49e37a83a7a | 212 | * @note This call is not-blocking, if this call would block, must |
DuaaAbusharkh | 0:a49e37a83a7a | 213 | * immediately return NSAPI_ERROR_WOULD_WAIT |
DuaaAbusharkh | 0:a49e37a83a7a | 214 | */ |
DuaaAbusharkh | 0:a49e37a83a7a | 215 | virtual int socket_recv(void *handle, void *data, unsigned size); |
DuaaAbusharkh | 0:a49e37a83a7a | 216 | |
DuaaAbusharkh | 0:a49e37a83a7a | 217 | /** Send a packet to a remote endpoint |
DuaaAbusharkh | 0:a49e37a83a7a | 218 | * @param handle Socket handle |
DuaaAbusharkh | 0:a49e37a83a7a | 219 | * @param address The remote SocketAddress |
DuaaAbusharkh | 0:a49e37a83a7a | 220 | * @param data The packet to be sent |
DuaaAbusharkh | 0:a49e37a83a7a | 221 | * @param size The length of the packet to be sent |
DuaaAbusharkh | 0:a49e37a83a7a | 222 | * @return The number of written bytes on success, negative on failure |
DuaaAbusharkh | 0:a49e37a83a7a | 223 | * @note This call is not-blocking, if this call would block, must |
DuaaAbusharkh | 0:a49e37a83a7a | 224 | * immediately return NSAPI_ERROR_WOULD_WAIT |
DuaaAbusharkh | 0:a49e37a83a7a | 225 | */ |
DuaaAbusharkh | 0:a49e37a83a7a | 226 | virtual int socket_sendto(void *handle, const SocketAddress &address, const void *data, unsigned size); |
DuaaAbusharkh | 0:a49e37a83a7a | 227 | |
DuaaAbusharkh | 0:a49e37a83a7a | 228 | /** Receive a packet from a remote endpoint |
DuaaAbusharkh | 0:a49e37a83a7a | 229 | * @param handle Socket handle |
DuaaAbusharkh | 0:a49e37a83a7a | 230 | * @param address Destination for the remote SocketAddress or null |
DuaaAbusharkh | 0:a49e37a83a7a | 231 | * @param buffer The buffer for storing the incoming packet data |
DuaaAbusharkh | 0:a49e37a83a7a | 232 | * If a packet is too long to fit in the supplied buffer, |
DuaaAbusharkh | 0:a49e37a83a7a | 233 | * excess bytes are discarded |
DuaaAbusharkh | 0:a49e37a83a7a | 234 | * @param size The length of the buffer |
DuaaAbusharkh | 0:a49e37a83a7a | 235 | * @return The number of received bytes on success, negative on failure |
DuaaAbusharkh | 0:a49e37a83a7a | 236 | * @note This call is not-blocking, if this call would block, must |
DuaaAbusharkh | 0:a49e37a83a7a | 237 | * immediately return NSAPI_ERROR_WOULD_WAIT |
DuaaAbusharkh | 0:a49e37a83a7a | 238 | */ |
DuaaAbusharkh | 0:a49e37a83a7a | 239 | virtual int socket_recvfrom(void *handle, SocketAddress *address, void *buffer, unsigned size); |
DuaaAbusharkh | 0:a49e37a83a7a | 240 | |
DuaaAbusharkh | 0:a49e37a83a7a | 241 | /** Register a callback on state change of the socket |
DuaaAbusharkh | 0:a49e37a83a7a | 242 | * @param handle Socket handle |
DuaaAbusharkh | 0:a49e37a83a7a | 243 | * @param callback Function to call on state change |
DuaaAbusharkh | 0:a49e37a83a7a | 244 | * @param data Argument to pass to callback |
DuaaAbusharkh | 0:a49e37a83a7a | 245 | * @note Callback may be called in an interrupt context. |
DuaaAbusharkh | 0:a49e37a83a7a | 246 | */ |
DuaaAbusharkh | 0:a49e37a83a7a | 247 | virtual void socket_attach(void *handle, void (*callback)(void *), void *data); |
DuaaAbusharkh | 0:a49e37a83a7a | 248 | |
DuaaAbusharkh | 0:a49e37a83a7a | 249 | /** Provide access to the NetworkStack object |
DuaaAbusharkh | 0:a49e37a83a7a | 250 | * |
DuaaAbusharkh | 0:a49e37a83a7a | 251 | * @return The underlying NetworkStack object |
DuaaAbusharkh | 0:a49e37a83a7a | 252 | */ |
DuaaAbusharkh | 0:a49e37a83a7a | 253 | virtual NetworkStack *get_stack() |
DuaaAbusharkh | 0:a49e37a83a7a | 254 | { |
DuaaAbusharkh | 0:a49e37a83a7a | 255 | return this; |
DuaaAbusharkh | 0:a49e37a83a7a | 256 | } |
DuaaAbusharkh | 0:a49e37a83a7a | 257 | |
DuaaAbusharkh | 0:a49e37a83a7a | 258 | private: |
DuaaAbusharkh | 0:a49e37a83a7a | 259 | ESP8266 _esp; |
DuaaAbusharkh | 0:a49e37a83a7a | 260 | bool _ids[ESP8266_SOCKET_COUNT]; |
DuaaAbusharkh | 0:a49e37a83a7a | 261 | |
DuaaAbusharkh | 0:a49e37a83a7a | 262 | char ap_ssid[33]; /* 32 is what 802.11 defines as longest possible name; +1 for the \0 */ |
DuaaAbusharkh | 0:a49e37a83a7a | 263 | nsapi_security_t ap_sec; |
DuaaAbusharkh | 0:a49e37a83a7a | 264 | uint8_t ap_ch; |
DuaaAbusharkh | 0:a49e37a83a7a | 265 | char ap_pass[64]; /* The longest allowed passphrase */ |
DuaaAbusharkh | 0:a49e37a83a7a | 266 | |
DuaaAbusharkh | 0:a49e37a83a7a | 267 | void event(); |
DuaaAbusharkh | 0:a49e37a83a7a | 268 | |
DuaaAbusharkh | 0:a49e37a83a7a | 269 | struct { |
DuaaAbusharkh | 0:a49e37a83a7a | 270 | void (*callback)(void *); |
DuaaAbusharkh | 0:a49e37a83a7a | 271 | void *data; |
DuaaAbusharkh | 0:a49e37a83a7a | 272 | } _cbs[ESP8266_SOCKET_COUNT]; |
DuaaAbusharkh | 0:a49e37a83a7a | 273 | }; |
DuaaAbusharkh | 0:a49e37a83a7a | 274 | |
DuaaAbusharkh | 0:a49e37a83a7a | 275 | #endif |