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/NetworkJoin.cpp
- Revision:
- 17:7268f365676b
- Parent:
- 16:7f1d6d359787
- Child:
- 23:8cfc6fdce6b0
- Child:
- 26:8067e3d463d3
--- a/internal/network/NetworkJoin.cpp Wed Aug 13 04:41:04 2014 -0700 +++ b/internal/network/NetworkJoin.cpp Sat Aug 23 05:39:17 2014 -0700 @@ -38,10 +38,12 @@ { FS_SET_SSID, FS_SET_PASSWORD, - FS_NETWORK_UP + FS_NETWORK_UP, + FS_GET_STATUS }; - CHECK_CALLBACK_AVAILABLE(completeHandler_); + CHECK_CALLBACK_AVAILABLE(completeHandler_); + CHECK_OTHER_COMMAND_EXECUTING(); if(wiconnect->internalProcessingState == FS_SET_SSID) @@ -65,18 +67,50 @@ if(wiconnect->internalProcessingState == FS_NETWORK_UP) { if(WICONNECT_SUCCEEDED(result, wiconnect->sendCommand("network_up"))) - { -#ifdef WICONNECT_ASYNC_TIMER_ENABLED - if(completeHandler_.isValid()) + { + if(!completeHandler_.isValid()) + { + wiconnect->internalProcessingState = FS_GET_STATUS; + } +#ifdef WICONNECT_ASYNC_TIMER_ENABLED + else { -#ifdef WICONNECT_ASYNC_TIMER_ENABLED monitorTimer.stop(); -#endif completeHandler = completeHandler_; monitorTimer.start(this, &NetworkInterface::joinStatusMonitor, 1000); } #endif } + } + + if(wiconnect->internalProcessingState == FS_GET_STATUS) + { +#define MAX_JOIN_TIME 15000 + TimeoutTimer timeout; + + status_loop: + if(WICONNECT_SUCCEEDED(result, wiconnect->sendCommand("get network.status"))) + { + int32_t status; + if(!WICONNECT_FAILED(result, wiconnect->responseToInt32(&status))) + { + if(status == NETWORK_STATUS_DOWN) + { + if(timeout.timedOut(MAX_JOIN_TIME)) + { + result = WICONNECT_TIMEOUT; + } + else if(!wiconnect->nonBlocking) + { + goto status_loop; + } + else + { + result = WICONNECT_PROCESSING; + } + } + } + } } CHECK_CLEANUP_COMMAND();