ThingPlug Test

Dependents:   WizFi310_ThingPlug_Test WizFi310_ThingPlug_Test_P

Fork of WizFi310Interface by WIZnet

Committer:
cliff1
Date:
Mon Aug 28 05:19:48 2017 +0000
Revision:
8:08588dd2a66f
Parent:
7:b7019399eb1e
20170828_RECV

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