Version of easy-connect with the u-blox cellular platforms C027 and C030 added.
esp8266-driver/ESP8266Interface.cpp@6:304d3ba87a01, 2017-11-03 (annotated)
- Committer:
- RobMeades
- Date:
- Fri Nov 03 13:01:23 2017 +0000
- Revision:
- 6:304d3ba87a01
- Parent:
- 0:19aa55d66228
Add comment concerning N2XX baud rate.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
group-ublox | 0:19aa55d66228 | 1 | /* ESP8266 implementation of NetworkInterfaceAPI |
group-ublox | 0:19aa55d66228 | 2 | * Copyright (c) 2015 ARM Limited |
group-ublox | 0:19aa55d66228 | 3 | * |
group-ublox | 0:19aa55d66228 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
group-ublox | 0:19aa55d66228 | 5 | * you may not use this file except in compliance with the License. |
group-ublox | 0:19aa55d66228 | 6 | * You may obtain a copy of the License at |
group-ublox | 0:19aa55d66228 | 7 | * |
group-ublox | 0:19aa55d66228 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
group-ublox | 0:19aa55d66228 | 9 | * |
group-ublox | 0:19aa55d66228 | 10 | * Unless required by applicable law or agreed to in writing, software |
group-ublox | 0:19aa55d66228 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
group-ublox | 0:19aa55d66228 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
group-ublox | 0:19aa55d66228 | 13 | * See the License for the specific language governing permissions and |
group-ublox | 0:19aa55d66228 | 14 | * limitations under the License. |
group-ublox | 0:19aa55d66228 | 15 | */ |
group-ublox | 0:19aa55d66228 | 16 | |
group-ublox | 0:19aa55d66228 | 17 | #include <string.h> |
group-ublox | 0:19aa55d66228 | 18 | #include "ESP8266Interface.h" |
group-ublox | 0:19aa55d66228 | 19 | #include "mbed_debug.h" |
group-ublox | 0:19aa55d66228 | 20 | |
group-ublox | 0:19aa55d66228 | 21 | // Various timeouts for different ESP8266 operations |
group-ublox | 0:19aa55d66228 | 22 | #ifndef ESP8266_CONNECT_TIMEOUT |
group-ublox | 0:19aa55d66228 | 23 | #define ESP8266_CONNECT_TIMEOUT 15000 |
group-ublox | 0:19aa55d66228 | 24 | #endif |
group-ublox | 0:19aa55d66228 | 25 | #ifndef ESP8266_SEND_TIMEOUT |
group-ublox | 0:19aa55d66228 | 26 | #define ESP8266_SEND_TIMEOUT 500 |
group-ublox | 0:19aa55d66228 | 27 | #endif |
group-ublox | 0:19aa55d66228 | 28 | #ifndef ESP8266_RECV_TIMEOUT |
group-ublox | 0:19aa55d66228 | 29 | #define ESP8266_RECV_TIMEOUT 0 |
group-ublox | 0:19aa55d66228 | 30 | #endif |
group-ublox | 0:19aa55d66228 | 31 | #ifndef ESP8266_MISC_TIMEOUT |
group-ublox | 0:19aa55d66228 | 32 | #define ESP8266_MISC_TIMEOUT 500 |
group-ublox | 0:19aa55d66228 | 33 | #endif |
group-ublox | 0:19aa55d66228 | 34 | |
group-ublox | 0:19aa55d66228 | 35 | // Firmware version |
group-ublox | 0:19aa55d66228 | 36 | #define ESP8266_VERSION 2 |
group-ublox | 0:19aa55d66228 | 37 | |
group-ublox | 0:19aa55d66228 | 38 | // ESP8266Interface implementation |
group-ublox | 0:19aa55d66228 | 39 | ESP8266Interface::ESP8266Interface(PinName tx, PinName rx, bool debug) |
group-ublox | 0:19aa55d66228 | 40 | : _esp(tx, rx, debug) |
group-ublox | 0:19aa55d66228 | 41 | { |
group-ublox | 0:19aa55d66228 | 42 | memset(_ids, 0, sizeof(_ids)); |
group-ublox | 0:19aa55d66228 | 43 | memset(_cbs, 0, sizeof(_cbs)); |
group-ublox | 0:19aa55d66228 | 44 | |
group-ublox | 0:19aa55d66228 | 45 | _esp.attach(this, &ESP8266Interface::event); |
group-ublox | 0:19aa55d66228 | 46 | } |
group-ublox | 0:19aa55d66228 | 47 | |
group-ublox | 0:19aa55d66228 | 48 | int ESP8266Interface::connect(const char *ssid, const char *pass, nsapi_security_t security, |
group-ublox | 0:19aa55d66228 | 49 | uint8_t channel) |
group-ublox | 0:19aa55d66228 | 50 | { |
group-ublox | 0:19aa55d66228 | 51 | if (channel != 0) { |
group-ublox | 0:19aa55d66228 | 52 | return NSAPI_ERROR_UNSUPPORTED; |
group-ublox | 0:19aa55d66228 | 53 | } |
group-ublox | 0:19aa55d66228 | 54 | |
group-ublox | 0:19aa55d66228 | 55 | set_credentials(ssid, pass, security); |
group-ublox | 0:19aa55d66228 | 56 | return connect(); |
group-ublox | 0:19aa55d66228 | 57 | } |
group-ublox | 0:19aa55d66228 | 58 | |
group-ublox | 0:19aa55d66228 | 59 | int ESP8266Interface::connect() |
group-ublox | 0:19aa55d66228 | 60 | { |
group-ublox | 0:19aa55d66228 | 61 | _esp.setTimeout(ESP8266_CONNECT_TIMEOUT); |
group-ublox | 0:19aa55d66228 | 62 | |
group-ublox | 0:19aa55d66228 | 63 | if (!_esp.reset()) { |
group-ublox | 0:19aa55d66228 | 64 | return NSAPI_ERROR_DEVICE_ERROR; |
group-ublox | 0:19aa55d66228 | 65 | } |
group-ublox | 0:19aa55d66228 | 66 | |
group-ublox | 0:19aa55d66228 | 67 | _esp.setTimeout(ESP8266_MISC_TIMEOUT); |
group-ublox | 0:19aa55d66228 | 68 | |
group-ublox | 0:19aa55d66228 | 69 | if (_esp.get_firmware_version() != ESP8266_VERSION) { |
group-ublox | 0:19aa55d66228 | 70 | debug("ESP8266: ERROR: Firmware incompatible with this driver.\ |
group-ublox | 0:19aa55d66228 | 71 | \r\nUpdate to v%d - https://developer.mbed.org/teams/ESP8266/wiki/Firmware-Update\r\n",ESP8266_VERSION); |
group-ublox | 0:19aa55d66228 | 72 | return NSAPI_ERROR_DEVICE_ERROR; |
group-ublox | 0:19aa55d66228 | 73 | } |
group-ublox | 0:19aa55d66228 | 74 | |
group-ublox | 0:19aa55d66228 | 75 | _esp.setTimeout(ESP8266_CONNECT_TIMEOUT); |
group-ublox | 0:19aa55d66228 | 76 | |
group-ublox | 0:19aa55d66228 | 77 | if (!_esp.startup(3)) { |
group-ublox | 0:19aa55d66228 | 78 | return NSAPI_ERROR_DEVICE_ERROR; |
group-ublox | 0:19aa55d66228 | 79 | } |
group-ublox | 0:19aa55d66228 | 80 | |
group-ublox | 0:19aa55d66228 | 81 | if (!_esp.dhcp(true, 1)) { |
group-ublox | 0:19aa55d66228 | 82 | return NSAPI_ERROR_DHCP_FAILURE; |
group-ublox | 0:19aa55d66228 | 83 | } |
group-ublox | 0:19aa55d66228 | 84 | |
group-ublox | 0:19aa55d66228 | 85 | if (!_esp.connect(ap_ssid, ap_pass)) { |
group-ublox | 0:19aa55d66228 | 86 | return NSAPI_ERROR_NO_CONNECTION; |
group-ublox | 0:19aa55d66228 | 87 | } |
group-ublox | 0:19aa55d66228 | 88 | |
group-ublox | 0:19aa55d66228 | 89 | if (!_esp.getIPAddress()) { |
group-ublox | 0:19aa55d66228 | 90 | return NSAPI_ERROR_DHCP_FAILURE; |
group-ublox | 0:19aa55d66228 | 91 | } |
group-ublox | 0:19aa55d66228 | 92 | |
group-ublox | 0:19aa55d66228 | 93 | return NSAPI_ERROR_OK; |
group-ublox | 0:19aa55d66228 | 94 | } |
group-ublox | 0:19aa55d66228 | 95 | |
group-ublox | 0:19aa55d66228 | 96 | int ESP8266Interface::set_credentials(const char *ssid, const char *pass, nsapi_security_t security) |
group-ublox | 0:19aa55d66228 | 97 | { |
group-ublox | 0:19aa55d66228 | 98 | memset(ap_ssid, 0, sizeof(ap_ssid)); |
group-ublox | 0:19aa55d66228 | 99 | strncpy(ap_ssid, ssid, sizeof(ap_ssid)); |
group-ublox | 0:19aa55d66228 | 100 | |
group-ublox | 0:19aa55d66228 | 101 | memset(ap_pass, 0, sizeof(ap_pass)); |
group-ublox | 0:19aa55d66228 | 102 | strncpy(ap_pass, pass, sizeof(ap_pass)); |
group-ublox | 0:19aa55d66228 | 103 | |
group-ublox | 0:19aa55d66228 | 104 | ap_sec = security; |
group-ublox | 0:19aa55d66228 | 105 | |
group-ublox | 0:19aa55d66228 | 106 | return 0; |
group-ublox | 0:19aa55d66228 | 107 | } |
group-ublox | 0:19aa55d66228 | 108 | |
group-ublox | 0:19aa55d66228 | 109 | int ESP8266Interface::set_channel(uint8_t channel) |
group-ublox | 0:19aa55d66228 | 110 | { |
group-ublox | 0:19aa55d66228 | 111 | return NSAPI_ERROR_UNSUPPORTED; |
group-ublox | 0:19aa55d66228 | 112 | } |
group-ublox | 0:19aa55d66228 | 113 | |
group-ublox | 0:19aa55d66228 | 114 | |
group-ublox | 0:19aa55d66228 | 115 | int ESP8266Interface::disconnect() |
group-ublox | 0:19aa55d66228 | 116 | { |
group-ublox | 0:19aa55d66228 | 117 | _esp.setTimeout(ESP8266_MISC_TIMEOUT); |
group-ublox | 0:19aa55d66228 | 118 | |
group-ublox | 0:19aa55d66228 | 119 | if (!_esp.disconnect()) { |
group-ublox | 0:19aa55d66228 | 120 | return NSAPI_ERROR_DEVICE_ERROR; |
group-ublox | 0:19aa55d66228 | 121 | } |
group-ublox | 0:19aa55d66228 | 122 | |
group-ublox | 0:19aa55d66228 | 123 | return NSAPI_ERROR_OK; |
group-ublox | 0:19aa55d66228 | 124 | } |
group-ublox | 0:19aa55d66228 | 125 | |
group-ublox | 0:19aa55d66228 | 126 | const char *ESP8266Interface::get_ip_address() |
group-ublox | 0:19aa55d66228 | 127 | { |
group-ublox | 0:19aa55d66228 | 128 | return _esp.getIPAddress(); |
group-ublox | 0:19aa55d66228 | 129 | } |
group-ublox | 0:19aa55d66228 | 130 | |
group-ublox | 0:19aa55d66228 | 131 | const char *ESP8266Interface::get_mac_address() |
group-ublox | 0:19aa55d66228 | 132 | { |
group-ublox | 0:19aa55d66228 | 133 | return _esp.getMACAddress(); |
group-ublox | 0:19aa55d66228 | 134 | } |
group-ublox | 0:19aa55d66228 | 135 | |
group-ublox | 0:19aa55d66228 | 136 | const char *ESP8266Interface::get_gateway() |
group-ublox | 0:19aa55d66228 | 137 | { |
group-ublox | 0:19aa55d66228 | 138 | return _esp.getGateway(); |
group-ublox | 0:19aa55d66228 | 139 | } |
group-ublox | 0:19aa55d66228 | 140 | |
group-ublox | 0:19aa55d66228 | 141 | const char *ESP8266Interface::get_netmask() |
group-ublox | 0:19aa55d66228 | 142 | { |
group-ublox | 0:19aa55d66228 | 143 | return _esp.getNetmask(); |
group-ublox | 0:19aa55d66228 | 144 | } |
group-ublox | 0:19aa55d66228 | 145 | |
group-ublox | 0:19aa55d66228 | 146 | int8_t ESP8266Interface::get_rssi() |
group-ublox | 0:19aa55d66228 | 147 | { |
group-ublox | 0:19aa55d66228 | 148 | return _esp.getRSSI(); |
group-ublox | 0:19aa55d66228 | 149 | } |
group-ublox | 0:19aa55d66228 | 150 | |
group-ublox | 0:19aa55d66228 | 151 | int ESP8266Interface::scan(WiFiAccessPoint *res, unsigned count) |
group-ublox | 0:19aa55d66228 | 152 | { |
group-ublox | 0:19aa55d66228 | 153 | return _esp.scan(res, count); |
group-ublox | 0:19aa55d66228 | 154 | } |
group-ublox | 0:19aa55d66228 | 155 | |
group-ublox | 0:19aa55d66228 | 156 | struct esp8266_socket { |
group-ublox | 0:19aa55d66228 | 157 | int id; |
group-ublox | 0:19aa55d66228 | 158 | nsapi_protocol_t proto; |
group-ublox | 0:19aa55d66228 | 159 | bool connected; |
group-ublox | 0:19aa55d66228 | 160 | SocketAddress addr; |
group-ublox | 0:19aa55d66228 | 161 | }; |
group-ublox | 0:19aa55d66228 | 162 | |
group-ublox | 0:19aa55d66228 | 163 | int ESP8266Interface::socket_open(void **handle, nsapi_protocol_t proto) |
group-ublox | 0:19aa55d66228 | 164 | { |
group-ublox | 0:19aa55d66228 | 165 | // Look for an unused socket |
group-ublox | 0:19aa55d66228 | 166 | int id = -1; |
group-ublox | 0:19aa55d66228 | 167 | |
group-ublox | 0:19aa55d66228 | 168 | for (int i = 0; i < ESP8266_SOCKET_COUNT; i++) { |
group-ublox | 0:19aa55d66228 | 169 | if (!_ids[i]) { |
group-ublox | 0:19aa55d66228 | 170 | id = i; |
group-ublox | 0:19aa55d66228 | 171 | _ids[i] = true; |
group-ublox | 0:19aa55d66228 | 172 | break; |
group-ublox | 0:19aa55d66228 | 173 | } |
group-ublox | 0:19aa55d66228 | 174 | } |
group-ublox | 0:19aa55d66228 | 175 | |
group-ublox | 0:19aa55d66228 | 176 | if (id == -1) { |
group-ublox | 0:19aa55d66228 | 177 | return NSAPI_ERROR_NO_SOCKET; |
group-ublox | 0:19aa55d66228 | 178 | } |
group-ublox | 0:19aa55d66228 | 179 | |
group-ublox | 0:19aa55d66228 | 180 | struct esp8266_socket *socket = new struct esp8266_socket; |
group-ublox | 0:19aa55d66228 | 181 | if (!socket) { |
group-ublox | 0:19aa55d66228 | 182 | return NSAPI_ERROR_NO_SOCKET; |
group-ublox | 0:19aa55d66228 | 183 | } |
group-ublox | 0:19aa55d66228 | 184 | |
group-ublox | 0:19aa55d66228 | 185 | socket->id = id; |
group-ublox | 0:19aa55d66228 | 186 | socket->proto = proto; |
group-ublox | 0:19aa55d66228 | 187 | socket->connected = false; |
group-ublox | 0:19aa55d66228 | 188 | *handle = socket; |
group-ublox | 0:19aa55d66228 | 189 | return 0; |
group-ublox | 0:19aa55d66228 | 190 | } |
group-ublox | 0:19aa55d66228 | 191 | |
group-ublox | 0:19aa55d66228 | 192 | int ESP8266Interface::socket_close(void *handle) |
group-ublox | 0:19aa55d66228 | 193 | { |
group-ublox | 0:19aa55d66228 | 194 | struct esp8266_socket *socket = (struct esp8266_socket *)handle; |
group-ublox | 0:19aa55d66228 | 195 | int err = 0; |
group-ublox | 0:19aa55d66228 | 196 | _esp.setTimeout(ESP8266_MISC_TIMEOUT); |
group-ublox | 0:19aa55d66228 | 197 | |
group-ublox | 0:19aa55d66228 | 198 | if (socket->connected && !_esp.close(socket->id)) { |
group-ublox | 0:19aa55d66228 | 199 | err = NSAPI_ERROR_DEVICE_ERROR; |
group-ublox | 0:19aa55d66228 | 200 | } |
group-ublox | 0:19aa55d66228 | 201 | |
group-ublox | 0:19aa55d66228 | 202 | socket->connected = false; |
group-ublox | 0:19aa55d66228 | 203 | _ids[socket->id] = false; |
group-ublox | 0:19aa55d66228 | 204 | delete socket; |
group-ublox | 0:19aa55d66228 | 205 | return err; |
group-ublox | 0:19aa55d66228 | 206 | } |
group-ublox | 0:19aa55d66228 | 207 | |
group-ublox | 0:19aa55d66228 | 208 | int ESP8266Interface::socket_bind(void *handle, const SocketAddress &address) |
group-ublox | 0:19aa55d66228 | 209 | { |
group-ublox | 0:19aa55d66228 | 210 | return NSAPI_ERROR_UNSUPPORTED; |
group-ublox | 0:19aa55d66228 | 211 | } |
group-ublox | 0:19aa55d66228 | 212 | |
group-ublox | 0:19aa55d66228 | 213 | int ESP8266Interface::socket_listen(void *handle, int backlog) |
group-ublox | 0:19aa55d66228 | 214 | { |
group-ublox | 0:19aa55d66228 | 215 | return NSAPI_ERROR_UNSUPPORTED; |
group-ublox | 0:19aa55d66228 | 216 | } |
group-ublox | 0:19aa55d66228 | 217 | |
group-ublox | 0:19aa55d66228 | 218 | int ESP8266Interface::socket_connect(void *handle, const SocketAddress &addr) |
group-ublox | 0:19aa55d66228 | 219 | { |
group-ublox | 0:19aa55d66228 | 220 | struct esp8266_socket *socket = (struct esp8266_socket *)handle; |
group-ublox | 0:19aa55d66228 | 221 | _esp.setTimeout(ESP8266_MISC_TIMEOUT); |
group-ublox | 0:19aa55d66228 | 222 | |
group-ublox | 0:19aa55d66228 | 223 | const char *proto = (socket->proto == NSAPI_UDP) ? "UDP" : "TCP"; |
group-ublox | 0:19aa55d66228 | 224 | if (!_esp.open(proto, socket->id, addr.get_ip_address(), addr.get_port())) { |
group-ublox | 0:19aa55d66228 | 225 | return NSAPI_ERROR_DEVICE_ERROR; |
group-ublox | 0:19aa55d66228 | 226 | } |
group-ublox | 0:19aa55d66228 | 227 | |
group-ublox | 0:19aa55d66228 | 228 | socket->connected = true; |
group-ublox | 0:19aa55d66228 | 229 | return 0; |
group-ublox | 0:19aa55d66228 | 230 | } |
group-ublox | 0:19aa55d66228 | 231 | |
group-ublox | 0:19aa55d66228 | 232 | int ESP8266Interface::socket_accept(void *server, void **socket, SocketAddress *addr) |
group-ublox | 0:19aa55d66228 | 233 | { |
group-ublox | 0:19aa55d66228 | 234 | return NSAPI_ERROR_UNSUPPORTED; |
group-ublox | 0:19aa55d66228 | 235 | } |
group-ublox | 0:19aa55d66228 | 236 | |
group-ublox | 0:19aa55d66228 | 237 | int ESP8266Interface::socket_send(void *handle, const void *data, unsigned size) |
group-ublox | 0:19aa55d66228 | 238 | { |
group-ublox | 0:19aa55d66228 | 239 | struct esp8266_socket *socket = (struct esp8266_socket *)handle; |
group-ublox | 0:19aa55d66228 | 240 | _esp.setTimeout(ESP8266_SEND_TIMEOUT); |
group-ublox | 0:19aa55d66228 | 241 | |
group-ublox | 0:19aa55d66228 | 242 | if (!_esp.send(socket->id, data, size)) { |
group-ublox | 0:19aa55d66228 | 243 | return NSAPI_ERROR_DEVICE_ERROR; |
group-ublox | 0:19aa55d66228 | 244 | } |
group-ublox | 0:19aa55d66228 | 245 | |
group-ublox | 0:19aa55d66228 | 246 | return size; |
group-ublox | 0:19aa55d66228 | 247 | } |
group-ublox | 0:19aa55d66228 | 248 | |
group-ublox | 0:19aa55d66228 | 249 | int ESP8266Interface::socket_recv(void *handle, void *data, unsigned size) |
group-ublox | 0:19aa55d66228 | 250 | { |
group-ublox | 0:19aa55d66228 | 251 | struct esp8266_socket *socket = (struct esp8266_socket *)handle; |
group-ublox | 0:19aa55d66228 | 252 | _esp.setTimeout(ESP8266_RECV_TIMEOUT); |
group-ublox | 0:19aa55d66228 | 253 | |
group-ublox | 0:19aa55d66228 | 254 | int32_t recv = _esp.recv(socket->id, data, size); |
group-ublox | 0:19aa55d66228 | 255 | if (recv < 0) { |
group-ublox | 0:19aa55d66228 | 256 | return NSAPI_ERROR_WOULD_BLOCK; |
group-ublox | 0:19aa55d66228 | 257 | } |
group-ublox | 0:19aa55d66228 | 258 | |
group-ublox | 0:19aa55d66228 | 259 | return recv; |
group-ublox | 0:19aa55d66228 | 260 | } |
group-ublox | 0:19aa55d66228 | 261 | |
group-ublox | 0:19aa55d66228 | 262 | int ESP8266Interface::socket_sendto(void *handle, const SocketAddress &addr, const void *data, unsigned size) |
group-ublox | 0:19aa55d66228 | 263 | { |
group-ublox | 0:19aa55d66228 | 264 | struct esp8266_socket *socket = (struct esp8266_socket *)handle; |
group-ublox | 0:19aa55d66228 | 265 | |
group-ublox | 0:19aa55d66228 | 266 | if (socket->connected && socket->addr != addr) { |
group-ublox | 0:19aa55d66228 | 267 | _esp.setTimeout(ESP8266_MISC_TIMEOUT); |
group-ublox | 0:19aa55d66228 | 268 | if (!_esp.close(socket->id)) { |
group-ublox | 0:19aa55d66228 | 269 | return NSAPI_ERROR_DEVICE_ERROR; |
group-ublox | 0:19aa55d66228 | 270 | } |
group-ublox | 0:19aa55d66228 | 271 | socket->connected = false; |
group-ublox | 0:19aa55d66228 | 272 | } |
group-ublox | 0:19aa55d66228 | 273 | |
group-ublox | 0:19aa55d66228 | 274 | if (!socket->connected) { |
group-ublox | 0:19aa55d66228 | 275 | int err = socket_connect(socket, addr); |
group-ublox | 0:19aa55d66228 | 276 | if (err < 0) { |
group-ublox | 0:19aa55d66228 | 277 | return err; |
group-ublox | 0:19aa55d66228 | 278 | } |
group-ublox | 0:19aa55d66228 | 279 | socket->addr = addr; |
group-ublox | 0:19aa55d66228 | 280 | } |
group-ublox | 0:19aa55d66228 | 281 | |
group-ublox | 0:19aa55d66228 | 282 | return socket_send(socket, data, size); |
group-ublox | 0:19aa55d66228 | 283 | } |
group-ublox | 0:19aa55d66228 | 284 | |
group-ublox | 0:19aa55d66228 | 285 | int ESP8266Interface::socket_recvfrom(void *handle, SocketAddress *addr, void *data, unsigned size) |
group-ublox | 0:19aa55d66228 | 286 | { |
group-ublox | 0:19aa55d66228 | 287 | struct esp8266_socket *socket = (struct esp8266_socket *)handle; |
group-ublox | 0:19aa55d66228 | 288 | int ret = socket_recv(socket, data, size); |
group-ublox | 0:19aa55d66228 | 289 | if (ret >= 0 && addr) { |
group-ublox | 0:19aa55d66228 | 290 | *addr = socket->addr; |
group-ublox | 0:19aa55d66228 | 291 | } |
group-ublox | 0:19aa55d66228 | 292 | |
group-ublox | 0:19aa55d66228 | 293 | return ret; |
group-ublox | 0:19aa55d66228 | 294 | } |
group-ublox | 0:19aa55d66228 | 295 | |
group-ublox | 0:19aa55d66228 | 296 | void ESP8266Interface::socket_attach(void *handle, void (*callback)(void *), void *data) |
group-ublox | 0:19aa55d66228 | 297 | { |
group-ublox | 0:19aa55d66228 | 298 | struct esp8266_socket *socket = (struct esp8266_socket *)handle; |
group-ublox | 0:19aa55d66228 | 299 | _cbs[socket->id].callback = callback; |
group-ublox | 0:19aa55d66228 | 300 | _cbs[socket->id].data = data; |
group-ublox | 0:19aa55d66228 | 301 | } |
group-ublox | 0:19aa55d66228 | 302 | |
group-ublox | 0:19aa55d66228 | 303 | void ESP8266Interface::event() { |
group-ublox | 0:19aa55d66228 | 304 | for (int i = 0; i < ESP8266_SOCKET_COUNT; i++) { |
group-ublox | 0:19aa55d66228 | 305 | if (_cbs[i].callback) { |
group-ublox | 0:19aa55d66228 | 306 | _cbs[i].callback(_cbs[i].data); |
group-ublox | 0:19aa55d66228 | 307 | } |
group-ublox | 0:19aa55d66228 | 308 | } |
group-ublox | 0:19aa55d66228 | 309 | } |