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: internal/network/NetworkWebSetup.cpp
- Revision:
- 0:ea85c4bb5e1f
- Child:
- 1:6ec9998427ad
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/internal/network/NetworkWebSetup.cpp Mon Aug 11 09:58:24 2014 +0000 @@ -0,0 +1,163 @@ +/* + * Copyright 2014, ACKme Networks + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of ACKme Networks; + * the contents of this file may not be disclosed to third parties, copied + * or duplicated in any form, in whole or in part, without the prior + * written permission of ACKme Networks. + */ + +#include "Wiconnect.h" +#include "internal/common.h" + + + +/*************************************************************************************************/ +WiconnectResult NetworkInterface::startWebSetup(const char *ssid, const char *password, const Callback &completeHandler_) +{ + WiconnectResult result; + + enum + { + FS_SET_SSID, + FS_SET_PASSWORD, + FS_NETWORK_UP + }; + + CHECK_CALLBACK_AVAILABLE(completeHandler_); + CHECK_OTHER_COMMAND_EXECUTING(); + + if(wiconnect->internalProcessingState == FS_SET_SSID) + { + if(ssid == NULL || + WICONNECT_SUCCEEDED(result, wiconnect->sendCommand("set setup.web.ssid %s", ssid))) + { + wiconnect->internalProcessingState = FS_SET_PASSWORD; + } + } + + if(wiconnect->internalProcessingState == FS_SET_PASSWORD) + { + if(password == NULL || + WICONNECT_SUCCEEDED(result, wiconnect->sendCommand("set setup.web.passkey %s", password))) + { + wiconnect->internalProcessingState = FS_NETWORK_UP; + } + } + + if(wiconnect->internalProcessingState == FS_NETWORK_UP) + { + if(WICONNECT_SUCCEEDED(result, wiconnect->sendCommand("setup web"))) + { +#ifdef WICONNECT_ASYNC_TIMER_ENABLED + if(completeHandler_.isValid()) + { + if(monitorTimer.isRunning()) + { + result = WICONNECT_MONITOR_NOT_AVAILABLE; + } + else + { + completeHandler = completeHandler_; + monitorTimer.start(this, &NetworkInterface::webSetupStatusMonitor, 1000); + } + } +#endif + } + } + + CHECK_CLEANUP_COMMAND(); + + return result; +} + +/*************************************************************************************************/ +WiconnectResult NetworkInterface::stopWebSetup() +{ + WiconnectResult result; + + CHECK_OTHER_COMMAND_EXECUTING(); + + #ifdef WICONNECT_ASYNC_TIMER_ENABLED + monitorTimer.stop(); + #endif + result = wiconnect->sendCommand("setup stop"); + + CHECK_CLEANUP_COMMAND(); + + return result; +} + + +/*************************************************************************************************/ +WiconnectResult NetworkInterface::isWebSetupRunning(bool *isRunningPtr) +{ + WiconnectResult result; + + CHECK_OTHER_COMMAND_EXECUTING(); + + if(WICONNECT_SUCCEEDED(result, wiconnect->sendCommand("setup status"))) + { + int32_t status; + if(!WICONNECT_FAILED(result, wiconnect->responseToInt32(&status))) + { + *isRunningPtr = (bool)status; + } + } + + CHECK_CLEANUP_COMMAND(); + + return result; +} + + +#ifdef WICONNECT_ASYNC_TIMER_ENABLED + +/*************************************************************************************************/ +void NetworkInterface::webSetupStatusMonitor() +{ + monitorTimer.stop(); + QueuedCommand *cmd = new QueuedCommand(32, NULL, "setup status"); + if(cmd == NULL) + return; + if(wiconnect->enqueueCommand(cmd, Callback(this, &NetworkInterface::webSetupStatusCheckCallback)) != WICONNECT_SUCCESS) + { + delete cmd; + } +} + +/*************************************************************************************************/ +void NetworkInterface::webSetupStatusCheckCallback(WiconnectResult result, void *arg1, void *arg2) +{ + bool isComplete = true; + + QueuedCommand *cmd = (QueuedCommand*)arg1; + + if(result == WICONNECT_SUCCESS) + { + int32_t status; + if(!StringUtil::strToInt32(cmd->responseBuffer, &status)) + { + result = WICONNECT_RESPONSE_PARSE_ERROR; + } + else if(status > 0) + { + isComplete = false; + } + } + + delete cmd; + + if(isComplete) + { + completeHandler.call(result, NULL, NULL); + } + else + { + monitorTimer.start(this, &NetworkInterface::webSetupStatusMonitor, 1000); + } +} + +#endif +