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
internal/wiconnect/Wiconnect.cpp@24:e27e23297f02, 2014-09-06 (annotated)
- Committer:
- dan_ackme
- Date:
- Sat Sep 06 20:34:01 2014 -0700
- Revision:
- 24:e27e23297f02
- Parent:
- 17:7268f365676b
- Child:
- 27:b63f5a9cdefa
add api to get/set module settings
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dan_ackme | 24:e27e23297f02 | 1 | /** |
dan_ackme | 24:e27e23297f02 | 2 | * ACKme WiConnect Host Library is licensed under the BSD licence: |
dan_ackme | 24:e27e23297f02 | 3 | * |
dan_ackme | 24:e27e23297f02 | 4 | * Copyright (c)2014 ACKme Networks. |
dan_ackme | 24:e27e23297f02 | 5 | * All rights reserved. |
dan_ackme | 24:e27e23297f02 | 6 | * |
dan_ackme | 24:e27e23297f02 | 7 | * Redistribution and use in source and binary forms, with or without modification, |
dan_ackme | 24:e27e23297f02 | 8 | * are permitted provided that the following conditions are met: |
dan_ackme | 24:e27e23297f02 | 9 | * |
dan_ackme | 24:e27e23297f02 | 10 | * 1. Redistributions of source code must retain the above copyright notice, |
dan_ackme | 24:e27e23297f02 | 11 | * this list of conditions and the following disclaimer. |
dan_ackme | 24:e27e23297f02 | 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
dan_ackme | 24:e27e23297f02 | 13 | * this list of conditions and the following disclaimer in the documentation |
dan_ackme | 24:e27e23297f02 | 14 | * and/or other materials provided with the distribution. |
dan_ackme | 24:e27e23297f02 | 15 | * 3. The name of the author may not be used to endorse or promote products |
dan_ackme | 24:e27e23297f02 | 16 | * derived from this software without specific prior written permission. |
dan_ackme | 24:e27e23297f02 | 17 | * |
dan_ackme | 24:e27e23297f02 | 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS AND ANY EXPRESS OR IMPLIED |
dan_ackme | 24:e27e23297f02 | 19 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
dan_ackme | 24:e27e23297f02 | 20 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT |
dan_ackme | 24:e27e23297f02 | 21 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
dan_ackme | 24:e27e23297f02 | 22 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT |
dan_ackme | 24:e27e23297f02 | 23 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
dan_ackme | 24:e27e23297f02 | 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
dan_ackme | 24:e27e23297f02 | 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
dan_ackme | 24:e27e23297f02 | 26 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY |
dan_ackme | 24:e27e23297f02 | 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 | 24:e27e23297f02 | 156 | |
dan_ackme | 24:e27e23297f02 | 157 | if(result == WICONNECT_SUCCESS) |
dan_ackme | 24:e27e23297f02 | 158 | { |
dan_ackme | 24:e27e23297f02 | 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 | 0:ea85c4bb5e1f | 232 | { |
dan_ackme | 0:ea85c4bb5e1f | 233 | if(versionBuffer != NULL && versionBufferSize == 0) |
dan_ackme | 0:ea85c4bb5e1f | 234 | { |
dan_ackme | 0:ea85c4bb5e1f | 235 | return WICONNECT_BAD_ARG; |
dan_ackme | 0:ea85c4bb5e1f | 236 | } |
dan_ackme | 0:ea85c4bb5e1f | 237 | return sendCommand(completeCallback, versionBuffer, versionBufferSize, CMD_GET_VERSION); |
dan_ackme | 0:ea85c4bb5e1f | 238 | } |
dan_ackme | 0:ea85c4bb5e1f | 239 | |
dan_ackme | 0:ea85c4bb5e1f | 240 | /*************************************************************************************************/ |
dan_ackme | 0:ea85c4bb5e1f | 241 | const char* Wiconnect::getWiconnectResultStr(WiconnectResult wiconnectResult) |
dan_ackme | 0:ea85c4bb5e1f | 242 | { |
dan_ackme | 0:ea85c4bb5e1f | 243 | static const char* const wiconnectSuccessStrTable[] = { |
dan_ackme | 0:ea85c4bb5e1f | 244 | "Success", // WICONNECT_SUCCESS |
dan_ackme | 0:ea85c4bb5e1f | 245 | "Processing command", // WICONNECT_PROCESSING |
dan_ackme | 0:ea85c4bb5e1f | 246 | "Idle", // WICONNECT_IDLE |
dan_ackme | 0:ea85c4bb5e1f | 247 | "Aborted", // WICONNECT_ABORTED |
dan_ackme | 0:ea85c4bb5e1f | 248 | }; |
dan_ackme | 0:ea85c4bb5e1f | 249 | static const char* const wiconnectErrorStrTable[] = { |
dan_ackme | 0:ea85c4bb5e1f | 250 | "", |
dan_ackme | 0:ea85c4bb5e1f | 251 | "General error", // WICONNECT_ERROR |
dan_ackme | 0:ea85c4bb5e1f | 252 | "WiConnect command code error", // WICONNECT_CMD_RESPONSE_ERROR |
dan_ackme | 0:ea85c4bb5e1f | 253 | "Null buffer", // WICONNECT_NULL_BUFFER |
dan_ackme | 0:ea85c4bb5e1f | 254 | "Not initialized", // WICONNECT_NOT_INITIALIZED |
dan_ackme | 0:ea85c4bb5e1f | 255 | "Overflow", // WICONNECT_OVERFLOW |
dan_ackme | 0:ea85c4bb5e1f | 256 | "Timeout", // WICONNECT_TIMEOUT |
dan_ackme | 0:ea85c4bb5e1f | 257 | "Response handler null", // WICONNECT_RESPONSE_HANDLER_NULL |
dan_ackme | 0:ea85c4bb5e1f | 258 | "Response parse error", // WICONNECT_RESPONSE_PARSE_ERROR |
dan_ackme | 0:ea85c4bb5e1f | 259 | "Another command is executing", // WICONNECT_ANOTHER_CMD_EXECUTING |
dan_ackme | 0:ea85c4bb5e1f | 260 | "Bad argument(s)", // WICONNECT_BAD_ARG |
dan_ackme | 0:ea85c4bb5e1f | 261 | "Unsupported", // WICONNECT_UNSUPPORTED |
dan_ackme | 0:ea85c4bb5e1f | 262 | "Pin name to GPIO mapper null", // WICONNECT_PINNAME_TO_GPIO_MAPPER_NULL |
dan_ackme | 0:ea85c4bb5e1f | 263 | "Duplicate", // WICONNECT_DUPLICATE |
dan_ackme | 0:ea85c4bb5e1f | 264 | "Not found", // WICONNECT_NOT_FOUND |
dan_ackme | 0:ea85c4bb5e1f | 265 | "No mapping for pinname to GPIO", // WICONNECT_PINNAME_TO_GPIO_NO_MAPPING |
dan_ackme | 0:ea85c4bb5e1f | 266 | "Not connected", // WICONNECT_NOT_CONNECTED |
dan_ackme | 0:ea85c4bb5e1f | 267 | "Underflow", // WICONNECT_UNDERFLOW |
dan_ackme | 11:ea484e1b7fc4 | 268 | "A monitor is not available", // WICONNECT_MONITOR_NOT_AVAILABLE |
dan_ackme | 11:ea484e1b7fc4 | 269 | "Not opened for reading", // WICONNECT_NOT_OPENED_FOR_READING |
dan_ackme | 0:ea85c4bb5e1f | 270 | }; |
dan_ackme | 0:ea85c4bb5e1f | 271 | |
dan_ackme | 0:ea85c4bb5e1f | 272 | if((int)wiconnectResult >= (int)WICONNECT_SUCCESS) |
dan_ackme | 0:ea85c4bb5e1f | 273 | { |
dan_ackme | 0:ea85c4bb5e1f | 274 | return wiconnectSuccessStrTable[wiconnectResult]; |
dan_ackme | 0:ea85c4bb5e1f | 275 | } |
dan_ackme | 0:ea85c4bb5e1f | 276 | else |
dan_ackme | 0:ea85c4bb5e1f | 277 | { |
dan_ackme | 0:ea85c4bb5e1f | 278 | wiconnectResult = (WiconnectResult)(-((int)wiconnectResult)); |
dan_ackme | 0:ea85c4bb5e1f | 279 | return wiconnectErrorStrTable[wiconnectResult]; |
dan_ackme | 0:ea85c4bb5e1f | 280 | } |
dan_ackme | 0:ea85c4bb5e1f | 281 | } |
dan_ackme | 0:ea85c4bb5e1f | 282 | |
dan_ackme | 0:ea85c4bb5e1f | 283 | |
dan_ackme | 0:ea85c4bb5e1f | 284 | /*************************************************************************************************/ |
dan_ackme | 0:ea85c4bb5e1f | 285 | void Wiconnect::setDebugLogger(LogFunc logFunc) |
dan_ackme | 0:ea85c4bb5e1f | 286 | { |
dan_ackme | 0:ea85c4bb5e1f | 287 | debugLogger = logFunc; |
dan_ackme | 0:ea85c4bb5e1f | 288 | } |
dan_ackme | 0:ea85c4bb5e1f | 289 | |
dan_ackme | 0:ea85c4bb5e1f | 290 | /*************************************************************************************************/ |
dan_ackme | 6:8a87a59d0d21 | 291 | void Wiconnect::setAssertLogger(LogFunc assertLogFunc) |
dan_ackme | 6:8a87a59d0d21 | 292 | { |
dan_ackme | 6:8a87a59d0d21 | 293 | assertLogger = assertLogFunc; |
dan_ackme | 6:8a87a59d0d21 | 294 | } |
dan_ackme | 6:8a87a59d0d21 | 295 | |
dan_ackme | 6:8a87a59d0d21 | 296 | /*************************************************************************************************/ |
dan_ackme | 0:ea85c4bb5e1f | 297 | void Wiconnect::debugLog(const char *msg, ...) |
dan_ackme | 0:ea85c4bb5e1f | 298 | { |
dan_ackme | 0:ea85c4bb5e1f | 299 | if(!debugLogger.isValid()) |
dan_ackme | 0:ea85c4bb5e1f | 300 | { |
dan_ackme | 0:ea85c4bb5e1f | 301 | return; |
dan_ackme | 0:ea85c4bb5e1f | 302 | } |
dan_ackme | 0:ea85c4bb5e1f | 303 | |
dan_ackme | 0:ea85c4bb5e1f | 304 | char buffer[96]; |
dan_ackme | 0:ea85c4bb5e1f | 305 | va_list args; |
dan_ackme | 0:ea85c4bb5e1f | 306 | va_start(args, msg); |
dan_ackme | 0:ea85c4bb5e1f | 307 | int len = vsnprintf(buffer, sizeof(buffer), msg, args); |
dan_ackme | 0:ea85c4bb5e1f | 308 | va_end(args); |
dan_ackme | 0:ea85c4bb5e1f | 309 | |
dan_ackme | 0:ea85c4bb5e1f | 310 | if(len > (int)(sizeof(buffer)-6)) |
dan_ackme | 0:ea85c4bb5e1f | 311 | { |
dan_ackme | 0:ea85c4bb5e1f | 312 | char *p = &buffer[sizeof(buffer)-6]; |
dan_ackme | 0:ea85c4bb5e1f | 313 | *p++ = '.'; |
dan_ackme | 0:ea85c4bb5e1f | 314 | *p++ = '.'; |
dan_ackme | 0:ea85c4bb5e1f | 315 | *p++ = '.'; |
dan_ackme | 0:ea85c4bb5e1f | 316 | *p++ = '\r'; |
dan_ackme | 0:ea85c4bb5e1f | 317 | *p++ = '\n'; |
dan_ackme | 0:ea85c4bb5e1f | 318 | *p = 0; |
dan_ackme | 0:ea85c4bb5e1f | 319 | } |
dan_ackme | 0:ea85c4bb5e1f | 320 | else |
dan_ackme | 0:ea85c4bb5e1f | 321 | { |
dan_ackme | 0:ea85c4bb5e1f | 322 | if(buffer[len-2] != '\r') |
dan_ackme | 0:ea85c4bb5e1f | 323 | { |
dan_ackme | 0:ea85c4bb5e1f | 324 | char *p = &buffer[len]; |
dan_ackme | 0:ea85c4bb5e1f | 325 | *p++ = '\r'; |
dan_ackme | 0:ea85c4bb5e1f | 326 | *p++ = '\n'; |
dan_ackme | 0:ea85c4bb5e1f | 327 | *p = 0; |
dan_ackme | 0:ea85c4bb5e1f | 328 | } |
dan_ackme | 0:ea85c4bb5e1f | 329 | } |
dan_ackme | 0:ea85c4bb5e1f | 330 | debugLogger.call(buffer); |
dan_ackme | 0:ea85c4bb5e1f | 331 | } |