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
Diff: SPWFInterface.cpp
- Revision:
- 7:0fdd186a7d90
- Parent:
- 6:e7a3fca2df10
- Child:
- 8:0f302a13e21b
--- a/SPWFInterface.cpp Mon May 09 10:38:22 2016 +0000 +++ b/SPWFInterface.cpp Wed May 11 06:12:16 2016 +0000 @@ -19,7 +19,7 @@ // Various timeouts for different SPWF operations #define SPWF_CONNECT_TIMEOUT 20000 #define SPWF_SEND_TIMEOUT 500 -#define SPWF_RECV_TIMEOUT 2000 +#define SPWF_RECV_TIMEOUT 1000 #define SPWF_MISC_TIMEOUT 15000 // Handle structure for socket @@ -133,8 +133,7 @@ int SpwfSAInterface::socket_bind(void *handle, const SocketAddress &address) { - struct spwf_socket *socket = (struct spwf_socket *)handle; - socket->id = SERVER_SOCKET_NO;//Special socket ID number for Server Socket + struct spwf_socket *socket = (struct spwf_socket *)handle; socket->server_port = address.get_port(); return 0; } @@ -153,6 +152,7 @@ if(err==0) { + socket->id = SERVER_SOCKET_NO;//Special socket ID number for Server Socket isListening = true; } else @@ -176,46 +176,38 @@ */ int SpwfSAInterface::socket_accept(void **handle, void *server) { - char debug_str[10]; struct spwf_socket *server_socket = (struct spwf_socket *)server; - int id = -1; if(server_socket->server_port==-1 || !isListening) return NSAPI_ERROR_NO_SOCKET; //server socket not bound or not listening - while(true) - { - if(_spwf.get_wait_for_incoming_client()) + if(_spwf.get_wait_for_incoming_client()) + { + server_socket->connected = true; + struct spwf_socket *socket = new struct spwf_socket;//create new network socket + if (!socket) { + return NSAPI_ERROR_NO_SOCKET; + } + + memset(socket, 0, sizeof (struct spwf_socket)); + /* + if(get_network_socket(&temp_socket)!=0) { - server_socket->connected = true; - - //struct spwf_socket *temp_socket;// = new struct spwf_socket;//create new network socket - struct spwf_socket *socket = new struct spwf_socket;//create new network socket - if (!socket) { - return NSAPI_ERROR_NO_SOCKET; - } - - memset(socket, 0, sizeof (struct spwf_socket)); - /* - if(get_network_socket(&temp_socket)!=0) - { - return NSAPI_ERROR_NO_SOCKET; - }*/ - - socket->id = server_socket->id; - socket->server_port = server_socket->server_port; - socket->proto = server_socket->proto; - socket->connected = true; - - *handle = socket; - socket = 0; - _spwf.set_wait_for_incoming_client(false);//reset - wait_ms(50);//CHECK:TODO:Why do we need this? - break; - } - } - - return 0; + return NSAPI_ERROR_NO_SOCKET; + }*/ + + socket->id = server_socket->id; + socket->server_port = server_socket->server_port; + socket->proto = server_socket->proto; + socket->connected = true; + + *handle = socket; + socket = 0; + _spwf.set_wait_for_incoming_client(false);//reset + wait_ms(50);//CHECK:TODO:Why do we need this? + return 0; + } + return NSAPI_ERROR_WOULD_BLOCK; } /* @@ -237,7 +229,7 @@ { struct spwf_socket *socket = (struct spwf_socket *)handle; int err = 0; - //_spwf.setTimeout(SPWF_MISC_TIMEOUT); + _spwf.setTimeout(SPWF_MISC_TIMEOUT); if(socket->id!=-1) { @@ -268,6 +260,9 @@ if(socket->id==SERVER_SOCKET_NO) { + if(socket->server_port==-1 || !isListening) + return NSAPI_ERROR_NO_SOCKET; //server socket not bound or not listening + err = _spwf.socket_server_write((uint16_t)size, (char*)data); } else @@ -284,6 +279,7 @@ struct spwf_socket *socket = (struct spwf_socket *)handle; int32_t recv; + if(!socket->connected) return NSAPI_ERROR_NO_SOCKET; _spwf.setTimeout(SPWF_RECV_TIMEOUT); //CHECK:Receive for both Client and Server Sockets same?