Host library for controlling a WiConnect enabled Wi-Fi module.

Dependents:   wiconnect-ota_example wiconnect-web_setup_example wiconnect-test-console wiconnect-tcp_server_example ... more

Revision:
5:8d91a87ebba2
Parent:
1:6ec9998427ad
Child:
16:7f1d6d359787
--- a/internal/wiconnect/ProcessCommand.cpp	Mon Aug 11 03:49:05 2014 -0700
+++ b/internal/wiconnect/ProcessCommand.cpp	Mon Aug 11 04:00:39 2014 -0700
@@ -103,61 +103,57 @@
 /*************************************************************************************************/
 WiconnectResult Wiconnect::receiveResponse()
 {
-    for(;;)
+loop:
+    WiconnectResult result = receivePacket();
+
+    if(result == WICONNECT_PROCESSING)
     {
-        WiconnectResult result = receivePacket();
+    }
+    else if(result == WICONNECT_SUCCESS)
+    {
+        CommandHeader *header = (CommandHeader*)commandHeaderBuffer;
+        CommandContext *context = (CommandContext*)commandContext;
 
-        if(result == WICONNECT_PROCESSING)
+        // TODO: need to notify safemode
+
+        if(header->response_type == WICONNECT_CMD_TYPE_REPLY || header->response_type == WICONNECT_CMD_TYPE_SAFEMODE)
         {
-            return WICONNECT_PROCESSING;
-        }
-        else if(result == WICONNECT_SUCCESS)
-        {
-            CommandHeader *header = (CommandHeader*)commandHeaderBuffer;
-            CommandContext *context = (CommandContext*)commandContext;
-
-            // TODO: need to notify safemode
-
-            if(header->response_type == WICONNECT_CMD_TYPE_REPLY || header->response_type == WICONNECT_CMD_TYPE_SAFEMODE)
+            if(header->response_code != WICONNECT_CMD_SUCCESS)
             {
-                if(header->response_code != WICONNECT_CMD_SUCCESS)
-                {
-                    DEBUG_CMD_ERROR(header->response_code);
-                    flush();
-                    issueCommandCallback(WICONNECT_CMD_RESPONSE_ERROR);
-                    return WICONNECT_CMD_RESPONSE_ERROR;
-                }
-                else if(header->response_len > 0)
-                {
-                    DEBUG_CMD_RESPONSE(context->responseBuffer);
-                    header->response_len -= 2;
-                    context->responseBuffer[header->response_len] = 0;
-                }
-                else
-                {
-                    *context->responseBuffer = 0;
-                }
-
-                issueCommandCallback(WICONNECT_SUCCESS);
-
-                return WICONNECT_SUCCESS;
+                DEBUG_CMD_ERROR(header->response_code);
+                flush();
+                issueCommandCallback(WICONNECT_CMD_RESPONSE_ERROR);
+                return WICONNECT_CMD_RESPONSE_ERROR;
+            }
+            else if(header->response_len > 0)
+            {
+                DEBUG_CMD_RESPONSE(context->responseBuffer);
+                header->response_len -= 2;
+                context->responseBuffer[header->response_len] = 0;
             }
             else
             {
-                DEBUG_CMD_LOG(context->responseBuffer);
-                RESET_CMD_HEADER(header);
-                context->responseBufferPtr = context->responseBuffer;
+                *context->responseBuffer = 0;
             }
+
+            issueCommandCallback(WICONNECT_SUCCESS);
+
+            return WICONNECT_SUCCESS;
         }
         else
         {
-            issueCommandCallback(result);
-            return result;
+            DEBUG_CMD_LOG(context->responseBuffer);
+            RESET_CMD_HEADER(header);
+            context->responseBufferPtr = context->responseBuffer;
+            goto loop;
         }
     }
+    else
+    {
+        issueCommandCallback(result);
+    }
 
-    // shouldn't get here...
-    return WICONNECT_ERROR;
+    return result;
 }
 
 /*************************************************************************************************/