Changes required by X-NUCLEO-IDWM01M1 and mbed-os 5.2.2

Dependencies:   ATParser

Dependents:   X_NUCLEO_IDW01M1v2-lapi-1

Fork of SPWF01SA by ST

Files at this revision

API Documentation at this revision

Comitter:
mridup
Date:
Thu Jun 30 08:25:26 2016 +0000
Parent:
2:40d183d7dc19
Child:
4:042d5b9bb6e7
Commit message:
client socket open

Changed in this revision

SPWFSA01.cpp Show annotated file Show diff for this revision Revisions of this file
SPWFSA01.h Show annotated file Show diff for this revision Revisions of this file
--- a/SPWFSA01.cpp	Thu Jun 30 06:59:25 2016 +0000
+++ b/SPWFSA01.cpp	Thu Jun 30 08:25:26 2016 +0000
@@ -232,15 +232,25 @@
     return getIPAddress() != 0;
 }
 
-bool SPWFSA01::open(const char *type, int id, const char* addr, int port)
+bool SPWFSA01::open(const char *type, int* id, const char* addr, int port)
 {
-    //IDs only 0-7
-    if(id > 7) {
-        return false;
-    }
+    
+    if(!_parser.send("AT+S.SOCKON=%s,%d,%s,ind", addr, port, type))
+        {
+            printf("\r\nerror opening socket\n");
+            return false;
+        }
+        
+    while(1)
+        {
+            if( _parser.recv(" ID: %d", id)
+                && _parser.recv("OK"))
+                break;
+            //TODO:implement time-out functionality in case of no response
+        }
+    printf("\r\nsock id = %d\r\n", *id);
 
-    return _parser.send("AT+CIPSTART=%d,\"%s\",\"%s\",%d", id, type, addr, port)
-        && _parser.recv("OK");
+    return true;
 }
 
 bool SPWFSA01::send(int id, const void *data, uint32_t amount)
--- a/SPWFSA01.h	Thu Jun 30 06:59:25 2016 +0000
+++ b/SPWFSA01.h	Thu Jun 30 08:25:26 2016 +0000
@@ -101,7 +101,7 @@
     * @param addr the IP address of the destination
     * @return true only if socket opened successfully
     */
-    bool open(const char *type, int id, const char* addr, int port);
+    bool open(const char *type, int* id, const char* addr, int port);
  
     /**
     * Sends data to an open socket