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:
Thu Oct 23 15:16:06 2014 -0700
Revision:
26:8067e3d463d3
Parent:
17:7268f365676b
Child:
27:b63f5a9cdefa
Added 'updateFirmware' and 'networkGetJoinResult' api methods
Various bug fixes
Updated documentation

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dan_ackme 16:7f1d6d359787 1 /**
dan_ackme 16:7f1d6d359787 2 * ACKme WiConnect Host Library is licensed under the BSD licence:
dan_ackme 16:7f1d6d359787 3 *
dan_ackme 16:7f1d6d359787 4 * Copyright (c)2014 ACKme Networks.
dan_ackme 16:7f1d6d359787 5 * All rights reserved.
dan_ackme 16:7f1d6d359787 6 *
dan_ackme 16:7f1d6d359787 7 * Redistribution and use in source and binary forms, with or without modification,
dan_ackme 16:7f1d6d359787 8 * are permitted provided that the following conditions are met:
dan_ackme 16:7f1d6d359787 9 *
dan_ackme 16:7f1d6d359787 10 * 1. Redistributions of source code must retain the above copyright notice,
dan_ackme 16:7f1d6d359787 11 * this list of conditions and the following disclaimer.
dan_ackme 16:7f1d6d359787 12 * 2. Redistributions in binary form must reproduce the above copyright notice,
dan_ackme 16:7f1d6d359787 13 * this list of conditions and the following disclaimer in the documentation
dan_ackme 16:7f1d6d359787 14 * and/or other materials provided with the distribution.
dan_ackme 16:7f1d6d359787 15 * 3. The name of the author may not be used to endorse or promote products
dan_ackme 16:7f1d6d359787 16 * derived from this software without specific prior written permission.
dan_ackme 16:7f1d6d359787 17 *
dan_ackme 16:7f1d6d359787 18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS AND ANY EXPRESS OR IMPLIED
dan_ackme 16:7f1d6d359787 19 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
dan_ackme 16:7f1d6d359787 20 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
dan_ackme 16:7f1d6d359787 21 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
dan_ackme 16:7f1d6d359787 22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
dan_ackme 16:7f1d6d359787 23 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
dan_ackme 16:7f1d6d359787 24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
dan_ackme 16:7f1d6d359787 25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
dan_ackme 16:7f1d6d359787 26 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
dan_ackme 16:7f1d6d359787 27 * OF SUCH DAMAGE.
dan_ackme 0:ea85c4bb5e1f 28 */
dan_ackme 0:ea85c4bb5e1f 29 #include <stdio.h>
dan_ackme 0:ea85c4bb5e1f 30 #include <stdarg.h>
dan_ackme 0:ea85c4bb5e1f 31 #include <string.h>
dan_ackme 0:ea85c4bb5e1f 32
dan_ackme 0:ea85c4bb5e1f 33 #include "WiconnectInterface.h"
dan_ackme 0:ea85c4bb5e1f 34 #include "internal/common.h"
dan_ackme 0:ea85c4bb5e1f 35
dan_ackme 0:ea85c4bb5e1f 36
dan_ackme 0:ea85c4bb5e1f 37
dan_ackme 0:ea85c4bb5e1f 38
dan_ackme 0:ea85c4bb5e1f 39
dan_ackme 0:ea85c4bb5e1f 40 using namespace wiconnect;
dan_ackme 0:ea85c4bb5e1f 41
dan_ackme 0:ea85c4bb5e1f 42
dan_ackme 0:ea85c4bb5e1f 43
dan_ackme 0:ea85c4bb5e1f 44
dan_ackme 0:ea85c4bb5e1f 45
dan_ackme 0:ea85c4bb5e1f 46 #ifdef WICONNECT_ENABLE_MALLOC
dan_ackme 0:ea85c4bb5e1f 47 #define MALLOC_ARGS , void* (*mallocPtr)(size_t), void (*freePtr)(void*)
dan_ackme 5:8d91a87ebba2 48 #define MALLOC_CONSTRUCTORS _malloc(mallocPtr), _free(freePtr),
dan_ackme 0:ea85c4bb5e1f 49 #else
dan_ackme 0:ea85c4bb5e1f 50 #define MALLOC_ARGS
dan_ackme 0:ea85c4bb5e1f 51 #define MALLOC_CONSTRUCTORS
dan_ackme 0:ea85c4bb5e1f 52 #endif
dan_ackme 0:ea85c4bb5e1f 53
dan_ackme 0:ea85c4bb5e1f 54
dan_ackme 0:ea85c4bb5e1f 55 static Wiconnect* instance = NULL;
dan_ackme 0:ea85c4bb5e1f 56
dan_ackme 0:ea85c4bb5e1f 57
dan_ackme 0:ea85c4bb5e1f 58
dan_ackme 0:ea85c4bb5e1f 59
dan_ackme 0:ea85c4bb5e1f 60 /*************************************************************************************************/
dan_ackme 0:ea85c4bb5e1f 61 void Wiconnect::prepare(void *internalBuffer_, int internalBufferSize_, bool nonBlocking_)
dan_ackme 0:ea85c4bb5e1f 62 {
dan_ackme 0:ea85c4bb5e1f 63 instance = this;
dan_ackme 0:ea85c4bb5e1f 64 internalBufferAlloc = false;
dan_ackme 0:ea85c4bb5e1f 65 #ifdef WICONNECT_ENABLE_MALLOC
dan_ackme 0:ea85c4bb5e1f 66 if(internalBufferSize_ > 0 && internalBuffer_ == NULL)
dan_ackme 0:ea85c4bb5e1f 67 {
dan_ackme 6:8a87a59d0d21 68 wiconnect_assert(this, "Wiconnect(), malloc not defined", _malloc != NULL);
dan_ackme 0:ea85c4bb5e1f 69 internalBuffer = (char*)_malloc(internalBufferSize_);
dan_ackme 0:ea85c4bb5e1f 70 internalBufferAlloc = true;
dan_ackme 0:ea85c4bb5e1f 71 }
dan_ackme 0:ea85c4bb5e1f 72 else
dan_ackme 0:ea85c4bb5e1f 73 #endif
dan_ackme 0:ea85c4bb5e1f 74 {
dan_ackme 0:ea85c4bb5e1f 75 internalBuffer = (char*)internalBuffer_;
dan_ackme 0:ea85c4bb5e1f 76 }
dan_ackme 0:ea85c4bb5e1f 77
dan_ackme 0:ea85c4bb5e1f 78 internalProcessingState = 0;
dan_ackme 0:ea85c4bb5e1f 79 currentCommandId = NULL;
dan_ackme 0:ea85c4bb5e1f 80 internalBufferSize = internalBufferSize_;
dan_ackme 0:ea85c4bb5e1f 81 nonBlocking = nonBlocking_;
dan_ackme 0:ea85c4bb5e1f 82 commandExecuting = false;
dan_ackme 0:ea85c4bb5e1f 83 initialized = false;
dan_ackme 0:ea85c4bb5e1f 84 pinToGpioMapper = NULL;
dan_ackme 0:ea85c4bb5e1f 85 defaultTimeoutMs = WICONNECT_DEFAULT_TIMEOUT;
dan_ackme 0:ea85c4bb5e1f 86
dan_ackme 0:ea85c4bb5e1f 87 memset(commandContext, 0, sizeof(commandContext));
dan_ackme 0:ea85c4bb5e1f 88
dan_ackme 0:ea85c4bb5e1f 89 #ifdef WICONNECT_ASYNC_TIMER_ENABLED
dan_ackme 0:ea85c4bb5e1f 90 commandProcessingPeriod = WICONNECT_DEFAULT_COMMAND_PROCESSING_PERIOD;
dan_ackme 0:ea85c4bb5e1f 91 currentQueuedCommand = NULL;
dan_ackme 0:ea85c4bb5e1f 92 #endif
dan_ackme 0:ea85c4bb5e1f 93 }
dan_ackme 0:ea85c4bb5e1f 94
dan_ackme 0:ea85c4bb5e1f 95
dan_ackme 0:ea85c4bb5e1f 96 /*************************************************************************************************/
dan_ackme 13:2b51f5267c92 97 Wiconnect::Wiconnect(const SerialConfig &serialConfig, int internalBufferSize, void *internalBuffer, Pin reset, Pin wake, bool nonBlocking MALLOC_ARGS) :
dan_ackme 5:8d91a87ebba2 98 NetworkInterface(this), SocketInterface(this), FileInterface(this), MALLOC_CONSTRUCTORS serial(serialConfig, this), resetGpio(reset), wakeGpio(wake)
dan_ackme 0:ea85c4bb5e1f 99 {
dan_ackme 6:8a87a59d0d21 100 #ifdef WICONNECT_ENABLE_MALLOC
dan_ackme 6:8a87a59d0d21 101 wiconnect_assert(this, "Wiconnect(), bad malloc/free", (mallocPtr == NULL && freePtr == NULL) || (mallocPtr != NULL && freePtr != NULL));
dan_ackme 6:8a87a59d0d21 102 #endif
dan_ackme 0:ea85c4bb5e1f 103 prepare(internalBuffer, internalBufferSize, nonBlocking);
dan_ackme 0:ea85c4bb5e1f 104 }
dan_ackme 0:ea85c4bb5e1f 105
dan_ackme 0:ea85c4bb5e1f 106 /*************************************************************************************************/
dan_ackme 0:ea85c4bb5e1f 107 Wiconnect::Wiconnect(const SerialConfig &serialConfig, Pin reset, Pin wake, bool nonBlocking MALLOC_ARGS) :
dan_ackme 5:8d91a87ebba2 108 NetworkInterface(this), SocketInterface(this), FileInterface(this), MALLOC_CONSTRUCTORS serial(serialConfig, this), resetGpio(reset), wakeGpio(wake)
dan_ackme 0:ea85c4bb5e1f 109 {
dan_ackme 6:8a87a59d0d21 110 #ifdef WICONNECT_ENABLE_MALLOC
dan_ackme 6:8a87a59d0d21 111 wiconnect_assert(this, "Wiconnect(), bad malloc/free", (mallocPtr == NULL && freePtr == NULL) || (mallocPtr != NULL && freePtr != NULL));
dan_ackme 6:8a87a59d0d21 112 #endif
dan_ackme 0:ea85c4bb5e1f 113 prepare(NULL, 0, nonBlocking);
dan_ackme 0:ea85c4bb5e1f 114 }
dan_ackme 0:ea85c4bb5e1f 115
dan_ackme 0:ea85c4bb5e1f 116 /*************************************************************************************************/
dan_ackme 0:ea85c4bb5e1f 117 Wiconnect::~Wiconnect()
dan_ackme 0:ea85c4bb5e1f 118 {
dan_ackme 0:ea85c4bb5e1f 119 #ifdef WICONNECT_ENABLE_MALLOC
dan_ackme 0:ea85c4bb5e1f 120 if(internalBufferAlloc)
dan_ackme 0:ea85c4bb5e1f 121 {
dan_ackme 0:ea85c4bb5e1f 122 _free(internalBuffer);
dan_ackme 0:ea85c4bb5e1f 123 }
dan_ackme 0:ea85c4bb5e1f 124 #endif
dan_ackme 0:ea85c4bb5e1f 125 }
dan_ackme 0:ea85c4bb5e1f 126
dan_ackme 0:ea85c4bb5e1f 127 /*************************************************************************************************/
dan_ackme 0:ea85c4bb5e1f 128 WiconnectResult Wiconnect::init(bool bringNetworkUp)
dan_ackme 0:ea85c4bb5e1f 129 {
dan_ackme 0:ea85c4bb5e1f 130 WiconnectResult result;
dan_ackme 0:ea85c4bb5e1f 131 int retries;
dan_ackme 0:ea85c4bb5e1f 132 bool savedNonBlocking = nonBlocking;
dan_ackme 0:ea85c4bb5e1f 133
dan_ackme 0:ea85c4bb5e1f 134 if(WICONNECT_FAILED(result, reset()))
dan_ackme 0:ea85c4bb5e1f 135 {
dan_ackme 0:ea85c4bb5e1f 136 return result;
dan_ackme 0:ea85c4bb5e1f 137 }
dan_ackme 0:ea85c4bb5e1f 138
dan_ackme 0:ea85c4bb5e1f 139 delayMs(1000);
dan_ackme 0:ea85c4bb5e1f 140
dan_ackme 0:ea85c4bb5e1f 141 initialized = true;
dan_ackme 0:ea85c4bb5e1f 142 nonBlocking = false;
dan_ackme 0:ea85c4bb5e1f 143
dan_ackme 0:ea85c4bb5e1f 144 for(retries = 3; retries > 0; --retries)
dan_ackme 0:ea85c4bb5e1f 145 {
dan_ackme 0:ea85c4bb5e1f 146 result = sendCommand(CMD_SET_SYSTEM_COMMAND_MODE, "machine");
dan_ackme 0:ea85c4bb5e1f 147 if(result != WICONNECT_SUCCESS)
dan_ackme 0:ea85c4bb5e1f 148 {
dan_ackme 0:ea85c4bb5e1f 149 delayMs(1000);
dan_ackme 0:ea85c4bb5e1f 150 }
dan_ackme 0:ea85c4bb5e1f 151 else
dan_ackme 0:ea85c4bb5e1f 152 {
dan_ackme 0:ea85c4bb5e1f 153 break;
dan_ackme 0:ea85c4bb5e1f 154 }
dan_ackme 0:ea85c4bb5e1f 155 }
dan_ackme 17:7268f365676b 156
dan_ackme 17:7268f365676b 157 if(result == WICONNECT_SUCCESS)
dan_ackme 17:7268f365676b 158 {
dan_ackme 17:7268f365676b 159 sendCommand("set stream.auto_close 0");
dan_ackme 17:7268f365676b 160 }
dan_ackme 0:ea85c4bb5e1f 161 if(result == WICONNECT_SUCCESS && bringNetworkUp)
dan_ackme 0:ea85c4bb5e1f 162 {
dan_ackme 0:ea85c4bb5e1f 163 sendCommand(15000, "ping -g");
dan_ackme 0:ea85c4bb5e1f 164 }
dan_ackme 0:ea85c4bb5e1f 165
dan_ackme 0:ea85c4bb5e1f 166 nonBlocking = savedNonBlocking;
dan_ackme 0:ea85c4bb5e1f 167 if(result != WICONNECT_SUCCESS)
dan_ackme 0:ea85c4bb5e1f 168 {
dan_ackme 0:ea85c4bb5e1f 169 initialized = false;
dan_ackme 0:ea85c4bb5e1f 170 }
dan_ackme 0:ea85c4bb5e1f 171
dan_ackme 0:ea85c4bb5e1f 172
dan_ackme 0:ea85c4bb5e1f 173 return result;
dan_ackme 0:ea85c4bb5e1f 174 }
dan_ackme 0:ea85c4bb5e1f 175
dan_ackme 0:ea85c4bb5e1f 176 /*************************************************************************************************/
dan_ackme 0:ea85c4bb5e1f 177 void Wiconnect::deinit(void)
dan_ackme 0:ea85c4bb5e1f 178 {
dan_ackme 0:ea85c4bb5e1f 179 initialized = false;
dan_ackme 0:ea85c4bb5e1f 180 }
dan_ackme 0:ea85c4bb5e1f 181
dan_ackme 0:ea85c4bb5e1f 182 /*************************************************************************************************/
dan_ackme 0:ea85c4bb5e1f 183 Wiconnect* Wiconnect::getInstance()
dan_ackme 0:ea85c4bb5e1f 184 {
dan_ackme 0:ea85c4bb5e1f 185 return instance;
dan_ackme 0:ea85c4bb5e1f 186 }
dan_ackme 0:ea85c4bb5e1f 187
dan_ackme 0:ea85c4bb5e1f 188 /*************************************************************************************************/
dan_ackme 0:ea85c4bb5e1f 189 bool Wiconnect::isInitialized()
dan_ackme 0:ea85c4bb5e1f 190 {
dan_ackme 0:ea85c4bb5e1f 191 return initialized;
dan_ackme 0:ea85c4bb5e1f 192 }
dan_ackme 0:ea85c4bb5e1f 193
dan_ackme 0:ea85c4bb5e1f 194 /*************************************************************************************************/
dan_ackme 0:ea85c4bb5e1f 195 WiconnectResult Wiconnect::reset()
dan_ackme 0:ea85c4bb5e1f 196 {
dan_ackme 0:ea85c4bb5e1f 197 resetGpio = 0;
dan_ackme 0:ea85c4bb5e1f 198 delayMs(10);
dan_ackme 0:ea85c4bb5e1f 199 resetGpio = 1;
dan_ackme 0:ea85c4bb5e1f 200 delayMs(1000);
dan_ackme 0:ea85c4bb5e1f 201 return WICONNECT_SUCCESS;
dan_ackme 0:ea85c4bb5e1f 202 }
dan_ackme 0:ea85c4bb5e1f 203
dan_ackme 0:ea85c4bb5e1f 204 /*************************************************************************************************/
dan_ackme 0:ea85c4bb5e1f 205 WiconnectResult Wiconnect::wakeup()
dan_ackme 0:ea85c4bb5e1f 206 {
dan_ackme 0:ea85c4bb5e1f 207 wakeGpio = 1;
dan_ackme 0:ea85c4bb5e1f 208 delayMs(1);
dan_ackme 0:ea85c4bb5e1f 209 wakeGpio = 0;
dan_ackme 0:ea85c4bb5e1f 210 return WICONNECT_SUCCESS;
dan_ackme 0:ea85c4bb5e1f 211 }
dan_ackme 0:ea85c4bb5e1f 212
dan_ackme 0:ea85c4bb5e1f 213 /*************************************************************************************************/
dan_ackme 0:ea85c4bb5e1f 214 void Wiconnect::flush(int delayMs)
dan_ackme 0:ea85c4bb5e1f 215 {
dan_ackme 0:ea85c4bb5e1f 216 if(delayMs != 0)
dan_ackme 0:ea85c4bb5e1f 217 {
dan_ackme 0:ea85c4bb5e1f 218 serial.write("\r\n\r\n", 4, 0);
dan_ackme 0:ea85c4bb5e1f 219 }
dan_ackme 0:ea85c4bb5e1f 220 delayMs(delayMs);
dan_ackme 0:ea85c4bb5e1f 221 serial.flush();
dan_ackme 0:ea85c4bb5e1f 222 }
dan_ackme 0:ea85c4bb5e1f 223
dan_ackme 0:ea85c4bb5e1f 224 /*************************************************************************************************/
dan_ackme 0:ea85c4bb5e1f 225 void Wiconnect::setPinToGpioMapper(PinToGpioMapper mapper)
dan_ackme 0:ea85c4bb5e1f 226 {
dan_ackme 0:ea85c4bb5e1f 227 pinToGpioMapper = mapper;
dan_ackme 0:ea85c4bb5e1f 228 }
dan_ackme 0:ea85c4bb5e1f 229
dan_ackme 0:ea85c4bb5e1f 230 /*************************************************************************************************/
dan_ackme 0:ea85c4bb5e1f 231 WiconnectResult Wiconnect::getVersion(char *versionBuffer, int versionBufferSize, const Callback &completeCallback)
dan_ackme 26:8067e3d463d3 232 {
dan_ackme 26:8067e3d463d3 233 WiconnectResult result;
dan_ackme 26:8067e3d463d3 234
dan_ackme 0:ea85c4bb5e1f 235 if(versionBuffer != NULL && versionBufferSize == 0)
dan_ackme 0:ea85c4bb5e1f 236 {
dan_ackme 0:ea85c4bb5e1f 237 return WICONNECT_BAD_ARG;
dan_ackme 26:8067e3d463d3 238 }
dan_ackme 26:8067e3d463d3 239
dan_ackme 26:8067e3d463d3 240 _CHECK_OTHER_COMMAND_EXECUTING();
dan_ackme 26:8067e3d463d3 241
dan_ackme 26:8067e3d463d3 242 if(versionBuffer == NULL)
dan_ackme 26:8067e3d463d3 243 {
dan_ackme 26:8067e3d463d3 244 result = sendCommand(completeCallback, CMD_GET_VERSION);
dan_ackme 26:8067e3d463d3 245 }
dan_ackme 26:8067e3d463d3 246 else
dan_ackme 26:8067e3d463d3 247 {
dan_ackme 26:8067e3d463d3 248 result = sendCommand(completeCallback, versionBuffer, versionBufferSize, CMD_GET_VERSION);
dan_ackme 26:8067e3d463d3 249 }
dan_ackme 26:8067e3d463d3 250
dan_ackme 26:8067e3d463d3 251 _CHECK_CLEANUP_COMMAND();
dan_ackme 26:8067e3d463d3 252
dan_ackme 26:8067e3d463d3 253 return result;
dan_ackme 0:ea85c4bb5e1f 254 }
dan_ackme 26:8067e3d463d3 255
dan_ackme 26:8067e3d463d3 256 /*************************************************************************************************/
dan_ackme 26:8067e3d463d3 257 WiconnectResult Wiconnect::updateFirmware(bool forced, const char *versionStr, const Callback &completeCallback)
dan_ackme 26:8067e3d463d3 258 {
dan_ackme 26:8067e3d463d3 259 WiconnectResult result;
dan_ackme 26:8067e3d463d3 260 char cmdBuffer[WICONNECT_MAX_CMD_SIZE];
dan_ackme 26:8067e3d463d3 261
dan_ackme 26:8067e3d463d3 262 if(_WICONNECT_IS_IDLE())
dan_ackme 26:8067e3d463d3 263 {
dan_ackme 26:8067e3d463d3 264 strcpy(cmdBuffer, "ota ");
dan_ackme 26:8067e3d463d3 265 if(versionStr != NULL)
dan_ackme 26:8067e3d463d3 266 {
dan_ackme 26:8067e3d463d3 267 strcat(cmdBuffer, "-b wiconnect-");
dan_ackme 26:8067e3d463d3 268 strcat(cmdBuffer, versionStr);
dan_ackme 26:8067e3d463d3 269 }
dan_ackme 26:8067e3d463d3 270 else if(forced)
dan_ackme 26:8067e3d463d3 271 {
dan_ackme 26:8067e3d463d3 272 strcat(cmdBuffer, "-f");
dan_ackme 26:8067e3d463d3 273 }
dan_ackme 26:8067e3d463d3 274 }
dan_ackme 26:8067e3d463d3 275
dan_ackme 26:8067e3d463d3 276 _CHECK_OTHER_COMMAND_EXECUTING();
dan_ackme 26:8067e3d463d3 277
dan_ackme 26:8067e3d463d3 278 result = sendCommand(completeCallback, WICONNECT_FIRMWARE_UPDATE_TIMEOUT, cmdBuffer);
dan_ackme 26:8067e3d463d3 279
dan_ackme 26:8067e3d463d3 280 _CHECK_CLEANUP_COMMAND();
dan_ackme 26:8067e3d463d3 281
dan_ackme 26:8067e3d463d3 282 return result;
dan_ackme 26:8067e3d463d3 283 }
dan_ackme 0:ea85c4bb5e1f 284
dan_ackme 0:ea85c4bb5e1f 285 /*************************************************************************************************/
dan_ackme 0:ea85c4bb5e1f 286 const char* Wiconnect::getWiconnectResultStr(WiconnectResult wiconnectResult)
dan_ackme 0:ea85c4bb5e1f 287 {
dan_ackme 0:ea85c4bb5e1f 288 static const char* const wiconnectSuccessStrTable[] = {
dan_ackme 0:ea85c4bb5e1f 289 "Success", // WICONNECT_SUCCESS
dan_ackme 0:ea85c4bb5e1f 290 "Processing command", // WICONNECT_PROCESSING
dan_ackme 0:ea85c4bb5e1f 291 "Idle", // WICONNECT_IDLE
dan_ackme 0:ea85c4bb5e1f 292 "Aborted", // WICONNECT_ABORTED
dan_ackme 0:ea85c4bb5e1f 293 };
dan_ackme 0:ea85c4bb5e1f 294 static const char* const wiconnectErrorStrTable[] = {
dan_ackme 0:ea85c4bb5e1f 295 "",
dan_ackme 0:ea85c4bb5e1f 296 "General error", // WICONNECT_ERROR
dan_ackme 0:ea85c4bb5e1f 297 "WiConnect command code error", // WICONNECT_CMD_RESPONSE_ERROR
dan_ackme 0:ea85c4bb5e1f 298 "Null buffer", // WICONNECT_NULL_BUFFER
dan_ackme 0:ea85c4bb5e1f 299 "Not initialized", // WICONNECT_NOT_INITIALIZED
dan_ackme 0:ea85c4bb5e1f 300 "Overflow", // WICONNECT_OVERFLOW
dan_ackme 0:ea85c4bb5e1f 301 "Timeout", // WICONNECT_TIMEOUT
dan_ackme 0:ea85c4bb5e1f 302 "Response handler null", // WICONNECT_RESPONSE_HANDLER_NULL
dan_ackme 0:ea85c4bb5e1f 303 "Response parse error", // WICONNECT_RESPONSE_PARSE_ERROR
dan_ackme 0:ea85c4bb5e1f 304 "Another command is executing", // WICONNECT_ANOTHER_CMD_EXECUTING
dan_ackme 0:ea85c4bb5e1f 305 "Bad argument(s)", // WICONNECT_BAD_ARG
dan_ackme 0:ea85c4bb5e1f 306 "Unsupported", // WICONNECT_UNSUPPORTED
dan_ackme 0:ea85c4bb5e1f 307 "Pin name to GPIO mapper null", // WICONNECT_PINNAME_TO_GPIO_MAPPER_NULL
dan_ackme 0:ea85c4bb5e1f 308 "Duplicate", // WICONNECT_DUPLICATE
dan_ackme 0:ea85c4bb5e1f 309 "Not found", // WICONNECT_NOT_FOUND
dan_ackme 0:ea85c4bb5e1f 310 "No mapping for pinname to GPIO", // WICONNECT_PINNAME_TO_GPIO_NO_MAPPING
dan_ackme 0:ea85c4bb5e1f 311 "Not connected", // WICONNECT_NOT_CONNECTED
dan_ackme 0:ea85c4bb5e1f 312 "Underflow", // WICONNECT_UNDERFLOW
dan_ackme 11:ea484e1b7fc4 313 "A monitor is not available", // WICONNECT_MONITOR_NOT_AVAILABLE
dan_ackme 11:ea484e1b7fc4 314 "Not opened for reading", // WICONNECT_NOT_OPENED_FOR_READING
dan_ackme 0:ea85c4bb5e1f 315 };
dan_ackme 0:ea85c4bb5e1f 316
dan_ackme 0:ea85c4bb5e1f 317 if((int)wiconnectResult >= (int)WICONNECT_SUCCESS)
dan_ackme 0:ea85c4bb5e1f 318 {
dan_ackme 0:ea85c4bb5e1f 319 return wiconnectSuccessStrTable[wiconnectResult];
dan_ackme 0:ea85c4bb5e1f 320 }
dan_ackme 0:ea85c4bb5e1f 321 else
dan_ackme 0:ea85c4bb5e1f 322 {
dan_ackme 0:ea85c4bb5e1f 323 wiconnectResult = (WiconnectResult)(-((int)wiconnectResult));
dan_ackme 0:ea85c4bb5e1f 324 return wiconnectErrorStrTable[wiconnectResult];
dan_ackme 0:ea85c4bb5e1f 325 }
dan_ackme 0:ea85c4bb5e1f 326 }
dan_ackme 0:ea85c4bb5e1f 327
dan_ackme 0:ea85c4bb5e1f 328
dan_ackme 0:ea85c4bb5e1f 329 /*************************************************************************************************/
dan_ackme 0:ea85c4bb5e1f 330 void Wiconnect::setDebugLogger(LogFunc logFunc)
dan_ackme 0:ea85c4bb5e1f 331 {
dan_ackme 0:ea85c4bb5e1f 332 debugLogger = logFunc;
dan_ackme 0:ea85c4bb5e1f 333 }
dan_ackme 0:ea85c4bb5e1f 334
dan_ackme 0:ea85c4bb5e1f 335 /*************************************************************************************************/
dan_ackme 6:8a87a59d0d21 336 void Wiconnect::setAssertLogger(LogFunc assertLogFunc)
dan_ackme 6:8a87a59d0d21 337 {
dan_ackme 6:8a87a59d0d21 338 assertLogger = assertLogFunc;
dan_ackme 6:8a87a59d0d21 339 }
dan_ackme 6:8a87a59d0d21 340
dan_ackme 6:8a87a59d0d21 341 /*************************************************************************************************/
dan_ackme 0:ea85c4bb5e1f 342 void Wiconnect::debugLog(const char *msg, ...)
dan_ackme 0:ea85c4bb5e1f 343 {
dan_ackme 0:ea85c4bb5e1f 344 if(!debugLogger.isValid())
dan_ackme 0:ea85c4bb5e1f 345 {
dan_ackme 0:ea85c4bb5e1f 346 return;
dan_ackme 0:ea85c4bb5e1f 347 }
dan_ackme 0:ea85c4bb5e1f 348
dan_ackme 0:ea85c4bb5e1f 349 char buffer[96];
dan_ackme 0:ea85c4bb5e1f 350 va_list args;
dan_ackme 0:ea85c4bb5e1f 351 va_start(args, msg);
dan_ackme 0:ea85c4bb5e1f 352 int len = vsnprintf(buffer, sizeof(buffer), msg, args);
dan_ackme 0:ea85c4bb5e1f 353 va_end(args);
dan_ackme 0:ea85c4bb5e1f 354
dan_ackme 0:ea85c4bb5e1f 355 if(len > (int)(sizeof(buffer)-6))
dan_ackme 0:ea85c4bb5e1f 356 {
dan_ackme 0:ea85c4bb5e1f 357 char *p = &buffer[sizeof(buffer)-6];
dan_ackme 0:ea85c4bb5e1f 358 *p++ = '.';
dan_ackme 0:ea85c4bb5e1f 359 *p++ = '.';
dan_ackme 0:ea85c4bb5e1f 360 *p++ = '.';
dan_ackme 0:ea85c4bb5e1f 361 *p++ = '\r';
dan_ackme 0:ea85c4bb5e1f 362 *p++ = '\n';
dan_ackme 0:ea85c4bb5e1f 363 *p = 0;
dan_ackme 0:ea85c4bb5e1f 364 }
dan_ackme 0:ea85c4bb5e1f 365 else
dan_ackme 0:ea85c4bb5e1f 366 {
dan_ackme 0:ea85c4bb5e1f 367 if(buffer[len-2] != '\r')
dan_ackme 0:ea85c4bb5e1f 368 {
dan_ackme 0:ea85c4bb5e1f 369 char *p = &buffer[len];
dan_ackme 0:ea85c4bb5e1f 370 *p++ = '\r';
dan_ackme 0:ea85c4bb5e1f 371 *p++ = '\n';
dan_ackme 0:ea85c4bb5e1f 372 *p = 0;
dan_ackme 0:ea85c4bb5e1f 373 }
dan_ackme 0:ea85c4bb5e1f 374 }
dan_ackme 0:ea85c4bb5e1f 375 debugLogger.call(buffer);
dan_ackme 0:ea85c4bb5e1f 376 }