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:
33:9b690d76eedf
Parent:
29:b6af04b77a56
--- a/Wiconnect.cpp	Mon Oct 27 14:16:03 2014 -0700
+++ b/Wiconnect.cpp	Mon Nov 03 23:48:38 2014 +0000
@@ -1,30 +1,30 @@
-/**
- * ACKme WiConnect Host Library is licensed under the BSD licence: 
- * 
- * Copyright (c)2014 ACKme Networks.
- * All rights reserved. 
- * 
- * Redistribution and use in source and binary forms, with or without modification, 
- * are permitted provided that the following conditions are met: 
- * 
- * 1. Redistributions of source code must retain the above copyright notice, 
- * this list of conditions and the following disclaimer. 
- * 2. Redistributions in binary form must reproduce the above copyright notice, 
- * this list of conditions and the following disclaimer in the documentation 
- * and/or other materials provided with the distribution. 
- * 3. The name of the author may not be used to endorse or promote products 
- * derived from this software without specific prior written permission. 
- * 
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS AND ANY EXPRESS OR IMPLIED 
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 
- * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 
- * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
- * OF SUCH DAMAGE.
+/**
+ * ACKme WiConnect Host Library is licensed under the BSD licence: 
+ * 
+ * Copyright (c)2014 ACKme Networks.
+ * All rights reserved. 
+ * 
+ * Redistribution and use in source and binary forms, with or without modification, 
+ * are permitted provided that the following conditions are met: 
+ * 
+ * 1. Redistributions of source code must retain the above copyright notice, 
+ * this list of conditions and the following disclaimer. 
+ * 2. Redistributions in binary form must reproduce the above copyright notice, 
+ * this list of conditions and the following disclaimer in the documentation 
+ * and/or other materials provided with the distribution. 
+ * 3. The name of the author may not be used to endorse or promote products 
+ * derived from this software without specific prior written permission. 
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS AND ANY EXPRESS OR IMPLIED 
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 
+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
+ * OF SUCH DAMAGE.
  */
 #include <stdio.h>
 #include <stdarg.h>
@@ -95,7 +95,7 @@
 
 /*************************************************************************************************/
 Wiconnect::Wiconnect(const SerialConfig &serialConfig, int internalBufferSize, void *internalBuffer, Pin reset, Pin wake, bool nonBlocking MALLOC_ARGS) :
-        NetworkInterface(this), SocketInterface(this), FileInterface(this), GhmInterface(this),
+        NetworkInterface(this), SocketInterface(this), FileInterface(this), GhmInterface(this),
         MALLOC_CONSTRUCTORS serial(serialConfig, this), resetGpio(reset), wakeGpio(wake)
 {
 #ifdef WICONNECT_ENABLE_MALLOC
@@ -106,7 +106,7 @@
 
 /*************************************************************************************************/
 Wiconnect::Wiconnect(const SerialConfig &serialConfig, Pin reset, Pin wake, bool nonBlocking MALLOC_ARGS) :
-    NetworkInterface(this), SocketInterface(this), FileInterface(this), GhmInterface(this),
+    NetworkInterface(this), SocketInterface(this), FileInterface(this), GhmInterface(this),
     MALLOC_CONSTRUCTORS serial(serialConfig, this), resetGpio(reset), wakeGpio(wake)
 {
 #ifdef WICONNECT_ENABLE_MALLOC
@@ -130,13 +130,13 @@
 WiconnectResult Wiconnect::init(bool bringNetworkUp)
 {
     WiconnectResult result;
-    int retries;
+    int retries;
     bool configuredBus = false;
     bool savedNonBlocking = nonBlocking;
-
-    DEBUG_INFO("Initializing wiconnect");
-
-    serial.initialize();
+
+    DEBUG_INFO("Initializing wiconnect");
+
+    serial.initialize();
 
     if(WICONNECT_FAILED(result, reset()))
     {
@@ -146,8 +146,8 @@
     delayMs(1000);
 
     initialized = true;
-    nonBlocking = false;
-
+    nonBlocking = false;
+
 
     loop:
     for(retries = 3; retries > 0; --retries)
@@ -161,20 +161,20 @@
         {
             break;
         }
-    }
-
-    if(result != WICONNECT_SUCCESS && !configuredBus)
-    {
-        configuredBus = true;
-        if(configureModuleDataBus())
-        {
-            goto loop;
-        }
     }
-
-    if(result == WICONNECT_SUCCESS)
-    {
-        sendCommand("set stream.auto_close 0");
+
+    if(result != WICONNECT_SUCCESS && !configuredBus)
+    {
+        configuredBus = true;
+        if(configureModuleDataBus())
+        {
+            goto loop;
+        }
+    }
+
+    if(result == WICONNECT_SUCCESS)
+    {
+        sendCommand("set stream.auto_close 0");
     }
     if(result == WICONNECT_SUCCESS && bringNetworkUp)
     {
@@ -199,7 +199,7 @@
 
 /*************************************************************************************************/
 Wiconnect* Wiconnect::getInstance()
-{
+{
     return instance;
 }
 
@@ -231,12 +231,12 @@
 /*************************************************************************************************/
 void Wiconnect::flush(int delayMs)
 {
-//    if(delayMs != 0)
-//    {
-//        serial.write("\r\n\r\n", 4, 0);
-//    }
-//    delayMs(delayMs);
-//    serial.flush();
+    if(delayMs != 0)
+    {
+        serial.write("\r\n\r\n", 4, 0);
+    }
+    delayMs(delayMs);
+    serial.flush();
 }
 
 /*************************************************************************************************/
@@ -247,58 +247,58 @@
 
 /*************************************************************************************************/
 WiconnectResult Wiconnect::getVersion(char *versionBuffer, int versionBufferSize, const Callback &completeCallback)
-{
-    WiconnectResult result;
+{
+    WiconnectResult result;
 
     if(versionBuffer != NULL && versionBufferSize == 0)
     {
         return WICONNECT_BAD_ARG;
-    }
-
-    _CHECK_OTHER_COMMAND_EXECUTING();
-
-    if(versionBuffer == NULL)
+    }
+
+    _CHECK_OTHER_COMMAND_EXECUTING();
+
+    if(versionBuffer == NULL)
     {
-        result = sendCommand(completeCallback, CMD_GET_VERSION);
-    }
-    else
-    {
-        result = sendCommand(completeCallback, versionBuffer, versionBufferSize, CMD_GET_VERSION);
-    }
-
-    _CHECK_CLEANUP_COMMAND();
-
+        result = sendCommand(completeCallback, CMD_GET_VERSION);
+    }
+    else
+    {
+        result = sendCommand(completeCallback, versionBuffer, versionBufferSize, CMD_GET_VERSION);
+    }
+
+    _CHECK_CLEANUP_COMMAND();
+
     return result;
 }
-
-/*************************************************************************************************/
-WiconnectResult Wiconnect::updateFirmware(bool forced, const char *versionStr, const Callback &completeCallback)
-{
-    WiconnectResult result;
-    char *cmdBuffer = internalBuffer;
-
-    if(_WICONNECT_IS_IDLE())
-    {
-        strcpy(cmdBuffer, "ota ");
-        if(versionStr != NULL)
-        {
-            strcat(cmdBuffer, "-b wiconnect-");
-            strcat(cmdBuffer, versionStr);
-        }
-        else if(forced)
-        {
-            strcat(cmdBuffer, "-f");
-        }
-    }
-
-    _CHECK_OTHER_COMMAND_EXECUTING();
-
-    result = sendCommand(completeCallback, WICONNECT_FIRMWARE_UPDATE_TIMEOUT, cmdBuffer);
-
-    _CHECK_CLEANUP_COMMAND();
-
-    return result;
-}
+
+/*************************************************************************************************/
+WiconnectResult Wiconnect::updateFirmware(bool forced, const char *versionStr, const Callback &completeCallback)
+{
+    WiconnectResult result;
+    char *cmdBuffer = internalBuffer;
+
+    if(_WICONNECT_IS_IDLE())
+    {
+        strcpy(cmdBuffer, "ota ");
+        if(versionStr != NULL)
+        {
+            strcat(cmdBuffer, "-b wiconnect-");
+            strcat(cmdBuffer, versionStr);
+        }
+        else if(forced)
+        {
+            strcat(cmdBuffer, "-f");
+        }
+    }
+
+    _CHECK_OTHER_COMMAND_EXECUTING();
+
+    result = sendCommand(completeCallback, WICONNECT_FIRMWARE_UPDATE_TIMEOUT, cmdBuffer);
+
+    _CHECK_CLEANUP_COMMAND();
+
+    return result;
+}
 
 /*************************************************************************************************/
 const char* Wiconnect::getWiconnectResultStr(WiconnectResult wiconnectResult)
@@ -346,9 +346,9 @@
 
 /*************************************************************************************************/
 void Wiconnect::setDebugLogger(LogFunc logFunc)
-{
+{
 #ifdef WICONNECT_ENABLE_DEBUGGING
-    debugLogger = logFunc;
+    debugLogger = logFunc;
 #endif
 }
 
@@ -357,7 +357,7 @@
 {
     assertLogger = assertLogFunc;
 }
-
+
 #ifdef WICONNECT_ENABLE_DEBUGGING
 /*************************************************************************************************/
 void Wiconnect::debugLog(const char *msg, ...)
@@ -395,4 +395,4 @@
     }
     debugLogger.call(buffer);
 }
-#endif
+#endif