ThingPlug Test
Dependents: WizFi310_ThingPlug_Test WizFi310_ThingPlug_Test_P
Fork of WizFi310Interface by
WizFi310Interface.h
00001 /* WizFi310 implementation of NetworkInterfaceAPI 00002 * Copyright (c) 2015 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef WIZFI250_INTERFACE_H 00018 #define WIZFI250_INTERFACE_H 00019 00020 #include "WiFiInterface.h" 00021 #include "WizFi310.h" 00022 00023 #define WIZFI310_SOCKET_COUNT 8 00024 00025 /** WizFi310Interface class 00026 * Implementation of the NetworkStack for the WizFi310 00027 */ 00028 00029 00030 class WizFi310Interface : public NetworkStack, public WiFiInterface 00031 { 00032 public: 00033 WizFi310Interface(PinName tx, PinName rx, PinName cts, PinName rts, PinName reset, PinName alarm, int baud=115200 ); 00034 00035 00036 00037 virtual int connect( 00038 const char *ssid, 00039 const char *pass, 00040 nsapi_security_t security); 00041 00042 /** Stop the interface 00043 * @return 0 on success, negative on failure 00044 */ 00045 virtual int disconnect(); 00046 00047 /** Get the internally stored IP address 00048 * @return IP address of the interface or null if not yet connected 00049 */ 00050 virtual const char *get_ip_address(); 00051 00052 /** Get the internally stored MAC address 00053 * @return MAC address of the interface 00054 */ 00055 virtual const char *get_mac_address(); 00056 00057 00058 virtual int conTP(const char *clientId, const char *credentialId, const char *serviceId, const char *devId, const char *containerNm, const char *commandName); 00059 virtual int sendTP(const char *containerNm, const char *sendData); 00060 virtual int recvTP(const char *commandName, int executeStatus, int executeResult); 00061 virtual int disConTP(); 00062 00063 00064 WizFi310* get_WizFi310_Pointer() 00065 { 00066 return &_wizfi310; 00067 } 00068 00069 protected: 00070 /** Open a socket 00071 * @param handle Handle in which to store new socket 00072 * @param proto Type of socket to open, NSAPI_TCP or NSAPI_UDP 00073 * @return 0 on success, negative on failure 00074 */ 00075 virtual int socket_open(void **handle, nsapi_protocol_t proto); 00076 00077 /** Close the socket 00078 * @param handle Socket handle 00079 * @return 0 on success, negative on failure 00080 * @note On failure, any memory associated with the socket must still 00081 * be cleaned up 00082 */ 00083 virtual int socket_close(void *handle); 00084 00085 /** Bind a server socket to a specific port 00086 * @param handle Socket handle 00087 * @param address Local address to listen for incoming connections on 00088 * @return 0 on success, negative on failure. 00089 */ 00090 virtual int socket_bind(void *handle, const SocketAddress &address); 00091 00092 /** Start listening for incoming connections 00093 * @param handle Socket handle 00094 * @param backlog Number of pending connections that can be queued up at any 00095 * one time [Default: 1] 00096 * @return 0 on success, negative on failure 00097 */ 00098 virtual int socket_listen(void *handle, int backlog); 00099 00100 /** Connects this TCP socket to the server 00101 * @param handle Socket handle 00102 * @param address SocketAddress to connect to 00103 * @return 0 on success, negative on failure 00104 */ 00105 virtual int socket_connect(void *handle, const SocketAddress &address); 00106 00107 /** Accept a new connection. 00108 * @param handle Handle in which to store new socket 00109 * @param server Socket handle to server to accept from 00110 * @return 0 on success, negative on failure 00111 * @note This call is not-blocking, if this call would block, must 00112 * immediately return NSAPI_ERROR_WOULD_WAIT 00113 */ 00114 virtual int socket_accept(void **handle, void *server); 00115 00116 /** Send data to the remote host 00117 * @param handle Socket handle 00118 * @param data The buffer to send to the host 00119 * @param size The length of the buffer to send 00120 * @return Number of written bytes on success, negative on failure 00121 * @note This call is not-blocking, if this call would block, must 00122 * immediately return NSAPI_ERROR_WOULD_WAIT 00123 */ 00124 virtual int socket_send(void *handle, const void *data, unsigned size); 00125 00126 /** Receive data from the remote host 00127 * @param handle Socket handle 00128 * @param data The buffer in which to store the data received from the host 00129 * @param size The maximum length of the buffer 00130 * @return Number of received bytes on success, negative on failure 00131 * @note This call is not-blocking, if this call would block, must 00132 * immediately return NSAPI_ERROR_WOULD_WAIT 00133 */ 00134 virtual int socket_recv(void *handle, void *data, unsigned size); 00135 00136 /** Send a packet to a remote endpoint 00137 * @param handle Socket handle 00138 * @param address The remote SocketAddress 00139 * @param data The packet to be sent 00140 * @param size The length of the packet to be sent 00141 * @return The number of written bytes on success, negative on failure 00142 * @note This call is not-blocking, if this call would block, must 00143 * immediately return NSAPI_ERROR_WOULD_WAIT 00144 */ 00145 virtual int socket_sendto(void *handle, const SocketAddress &address, const void *data, unsigned size); 00146 00147 /** Receive a packet from a remote endpoint 00148 * @param handle Socket handle 00149 * @param address Destination for the remote SocketAddress or null 00150 * @param buffer The buffer for storing the incoming packet data 00151 * If a packet is too long to fit in the supplied buffer, 00152 * excess bytes are discarded 00153 * @param size The length of the buffer 00154 * @return The number of received bytes on success, negative on failure 00155 * @note This call is not-blocking, if this call would block, must 00156 * immediately return NSAPI_ERROR_WOULD_WAIT 00157 */ 00158 virtual int socket_recvfrom(void *handle, SocketAddress *address, void *buffer, unsigned size); 00159 00160 /** Register a callback on state change of the socket 00161 * @param handle Socket handle 00162 * @param callback Function to call on state change 00163 * @param data Argument to pass to callback 00164 * @note Callback may be called in an interrupt context. 00165 */ 00166 virtual void socket_attach(void *handle, void (*callback)(void *), void *data); 00167 00168 00169 00170 00171 private: 00172 WizFi310 _wizfi310; 00173 bool _ids[WIZFI310_SOCKET_COUNT]; 00174 }; 00175 00176 #endif 00177
Generated on Sat Jul 16 2022 03:26:38 by 1.7.2