iowfehu;gdbjwHJAOPIHO?L
Fork of X_NUCLEO_IDW01M1 by
Diff: SPWFInterface.cpp
- Revision:
- 3:fd9d20c4d3f0
- Parent:
- 2:bf3b3c6ce3a0
- Child:
- 4:d7d25616f1f7
diff -r bf3b3c6ce3a0 -r fd9d20c4d3f0 SPWFInterface.cpp --- a/SPWFInterface.cpp Tue Apr 19 06:28:52 2016 +0000 +++ b/SPWFInterface.cpp Tue Apr 19 07:19:10 2016 +0000 @@ -28,6 +28,7 @@ : _spwf(tx, rx, rst, wkup, rts) { memset(_ids, 0, sizeof(_ids)); + isInitialized = false; } SpwfSAInterface::~SpwfSAInterface() @@ -45,6 +46,14 @@ const char *pass_phrase, ns_security_t security) { + //initialize the device before connecting + if(!isInitialized) + { + if(init()==0) + isInitialized=true; + else return NS_ERROR_DEVICE_ERROR; + } + _spwf.setTimeout(SPWF_CONNECT_TIMEOUT); if(security == NS_SECURITY_WPA2) return NS_ERROR_DEVICE_ERROR; @@ -56,7 +65,7 @@ int32_t SpwfSAInterface::disconnect() { - //_spwf.setTimeout(SPWF_SEND_TIMEOUT); + if(!isConnected()) return NS_ERROR_NO_CONNECTION; return (_spwf.disconnect()); } @@ -97,7 +106,7 @@ { uint8_t sock_id = 99; - //__spwf->setTimeout(SPWF_SEND_TIMEOUT); + if(!_itf->isConnected()) return NS_ERROR_NO_CONNECTION; const char *proto = (_proto == NS_UDP) ? "u" : "t";//"s" for secure socket? @@ -123,7 +132,7 @@ { int32_t err; - //__spwf->setTimeout(SPWF_SEND_TIMEOUT); + if(!_itf->isConnected()) return NS_ERROR_NO_CONNECTION; _itf->setid(false, _id); //_itf->c_table.empty(); @@ -137,7 +146,7 @@ { int32_t err; - //__spwf->setTimeout(SPWF_SEND_TIMEOUT); + if(!_itf->isConnected()) return NS_ERROR_NO_CONNECTION; err = __spwf->socket_client_write((uint8_t)_id, (uint16_t)size, (char*)data); @@ -149,6 +158,8 @@ { int32_t recv; + if(!_itf->isConnected()) return NS_ERROR_NO_CONNECTION; + __spwf->setTimeout(SPWF_RECV_TIMEOUT); recv = __spwf->socket_client_recv((uint8_t)_id, (uint16_t)size, (char*)data);