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

Committer:
dan_ackme
Date:
Mon Aug 11 03:29:30 2014 -0700
Revision:
1:6ec9998427ad
Parent:
0:ea85c4bb5e1f
Child:
5:8d91a87ebba2
fixed compiler warnings

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dan_ackme 0:ea85c4bb5e1f 1 /*
dan_ackme 0:ea85c4bb5e1f 2 * Copyright 2014, ACKme Networks
dan_ackme 0:ea85c4bb5e1f 3 * All Rights Reserved.
dan_ackme 0:ea85c4bb5e1f 4 *
dan_ackme 0:ea85c4bb5e1f 5 * This is UNPUBLISHED PROPRIETARY SOURCE CODE of ACKme Networks;
dan_ackme 0:ea85c4bb5e1f 6 * the contents of this file may not be disclosed to third parties, copied
dan_ackme 0:ea85c4bb5e1f 7 * or duplicated in any form, in whole or in part, without the prior
dan_ackme 0:ea85c4bb5e1f 8 * written permission of ACKme Networks.
dan_ackme 0:ea85c4bb5e1f 9 */
dan_ackme 0:ea85c4bb5e1f 10
dan_ackme 0:ea85c4bb5e1f 11
dan_ackme 0:ea85c4bb5e1f 12 #include "CommandCommon.h"
dan_ackme 0:ea85c4bb5e1f 13
dan_ackme 0:ea85c4bb5e1f 14 #ifdef WICONNECT_ASYNC_TIMER_ENABLED
dan_ackme 0:ea85c4bb5e1f 15
dan_ackme 0:ea85c4bb5e1f 16
dan_ackme 0:ea85c4bb5e1f 17
dan_ackme 0:ea85c4bb5e1f 18 /*************************************************************************************************/
dan_ackme 0:ea85c4bb5e1f 19 WiconnectResult Wiconnect::enqueueCommand(QueuedCommand *command, const Callback &commandCompleteHandler)
dan_ackme 0:ea85c4bb5e1f 20 {
dan_ackme 0:ea85c4bb5e1f 21 if(commandQueue.isFull())
dan_ackme 0:ea85c4bb5e1f 22 {
dan_ackme 0:ea85c4bb5e1f 23 return WICONNECT_OVERFLOW;
dan_ackme 0:ea85c4bb5e1f 24 }
dan_ackme 0:ea85c4bb5e1f 25 command->setCompletedCallback(commandCompleteHandler);
dan_ackme 0:ea85c4bb5e1f 26 DEBUG_INFO("Queuing command: %s", command->getCommand());
dan_ackme 0:ea85c4bb5e1f 27 commandQueue.push(command);
dan_ackme 0:ea85c4bb5e1f 28 processNextQueuedCommand();
dan_ackme 0:ea85c4bb5e1f 29 return WICONNECT_SUCCESS;
dan_ackme 0:ea85c4bb5e1f 30 }
dan_ackme 0:ea85c4bb5e1f 31
dan_ackme 0:ea85c4bb5e1f 32 /*************************************************************************************************/
dan_ackme 0:ea85c4bb5e1f 33 void Wiconnect::processNextQueuedCommand()
dan_ackme 0:ea85c4bb5e1f 34 {
dan_ackme 0:ea85c4bb5e1f 35 if(commandQueue.isEmpty())
dan_ackme 0:ea85c4bb5e1f 36 {
dan_ackme 0:ea85c4bb5e1f 37 return;
dan_ackme 0:ea85c4bb5e1f 38 }
dan_ackme 0:ea85c4bb5e1f 39 else if(commandExecuting)
dan_ackme 0:ea85c4bb5e1f 40 {
dan_ackme 0:ea85c4bb5e1f 41 return;
dan_ackme 0:ea85c4bb5e1f 42 }
dan_ackme 0:ea85c4bb5e1f 43
dan_ackme 0:ea85c4bb5e1f 44 WiconnectResult result = WICONNECT_SUCCESS;
dan_ackme 0:ea85c4bb5e1f 45 CommandContext *context = (CommandContext*)commandContext;
dan_ackme 0:ea85c4bb5e1f 46 CommandHeader *header = (CommandHeader*)commandHeaderBuffer;
dan_ackme 0:ea85c4bb5e1f 47
dan_ackme 0:ea85c4bb5e1f 48 commandExecuting = true;
dan_ackme 0:ea85c4bb5e1f 49 currentQueuedCommand = commandQueue.pop();
dan_ackme 0:ea85c4bb5e1f 50
dan_ackme 0:ea85c4bb5e1f 51 DEBUG_INFO("Processing next cmd in queue");
dan_ackme 0:ea85c4bb5e1f 52
dan_ackme 0:ea85c4bb5e1f 53 strcpy(commandFormatBuffer, currentQueuedCommand->command);
dan_ackme 0:ea85c4bb5e1f 54
dan_ackme 0:ea85c4bb5e1f 55 RESET_CMD_HEADER(header);
dan_ackme 0:ea85c4bb5e1f 56
dan_ackme 0:ea85c4bb5e1f 57 memset(context, 0, sizeof(CommandContext));
dan_ackme 0:ea85c4bb5e1f 58 if(currentQueuedCommand->responseBufferLen > 0)
dan_ackme 0:ea85c4bb5e1f 59 {
dan_ackme 0:ea85c4bb5e1f 60 context->responseBuffer = currentQueuedCommand->responseBuffer;
dan_ackme 0:ea85c4bb5e1f 61 context->responseBufferLen = currentQueuedCommand->responseBufferLen;
dan_ackme 0:ea85c4bb5e1f 62 }
dan_ackme 0:ea85c4bb5e1f 63 else
dan_ackme 0:ea85c4bb5e1f 64 {
dan_ackme 0:ea85c4bb5e1f 65 context->responseBuffer = internalBuffer;
dan_ackme 0:ea85c4bb5e1f 66 context->responseBufferLen = internalBufferSize;
dan_ackme 0:ea85c4bb5e1f 67 }
dan_ackme 0:ea85c4bb5e1f 68
dan_ackme 0:ea85c4bb5e1f 69 context->responseBufferPtr = context->responseBuffer;
dan_ackme 0:ea85c4bb5e1f 70 context->commandLen = strlen(commandFormatBuffer);
dan_ackme 0:ea85c4bb5e1f 71 context->commandPtr = commandFormatBuffer;
dan_ackme 0:ea85c4bb5e1f 72 context->reader = currentQueuedCommand->reader;
dan_ackme 0:ea85c4bb5e1f 73 context->user = currentQueuedCommand->userData;
dan_ackme 0:ea85c4bb5e1f 74 context->timeoutMs = currentQueuedCommand->timeoutMs;
dan_ackme 0:ea85c4bb5e1f 75 context->callback = currentQueuedCommand->completeCallback;
dan_ackme 0:ea85c4bb5e1f 76 context->nonBlocking = true;
dan_ackme 0:ea85c4bb5e1f 77
dan_ackme 0:ea85c4bb5e1f 78 DEBUG_CMD_SEND(commandFormatBuffer);
dan_ackme 0:ea85c4bb5e1f 79
dan_ackme 0:ea85c4bb5e1f 80 commandExecuting = true;
dan_ackme 0:ea85c4bb5e1f 81 timeoutTimer.reset();
dan_ackme 0:ea85c4bb5e1f 82
dan_ackme 0:ea85c4bb5e1f 83 commandProcessorTimer.start(this, &Wiconnect::commandProcessingTimerHandler, commandProcessingPeriod);
dan_ackme 0:ea85c4bb5e1f 84 }
dan_ackme 0:ea85c4bb5e1f 85
dan_ackme 0:ea85c4bb5e1f 86 /*************************************************************************************************/
dan_ackme 0:ea85c4bb5e1f 87 void Wiconnect::setCommandProcessingPeriod(uint32_t periodMs)
dan_ackme 0:ea85c4bb5e1f 88 {
dan_ackme 0:ea85c4bb5e1f 89 commandProcessingPeriod = periodMs;
dan_ackme 0:ea85c4bb5e1f 90 }
dan_ackme 0:ea85c4bb5e1f 91
dan_ackme 0:ea85c4bb5e1f 92 /*************************************************************************************************/
dan_ackme 0:ea85c4bb5e1f 93 void Wiconnect::commandProcessingTimerHandler()
dan_ackme 0:ea85c4bb5e1f 94 {
dan_ackme 0:ea85c4bb5e1f 95 checkCurrentCommand();
dan_ackme 0:ea85c4bb5e1f 96 }
dan_ackme 0:ea85c4bb5e1f 97
dan_ackme 0:ea85c4bb5e1f 98 #endif
dan_ackme 0:ea85c4bb5e1f 99