ThingPlug Test

Dependents:   WizFi310_ThingPlug_Test WizFi310_ThingPlug_Test_P

Fork of WizFi310Interface by WIZnet

Committer:
jehoon
Date:
Mon Oct 10 05:12:51 2016 +0000
Revision:
1:16e57103a7dd
Parent:
0:df571f8f8c03
Child:
3:dae9a0924a73
Child:
7:b7019399eb1e
mqtt receive

Who changed what in which revision?

UserRevisionLine numberNew 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
jehoon 0:df571f8f8c03 42 /** Stop the interface
jehoon 0:df571f8f8c03 43 * @return 0 on success, negative on failure
jehoon 0:df571f8f8c03 44 */
jehoon 0:df571f8f8c03 45 virtual int disconnect();
jehoon 0:df571f8f8c03 46
jehoon 0:df571f8f8c03 47 /** Get the internally stored IP address
jehoon 0:df571f8f8c03 48 * @return IP address of the interface or null if not yet connected
jehoon 0:df571f8f8c03 49 */
jehoon 0:df571f8f8c03 50 virtual const char *get_ip_address();
jehoon 0:df571f8f8c03 51
jehoon 0:df571f8f8c03 52 /** Get the internally stored MAC address
jehoon 0:df571f8f8c03 53 * @return MAC address of the interface
jehoon 0:df571f8f8c03 54 */
jehoon 0:df571f8f8c03 55 virtual const char *get_mac_address();
jehoon 1:16e57103a7dd 56
jehoon 1:16e57103a7dd 57
jehoon 1:16e57103a7dd 58 WizFi310* get_WizFi310_Pointer()
jehoon 1:16e57103a7dd 59 {
jehoon 1:16e57103a7dd 60 return &_wizfi310;
jehoon 1:16e57103a7dd 61 }
jehoon 1:16e57103a7dd 62
jehoon 0:df571f8f8c03 63 protected:
jehoon 0:df571f8f8c03 64 /** Open a socket
jehoon 0:df571f8f8c03 65 * @param handle Handle in which to store new socket
jehoon 0:df571f8f8c03 66 * @param proto Type of socket to open, NSAPI_TCP or NSAPI_UDP
jehoon 0:df571f8f8c03 67 * @return 0 on success, negative on failure
jehoon 0:df571f8f8c03 68 */
jehoon 0:df571f8f8c03 69 virtual int socket_open(void **handle, nsapi_protocol_t proto);
jehoon 0:df571f8f8c03 70
jehoon 0:df571f8f8c03 71 /** Close the socket
jehoon 0:df571f8f8c03 72 * @param handle Socket handle
jehoon 0:df571f8f8c03 73 * @return 0 on success, negative on failure
jehoon 0:df571f8f8c03 74 * @note On failure, any memory associated with the socket must still
jehoon 0:df571f8f8c03 75 * be cleaned up
jehoon 0:df571f8f8c03 76 */
jehoon 0:df571f8f8c03 77 virtual int socket_close(void *handle);
jehoon 0:df571f8f8c03 78
jehoon 0:df571f8f8c03 79 /** Bind a server socket to a specific port
jehoon 0:df571f8f8c03 80 * @param handle Socket handle
jehoon 0:df571f8f8c03 81 * @param address Local address to listen for incoming connections on
jehoon 0:df571f8f8c03 82 * @return 0 on success, negative on failure.
jehoon 0:df571f8f8c03 83 */
jehoon 0:df571f8f8c03 84 virtual int socket_bind(void *handle, const SocketAddress &address);
jehoon 0:df571f8f8c03 85
jehoon 0:df571f8f8c03 86 /** Start listening for incoming connections
jehoon 0:df571f8f8c03 87 * @param handle Socket handle
jehoon 0:df571f8f8c03 88 * @param backlog Number of pending connections that can be queued up at any
jehoon 0:df571f8f8c03 89 * one time [Default: 1]
jehoon 0:df571f8f8c03 90 * @return 0 on success, negative on failure
jehoon 0:df571f8f8c03 91 */
jehoon 0:df571f8f8c03 92 virtual int socket_listen(void *handle, int backlog);
jehoon 0:df571f8f8c03 93
jehoon 0:df571f8f8c03 94 /** Connects this TCP socket to the server
jehoon 0:df571f8f8c03 95 * @param handle Socket handle
jehoon 0:df571f8f8c03 96 * @param address SocketAddress to connect to
jehoon 0:df571f8f8c03 97 * @return 0 on success, negative on failure
jehoon 0:df571f8f8c03 98 */
jehoon 0:df571f8f8c03 99 virtual int socket_connect(void *handle, const SocketAddress &address);
jehoon 0:df571f8f8c03 100
jehoon 0:df571f8f8c03 101 /** Accept a new connection.
jehoon 0:df571f8f8c03 102 * @param handle Handle in which to store new socket
jehoon 0:df571f8f8c03 103 * @param server Socket handle to server to accept from
jehoon 0:df571f8f8c03 104 * @return 0 on success, negative on failure
jehoon 0:df571f8f8c03 105 * @note This call is not-blocking, if this call would block, must
jehoon 0:df571f8f8c03 106 * immediately return NSAPI_ERROR_WOULD_WAIT
jehoon 0:df571f8f8c03 107 */
jehoon 0:df571f8f8c03 108 virtual int socket_accept(void **handle, void *server);
jehoon 0:df571f8f8c03 109
jehoon 0:df571f8f8c03 110 /** Send data to the remote host
jehoon 0:df571f8f8c03 111 * @param handle Socket handle
jehoon 0:df571f8f8c03 112 * @param data The buffer to send to the host
jehoon 0:df571f8f8c03 113 * @param size The length of the buffer to send
jehoon 0:df571f8f8c03 114 * @return Number of written bytes on success, negative on failure
jehoon 0:df571f8f8c03 115 * @note This call is not-blocking, if this call would block, must
jehoon 0:df571f8f8c03 116 * immediately return NSAPI_ERROR_WOULD_WAIT
jehoon 0:df571f8f8c03 117 */
jehoon 0:df571f8f8c03 118 virtual int socket_send(void *handle, const void *data, unsigned size);
jehoon 0:df571f8f8c03 119
jehoon 0:df571f8f8c03 120 /** Receive data from the remote host
jehoon 0:df571f8f8c03 121 * @param handle Socket handle
jehoon 0:df571f8f8c03 122 * @param data The buffer in which to store the data received from the host
jehoon 0:df571f8f8c03 123 * @param size The maximum length of the buffer
jehoon 0:df571f8f8c03 124 * @return Number of received bytes on success, negative on failure
jehoon 0:df571f8f8c03 125 * @note This call is not-blocking, if this call would block, must
jehoon 0:df571f8f8c03 126 * immediately return NSAPI_ERROR_WOULD_WAIT
jehoon 0:df571f8f8c03 127 */
jehoon 0:df571f8f8c03 128 virtual int socket_recv(void *handle, void *data, unsigned size);
jehoon 0:df571f8f8c03 129
jehoon 0:df571f8f8c03 130 /** Send a packet to a remote endpoint
jehoon 0:df571f8f8c03 131 * @param handle Socket handle
jehoon 0:df571f8f8c03 132 * @param address The remote SocketAddress
jehoon 0:df571f8f8c03 133 * @param data The packet to be sent
jehoon 0:df571f8f8c03 134 * @param size The length of the packet to be sent
jehoon 0:df571f8f8c03 135 * @return The number of written bytes on success, negative on failure
jehoon 0:df571f8f8c03 136 * @note This call is not-blocking, if this call would block, must
jehoon 0:df571f8f8c03 137 * immediately return NSAPI_ERROR_WOULD_WAIT
jehoon 0:df571f8f8c03 138 */
jehoon 0:df571f8f8c03 139 virtual int socket_sendto(void *handle, const SocketAddress &address, const void *data, unsigned size);
jehoon 0:df571f8f8c03 140
jehoon 0:df571f8f8c03 141 /** Receive a packet from a remote endpoint
jehoon 0:df571f8f8c03 142 * @param handle Socket handle
jehoon 0:df571f8f8c03 143 * @param address Destination for the remote SocketAddress or null
jehoon 0:df571f8f8c03 144 * @param buffer The buffer for storing the incoming packet data
jehoon 0:df571f8f8c03 145 * If a packet is too long to fit in the supplied buffer,
jehoon 0:df571f8f8c03 146 * excess bytes are discarded
jehoon 0:df571f8f8c03 147 * @param size The length of the buffer
jehoon 0:df571f8f8c03 148 * @return The number of received bytes on success, negative on failure
jehoon 0:df571f8f8c03 149 * @note This call is not-blocking, if this call would block, must
jehoon 0:df571f8f8c03 150 * immediately return NSAPI_ERROR_WOULD_WAIT
jehoon 0:df571f8f8c03 151 */
jehoon 0:df571f8f8c03 152 virtual int socket_recvfrom(void *handle, SocketAddress *address, void *buffer, unsigned size);
jehoon 0:df571f8f8c03 153
jehoon 0:df571f8f8c03 154 /** Register a callback on state change of the socket
jehoon 0:df571f8f8c03 155 * @param handle Socket handle
jehoon 0:df571f8f8c03 156 * @param callback Function to call on state change
jehoon 0:df571f8f8c03 157 * @param data Argument to pass to callback
jehoon 0:df571f8f8c03 158 * @note Callback may be called in an interrupt context.
jehoon 0:df571f8f8c03 159 */
jehoon 0:df571f8f8c03 160 virtual void socket_attach(void *handle, void (*callback)(void *), void *data);
jehoon 1:16e57103a7dd 161
jehoon 1:16e57103a7dd 162
jehoon 1:16e57103a7dd 163
jehoon 0:df571f8f8c03 164
jehoon 0:df571f8f8c03 165 private:
jehoon 0:df571f8f8c03 166 WizFi310 _wizfi310;
jehoon 0:df571f8f8c03 167 bool _ids[WIZFI310_SOCKET_COUNT];
jehoon 0:df571f8f8c03 168 };
jehoon 0:df571f8f8c03 169
jehoon 0:df571f8f8c03 170 #endif
jehoon 0:df571f8f8c03 171