WIZnet / WizFi310Interface

Dependents:   KT_IoTMakers_WizFi310_Example WizFi310_STATION_HelloWorld WizFi310_DNS_TCP_HelloWorld WizFi310_Ubidots ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers WizFi310Interface.h Source File

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     virtual int connectAP(
00043         const char *ssid,
00044         const char *pass,
00045         nsapi_security_t security);
00046 
00047     /** Stop the interface
00048      *  @return             0 on success, negative on failure
00049      */
00050     virtual int disconnect();
00051 
00052     /** Get the internally stored IP address
00053      *  @return             IP address of the interface or null if not yet connected
00054      */
00055     virtual const char *get_ip_address();
00056 
00057     /** Get the internally stored MAC address
00058      *  @return             MAC address of the interface
00059      */
00060     virtual const char *get_mac_address();
00061     
00062     
00063     WizFi310* get_WizFi310_Pointer()
00064     {
00065          return &_wizfi310;
00066     }
00067 
00068 protected:
00069     /** Open a socket
00070      *  @param handle       Handle in which to store new socket
00071      *  @param proto        Type of socket to open, NSAPI_TCP or NSAPI_UDP
00072      *  @return             0 on success, negative on failure
00073      */
00074     virtual int socket_open(void **handle, nsapi_protocol_t proto);
00075 
00076     /** Close the socket
00077      *  @param handle       Socket handle
00078      *  @return             0 on success, negative on failure
00079      *  @note On failure, any memory associated with the socket must still 
00080      *        be cleaned up
00081      */
00082     virtual int socket_close(void *handle);
00083 
00084     /** Bind a server socket to a specific port
00085      *  @param handle       Socket handle
00086      *  @param address      Local address to listen for incoming connections on 
00087      *  @return             0 on success, negative on failure.
00088      */
00089     virtual int socket_bind(void *handle, const SocketAddress &address);
00090 
00091     /** Start listening for incoming connections
00092      *  @param handle       Socket handle
00093      *  @param backlog      Number of pending connections that can be queued up at any
00094      *                      one time [Default: 1]
00095      *  @return             0 on success, negative on failure
00096      */
00097     virtual int socket_listen(void *handle, int backlog);
00098 
00099     /** Connects this TCP socket to the server
00100      *  @param handle       Socket handle
00101      *  @param address      SocketAddress to connect to
00102      *  @return             0 on success, negative on failure
00103      */
00104     virtual int socket_connect(void *handle, const SocketAddress &address);
00105 
00106     /** Accept a new connection.
00107      *  @param handle       Handle in which to store new socket
00108      *  @param server       Socket handle to server to accept from
00109      *  @return             0 on success, negative on failure
00110      *  @note This call is not-blocking, if this call would block, must
00111      *        immediately return NSAPI_ERROR_WOULD_WAIT
00112      */
00113     virtual int socket_accept(void **handle, void *server);
00114 
00115     /** Send data to the remote host
00116      *  @param handle       Socket handle
00117      *  @param data         The buffer to send to the host
00118      *  @param size         The length of the buffer to send
00119      *  @return             Number of written bytes on success, negative on failure
00120      *  @note This call is not-blocking, if this call would block, must
00121      *        immediately return NSAPI_ERROR_WOULD_WAIT
00122      */
00123     virtual int socket_send(void *handle, const void *data, unsigned size);
00124 
00125     /** Receive data from the remote host
00126      *  @param handle       Socket handle
00127      *  @param data         The buffer in which to store the data received from the host
00128      *  @param size         The maximum length of the buffer
00129      *  @return             Number of received bytes on success, negative on failure
00130      *  @note This call is not-blocking, if this call would block, must
00131      *        immediately return NSAPI_ERROR_WOULD_WAIT
00132      */
00133     virtual int socket_recv(void *handle, void *data, unsigned size);
00134 
00135     /** Send a packet to a remote endpoint
00136      *  @param handle       Socket handle
00137      *  @param address      The remote SocketAddress
00138      *  @param data         The packet to be sent
00139      *  @param size         The length of the packet to be sent
00140      *  @return             The number of written bytes on success, negative on failure
00141      *  @note This call is not-blocking, if this call would block, must
00142      *        immediately return NSAPI_ERROR_WOULD_WAIT
00143      */
00144     virtual int socket_sendto(void *handle, const SocketAddress &address, const void *data, unsigned size);
00145 
00146     /** Receive a packet from a remote endpoint
00147      *  @param handle       Socket handle
00148      *  @param address      Destination for the remote SocketAddress or null
00149      *  @param buffer       The buffer for storing the incoming packet data
00150      *                      If a packet is too long to fit in the supplied buffer,
00151      *                      excess bytes are discarded
00152      *  @param size         The length of the buffer
00153      *  @return             The number of received bytes on success, negative on failure
00154      *  @note This call is not-blocking, if this call would block, must
00155      *        immediately return NSAPI_ERROR_WOULD_WAIT
00156      */
00157     virtual int socket_recvfrom(void *handle, SocketAddress *address, void *buffer, unsigned size);
00158 
00159     /** Register a callback on state change of the socket
00160      *  @param handle       Socket handle
00161      *  @param callback     Function to call on state change
00162      *  @param data         Argument to pass to callback
00163      *  @note Callback may be called in an interrupt context.
00164      */
00165     virtual void socket_attach(void *handle, void (*callback)(void *), void *data);
00166     
00167     
00168     
00169 
00170 private:
00171     WizFi310 _wizfi310;
00172     bool _ids[WIZFI310_SOCKET_COUNT];
00173 };
00174 
00175 #endif
00176