cc
Diff: SPWFSA01.cpp
- Revision:
- 20:01031cd39e73
- Parent:
- 19:df8d7f70a740
- Child:
- 21:cd722edbb644
diff -r df8d7f70a740 -r 01031cd39e73 SPWFSA01.cpp --- a/SPWFSA01.cpp Wed Sep 21 10:22:40 2016 +0000 +++ b/SPWFSA01.cpp Wed Sep 21 12:50:50 2016 +0000 @@ -17,10 +17,11 @@ #include "SPWFSA01.h" #include "mbed_debug.h" -#define SPWFSA01_CONNECT_TIMEOUT 15000 -#define SPWFSA01_SEND_TIMEOUT 500 -#define SPWFSA01_RECV_TIMEOUT 1500//some commands like AT&F/W takes some time to get the result back! -#define SPWFSA01_MISC_TIMEOUT 500 +#define SPWFSA01_CONNECT_TIMEOUT 15000 +#define SPWFSA01_SEND_TIMEOUT 500 +#define SPWFSA01_RECV_TIMEOUT 1500//some commands like AT&F/W takes some time to get the result back! +#define SPWFSA01_MISC_TIMEOUT 500 +#define SPWFSA01_SOCKQ_TIMEOUT 3000 SPWFSA01::SPWFSA01(PinName tx, PinName rx, bool debug) : _serial(tx, rx, 1024), _parser(_serial), @@ -330,7 +331,16 @@ int32_t SPWFSA01::recv(int id, void *data, uint32_t amount) { + Timer timer; + timer.start(); + uint32_t recv_amount=0; + int recv_id; + + if(!(_parser.recv("+WIND:55:Pending Data:%d:", &recv_id))) { + //do nothing; + debug_if(dbg_on, "SPWF> WIND:55 Timeout\r\n"); + } while(!recv_amount) { if(!(_parser.send("AT+S.SOCKQ=%d", id) //send a query (will be required for secure sockets) @@ -338,6 +348,9 @@ && _parser.recv("OK"))) { return -2; } + if (timer.read_ms() > SPWFSA01_SOCKQ_TIMEOUT) { + return -2; + } } if(recv_amount > amount) recv_amount = amount;