RC

Dependents:   WizFi250_AP_HelloWorld

Fork of WizFi250Interface by DongEun Koak

Revision:
7:ba28fe711055
Parent:
5:8a0702aa91e3
Child:
9:12ecb377f63f
diff -r e149bf87a1bd -r ba28fe711055 WizFi250/WizFi250_at.cpp
--- a/WizFi250/WizFi250_at.cpp	Fri Nov 14 15:22:27 2014 +0900
+++ b/WizFi250/WizFi250_at.cpp	Fri Nov 14 15:27:47 2014 +0900
@@ -33,88 +33,10 @@
     _state.n = 0;
 }
 
-int WizFi250::sendCommand(const char * cmd, const char *ACK, char *res , int timeout, int opt)
-{
-    char read;
-    int i;
-    Timer t;
-    string checking;
-    size_t found = string::npos;
-
-
-    //attach_rx(false);
-    if (lockUart(timeout))  return -1;
-
-    // flush the buffer
-    while(_wizfi.readable())
-    {
-        printf("%c",_wizfi.getc());
-    }
-
-    clearFlags();
-
-    INFO("command: '%s'", cmd)
-    for (i=0; i< strlen(cmd); i++)
-    {
-        putUart(cmd[i]);
-    }
-
-    if(opt == 0)
-    {
-
-    }
-    else if(opt == 1)
-    {
-        putUart('\r');
-    }
-    else
-    {
-        putUart('\r');
-        putUart('\n');
-    }
-    unlockUart();
-
-    while(1)
-    {
-        if(t.read_ms() > timeout)
-        {
-            while(_wizfi.readable())
-                _wizfi.getc();
-
-            DBG("check: %s\r\n", checking.c_str());
-            return -1;
-        }
-        else if(_wizfi.readable())
-        {
-            read = _wizfi.getc();
-            if(read != '\r' && read != '\n')
-            {
-                checking += read;
-                found = checking.find(ACK);
-                if (found != string::npos)
-                {
-                    wait(0.01);
-
-                    while(_wizfi.readable())
-                        _wizfi.getc();
-
-                    break;
-                }
-            }
-        }
-    }
-    DBG("check:%s\r\n", checking.c_str());
-
-//    attach_rx(true);
-
-    return 0;
-}
-
-
 
 int WizFi250::sendCommand(const char * cmd, Response res, int timeout, int opt)
 {
-    int i, cnt=0;
+    unsigned int i;
     Timer t;
 
   if (lockUart(timeout)) return -1;
@@ -128,15 +50,11 @@
         putUart(cmd[i]);
     }
 
-    if(opt == 0)
-    {
-
-    }
-    else if(opt == 1)
+    if(opt == 1)
     {
         putUart('\r');
     }
-    else
+    else if(opt == 2)
     {
         putUart('\r');
         putUart('\n');
@@ -155,6 +73,7 @@
             {
             	WIZ_WARN("failure of timeout[%d]ms\r\n",t.read_ms());
                 _state.res = RES_NULL;
+                t.stop();
                 return -1;
             }
         }
@@ -175,9 +94,6 @@
     resp = sendCommand("AT");
 
     return resp;
-
-    //return sendCommand("AT");
-    //sendCommand("AT","[OK]");
 }
 
 int WizFi250::cmdMECHO(bool flg)
@@ -223,10 +139,6 @@
     {
         sprintf(cmd, "AT+MMAC=?");
         resp = sendCommand(cmd, RES_MACADDRESS);
-        if (!resp && strncmp(_state.mac, xmac, 17) == 0)
-        {
-            resp = -1;
-        }
     }
 
     return resp;
@@ -266,7 +178,6 @@
 
 int WizFi250::cmdWJOIN()
 {
-    sendCommand("AT+WJOIN", RES_WJOIN, CFG_TIMEOUT);
 
 	if( sendCommand("AT+WJOIN", RES_WJOIN, CFG_JOIN_TIMEOUT) ) return -1;
 
@@ -277,7 +188,6 @@
     return 0;
 }
 
-
 int WizFi250::cmdSCON ( const char *openType, const char *socketType, int localPort, const char *dataMode)
 {
     char cmd[CFG_CMD_SIZE];
@@ -327,7 +237,7 @@
     unlockUart();
     if(resp){
     	WIZ_DBG("Fail cmdSSEND")
-        return -1;
+       return -1;
     }
 
     for(i=0; i<sendSize; i++)
@@ -372,7 +282,7 @@
     int resp;
 
     sprintf(cmd,"AT+FDNS=%s,1000",host);
-    resp = sendCommand(cmd, RES_FDNS, CFG_TIMEOUT);
+    resp = sendCommand(cmd, RES_FDNS);
 
     WIZ_DBG("%s",_state.resolv);
     return resp;