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
AsyncCommand.cpp
00001 /** 00002 * ACKme WiConnect Host Library is licensed under the BSD licence: 00003 * 00004 * Copyright (c)2014 ACKme Networks. 00005 * All rights reserved. 00006 * 00007 * Redistribution and use in source and binary forms, with or without modification, 00008 * are permitted provided that the following conditions are met: 00009 * 00010 * 1. Redistributions of source code must retain the above copyright notice, 00011 * this list of conditions and the following disclaimer. 00012 * 2. Redistributions in binary form must reproduce the above copyright notice, 00013 * this list of conditions and the following disclaimer in the documentation 00014 * and/or other materials provided with the distribution. 00015 * 3. The name of the author may not be used to endorse or promote products 00016 * derived from this software without specific prior written permission. 00017 * 00018 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS AND ANY EXPRESS OR IMPLIED 00019 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00020 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 00021 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00022 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 00023 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00024 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00025 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 00026 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 00027 * OF SUCH DAMAGE. 00028 */ 00029 00030 #include "internal/CommandCommon.h" 00031 00032 #ifdef WICONNECT_ASYNC_TIMER_ENABLED 00033 00034 00035 00036 /*************************************************************************************************/ 00037 WiconnectResult Wiconnect::enqueueCommand(QueuedCommand *command, const Callback &commandCompleteHandler) 00038 { 00039 if(commandQueue.isFull()) 00040 { 00041 return WICONNECT_OVERFLOW; 00042 } 00043 command->setCompletedCallback(commandCompleteHandler); 00044 DEBUG_INFO("Queuing command: %s", command->getCommand()); 00045 commandQueue.push(command); 00046 processNextQueuedCommand(); 00047 return WICONNECT_SUCCESS; 00048 } 00049 00050 /*************************************************************************************************/ 00051 void Wiconnect::processNextQueuedCommand() 00052 { 00053 if(commandQueue.isEmpty()) 00054 { 00055 return; 00056 } 00057 else if(commandExecuting) 00058 { 00059 return; 00060 } 00061 00062 CommandContext *context = (CommandContext*)commandContext; 00063 CommandHeader *header = (CommandHeader*)commandHeaderBuffer; 00064 00065 commandExecuting = true; 00066 currentQueuedCommand = commandQueue.pop(); 00067 00068 DEBUG_INFO("Processing next cmd in queue"); 00069 00070 strcpy(commandFormatBuffer, currentQueuedCommand->command); 00071 00072 RESET_CMD_HEADER(header); 00073 00074 memset(context, 0, sizeof(CommandContext)); 00075 if(currentQueuedCommand->responseBufferLen > 0) 00076 { 00077 context->responseBuffer = currentQueuedCommand->responseBuffer; 00078 context->responseBufferLen = currentQueuedCommand->responseBufferLen; 00079 } 00080 else 00081 { 00082 context->responseBuffer = internalBuffer; 00083 context->responseBufferLen = internalBufferSize; 00084 } 00085 00086 context->responseBufferPtr = context->responseBuffer; 00087 context->commandLen = strlen(commandFormatBuffer); 00088 context->commandPtr = commandFormatBuffer; 00089 context->reader = currentQueuedCommand->reader; 00090 context->user = currentQueuedCommand->userData; 00091 context->timeoutMs = currentQueuedCommand->timeoutMs; 00092 context->callback = currentQueuedCommand->completeCallback; 00093 context->nonBlocking = true; 00094 00095 DEBUG_CMD_SEND(commandFormatBuffer); 00096 00097 commandExecuting = true; 00098 timeoutTimer.reset(); 00099 00100 commandProcessorTimer.start(this, &Wiconnect::commandProcessingTimerHandler, commandProcessingPeriod); 00101 } 00102 00103 /*************************************************************************************************/ 00104 void Wiconnect::setCommandProcessingPeriod(uint32_t periodMs) 00105 { 00106 commandProcessingPeriod = periodMs; 00107 } 00108 00109 /*************************************************************************************************/ 00110 void Wiconnect::commandProcessingTimerHandler() 00111 { 00112 checkCurrentCommand(); 00113 } 00114 00115 #endif 00116
Generated on Tue Jul 12 2022 17:35:58 by 1.7.2