Giung Kim / Mbed OS WIZnet-IoTShield-WM-N400MSE-TCP
Revision:
1:1c65b1dd9e7a
Parent:
0:8f61900631fe
Child:
2:2e1002e6798a
--- a/main.cpp	Wed Sep 11 07:35:05 2019 +0000
+++ b/main.cpp	Wed Sep 18 05:52:10 2019 +0000
@@ -38,7 +38,6 @@
 #define WM01_CONNECT_TIMEOUT        15000
 #define WM01_SEND_TIMEOUT           500
 #define WM01_RECV_TIMEOUT           500
-#define WM01_BOOTING_TIME           15000
 
 #define WM01_APN_PROTOCOL           WM01_APN_PROTOCOL_IPv6
 #define WM01_DEFAULT_BAUD_RATE      115200
@@ -71,7 +70,7 @@
 // IP address and Port number
 // char dest_ip[] = "222.xxx.xxx.xxx";
 // int  dest_port = xxxx;
-char dest_ip[] = "222.98.173.214";  // Test IP
+char dest_ip[] = "222.98.173.214";
 int  dest_port = 8080;
 int  protocol = 1;                  // 1 : TCP, 2 : UPD
 int  packet_type = 0;               // 0 : ASCII, 1 : HEX, 2 : Binary
@@ -160,8 +159,6 @@
     myprintf("Waiting for Cat.M1 Module Ready...\r\n");
     
     catm1DeviceReset_WM01();
-
-    wait_ms(WM01_BOOTING_TIME); // WM01 booting time
     
     waitCatM1Ready();
     
@@ -176,7 +173,9 @@
     getUsimStatus_WM01();
     
     getNetworkStatus_WM01();
-   
+
+    wait_ms(3000);
+
     setContextActivate_WM01();
 
     // TCP Client: Send and Receive
@@ -184,29 +183,28 @@
     
     if(sockOpenConnect_WM01(protocol, dest_ip, dest_port, packet_type) == RET_OK)
     {
-        myprintf("sockOpenConnect: success\r\n"); 
+        myprintf("Socket Open Connect : success\r\n");
 
         if(sendData_WM01(sendbuf, strlen(sendbuf)))
         {
-            myprintf("sendData [%d] %s\r\n", strlen(sendbuf), sendbuf);
+            myprintf("Data Send : success [%d] %s\r\n", strlen(sendbuf), sendbuf);
         }
         else
         {
-            ;   /* nothing to do */
-        }
-        
+            myprintf("Data Send : failed\r\n");
+        } 
     } 
     else 
     {
-        myprintf("sockOpen: failed\r\n");
+        myprintf("Socket Open Connect : failed\r\n");
         
         if(sockClose_WM01() == RET_OK) 
         {
-            myprintf("sockClose: success\r\n");
+            myprintf("Socket Close : success\r\n");
         }
         else
         {
-            myprintf("sockClose: failed\r\n");
+            myprintf("Socket Close : failed\r\n");
         }
     }    
     
@@ -215,11 +213,10 @@
         // Data received
         char recvbuf[100] = {0, };
         int recvlen = 0;
-        
-        // have to modify
+
         if(recvData_WM01(recvbuf, &recvlen) == RET_OK) 
         {
-            myprintf("dataRecv [%d] %s\r\n", recvlen, recvbuf);
+            myprintf("Data Receive [%d] %s\r\n", recvlen, recvbuf);
             
             char *ptr = strstr(recvbuf, "exit");
 
@@ -227,24 +224,16 @@
             {
                 break;
             }
-            else
-            {
-                ;   /* nothing to do */
-            }
-        }
-        else
-        {
-            ;   /* nothing to do */
         }
     }
     
     if(sockClose_WM01() == RET_OK) 
     {
-        myprintf("sockClose: success\r\n");
+        myprintf("Socket Close : success\r\n");
     }
     else
     {
-        myprintf("sockClose: failed\r\n");
+        myprintf("Socket Close : failed\r\n");
     }
 
     setContextDeactivate_WM01(); 
@@ -260,7 +249,7 @@
     myprintf("LTE Cat.M1 Version");
     myprintf("=================================================");
     myprintf(">> Target Board: WIoT-WM01 (Woorinet WM-N400MSE)");
-    myprintf(">> Sample Code: Ping Test");
+    myprintf(">> Sample Code: TCP Test");
     myprintf("=================================================\r\n");
 }
 
@@ -278,13 +267,7 @@
             
             return;
         }
-        else
-        {
-            myprintf("WM01 is not Available\r\n");
-
-            return;
-        }     
-    }    
+    }
 }
 
 int8_t setEchoStatus_WM01(bool onoff)
@@ -296,13 +279,13 @@
     
     if(_parser->send(_buf) && _parser->recv("OK")) 
     {        
-        devlog("Turn Echo %s success\r\n", onoff?"ON":"OFF");
+        devlog("Turn Echo %s : success\r\n", onoff?"ON":"OFF");
 
         ret = RET_OK;
     } 
     else 
     { 
-        devlog("Turn Echo %s failed\r\n", onoff?"ON":"OFF");
+        devlog("Turn Echo %s : failed\r\n", onoff?"ON":"OFF");
     }    
 
     return ret;
@@ -314,7 +297,7 @@
     
     if(_parser->send("AT$$STAT?") && _parser->recv("$$STAT:READY") && _parser->recv("OK")) 
     {
-        devlog("USIM Status: READY\r\n");
+        devlog("USIM Status : READY\r\n");
 
         ret = RET_OK;
     } 
@@ -335,18 +318,18 @@
     {
         if((val == 0) && (stat == 1))
         {
-            devlog("Network Status: attached\r\n");
+            devlog("Network Status : attached\r\n");
 
             ret = RET_OK;
         }
         else
         {
-            devlog("Network Status: %d, %d\r\n", val, stat);
+            devlog("Network Status : %d, %d\r\n", val, stat);
         }
     }
     else
     {
-        devlog("Network Status: Error\r\n");
+        devlog("Network Status : Error\r\n");
     }
 
     return ret;
@@ -392,6 +375,7 @@
     { 
         devlog("PDP Context Deactivation failed\r\n");        
     }
+
     return ret;
 }
 
@@ -434,20 +418,7 @@
                 {
                     ret = RET_OK;
                 }
-                else
-                {
-                    ;   /* nothing to do */
-                }
-
             }
-            else
-            {
-                ;   /* nothing to do */
-            }
-        }
-        else
-        {
-            ;   /* nothing to do */
         }
     }
 
@@ -470,13 +441,9 @@
         if(ok == 1)
         {
             ret = RET_OK;
-        }
-        else
-        {
-            ;   /* nothing to do */
-        }
-                
+        }        
     }
+
     _parser->set_timeout(WM01_DEFAULT_TIMEOUT);
     
     return ret;
@@ -496,18 +463,8 @@
     {
         if(ok == 1)    // success
         {
-            devlog("sendData: success\r\n");
-
             ret = RET_OK;
         }
-        else            // failure
-        {
-            devlog("sendData: failed\r\n");
-        }
-    }
-    else
-    {
-        ;   /* nothing to do */
     }
 
     _parser->set_timeout(WM01_DEFAULT_TIMEOUT);
@@ -515,16 +472,27 @@
     return ret;
 }
 
-// have to modify
 int8_t recvData_WM01(char *data, int *len)
 {
     int8_t ret = RET_NOK;
+    char _buf[100] = {0, };
     int id = 0;
-    int recvCount = 0;
+    int i = 0;
+
+    Timer t;
     
     _parser->set_timeout(WM01_RECV_TIMEOUT);
 
-    if(_parser->recv("+WSORD:%d,%d,%s", &id, len, data)) 
+    t.start();
+
+    while(t.read_ms() < WM01_RECV_TIMEOUT)
+    {
+        _buf[i] = _parser->getc();
+
+        i++;
+    }
+
+    if(sscanf(_buf,"+WSORD:%d,%d,%[^\n]", &id, len, data))
     {
         ret = RET_OK;
     }