versione corretta

Dependents:   DISCO_L475VG_IOT01-Sensors-BSP

Committer:
group-Farnell24-IOT-Team
Date:
Tue Aug 21 08:34:28 2018 +0000
Revision:
0:766454e296c3
Initial commit

Who changed what in which revision?

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