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
Diff: Wiconnect.cpp
- Revision:
- 35:15725177aa60
- Parent:
- 29:b6af04b77a56
- Child:
- 36:a30cbf4bdb13
diff -r 2616445d0823 -r 15725177aa60 Wiconnect.cpp --- a/Wiconnect.cpp Wed Nov 26 23:46:00 2014 -0800 +++ b/Wiconnect.cpp Thu Nov 27 00:25:09 2014 -0800 @@ -80,7 +80,8 @@ internalBufferSize = internalBufferSize_;; nonBlocking = nonBlocking_; commandExecuting = false; - initialized = false; + initialized = false; + needUpdate = false; pinToGpioMapper = NULL; defaultTimeoutMs = WICONNECT_DEFAULT_TIMEOUT; @@ -174,6 +175,18 @@ if(result == WICONNECT_SUCCESS) { + if(WICONNECT_SUCCEEDED(result, getVersion())) + { + const uint32_t version = Wiconnect::wiconnectVersionToInt(this->internalBuffer); + if(version < WICONNECT_MINIMUM_VERSION) + { + needUpdate = true; + result = WICONNECT_FIRMWARE_OUTDATED; + } + } + } + if(result == WICONNECT_SUCCESS) + { sendCommand("set stream.auto_close 0"); } if(result == WICONNECT_SUCCESS && bringNetworkUp) @@ -207,6 +220,12 @@ bool Wiconnect::isInitialized() { return initialized; +} + +/*************************************************************************************************/ +bool Wiconnect::updateRequired() +{ + return needUpdate; } /*************************************************************************************************/ @@ -231,12 +250,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(); } /*************************************************************************************************/ @@ -329,7 +348,8 @@ "Not connected", // WICONNECT_NOT_CONNECTED "Underflow", // WICONNECT_UNDERFLOW "A monitor is not available", // WICONNECT_MONITOR_NOT_AVAILABLE - "Not opened for reading", // WICONNECT_NOT_OPENED_FOR_READING + "Not opened for reading", // WICONNECT_NOT_OPENED_FOR_READING + "WiFi firmware update required", // WICONNECT_FIRMWARE_OUTDATED }; if((int)wiconnectResult >= (int)WICONNECT_SUCCESS) @@ -342,7 +362,31 @@ return wiconnectErrorStrTable[wiconnectResult]; } } - + +/*************************************************************************************************/ +uint32_t Wiconnect::wiconnectVersionToInt(char *versionStr) +{ + char *idx = strchr(versionStr, ','); + if(idx == NULL) + { + return -1; + } + *idx = 0; + idx = versionStr; + while((idx = strchr(versionStr, '-')) != NULL) + { + versionStr = idx + 1; + } + + uint32_t ver; + + if(Wiconnect::fileVersionStrToInt(versionStr, &ver)) + { + return ver; + } + + return -1; +} /*************************************************************************************************/ void Wiconnect::setDebugLogger(LogFunc logFunc)