cc
Diff: SpwfInterface.cpp
- Revision:
- 13:0368732b5b9d
- Parent:
- 9:4cd89586b370
- Child:
- 14:4ec13009341c
--- a/SpwfInterface.cpp Thu Nov 03 06:57:03 2016 +0000 +++ b/SpwfInterface.cpp Tue Nov 22 14:38:43 2016 +0000 @@ -62,13 +62,21 @@ * debug : not used * @retval none */ -SpwfSAInterface::SpwfSAInterface(PinName tx, PinName rx, bool debug) - : _spwf(tx, rx, debug) +SpwfSAInterface::SpwfSAInterface(PinName tx, PinName rx, bool debug) + : _spwf(tx, rx, PC_12, PC_8, debug) +{ + memset(_ids, 0, sizeof(_ids)); + isInitialized = false; + isListening = false; +} + +SpwfSAInterface::SpwfSAInterface(PinName tx, PinName rx, PinName reset, PinName wakeup, bool debug) + : _spwf(tx, rx, reset, wakeup, debug) { memset(_ids, 0, sizeof(_ids)); isInitialized = false; isListening = false; -} +} /** * @brief SpwfSAInterface destructor @@ -87,7 +95,6 @@ */ int SpwfSAInterface::init(void) { - _spwf.setTimeout(SPWF_MISC_TIMEOUT); if(_spwf.startup(0)) { isInitialized=true; return true; @@ -115,9 +122,7 @@ if(!init()) return NSAPI_ERROR_DEVICE_ERROR; } - - _spwf.setTimeout(SPWF_CONNECT_TIMEOUT); - + switch(security) { case NSAPI_SECURITY_NONE: @@ -181,7 +186,7 @@ { int id = -1; - struct spwf_socket *socket = new struct spwf_socket; + struct spwf_socket *socket = new struct spwf_socket; if (!socket) { return NSAPI_ERROR_NO_SOCKET; } @@ -271,7 +276,6 @@ { struct spwf_socket *socket = (struct spwf_socket *)handle; int err = 0; - _spwf.setTimeout(SPWF_MISC_TIMEOUT); if(socket->id!=-1) { @@ -330,19 +334,16 @@ struct spwf_socket *socket = (struct spwf_socket *)handle; int32_t recv; - _spwf.setTimeout(SPWF_RECV_TIMEOUT); - //CHECK:Receive for both Client and Server Sockets same? recv = _spwf.recv(socket->id, (char*)data, (uint32_t)size); if (recv < 0) { //wait_ms(1);//delay of 1ms <for F4>?? //printf("."); if (recv == -1) return NSAPI_ERROR_WOULD_BLOCK;//send this if we want to block call (else timeout will happen) - else return NSAPI_ERROR_DEVICE_ERROR; + else if (recv == -2)return NSAPI_ERROR_DEVICE_ERROR; + else if (recv == -3)return NSAPI_ERROR_NO_CONNECTION; } - - return recv; - + return recv; } /** @@ -356,7 +357,7 @@ int SpwfSAInterface::socket_sendto(void *handle, const SocketAddress &addr, const void *data, unsigned size) { struct spwf_socket *socket = (struct spwf_socket *)handle; - if (!socket->connected) { + if (!socket->connected) { int err = socket_connect(socket, addr); if (err < 0) { return err; @@ -402,3 +403,45 @@ { //_spwf.debug_print(string); } + +/** +* @brief Set the socket options +* Not used +* @param handle: Pointer to handle +* level: SOL_SOCKET +* optname: option name +* optval: pointer to option value +* optlen: option length +@retval NSAPI Error Type +*/ +int SpwfSAInterface::setsockopt(void *handle, int level, int optname, const void *optval, unsigned optlen) +{ +// struct spwf_socket *socket = (struct spwf_socket *)handle; + + switch (optname) { + case NSAPI_REUSEADDR: /*!< Allow bind to reuse local addresses */ + case NSAPI_KEEPALIVE: /*!< Enables sending of keepalive messages */ + case NSAPI_LINGER: /*!< Keeps close from returning until queues empty */ + case NSAPI_SNDBUF: /*!< Sets send buffer size */ + case NSAPI_RCVBUF: /*!< Sets recv buffer size */ + default: + printf("SpwfSAInterface::setsockopt> ERROR!!!! Unknown optname: %d \r\n", optname); + return -1; + } + return NSAPI_ERROR_UNSUPPORTED; +} + +/** +* @brief Get the socket options +* Not used +* @param handle: Pointer to handle +* level: SOL_SOCKET +* optname: option name +* optval: pointer to option value +* optlen: pointer to option length +@retval NSAPI Error Type +*/ +int SpwfSAInterface::getsockopt(void *handle, int level, int optname, void *optval, unsigned *optlen) +{ + return NSAPI_ERROR_UNSUPPORTED; +}