Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: X_NUCLEO_IDW01M1v2-lapi-1
Fork of SPWF01SA by
Revision 15:e56c9e744ab6, committed 2016-09-05
- Comitter:
- mansiag
- Date:
- Mon Sep 05 07:09:49 2016 +0000
- Parent:
- 14:868b0fd4e84a
- Child:
- 16:aa67601954de
- Commit message:
- recv() modified to accept multiple wind:55 messages.
Changed in this revision
| ATParser.lib | Show annotated file Show diff for this revision Revisions of this file |
| SPWFSA01.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/ATParser.lib Fri Aug 19 08:50:10 2016 +0000 +++ b/ATParser.lib Mon Sep 05 07:09:49 2016 +0000 @@ -1,1 +1,1 @@ -https://developer.mbed.org/users/mridup/code/ATParser/#23f4573bcda2 +https://developer.mbed.org/users/mridup/code/ATParser/#537f1380c44a
--- a/SPWFSA01.cpp Fri Aug 19 08:50:10 2016 +0000
+++ b/SPWFSA01.cpp Mon Sep 05 07:09:49 2016 +0000
@@ -285,55 +285,44 @@
int32_t SPWFSA01::recv(int id, void *data, uint32_t amount)
{
- uint32_t recv_amount, read_amt;
+ uint32_t recv_amount;
int recv_id;
- char _buf[18];
-
+ bool wind_recv = true;
+
if (!(_parser.recv("+WIND:55:Pending Data:%d:%u", &recv_id, &recv_amount)
- && recv_id == id
- //&& _parser.send("AT+S.SOCKQ=%d", id)//send a query (will be required for secure sockets)
- //&& _parser.recv(" DATALEN: %u", &recv_amount)
- //&& _parser.recv("OK")
- && recv_amount <= amount)) {
- return -1;//Block call
+ && recv_id == id
+ && recv_amount <= amount
+ && recv_amount%730
+ && _parser.send("AT+S.SOCKQ=%d", id) //send a query (will be required for secure sockets)
+ && _parser.recv(" DATALEN: %u", &recv_amount)
+ && _parser.recv("OK")
+ && recv_amount > 0
+ && _parser.send("AT+S.SOCKR=%d,%d", id, recv_amount)
+ && (_parser.read((char*)data, recv_amount) >0)
+ && _parser.recv("OK"))) {
+ if(!(recv_amount%730))
+ {
+ // receive all the WIND messages
+ do {
+ if (!(_parser.recv("+WIND:55:Pending Data:%d:%u", &recv_id, &recv_amount)
+ && recv_id == id
+ && recv_amount <= amount
+ && recv_amount > 0))
+ wind_recv = false;
+ } while (!(recv_amount%730) && wind_recv);
+
+ // Read all the data pending on a socket
+ if(!( recv_amount > 0
+ && _parser.send("AT+S.SOCKR=%d,%d", id, recv_amount)
+ && (_parser.read((char*)data, recv_amount) >0)
+ && _parser.recv("OK"))) {
+ return -1;
+ }
}
- //&& sprintf((char*)_buf,"AT+S.SOCKR=%d,%d\r", id, recv_amount)
- //&& _parser.write((char*)_buf, strlen(_buf))
- if (!_parser.send("AT+S.SOCKR=%d,%d", id, recv_amount)) {
- //if error, resend SOCKR again to flush the socket
- //This should prevent Error: Pending Data errors or the next WIND showing this pending data
- sprintf((char*)_buf,"AT+S.SOCKR=%d,%d\r", id, recv_amount);
- _parser.write((char*)_buf, strlen(_buf));
- debug_if(dbg_on, "SPWF> read send SOCKR error\r\n");
- return -2;//return NSAPI_ERROR_DEVICE_ERROR
- }
-
- read_amt = _parser.read((char*)data, recv_amount);
- if (read_amt<=0) {
- debug_if(dbg_on, "SPWF> read recv SOCKR error: read_amt = %d\r\n", read_amt);
- return -2;//return NSAPI_ERROR_DEVICE_ERROR
- }
-
- //Sometimes OK is not received because _parser.read() reads in ERROR statement. "E.g. ERROR: Command not found".
- //ERROR statement hence takes up space in recv_amount and hence OK is not read as a result.
-
- if (!_parser.recv("OK")) {
- debug_if(dbg_on, "SPWF> read recv SOCKR OK error\r\n");
-
- if(std::strncmp("\r\nERROR: ", (const char* )data, 9)==0) {
- debug_if(dbg_on, "SPWF> Module Error Reply\r\n");
- return -2;
+ else {
+ return -2;
}
-
- /*int i = 0;
- char * buf = (char*)data;
-
- for ( ; i < recv_amount; i++) {
- debug_if(dbg_on, ("%d = %c\r\n", i, buf[i]);
- }*/
- return -2;//return NSAPI_ERROR_DEVICE_ERROR
- }
-
+ }
return recv_amount;
}
