ThingPlug Test
Dependents: WizFi310_ThingPlug_Test WizFi310_ThingPlug_Test_P
Fork of WizFi310Interface by
WizFi310Interface.h@3:dae9a0924a73, 2017-04-12 (annotated)
- Committer:
- stkim92
- Date:
- Wed Apr 12 05:18:09 2017 +0000
- Revision:
- 3:dae9a0924a73
- Parent:
- 1:16e57103a7dd
- Child:
- 5:72212beb817c
Added connectAP function for AP mode
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jehoon | 0:df571f8f8c03 | 1 | /* WizFi310 implementation of NetworkInterfaceAPI |
jehoon | 0:df571f8f8c03 | 2 | * Copyright (c) 2015 ARM Limited |
jehoon | 0:df571f8f8c03 | 3 | * |
jehoon | 0:df571f8f8c03 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
jehoon | 0:df571f8f8c03 | 5 | * you may not use this file except in compliance with the License. |
jehoon | 0:df571f8f8c03 | 6 | * You may obtain a copy of the License at |
jehoon | 0:df571f8f8c03 | 7 | * |
jehoon | 0:df571f8f8c03 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
jehoon | 0:df571f8f8c03 | 9 | * |
jehoon | 0:df571f8f8c03 | 10 | * Unless required by applicable law or agreed to in writing, software |
jehoon | 0:df571f8f8c03 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
jehoon | 0:df571f8f8c03 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
jehoon | 0:df571f8f8c03 | 13 | * See the License for the specific language governing permissions and |
jehoon | 0:df571f8f8c03 | 14 | * limitations under the License. |
jehoon | 0:df571f8f8c03 | 15 | */ |
jehoon | 0:df571f8f8c03 | 16 | |
jehoon | 0:df571f8f8c03 | 17 | #ifndef WIZFI250_INTERFACE_H |
jehoon | 0:df571f8f8c03 | 18 | #define WIZFI250_INTERFACE_H |
jehoon | 0:df571f8f8c03 | 19 | |
jehoon | 0:df571f8f8c03 | 20 | #include "WiFiInterface.h" |
jehoon | 0:df571f8f8c03 | 21 | #include "WizFi310.h" |
jehoon | 0:df571f8f8c03 | 22 | |
jehoon | 0:df571f8f8c03 | 23 | #define WIZFI310_SOCKET_COUNT 8 |
jehoon | 0:df571f8f8c03 | 24 | |
jehoon | 0:df571f8f8c03 | 25 | /** WizFi310Interface class |
jehoon | 0:df571f8f8c03 | 26 | * Implementation of the NetworkStack for the WizFi310 |
jehoon | 0:df571f8f8c03 | 27 | */ |
jehoon | 1:16e57103a7dd | 28 | |
jehoon | 1:16e57103a7dd | 29 | |
jehoon | 0:df571f8f8c03 | 30 | class WizFi310Interface : public NetworkStack, public WiFiInterface |
jehoon | 0:df571f8f8c03 | 31 | { |
jehoon | 0:df571f8f8c03 | 32 | public: |
jehoon | 0:df571f8f8c03 | 33 | WizFi310Interface(PinName tx, PinName rx, PinName cts, PinName rts, PinName reset, PinName alarm, int baud=115200 ); |
jehoon | 0:df571f8f8c03 | 34 | |
jehoon | 1:16e57103a7dd | 35 | |
jehoon | 1:16e57103a7dd | 36 | |
jehoon | 0:df571f8f8c03 | 37 | virtual int connect( |
jehoon | 0:df571f8f8c03 | 38 | const char *ssid, |
jehoon | 0:df571f8f8c03 | 39 | const char *pass, |
jehoon | 0:df571f8f8c03 | 40 | nsapi_security_t security); |
jehoon | 0:df571f8f8c03 | 41 | |
stkim92 | 3:dae9a0924a73 | 42 | virtual int connectAP( |
stkim92 | 3:dae9a0924a73 | 43 | const char *ssid, |
stkim92 | 3:dae9a0924a73 | 44 | const char *pass, |
stkim92 | 3:dae9a0924a73 | 45 | nsapi_security_t security); |
stkim92 | 3:dae9a0924a73 | 46 | |
jehoon | 0:df571f8f8c03 | 47 | /** Stop the interface |
jehoon | 0:df571f8f8c03 | 48 | * @return 0 on success, negative on failure |
jehoon | 0:df571f8f8c03 | 49 | */ |
jehoon | 0:df571f8f8c03 | 50 | virtual int disconnect(); |
jehoon | 0:df571f8f8c03 | 51 | |
jehoon | 0:df571f8f8c03 | 52 | /** Get the internally stored IP address |
jehoon | 0:df571f8f8c03 | 53 | * @return IP address of the interface or null if not yet connected |
jehoon | 0:df571f8f8c03 | 54 | */ |
jehoon | 0:df571f8f8c03 | 55 | virtual const char *get_ip_address(); |
jehoon | 0:df571f8f8c03 | 56 | |
jehoon | 0:df571f8f8c03 | 57 | /** Get the internally stored MAC address |
jehoon | 0:df571f8f8c03 | 58 | * @return MAC address of the interface |
jehoon | 0:df571f8f8c03 | 59 | */ |
jehoon | 0:df571f8f8c03 | 60 | virtual const char *get_mac_address(); |
jehoon | 1:16e57103a7dd | 61 | |
jehoon | 1:16e57103a7dd | 62 | |
jehoon | 1:16e57103a7dd | 63 | WizFi310* get_WizFi310_Pointer() |
jehoon | 1:16e57103a7dd | 64 | { |
jehoon | 1:16e57103a7dd | 65 | return &_wizfi310; |
jehoon | 1:16e57103a7dd | 66 | } |
jehoon | 1:16e57103a7dd | 67 | |
jehoon | 0:df571f8f8c03 | 68 | protected: |
jehoon | 0:df571f8f8c03 | 69 | /** Open a socket |
jehoon | 0:df571f8f8c03 | 70 | * @param handle Handle in which to store new socket |
jehoon | 0:df571f8f8c03 | 71 | * @param proto Type of socket to open, NSAPI_TCP or NSAPI_UDP |
jehoon | 0:df571f8f8c03 | 72 | * @return 0 on success, negative on failure |
jehoon | 0:df571f8f8c03 | 73 | */ |
jehoon | 0:df571f8f8c03 | 74 | virtual int socket_open(void **handle, nsapi_protocol_t proto); |
jehoon | 0:df571f8f8c03 | 75 | |
jehoon | 0:df571f8f8c03 | 76 | /** Close the socket |
jehoon | 0:df571f8f8c03 | 77 | * @param handle Socket handle |
jehoon | 0:df571f8f8c03 | 78 | * @return 0 on success, negative on failure |
jehoon | 0:df571f8f8c03 | 79 | * @note On failure, any memory associated with the socket must still |
jehoon | 0:df571f8f8c03 | 80 | * be cleaned up |
jehoon | 0:df571f8f8c03 | 81 | */ |
jehoon | 0:df571f8f8c03 | 82 | virtual int socket_close(void *handle); |
jehoon | 0:df571f8f8c03 | 83 | |
jehoon | 0:df571f8f8c03 | 84 | /** Bind a server socket to a specific port |
jehoon | 0:df571f8f8c03 | 85 | * @param handle Socket handle |
jehoon | 0:df571f8f8c03 | 86 | * @param address Local address to listen for incoming connections on |
jehoon | 0:df571f8f8c03 | 87 | * @return 0 on success, negative on failure. |
jehoon | 0:df571f8f8c03 | 88 | */ |
jehoon | 0:df571f8f8c03 | 89 | virtual int socket_bind(void *handle, const SocketAddress &address); |
jehoon | 0:df571f8f8c03 | 90 | |
jehoon | 0:df571f8f8c03 | 91 | /** Start listening for incoming connections |
jehoon | 0:df571f8f8c03 | 92 | * @param handle Socket handle |
jehoon | 0:df571f8f8c03 | 93 | * @param backlog Number of pending connections that can be queued up at any |
jehoon | 0:df571f8f8c03 | 94 | * one time [Default: 1] |
jehoon | 0:df571f8f8c03 | 95 | * @return 0 on success, negative on failure |
jehoon | 0:df571f8f8c03 | 96 | */ |
jehoon | 0:df571f8f8c03 | 97 | virtual int socket_listen(void *handle, int backlog); |
jehoon | 0:df571f8f8c03 | 98 | |
jehoon | 0:df571f8f8c03 | 99 | /** Connects this TCP socket to the server |
jehoon | 0:df571f8f8c03 | 100 | * @param handle Socket handle |
jehoon | 0:df571f8f8c03 | 101 | * @param address SocketAddress to connect to |
jehoon | 0:df571f8f8c03 | 102 | * @return 0 on success, negative on failure |
jehoon | 0:df571f8f8c03 | 103 | */ |
jehoon | 0:df571f8f8c03 | 104 | virtual int socket_connect(void *handle, const SocketAddress &address); |
jehoon | 0:df571f8f8c03 | 105 | |
jehoon | 0:df571f8f8c03 | 106 | /** Accept a new connection. |
jehoon | 0:df571f8f8c03 | 107 | * @param handle Handle in which to store new socket |
jehoon | 0:df571f8f8c03 | 108 | * @param server Socket handle to server to accept from |
jehoon | 0:df571f8f8c03 | 109 | * @return 0 on success, negative on failure |
jehoon | 0:df571f8f8c03 | 110 | * @note This call is not-blocking, if this call would block, must |
jehoon | 0:df571f8f8c03 | 111 | * immediately return NSAPI_ERROR_WOULD_WAIT |
jehoon | 0:df571f8f8c03 | 112 | */ |
jehoon | 0:df571f8f8c03 | 113 | virtual int socket_accept(void **handle, void *server); |
jehoon | 0:df571f8f8c03 | 114 | |
jehoon | 0:df571f8f8c03 | 115 | /** Send data to the remote host |
jehoon | 0:df571f8f8c03 | 116 | * @param handle Socket handle |
jehoon | 0:df571f8f8c03 | 117 | * @param data The buffer to send to the host |
jehoon | 0:df571f8f8c03 | 118 | * @param size The length of the buffer to send |
jehoon | 0:df571f8f8c03 | 119 | * @return Number of written bytes on success, negative on failure |
jehoon | 0:df571f8f8c03 | 120 | * @note This call is not-blocking, if this call would block, must |
jehoon | 0:df571f8f8c03 | 121 | * immediately return NSAPI_ERROR_WOULD_WAIT |
jehoon | 0:df571f8f8c03 | 122 | */ |
jehoon | 0:df571f8f8c03 | 123 | virtual int socket_send(void *handle, const void *data, unsigned size); |
jehoon | 0:df571f8f8c03 | 124 | |
jehoon | 0:df571f8f8c03 | 125 | /** Receive data from the remote host |
jehoon | 0:df571f8f8c03 | 126 | * @param handle Socket handle |
jehoon | 0:df571f8f8c03 | 127 | * @param data The buffer in which to store the data received from the host |
jehoon | 0:df571f8f8c03 | 128 | * @param size The maximum length of the buffer |
jehoon | 0:df571f8f8c03 | 129 | * @return Number of received bytes on success, negative on failure |
jehoon | 0:df571f8f8c03 | 130 | * @note This call is not-blocking, if this call would block, must |
jehoon | 0:df571f8f8c03 | 131 | * immediately return NSAPI_ERROR_WOULD_WAIT |
jehoon | 0:df571f8f8c03 | 132 | */ |
jehoon | 0:df571f8f8c03 | 133 | virtual int socket_recv(void *handle, void *data, unsigned size); |
jehoon | 0:df571f8f8c03 | 134 | |
jehoon | 0:df571f8f8c03 | 135 | /** Send a packet to a remote endpoint |
jehoon | 0:df571f8f8c03 | 136 | * @param handle Socket handle |
jehoon | 0:df571f8f8c03 | 137 | * @param address The remote SocketAddress |
jehoon | 0:df571f8f8c03 | 138 | * @param data The packet to be sent |
jehoon | 0:df571f8f8c03 | 139 | * @param size The length of the packet to be sent |
jehoon | 0:df571f8f8c03 | 140 | * @return The number of written bytes on success, negative on failure |
jehoon | 0:df571f8f8c03 | 141 | * @note This call is not-blocking, if this call would block, must |
jehoon | 0:df571f8f8c03 | 142 | * immediately return NSAPI_ERROR_WOULD_WAIT |
jehoon | 0:df571f8f8c03 | 143 | */ |
jehoon | 0:df571f8f8c03 | 144 | virtual int socket_sendto(void *handle, const SocketAddress &address, const void *data, unsigned size); |
jehoon | 0:df571f8f8c03 | 145 | |
jehoon | 0:df571f8f8c03 | 146 | /** Receive a packet from a remote endpoint |
jehoon | 0:df571f8f8c03 | 147 | * @param handle Socket handle |
jehoon | 0:df571f8f8c03 | 148 | * @param address Destination for the remote SocketAddress or null |
jehoon | 0:df571f8f8c03 | 149 | * @param buffer The buffer for storing the incoming packet data |
jehoon | 0:df571f8f8c03 | 150 | * If a packet is too long to fit in the supplied buffer, |
jehoon | 0:df571f8f8c03 | 151 | * excess bytes are discarded |
jehoon | 0:df571f8f8c03 | 152 | * @param size The length of the buffer |
jehoon | 0:df571f8f8c03 | 153 | * @return The number of received bytes on success, negative on failure |
jehoon | 0:df571f8f8c03 | 154 | * @note This call is not-blocking, if this call would block, must |
jehoon | 0:df571f8f8c03 | 155 | * immediately return NSAPI_ERROR_WOULD_WAIT |
jehoon | 0:df571f8f8c03 | 156 | */ |
jehoon | 0:df571f8f8c03 | 157 | virtual int socket_recvfrom(void *handle, SocketAddress *address, void *buffer, unsigned size); |
jehoon | 0:df571f8f8c03 | 158 | |
jehoon | 0:df571f8f8c03 | 159 | /** Register a callback on state change of the socket |
jehoon | 0:df571f8f8c03 | 160 | * @param handle Socket handle |
jehoon | 0:df571f8f8c03 | 161 | * @param callback Function to call on state change |
jehoon | 0:df571f8f8c03 | 162 | * @param data Argument to pass to callback |
jehoon | 0:df571f8f8c03 | 163 | * @note Callback may be called in an interrupt context. |
jehoon | 0:df571f8f8c03 | 164 | */ |
jehoon | 0:df571f8f8c03 | 165 | virtual void socket_attach(void *handle, void (*callback)(void *), void *data); |
jehoon | 1:16e57103a7dd | 166 | |
jehoon | 1:16e57103a7dd | 167 | |
jehoon | 1:16e57103a7dd | 168 | |
jehoon | 0:df571f8f8c03 | 169 | |
jehoon | 0:df571f8f8c03 | 170 | private: |
jehoon | 0:df571f8f8c03 | 171 | WizFi310 _wizfi310; |
jehoon | 0:df571f8f8c03 | 172 | bool _ids[WIZFI310_SOCKET_COUNT]; |
jehoon | 0:df571f8f8c03 | 173 | }; |
jehoon | 0:df571f8f8c03 | 174 | |
jehoon | 0:df571f8f8c03 | 175 | #endif |
jehoon | 0:df571f8f8c03 | 176 |