This is boring
Diff: SPWFSA01.cpp
- Revision:
- 21:cd722edbb644
- Parent:
- 20:01031cd39e73
- Child:
- 22:2eb9b3c54506
--- a/SPWFSA01.cpp Wed Sep 21 12:50:50 2016 +0000 +++ b/SPWFSA01.cpp Tue Sep 27 04:05:46 2016 +0000 @@ -356,12 +356,51 @@ recv_amount = amount; _parser.flush(); - if(!(_parser.send("AT+S.SOCKR=%d,%d", id, recv_amount) - && (_parser.read((char*)data, recv_amount) >0) - && _parser.recv("OK"))) { - return -2; + if(!(_parser.send("AT+S.SOCKR=%d,%d", id, recv_amount))) + return -2; + + /* only when the data recv is greater than 3 bytes */ + if(recv_amount > 3) { + /* look for WIND messages in data */ + + // get first 3 bytes of data + for(int i=0;i<3;i++) { + int c = -1; + while(c < 0) { + c = _parser.getc(); + } + ((char *)data)[i] = c; + } + + /* 0xD: \r && 0xA: \n */ + if(((char *)data)[0] == 0xD + &&((char *)data)[1] == 0xA + &&((char *)data)[2] == '+') { + ((char *)data)[0] = 0; + while(((char *)data)[0] != 0xA) { + ((char *)data)[0] = _parser.getc(); + } + + // complete data is yet to be read + if(!((_parser.read((char*)data, recv_amount) >0) + && _parser.recv("OK"))) { + return -2; + } + } + else { + // data left to be read is 3 bytes less. + if(!((_parser.read((char*)data+3, recv_amount-3) >0) + && _parser.recv("OK"))) { + return -2; } - + } + } + else { + if(!((_parser.read((char*)data, recv_amount) >0) + && _parser.recv("OK"))) { + return -2; + } + } return recv_amount; }