Extending the X_NUCLEO_IDW01M1 to allow configuration of the board as an access point

Dependents:   X_NUCLEO_IDW01M1_AP_Test

Fork of X_NUCLEO_IDW01M1 by ST

Revision:
12:3799f8475c8a
Parent:
11:67a8c3499caf
Child:
13:cdcc13d78252
--- a/SPWFInterface.cpp	Sat May 14 07:28:29 2016 +0000
+++ b/SPWFInterface.cpp	Sat May 14 08:31:39 2016 +0000
@@ -48,17 +48,36 @@
     isInitialized = false;
     isListening = false;
 }
- 
+
+/**
+* @brief  SpwfSAInterface destructor         
+* @param  none
+* @retval none
+*/
 SpwfSAInterface::~SpwfSAInterface()
 {
 }
 
+/**
+* @brief  init function
+          initializes SPWF FW and module         
+* @param  none
+* @retval error value
+*/
 int SpwfSAInterface::init(void) 
 {
     _spwf.setTimeout(SPWF_MISC_TIMEOUT);
     return (_spwf.init());
 }
 
+/**
+* @brief  network connect
+          connects to Access Point
+* @param  ap: Access Point (AP) Name String  
+*         pass_phrase: Password String for AP
+*         security: type of NSAPI security supported
+* @retval NSAPI Error Type
+*/
 int SpwfSAInterface::connect(
     const char *ap, 
     const char *pass_phrase, 
@@ -78,28 +97,50 @@
     
     WiFi_Priv_Mode mode = (WiFi_Priv_Mode)security;
   
-    return (_spwf.connect((char*)ap, (char*)pass_phrase, mode));//0 on success
+    return (_spwf.connect((char*)ap, (char*)pass_phrase, mode));
 }
- 
+
+/**
+* @brief  network disconnect
+          disconnects from Access Point
+* @param  none
+* @retval NSAPI Error Type
+*/
 int SpwfSAInterface::disconnect()
 {    
     return (_spwf.disconnect());
 }
- 
+
+/** 
+* @brief  Get the local IP address
+* @param  none
+* @retval Null-terminated representation of the local IP address
+*         or null if not yet connected
+*/
 const char *SpwfSAInterface::get_ip_address()
 {
     return _spwf.getIPAddress();
 }
- 
+
+/** 
+* @brief  Get the MAC address
+* @param  none
+* @retval Null-terminated representation of the MAC address
+*         or null if not yet connected
+*/
 const char *SpwfSAInterface::get_mac_address()
 {
     return _spwf.getMACAddress();
 }
 
-
+/**
+* @brief  open a socket handle
+* @param  handle: Pointer to handle
+*         proto: TCP/UDP protocol
+* @retval NSAPI Error Type
+*/
 int SpwfSAInterface::socket_open(void **handle, nsapi_protocol_t proto)
 {
-    // Look for an unused socket
     int id = -1;    
 
     struct spwf_socket *socket = new struct spwf_socket;
@@ -115,6 +156,12 @@
     return 0;
 }
 
+/**
+* @brief  connect to a remote socket
+* @param  handle: Pointer to socket handle
+*         addr: Address to connect to
+* @retval NSAPI Error Type
+*/
 int SpwfSAInterface::socket_connect(void *handle, const SocketAddress &addr)
 {
     uint8_t sock_id = 99;
@@ -130,7 +177,6 @@
       
     if(sock_id <= SPWFSA_SOCKET_COUNT)
     {
-        //_ids[socket->id] = false;
         socket->id = sock_id;//the socket ID of this Socket instance
         _ids[socket->id] = true;
         socket->connected = true;
@@ -138,9 +184,15 @@
     else 
         return NSAPI_ERROR_NO_SOCKET;
     
-    return 0;//0 means SUCCESS
+    return 0;
 }
 
+/**
+* @brief  bind to a port number and address
+* @param  handle: Pointer to socket handle
+*         proto: address to bind to
+* @retval NSAPI Error Type
+*/
 int SpwfSAInterface::socket_bind(void *handle, const SocketAddress &address)
 {
     struct spwf_socket *socket = (struct spwf_socket *)handle;    
@@ -148,6 +200,12 @@
     return 0;
 }
 
+/**
+* @brief  start listening on a port and address
+* @param  handle: Pointer to handle
+*         backlog: not used (always value is 1)
+* @retval NSAPI Error Type
+*/
 int SpwfSAInterface::socket_listen(void *handle, int backlog)
 {
     struct spwf_socket *socket = (struct spwf_socket *)handle;
@@ -171,6 +229,12 @@
     return err;
 }
 
+/**
+* @brief  accept connections from remote sockets
+* @param  handle: Pointer to handle of client socket (connecting)
+*         proto: handle of server socket which will accept connections
+* @retval NSAPI Error Type
+*/
 int SpwfSAInterface::socket_accept(void **handle, void *server)
 {
     struct spwf_socket *server_socket = (struct spwf_socket *)server;
@@ -195,13 +259,18 @@
         
         *handle = socket; 
         socket = 0;
-        _spwf.set_wait_for_incoming_client(false);//reset
+        _spwf.set_wait_for_incoming_client(false);
         wait_ms(50);//CHECK:TODO:Why do we need this?
         return 0;
     }    
     return NSAPI_ERROR_WOULD_BLOCK;
 }
 
+/**
+* @brief  close a socket
+* @param  handle: Pointer to handle
+* @retval NSAPI Error Type
+*/
 int SpwfSAInterface::socket_close(void *handle)
 {
     struct spwf_socket *socket = (struct spwf_socket *)handle;
@@ -230,6 +299,13 @@
     return err;
 }
 
+/**
+* @brief  write to a socket
+* @param  handle: Pointer to handle
+*         data: pointer to data
+*         size: size of data
+* @retval no of bytes sent
+*/
 int SpwfSAInterface::socket_send(void *handle, const void *data, unsigned size)
 {    
     struct spwf_socket *socket = (struct spwf_socket *)handle;
@@ -250,7 +326,13 @@
     return err;
 }
 
-//return no of bytes read
+/**
+* @brief  receive data on a socket
+* @param  handle: Pointer to handle
+*         data: pointer to data
+*         size: size of data
+* @retval no of bytes read
+*/
 int SpwfSAInterface::socket_recv(void *handle, void *data, unsigned size)
 {
     struct spwf_socket *socket = (struct spwf_socket *)handle;
@@ -267,6 +349,14 @@
     
 }
 
+/**
+* @brief  send data to a udp socket
+* @param  handle: Pointer to handle
+*         addr: address of udp socket
+*         data: pointer to data
+*         size: size of data
+* @retval no of bytes sent
+*/
 int SpwfSAInterface::socket_sendto(void *handle, const SocketAddress &addr, const void *data, unsigned size)
 {
     struct spwf_socket *socket = (struct spwf_socket *)handle;
@@ -280,17 +370,38 @@
     return socket_send(socket, data, size);
 }
 
+/**
+* @brief  receive data on a udp socket
+* @param  handle: Pointer to handle
+*         addr: address of udp socket
+*         data: pointer to data
+*         size: size of data
+* @retval no of bytes read
+*/
 int SpwfSAInterface::socket_recvfrom(void *handle, SocketAddress *addr, void *data, unsigned size)
 {
     struct spwf_socket *socket = (struct spwf_socket *)handle;    
     return socket_recv(socket, data, size);
 }
 
+/**
+* @brief  attach function/callback to the socket
+*         Not used
+* @param  handle: Pointer to handle
+*         callback: callback function pointer
+*         data: pointer to data
+* @retval none
+*/
 void SpwfSAInterface::socket_attach(void *handle, void (*callback)(void *), void *data)
 {
     //No implementation yet
 }
 
+/**
+* @brief  utility debug function for printing to serial terminal
+* @param  string: Pointer to data
+* @retval none
+*/
 void SpwfSAInterface::debug(const char * string)
 {
     _spwf.debug_print(string);