cc

Dependencies:   ATParser

Revision:
11:643a8c0f07ea
Parent:
10:580379efe167
Child:
12:00bc9c029aec
--- a/SPWFSA01.cpp	Mon Jul 04 13:04:04 2016 +0000
+++ b/SPWFSA01.cpp	Thu Jul 07 06:40:55 2016 +0000
@@ -247,16 +247,23 @@
             //TODO:implement time-out functionality in case of no response
             //if(timeout) return false;
             //TODO: deal with errors like "ERROR: Failed to resolve name"
+            //TODO: deal with errors like "ERROR: Data mode not available"
         }
 
     return true;
 }
 
 bool SPWFSA01::send(int id, const void *data, uint32_t amount)
-{
+{    
+    char _buf[18];
+    
+    setTimeout(SPWFSA01_SEND_TIMEOUT);
+    
+    sprintf((char*)_buf,"AT+S.SOCKW=%d,%d\r", id, amount);   
+    
     //May take a second try if device is busy
     for (unsigned i = 0; i < 2; i++) {
-        if (_parser.send("AT+S.SOCKW=%d,%d", id, amount)
+        if (_parser.write((char*)_buf, strlen(_buf)) >=0
             && _parser.write((char*)data, (int)amount) >= 0
             && _parser.recv("OK")) {
             return true;
@@ -270,6 +277,7 @@
 {
     uint32_t recv_amount;
     int recv_id;
+    //char _buf[18];
 
     if (!(_parser.recv("+WIND:55:Pending Data:%d:%u", &recv_id, &recv_amount)
         && recv_id == id        
@@ -277,12 +285,21 @@
         //&& _parser.recv(" DATALEN: %u", &recv_amount)
         //&& _parser.recv("OK")
         && recv_amount <= amount
+        //&& sprintf((char*)_buf,"AT+S.SOCKR=%d,%d\r", id, recv_amount)
+        //&& _parser.write((char*)_buf, strlen(_buf))
         && _parser.send("AT+S.SOCKR=%d,%d", id, recv_amount)
-        && _parser.read((char*)data, recv_amount)
+        && _parser.read((char*)data, recv_amount) 
         && _parser.recv("OK"))) {
         return -1;
     }
-
+    
+    /*int i = 0;
+    char * buf = (char*)data;
+    
+    for ( ; i < recv_amount; i++) {
+        printf("%d = %d\r\n", i, buf[i]);
+        }*/
+    
     return recv_amount;
 }