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 21:25:37 2014 -0700
Revision:
9:b6218dc218ad
Parent:
6:8a87a59d0d21
Child:
11:ea484e1b7fc4
started adding docs

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 #pragma once
dan_ackme 0:ea85c4bb5e1f 12
dan_ackme 0:ea85c4bb5e1f 13 #include "WiconnectTypes.h"
dan_ackme 0:ea85c4bb5e1f 14
dan_ackme 0:ea85c4bb5e1f 15
dan_ackme 0:ea85c4bb5e1f 16 #include "types/LogFunc.h"
dan_ackme 0:ea85c4bb5e1f 17 #include "types/ReaderFunc.h"
dan_ackme 0:ea85c4bb5e1f 18 #include "types/Callback.h"
dan_ackme 0:ea85c4bb5e1f 19 #include "types/QueuedCommand.h"
dan_ackme 0:ea85c4bb5e1f 20 #include "types/CommandQueue.h"
dan_ackme 0:ea85c4bb5e1f 21 #include "types/TimeoutTimer.h"
dan_ackme 0:ea85c4bb5e1f 22 #include "types/PeriodicTimer.h"
dan_ackme 0:ea85c4bb5e1f 23 #include "types/Gpio.h"
dan_ackme 0:ea85c4bb5e1f 24 #include "types/WiconnectSerial.h"
dan_ackme 0:ea85c4bb5e1f 25
dan_ackme 0:ea85c4bb5e1f 26 #include "NetworkInterface.h"
dan_ackme 0:ea85c4bb5e1f 27 #include "SocketInterface.h"
dan_ackme 0:ea85c4bb5e1f 28 #include "FileInterface.h"
dan_ackme 0:ea85c4bb5e1f 29
dan_ackme 0:ea85c4bb5e1f 30
dan_ackme 0:ea85c4bb5e1f 31 #ifdef WICONNECT_ENABLE_MALLOC
dan_ackme 9:b6218dc218ad 32 /// These are optional arguments for host specific malloc/free
dan_ackme 0:ea85c4bb5e1f 33 #define WICONNECT_MALLOC_ARGS , void* (*malloc_)(size_t) = WICONNECT_DEFAULT_MALLOC, void (*free_)(void*) = WICONNECT_DEFAULT_FREE
dan_ackme 0:ea85c4bb5e1f 34 #else
dan_ackme 0:ea85c4bb5e1f 35 #define WICONNECT_MALLOC_ARGS
dan_ackme 0:ea85c4bb5e1f 36 #endif
dan_ackme 0:ea85c4bb5e1f 37
dan_ackme 0:ea85c4bb5e1f 38
dan_ackme 0:ea85c4bb5e1f 39 namespace wiconnect {
dan_ackme 0:ea85c4bb5e1f 40
dan_ackme 0:ea85c4bb5e1f 41
dan_ackme 9:b6218dc218ad 42 /**
dan_ackme 9:b6218dc218ad 43 *
dan_ackme 9:b6218dc218ad 44 *
dan_ackme 9:b6218dc218ad 45 * The root WiConnect library class. This class
dan_ackme 9:b6218dc218ad 46 * inheriets all WiConnect functionality.
dan_ackme 9:b6218dc218ad 47 *
dan_ackme 9:b6218dc218ad 48 * This class is implemented as a 'singleton'. This means it
dan_ackme 9:b6218dc218ad 49 * only needs to be instantiated once. Subsequent class may either
dan_ackme 9:b6218dc218ad 50 * use the class instance or the static function: @ref Wiconnect::getInstance()
dan_ackme 9:b6218dc218ad 51 *
dan_ackme 9:b6218dc218ad 52 */
dan_ackme 0:ea85c4bb5e1f 53 class Wiconnect : public NetworkInterface,
dan_ackme 0:ea85c4bb5e1f 54 public SocketInterface,
dan_ackme 0:ea85c4bb5e1f 55 public FileInterface
dan_ackme 0:ea85c4bb5e1f 56 {
dan_ackme 0:ea85c4bb5e1f 57 public:
dan_ackme 9:b6218dc218ad 58
dan_ackme 9:b6218dc218ad 59 /**
dan_ackme 9:b6218dc218ad 60 *
dan_ackme 9:b6218dc218ad 61 *
dan_ackme 9:b6218dc218ad 62 * WiConnect class constructor
dan_ackme 9:b6218dc218ad 63 *
dan_ackme 9:b6218dc218ad 64 * @note This should only be called once within a program as the WiConnect
dan_ackme 9:b6218dc218ad 65 * library is implemented as a singleton.
dan_ackme 9:b6218dc218ad 66 *
dan_ackme 9:b6218dc218ad 67 * @note If this constructor is used, then all commands must be supplied with an external response buffer.
dan_ackme 9:b6218dc218ad 68 * This means most the API functions will not work as they use the internal buffer.
dan_ackme 9:b6218dc218ad 69 * It's recommended to use the other constructor that supplies an internal buffer. See @ref setting_alloc
dan_ackme 9:b6218dc218ad 70 *
dan_ackme 9:b6218dc218ad 71 * @param[in] serialConfig The serial (i.e. UART) configuration connected to a WiConnect module.
dan_ackme 9:b6218dc218ad 72 * @param[in] reset Optional, The pin connected to the WiConnect module reset signal. Default: No connection
dan_ackme 9:b6218dc218ad 73 * @param[in] wake Optional, The pin connected to the WiConnect module wake signal. Default: No connection
dan_ackme 9:b6218dc218ad 74 * @param[in] nonBlocking Optional, indicates if the API blocking mode. See @ref setting_blocking_modes
dan_ackme 9:b6218dc218ad 75 */
dan_ackme 0:ea85c4bb5e1f 76 Wiconnect(const SerialConfig &serialConfig, Pin reset = PIN_NC, Pin wake = PIN_NC, bool nonBlocking = WICONNECT_DEFAULT_NONBLOCKING WICONNECT_MALLOC_ARGS);
dan_ackme 9:b6218dc218ad 77
dan_ackme 9:b6218dc218ad 78 /**
dan_ackme 9:b6218dc218ad 79 *
dan_ackme 9:b6218dc218ad 80 *
dan_ackme 9:b6218dc218ad 81 * WiConnect class constructor
dan_ackme 9:b6218dc218ad 82 *
dan_ackme 9:b6218dc218ad 83 * @note This should only be called once within a program as the WiConnect
dan_ackme 9:b6218dc218ad 84 * library is implemented as a singleton.
dan_ackme 9:b6218dc218ad 85 *
dan_ackme 9:b6218dc218ad 86 * @note This is the recommended construstor as it supplies the WiConnect library with an
dan_ackme 9:b6218dc218ad 87 * internal buffer. Most API calls require the internal buffer.
dan_ackme 9:b6218dc218ad 88 *
dan_ackme 9:b6218dc218ad 89 * @param[in] serialConfig The serial (i.e. UART) configuration connected to a WiConnect module.
dan_ackme 9:b6218dc218ad 90 * @param[in] internalBuffer Optional, a user allocated buffer. See @ref setting_alloc
dan_ackme 9:b6218dc218ad 91 * @param[in] internalBufferSize The size of the internal buffer. If internalBuffer is NULL, then this size will be dynamically allocated. See @ref setting_alloc
dan_ackme 9:b6218dc218ad 92 * @param[in] reset Optional, The pin connected to the WiConnect module reset signal. Default: No connection
dan_ackme 9:b6218dc218ad 93 * @param[in] wake Optional, The pin connected to the WiConnect module wake signal. Default: No connection
dan_ackme 9:b6218dc218ad 94 * @param[in] nonBlocking Optional, indicates if the API blocking mode. See @ref setting_blocking_modes
dan_ackme 9:b6218dc218ad 95 */
dan_ackme 0:ea85c4bb5e1f 96 Wiconnect(const SerialConfig &serialConfig, void *internalBuffer, int internalBufferSize, Pin reset = PIN_NC, Pin wake = PIN_NC, bool nonBlocking = WICONNECT_DEFAULT_NONBLOCKING WICONNECT_MALLOC_ARGS);
dan_ackme 0:ea85c4bb5e1f 97 ~Wiconnect();
dan_ackme 0:ea85c4bb5e1f 98
dan_ackme 9:b6218dc218ad 99 /**
dan_ackme 9:b6218dc218ad 100 * @ingroup api_core_misc
dan_ackme 9:b6218dc218ad 101 *
dan_ackme 9:b6218dc218ad 102 * Get instance of previously instantiated Wiconnect Library
dan_ackme 9:b6218dc218ad 103 *
dan_ackme 9:b6218dc218ad 104 * @return Pointer to instance of @ref Wiconnect Library.
dan_ackme 9:b6218dc218ad 105 */
dan_ackme 0:ea85c4bb5e1f 106 static Wiconnect* getInstance();
dan_ackme 0:ea85c4bb5e1f 107
dan_ackme 9:b6218dc218ad 108 /**
dan_ackme 9:b6218dc218ad 109 * @ingroup api_core_misc
dan_ackme 9:b6218dc218ad 110 *
dan_ackme 9:b6218dc218ad 111 * Initialize library and communication link with WiConnect WiFi module.
dan_ackme 9:b6218dc218ad 112 *
dan_ackme 9:b6218dc218ad 113 * @note This function is always blocking regardless of configured mode.
dan_ackme 9:b6218dc218ad 114 *
dan_ackme 9:b6218dc218ad 115 * @param[in] bringNetworkUp Flag indicating if the module should try to bring the network up upon initialization.
dan_ackme 9:b6218dc218ad 116 * @return Result of initialization. See @ref WiconnectResult
dan_ackme 9:b6218dc218ad 117 */
dan_ackme 0:ea85c4bb5e1f 118 WiconnectResult init(bool bringNetworkUp);
dan_ackme 9:b6218dc218ad 119
dan_ackme 9:b6218dc218ad 120 /**
dan_ackme 9:b6218dc218ad 121 * @ingroup api_core_misc
dan_ackme 9:b6218dc218ad 122 *
dan_ackme 9:b6218dc218ad 123 * De-initialize library.
dan_ackme 9:b6218dc218ad 124 */
dan_ackme 0:ea85c4bb5e1f 125 void deinit();
dan_ackme 9:b6218dc218ad 126
dan_ackme 9:b6218dc218ad 127 /**
dan_ackme 9:b6218dc218ad 128 * @ingroup api_core_misc
dan_ackme 9:b6218dc218ad 129 *
dan_ackme 9:b6218dc218ad 130 * Return TRUE if library is able to communicated with WiConnect WiFi module.
dan_ackme 9:b6218dc218ad 131 * FALSE else.
dan_ackme 9:b6218dc218ad 132 *
dan_ackme 9:b6218dc218ad 133 * @return TRUE if library can communicate with WiFi module, FALSE else.
dan_ackme 9:b6218dc218ad 134 */
dan_ackme 0:ea85c4bb5e1f 135 bool isInitialized();
dan_ackme 9:b6218dc218ad 136
dan_ackme 9:b6218dc218ad 137 /**
dan_ackme 9:b6218dc218ad 138 * @ingroup api_core_misc
dan_ackme 9:b6218dc218ad 139 *
dan_ackme 9:b6218dc218ad 140 * Toggle the WiConnect WiFi module reset signal.
dan_ackme 9:b6218dc218ad 141 *
dan_ackme 9:b6218dc218ad 142 * @note This only resets the module if the library was instantiated with the 'reset' pin
dan_ackme 9:b6218dc218ad 143 * parameter in the Wiconnect::Wiconnect constructor.
dan_ackme 9:b6218dc218ad 144 * @note This method is always blocking. A small (1s) delay is added to ensure the module
dan_ackme 9:b6218dc218ad 145 * has returned from reset and ready.
dan_ackme 9:b6218dc218ad 146 *
dan_ackme 9:b6218dc218ad 147 * @return Result of method. See @ref WiconnectResult
dan_ackme 9:b6218dc218ad 148 */
dan_ackme 0:ea85c4bb5e1f 149 WiconnectResult reset();
dan_ackme 9:b6218dc218ad 150
dan_ackme 9:b6218dc218ad 151 /**
dan_ackme 9:b6218dc218ad 152 * @ingroup api_core_misc
dan_ackme 9:b6218dc218ad 153 *
dan_ackme 9:b6218dc218ad 154 * Toggle the WiConnect WiFi moduel wakeup signal.
dan_ackme 9:b6218dc218ad 155 *
dan_ackme 9:b6218dc218ad 156 * @note This only wakes the module if the library was instantiated with the 'wake' pin
dan_ackme 9:b6218dc218ad 157 * parameter in the Wiconnect::Wiconnect constructor.
dan_ackme 9:b6218dc218ad 158 * @note This method is always blocking.
dan_ackme 9:b6218dc218ad 159 *
dan_ackme 9:b6218dc218ad 160 * @return Result of method. See @ref WiconnectResult
dan_ackme 9:b6218dc218ad 161 */
dan_ackme 0:ea85c4bb5e1f 162 WiconnectResult wakeup();
dan_ackme 9:b6218dc218ad 163
dan_ackme 9:b6218dc218ad 164 /**
dan_ackme 9:b6218dc218ad 165 * @ingroup api_core_misc
dan_ackme 9:b6218dc218ad 166 *
dan_ackme 9:b6218dc218ad 167 * Flush any received data in serial RX buffer and terminate any commands on WiConnect WiFi module.
dan_ackme 9:b6218dc218ad 168 */
dan_ackme 0:ea85c4bb5e1f 169 void flush(int delayMs = 500);
dan_ackme 0:ea85c4bb5e1f 170
dan_ackme 9:b6218dc218ad 171 /**
dan_ackme 9:b6218dc218ad 172 * @ingroup api_core_misc
dan_ackme 9:b6218dc218ad 173 *
dan_ackme 9:b6218dc218ad 174 * Return current version of WiConnect WiFi module.
dan_ackme 9:b6218dc218ad 175 */
dan_ackme 0:ea85c4bb5e1f 176 WiconnectResult getVersion(char *versionBuffer = NULL, int versionBufferSize = 0, const Callback &completeCallback = Callback());
dan_ackme 0:ea85c4bb5e1f 177
dan_ackme 9:b6218dc218ad 178 /**
dan_ackme 9:b6218dc218ad 179 * @ingroup api_core_send_command
dan_ackme 9:b6218dc218ad 180 *
dan_ackme 9:b6218dc218ad 181 * @brief Send command to WiConnect WiFi module
dan_ackme 9:b6218dc218ad 182 * Refer to @ref send_command_desc for more info
dan_ackme 9:b6218dc218ad 183 */
dan_ackme 0:ea85c4bb5e1f 184 WiconnectResult sendCommand(const Callback &completeCallback, char *responseBuffer, int responseBufferLen,
dan_ackme 0:ea85c4bb5e1f 185 int timeoutMs, const ReaderFunc &reader, void *user, const char *cmd, va_list vaList);
dan_ackme 9:b6218dc218ad 186 /**
dan_ackme 9:b6218dc218ad 187 * @ingroup api_core_send_command
dan_ackme 9:b6218dc218ad 188 *
dan_ackme 9:b6218dc218ad 189 * @brief Send command to WiConnect WiFi module
dan_ackme 9:b6218dc218ad 190 * Refer to @ref send_command_desc for more info
dan_ackme 9:b6218dc218ad 191 */
dan_ackme 0:ea85c4bb5e1f 192 WiconnectResult sendCommand(char *responseBuffer, int responseBufferLen, int timeoutMs, const ReaderFunc &reader,
dan_ackme 0:ea85c4bb5e1f 193 void *user, const char *cmd, va_list vaList);
dan_ackme 9:b6218dc218ad 194
dan_ackme 9:b6218dc218ad 195 /**
dan_ackme 9:b6218dc218ad 196 * @ingroup api_core_send_command
dan_ackme 9:b6218dc218ad 197 *
dan_ackme 9:b6218dc218ad 198 * @brief Send command to WiConnect WiFi module
dan_ackme 9:b6218dc218ad 199 * Refer to @ref send_command_desc for more info
dan_ackme 9:b6218dc218ad 200 *
dan_ackme 9:b6218dc218ad 201 * @note This method supports variable arguments
dan_ackme 9:b6218dc218ad 202 *
dan_ackme 9:b6218dc218ad 203 */
dan_ackme 0:ea85c4bb5e1f 204 WiconnectResult sendCommand(char *responseBuffer, int responseBufferLen, int timeoutMs, const ReaderFunc &reader,
dan_ackme 0:ea85c4bb5e1f 205 void *user, const char *cmd, ...);
dan_ackme 9:b6218dc218ad 206
dan_ackme 9:b6218dc218ad 207 /**
dan_ackme 9:b6218dc218ad 208 * @ingroup api_core_send_command
dan_ackme 9:b6218dc218ad 209 *
dan_ackme 9:b6218dc218ad 210 * @brief Send command to WiConnect WiFi module
dan_ackme 9:b6218dc218ad 211 * Refer to @ref send_command_desc for more info
dan_ackme 9:b6218dc218ad 212 *
dan_ackme 9:b6218dc218ad 213 * @note This method supports variable arguments
dan_ackme 9:b6218dc218ad 214 *
dan_ackme 9:b6218dc218ad 215 */
dan_ackme 0:ea85c4bb5e1f 216 WiconnectResult sendCommand( int timeoutMs, const ReaderFunc &reader, void *user, const char *cmd, ...);
dan_ackme 9:b6218dc218ad 217
dan_ackme 9:b6218dc218ad 218 /**
dan_ackme 9:b6218dc218ad 219 * @ingroup api_core_send_command
dan_ackme 9:b6218dc218ad 220 *
dan_ackme 9:b6218dc218ad 221 * @brief Send command to WiConnect WiFi module
dan_ackme 9:b6218dc218ad 222 * Refer to @ref send_command_desc for more info
dan_ackme 9:b6218dc218ad 223 *
dan_ackme 9:b6218dc218ad 224 * @note This method supports variable arguments
dan_ackme 9:b6218dc218ad 225 *
dan_ackme 9:b6218dc218ad 226 */
dan_ackme 0:ea85c4bb5e1f 227 WiconnectResult sendCommand(const ReaderFunc &reader, void *user, const char *cmd, ...);
dan_ackme 9:b6218dc218ad 228
dan_ackme 9:b6218dc218ad 229 /**
dan_ackme 9:b6218dc218ad 230 * @ingroup api_core_send_command
dan_ackme 9:b6218dc218ad 231 *
dan_ackme 9:b6218dc218ad 232 * @brief Send command to WiConnect WiFi module
dan_ackme 9:b6218dc218ad 233 * Refer to @ref send_command_desc for more info
dan_ackme 9:b6218dc218ad 234 *
dan_ackme 9:b6218dc218ad 235 * @note This method supports variable arguments
dan_ackme 9:b6218dc218ad 236 *
dan_ackme 9:b6218dc218ad 237 */
dan_ackme 0:ea85c4bb5e1f 238 WiconnectResult sendCommand(char *responseBuffer, int responseBufferLen, int timeoutMs, const char *cmd, ...);
dan_ackme 9:b6218dc218ad 239
dan_ackme 9:b6218dc218ad 240 /**
dan_ackme 9:b6218dc218ad 241 * @ingroup api_core_send_command
dan_ackme 9:b6218dc218ad 242 *
dan_ackme 9:b6218dc218ad 243 * @brief Send command to WiConnect WiFi module
dan_ackme 9:b6218dc218ad 244 * Refer to @ref send_command_desc for more info
dan_ackme 9:b6218dc218ad 245 *
dan_ackme 9:b6218dc218ad 246 * @note This method supports variable arguments
dan_ackme 9:b6218dc218ad 247 *
dan_ackme 9:b6218dc218ad 248 */
dan_ackme 0:ea85c4bb5e1f 249 WiconnectResult sendCommand(const Callback &completeCallback, char *responseBuffer, int responseBufferLen, const char *cmd, ...);
dan_ackme 9:b6218dc218ad 250
dan_ackme 9:b6218dc218ad 251 /**
dan_ackme 9:b6218dc218ad 252 * @ingroup api_core_send_command
dan_ackme 9:b6218dc218ad 253 *
dan_ackme 9:b6218dc218ad 254 * @brief Send command to WiConnect WiFi module
dan_ackme 9:b6218dc218ad 255 * Refer to @ref send_command_desc for more info
dan_ackme 9:b6218dc218ad 256 *
dan_ackme 9:b6218dc218ad 257 * @note This method supports variable arguments
dan_ackme 9:b6218dc218ad 258 *
dan_ackme 9:b6218dc218ad 259 */
dan_ackme 0:ea85c4bb5e1f 260 WiconnectResult sendCommand(char *responseBuffer, int responseBufferLen, const char *cmd, ...);
dan_ackme 9:b6218dc218ad 261
dan_ackme 9:b6218dc218ad 262 /**
dan_ackme 9:b6218dc218ad 263 * @ingroup api_core_send_command
dan_ackme 9:b6218dc218ad 264 *
dan_ackme 9:b6218dc218ad 265 * @brief Send command to WiConnect WiFi module
dan_ackme 9:b6218dc218ad 266 * Refer to @ref send_command_desc for more info
dan_ackme 9:b6218dc218ad 267 *
dan_ackme 9:b6218dc218ad 268 * @note This method supports variable arguments
dan_ackme 9:b6218dc218ad 269 *
dan_ackme 9:b6218dc218ad 270 */
dan_ackme 0:ea85c4bb5e1f 271 WiconnectResult sendCommand(const Callback &completeCallback, const char *cmd, ...);
dan_ackme 9:b6218dc218ad 272
dan_ackme 9:b6218dc218ad 273 /**
dan_ackme 9:b6218dc218ad 274 * @ingroup api_core_send_command
dan_ackme 9:b6218dc218ad 275 *
dan_ackme 9:b6218dc218ad 276 * @brief Send command to WiConnect WiFi module
dan_ackme 9:b6218dc218ad 277 * Refer to @ref send_command_desc for more info
dan_ackme 9:b6218dc218ad 278 *
dan_ackme 9:b6218dc218ad 279 * @note This method supports variable arguments
dan_ackme 9:b6218dc218ad 280 *
dan_ackme 9:b6218dc218ad 281 */
dan_ackme 0:ea85c4bb5e1f 282 WiconnectResult sendCommand(const char *cmd, ...);
dan_ackme 9:b6218dc218ad 283
dan_ackme 9:b6218dc218ad 284 /**
dan_ackme 9:b6218dc218ad 285 * @ingroup api_core_send_command
dan_ackme 9:b6218dc218ad 286 *
dan_ackme 9:b6218dc218ad 287 * @brief Send command to WiConnect WiFi module
dan_ackme 9:b6218dc218ad 288 * Refer to @ref send_command_desc for more info
dan_ackme 9:b6218dc218ad 289 *
dan_ackme 9:b6218dc218ad 290 * @note This method supports variable arguments
dan_ackme 9:b6218dc218ad 291 *
dan_ackme 9:b6218dc218ad 292 */
dan_ackme 0:ea85c4bb5e1f 293 WiconnectResult sendCommand(const Callback &completeCallback, int timeoutMs, const char *cmd, ...);
dan_ackme 9:b6218dc218ad 294
dan_ackme 9:b6218dc218ad 295 /**
dan_ackme 9:b6218dc218ad 296 * @ingroup api_core_send_command
dan_ackme 9:b6218dc218ad 297 *
dan_ackme 9:b6218dc218ad 298 * @brief Send command to WiConnect WiFi module
dan_ackme 9:b6218dc218ad 299 * Refer to @ref send_command_desc for more info
dan_ackme 9:b6218dc218ad 300 *
dan_ackme 9:b6218dc218ad 301 * @note This method supports variable arguments
dan_ackme 9:b6218dc218ad 302 *
dan_ackme 9:b6218dc218ad 303 */
dan_ackme 0:ea85c4bb5e1f 304 WiconnectResult sendCommand(int timeoutMs, const char *cmd, ...);
dan_ackme 9:b6218dc218ad 305
dan_ackme 9:b6218dc218ad 306 /**
dan_ackme 9:b6218dc218ad 307 * @ingroup api_core_send_command
dan_ackme 9:b6218dc218ad 308 *
dan_ackme 9:b6218dc218ad 309 * @brief Send command to WiConnect WiFi module
dan_ackme 9:b6218dc218ad 310 * Refer to @ref send_command_desc for more info
dan_ackme 9:b6218dc218ad 311 *
dan_ackme 9:b6218dc218ad 312 */
dan_ackme 0:ea85c4bb5e1f 313 WiconnectResult sendCommand(const char *cmd, va_list vaList);
dan_ackme 0:ea85c4bb5e1f 314
dan_ackme 9:b6218dc218ad 315 /**
dan_ackme 9:b6218dc218ad 316 * @ingroup api_core_misc
dan_ackme 9:b6218dc218ad 317 *
dan_ackme 9:b6218dc218ad 318 * When the WiConnect WiFi module returns a response, it contains a
dan_ackme 9:b6218dc218ad 319 * response code in the header. This function converts the previous response code
dan_ackme 9:b6218dc218ad 320 * to a readable string.
dan_ackme 9:b6218dc218ad 321 */
dan_ackme 0:ea85c4bb5e1f 322 const char* getLastCommandResponseCodeStr();
dan_ackme 9:b6218dc218ad 323
dan_ackme 9:b6218dc218ad 324 /**
dan_ackme 9:b6218dc218ad 325 * @ingroup api_core_misc
dan_ackme 9:b6218dc218ad 326 *
dan_ackme 9:b6218dc218ad 327 * Return the length in bytes of the previous response.
dan_ackme 9:b6218dc218ad 328 */
dan_ackme 0:ea85c4bb5e1f 329 uint16_t getLastCommandResponseLength();
dan_ackme 9:b6218dc218ad 330
dan_ackme 9:b6218dc218ad 331 /**
dan_ackme 9:b6218dc218ad 332 * @ingroup api_core_misc
dan_ackme 9:b6218dc218ad 333 *
dan_ackme 9:b6218dc218ad 334 * Return pointer to internal response buffer.
dan_ackme 9:b6218dc218ad 335 */
dan_ackme 0:ea85c4bb5e1f 336 char* getResponseBuffer();
dan_ackme 9:b6218dc218ad 337
dan_ackme 9:b6218dc218ad 338 /**
dan_ackme 9:b6218dc218ad 339 * @ingroup api_core_misc
dan_ackme 9:b6218dc218ad 340 *
dan_ackme 9:b6218dc218ad 341 * Helper method to convert previous response to uint32
dan_ackme 9:b6218dc218ad 342 */
dan_ackme 0:ea85c4bb5e1f 343 WiconnectResult responseToUint32(uint32_t *uint32Ptr);
dan_ackme 9:b6218dc218ad 344
dan_ackme 9:b6218dc218ad 345 /**
dan_ackme 9:b6218dc218ad 346 * @ingroup api_core_misc
dan_ackme 9:b6218dc218ad 347 *
dan_ackme 9:b6218dc218ad 348 * Helper method to convert previous response to int32
dan_ackme 9:b6218dc218ad 349 */
dan_ackme 0:ea85c4bb5e1f 350 WiconnectResult responseToInt32(int32_t *int32Ptr);
dan_ackme 0:ea85c4bb5e1f 351
dan_ackme 9:b6218dc218ad 352 /**
dan_ackme 9:b6218dc218ad 353 * @ingroup api_core_send_command
dan_ackme 9:b6218dc218ad 354 *
dan_ackme 9:b6218dc218ad 355 * Check the status of the currently executing command.
dan_ackme 9:b6218dc218ad 356 *
dan_ackme 9:b6218dc218ad 357 * Refer to @ref WiconnectResult for more information about the return code.
dan_ackme 9:b6218dc218ad 358 *
dan_ackme 9:b6218dc218ad 359 * @note This command is only applicable for non-blocking mode. Refer to @ref setting_blocking_modes.
dan_ackme 9:b6218dc218ad 360 */
dan_ackme 0:ea85c4bb5e1f 361 WiconnectResult checkCurrentCommand();
dan_ackme 9:b6218dc218ad 362
dan_ackme 9:b6218dc218ad 363 /**
dan_ackme 9:b6218dc218ad 364 * @ingroup api_core_send_command
dan_ackme 9:b6218dc218ad 365 *
dan_ackme 9:b6218dc218ad 366 * Stop the currently executing command.
dan_ackme 9:b6218dc218ad 367 *
dan_ackme 9:b6218dc218ad 368 * @note This command is only applicable for non-blocking mode. Refer to @ref setting_blocking_modes.
dan_ackme 9:b6218dc218ad 369 */
dan_ackme 0:ea85c4bb5e1f 370 void stopCurrentCommand();
dan_ackme 9:b6218dc218ad 371
dan_ackme 9:b6218dc218ad 372 /**
dan_ackme 9:b6218dc218ad 373 * @ingroup api_core_settings
dan_ackme 9:b6218dc218ad 374 *
dan_ackme 9:b6218dc218ad 375 * Sets the default maximum time an API method may execute before
dan_ackme 9:b6218dc218ad 376 * terminating and return a timeout error code.
dan_ackme 9:b6218dc218ad 377 *
dan_ackme 9:b6218dc218ad 378 * @note All API method (execpt some sendCommand()) use this default value.
dan_ackme 9:b6218dc218ad 379 */
dan_ackme 0:ea85c4bb5e1f 380 void setCommandDefaultTimeout(int timeoutMs);
dan_ackme 9:b6218dc218ad 381
dan_ackme 9:b6218dc218ad 382 /**
dan_ackme 9:b6218dc218ad 383 * @ingroup api_core_settings
dan_ackme 9:b6218dc218ad 384 *
dan_ackme 9:b6218dc218ad 385 * Returns the current default maximum API execution time.
dan_ackme 9:b6218dc218ad 386 */
dan_ackme 0:ea85c4bb5e1f 387 int getCommandDefaultTimeout();
dan_ackme 0:ea85c4bb5e1f 388
dan_ackme 9:b6218dc218ad 389 /**
dan_ackme 9:b6218dc218ad 390 * @ingroup api_core_settings
dan_ackme 9:b6218dc218ad 391 *
dan_ackme 9:b6218dc218ad 392 * Sets a mapping function used to convert from a host Pin to WiConnect WiFi module GPIO.
dan_ackme 9:b6218dc218ad 393 */
dan_ackme 0:ea85c4bb5e1f 394 void setPinToGpioMapper(PinToGpioMapper mapper);
dan_ackme 0:ea85c4bb5e1f 395
dan_ackme 9:b6218dc218ad 396 /**
dan_ackme 9:b6218dc218ad 397 * @ingroup api_core_settings
dan_ackme 9:b6218dc218ad 398 *
dan_ackme 9:b6218dc218ad 399 * Sets callback function used to debug WiConnect WiFi module RX/TX serial data.
dan_ackme 9:b6218dc218ad 400 */
dan_ackme 0:ea85c4bb5e1f 401 void setDebugLogger(LogFunc logFunc);
dan_ackme 9:b6218dc218ad 402
dan_ackme 9:b6218dc218ad 403 /**
dan_ackme 9:b6218dc218ad 404 * @ingroup api_core_settings
dan_ackme 9:b6218dc218ad 405 *
dan_ackme 9:b6218dc218ad 406 * Sets callback used when Wiconnect Library hits and internal assertion.
dan_ackme 9:b6218dc218ad 407 *
dan_ackme 9:b6218dc218ad 408 * @note This is mainly for debugging. There's nothing the callback can do to fix the assertion.
dan_ackme 9:b6218dc218ad 409 */
dan_ackme 6:8a87a59d0d21 410 void setAssertLogger(LogFunc assertLogFunc);
dan_ackme 0:ea85c4bb5e1f 411
dan_ackme 0:ea85c4bb5e1f 412 #ifdef WICONNECT_ASYNC_TIMER_ENABLED
dan_ackme 9:b6218dc218ad 413 /**
dan_ackme 9:b6218dc218ad 414 * @ingroup api_core_send_command
dan_ackme 9:b6218dc218ad 415 *
dan_ackme 9:b6218dc218ad 416 * Add user command to be executed asynchronously.
dan_ackme 9:b6218dc218ad 417 *
dan_ackme 9:b6218dc218ad 418 */
dan_ackme 0:ea85c4bb5e1f 419 WiconnectResult enqueueCommand(QueuedCommand *command, const Callback &commandCompleteHandler = Callback());
dan_ackme 9:b6218dc218ad 420
dan_ackme 9:b6218dc218ad 421 /**
dan_ackme 9:b6218dc218ad 422 * @ingroup api_core_settings
dan_ackme 9:b6218dc218ad 423 *
dan_ackme 9:b6218dc218ad 424 * Set the period at which an asynchronous command should be processed.
dan_ackme 9:b6218dc218ad 425 */
dan_ackme 0:ea85c4bb5e1f 426 void setCommandProcessingPeriod(uint32_t periodMs);
dan_ackme 0:ea85c4bb5e1f 427 #endif
dan_ackme 0:ea85c4bb5e1f 428
dan_ackme 9:b6218dc218ad 429
dan_ackme 9:b6218dc218ad 430 /**
dan_ackme 9:b6218dc218ad 431 * @ingroup conversion_util
dan_ackme 9:b6218dc218ad 432 *
dan_ackme 9:b6218dc218ad 433 * Converts a @ref WiconnectResult to string representation.
dan_ackme 9:b6218dc218ad 434 */
dan_ackme 9:b6218dc218ad 435 static const char* getWiconnectResultStr(WiconnectResult wiconnectResult);
dan_ackme 9:b6218dc218ad 436
dan_ackme 0:ea85c4bb5e1f 437 protected:
dan_ackme 0:ea85c4bb5e1f 438
dan_ackme 0:ea85c4bb5e1f 439 #ifdef WICONNECT_ENABLE_MALLOC
dan_ackme 0:ea85c4bb5e1f 440 void* (*_malloc)(size_t);
dan_ackme 0:ea85c4bb5e1f 441 void (*_free)(void *);
dan_ackme 0:ea85c4bb5e1f 442 friend class QueuedCommand;
dan_ackme 0:ea85c4bb5e1f 443 friend class WiconnectSerial;
dan_ackme 0:ea85c4bb5e1f 444 friend class ScanResult;
dan_ackme 6:8a87a59d0d21 445 friend class ScanResultList;
dan_ackme 0:ea85c4bb5e1f 446 friend class Socket;
dan_ackme 0:ea85c4bb5e1f 447 friend class File;
dan_ackme 0:ea85c4bb5e1f 448 #endif
dan_ackme 0:ea85c4bb5e1f 449
dan_ackme 0:ea85c4bb5e1f 450 wiconnect::WiconnectSerial serial;
dan_ackme 0:ea85c4bb5e1f 451 wiconnect::Gpio resetGpio;
dan_ackme 0:ea85c4bb5e1f 452 wiconnect::Gpio wakeGpio;
dan_ackme 0:ea85c4bb5e1f 453
dan_ackme 0:ea85c4bb5e1f 454 volatile bool commandExecuting;
dan_ackme 0:ea85c4bb5e1f 455 bool initialized;
dan_ackme 0:ea85c4bb5e1f 456 bool nonBlocking;
dan_ackme 0:ea85c4bb5e1f 457
dan_ackme 0:ea85c4bb5e1f 458 PinToGpioMapper pinToGpioMapper;
dan_ackme 0:ea85c4bb5e1f 459
dan_ackme 0:ea85c4bb5e1f 460 char *internalBuffer;
dan_ackme 0:ea85c4bb5e1f 461 int internalBufferSize;
dan_ackme 0:ea85c4bb5e1f 462 bool internalBufferAlloc;
dan_ackme 0:ea85c4bb5e1f 463 uint8_t internalProcessingState;
dan_ackme 0:ea85c4bb5e1f 464 void *currentCommandId;
dan_ackme 0:ea85c4bb5e1f 465
dan_ackme 0:ea85c4bb5e1f 466 wiconnect::TimeoutTimer timeoutTimer;
dan_ackme 0:ea85c4bb5e1f 467 int defaultTimeoutMs;
dan_ackme 0:ea85c4bb5e1f 468
dan_ackme 0:ea85c4bb5e1f 469 uint8_t commandHeaderBuffer[32];
dan_ackme 0:ea85c4bb5e1f 470 char commandFormatBuffer[WICONNECT_MAX_CMD_SIZE];
dan_ackme 0:ea85c4bb5e1f 471 uint8_t commandContext[96];
dan_ackme 0:ea85c4bb5e1f 472
dan_ackme 0:ea85c4bb5e1f 473 void prepare(void *internalBuffer, int internalBufferSize, bool nonBlocking);
dan_ackme 0:ea85c4bb5e1f 474 WiconnectResult inline receiveResponse();
dan_ackme 0:ea85c4bb5e1f 475 WiconnectResult inline receivePacket();
dan_ackme 0:ea85c4bb5e1f 476 void issueCommandCallback(WiconnectResult result);
dan_ackme 0:ea85c4bb5e1f 477
dan_ackme 6:8a87a59d0d21 478 LogFunc debugLogger;
dan_ackme 6:8a87a59d0d21 479 LogFunc assertLogger;
dan_ackme 0:ea85c4bb5e1f 480 void debugLog(const char *msg, ...);
dan_ackme 0:ea85c4bb5e1f 481
dan_ackme 0:ea85c4bb5e1f 482 #ifdef WICONNECT_ASYNC_TIMER_ENABLED
dan_ackme 0:ea85c4bb5e1f 483 wiconnect::PeriodicTimer commandProcessorTimer;
dan_ackme 0:ea85c4bb5e1f 484 uint32_t commandProcessingPeriod;
dan_ackme 0:ea85c4bb5e1f 485 CommandQueue commandQueue;
dan_ackme 0:ea85c4bb5e1f 486 wiconnect::QueuedCommand *currentQueuedCommand;
dan_ackme 0:ea85c4bb5e1f 487
dan_ackme 0:ea85c4bb5e1f 488 void commandProcessingTimerHandler(void);
dan_ackme 0:ea85c4bb5e1f 489 void processNextQueuedCommand();
dan_ackme 0:ea85c4bb5e1f 490 void checkQueuedCommandTimeout();
dan_ackme 0:ea85c4bb5e1f 491 #endif
dan_ackme 0:ea85c4bb5e1f 492
dan_ackme 0:ea85c4bb5e1f 493 friend class NetworkInterface;
dan_ackme 0:ea85c4bb5e1f 494 friend class SocketInterface;
dan_ackme 0:ea85c4bb5e1f 495 friend class FileInterface;
dan_ackme 0:ea85c4bb5e1f 496 };
dan_ackme 0:ea85c4bb5e1f 497
dan_ackme 0:ea85c4bb5e1f 498 }