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
WiconnectInterface.h@11:ea484e1b7fc4, 2014-08-12 (annotated)
- Committer:
- dan_ackme
- Date:
- Tue Aug 12 02:34:46 2014 -0700
- Revision:
- 11:ea484e1b7fc4
- Parent:
- 9:b6218dc218ad
- Child:
- 13:2b51f5267c92
updated documnetation
Who changed what in which revision?
User | Revision | Line number | New 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 | 11:ea484e1b7fc4 | 39 | /** |
dan_ackme | 11:ea484e1b7fc4 | 40 | * @namespace wiconnect |
dan_ackme | 11:ea484e1b7fc4 | 41 | */ |
dan_ackme | 0:ea85c4bb5e1f | 42 | namespace wiconnect { |
dan_ackme | 0:ea85c4bb5e1f | 43 | |
dan_ackme | 0:ea85c4bb5e1f | 44 | |
dan_ackme | 9:b6218dc218ad | 45 | /** |
dan_ackme | 11:ea484e1b7fc4 | 46 | * @ingroup types_core |
dan_ackme | 9:b6218dc218ad | 47 | * |
dan_ackme | 11:ea484e1b7fc4 | 48 | * @brief The root WiConnect library class. This class |
dan_ackme | 9:b6218dc218ad | 49 | * inheriets all WiConnect functionality. |
dan_ackme | 9:b6218dc218ad | 50 | * |
dan_ackme | 9:b6218dc218ad | 51 | * This class is implemented as a 'singleton'. This means it |
dan_ackme | 9:b6218dc218ad | 52 | * only needs to be instantiated once. Subsequent class may either |
dan_ackme | 9:b6218dc218ad | 53 | * use the class instance or the static function: @ref Wiconnect::getInstance() |
dan_ackme | 9:b6218dc218ad | 54 | * |
dan_ackme | 9:b6218dc218ad | 55 | */ |
dan_ackme | 0:ea85c4bb5e1f | 56 | class Wiconnect : public NetworkInterface, |
dan_ackme | 0:ea85c4bb5e1f | 57 | public SocketInterface, |
dan_ackme | 0:ea85c4bb5e1f | 58 | public FileInterface |
dan_ackme | 0:ea85c4bb5e1f | 59 | { |
dan_ackme | 0:ea85c4bb5e1f | 60 | public: |
dan_ackme | 9:b6218dc218ad | 61 | |
dan_ackme | 9:b6218dc218ad | 62 | /** |
dan_ackme | 11:ea484e1b7fc4 | 63 | * @ingroup types_core |
dan_ackme | 9:b6218dc218ad | 64 | * |
dan_ackme | 11:ea484e1b7fc4 | 65 | * @brief WiConnect class constructor |
dan_ackme | 9:b6218dc218ad | 66 | * |
dan_ackme | 9:b6218dc218ad | 67 | * @note This should only be called once within a program as the WiConnect |
dan_ackme | 9:b6218dc218ad | 68 | * library is implemented as a singleton. |
dan_ackme | 9:b6218dc218ad | 69 | * |
dan_ackme | 9:b6218dc218ad | 70 | * @note If this constructor is used, then all commands must be supplied with an external response buffer. |
dan_ackme | 9:b6218dc218ad | 71 | * This means most the API functions will not work as they use the internal buffer. |
dan_ackme | 9:b6218dc218ad | 72 | * It's recommended to use the other constructor that supplies an internal buffer. See @ref setting_alloc |
dan_ackme | 9:b6218dc218ad | 73 | * |
dan_ackme | 9:b6218dc218ad | 74 | * @param[in] serialConfig The serial (i.e. UART) configuration connected to a WiConnect module. |
dan_ackme | 9:b6218dc218ad | 75 | * @param[in] reset Optional, The pin connected to the WiConnect module reset signal. Default: No connection |
dan_ackme | 9:b6218dc218ad | 76 | * @param[in] wake Optional, The pin connected to the WiConnect module wake signal. Default: No connection |
dan_ackme | 9:b6218dc218ad | 77 | * @param[in] nonBlocking Optional, indicates if the API blocking mode. See @ref setting_blocking_modes |
dan_ackme | 9:b6218dc218ad | 78 | */ |
dan_ackme | 0:ea85c4bb5e1f | 79 | Wiconnect(const SerialConfig &serialConfig, Pin reset = PIN_NC, Pin wake = PIN_NC, bool nonBlocking = WICONNECT_DEFAULT_NONBLOCKING WICONNECT_MALLOC_ARGS); |
dan_ackme | 9:b6218dc218ad | 80 | |
dan_ackme | 9:b6218dc218ad | 81 | /** |
dan_ackme | 11:ea484e1b7fc4 | 82 | * @ingroup types_core |
dan_ackme | 9:b6218dc218ad | 83 | * |
dan_ackme | 11:ea484e1b7fc4 | 84 | * @brief WiConnect class constructor |
dan_ackme | 9:b6218dc218ad | 85 | * |
dan_ackme | 9:b6218dc218ad | 86 | * @note This should only be called once within a program as the WiConnect |
dan_ackme | 9:b6218dc218ad | 87 | * library is implemented as a singleton. |
dan_ackme | 9:b6218dc218ad | 88 | * |
dan_ackme | 9:b6218dc218ad | 89 | * @note This is the recommended construstor as it supplies the WiConnect library with an |
dan_ackme | 9:b6218dc218ad | 90 | * internal buffer. Most API calls require the internal buffer. |
dan_ackme | 9:b6218dc218ad | 91 | * |
dan_ackme | 9:b6218dc218ad | 92 | * @param[in] serialConfig The serial (i.e. UART) configuration connected to a WiConnect module. |
dan_ackme | 9:b6218dc218ad | 93 | * @param[in] internalBuffer Optional, a user allocated buffer. See @ref setting_alloc |
dan_ackme | 9:b6218dc218ad | 94 | * @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 | 95 | * @param[in] reset Optional, The pin connected to the WiConnect module reset signal. Default: No connection |
dan_ackme | 9:b6218dc218ad | 96 | * @param[in] wake Optional, The pin connected to the WiConnect module wake signal. Default: No connection |
dan_ackme | 9:b6218dc218ad | 97 | * @param[in] nonBlocking Optional, indicates if the API blocking mode. See @ref setting_blocking_modes |
dan_ackme | 9:b6218dc218ad | 98 | */ |
dan_ackme | 0:ea85c4bb5e1f | 99 | 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 | 100 | ~Wiconnect(); |
dan_ackme | 0:ea85c4bb5e1f | 101 | |
dan_ackme | 11:ea484e1b7fc4 | 102 | |
dan_ackme | 11:ea484e1b7fc4 | 103 | // ------------------------------------------------------------------------ |
dan_ackme | 11:ea484e1b7fc4 | 104 | |
dan_ackme | 11:ea484e1b7fc4 | 105 | |
dan_ackme | 9:b6218dc218ad | 106 | /** |
dan_ackme | 9:b6218dc218ad | 107 | * @ingroup api_core_misc |
dan_ackme | 9:b6218dc218ad | 108 | * |
dan_ackme | 11:ea484e1b7fc4 | 109 | * @brief Get instance of previously instantiated Wiconnect Library |
dan_ackme | 9:b6218dc218ad | 110 | * |
dan_ackme | 9:b6218dc218ad | 111 | * @return Pointer to instance of @ref Wiconnect Library. |
dan_ackme | 9:b6218dc218ad | 112 | */ |
dan_ackme | 0:ea85c4bb5e1f | 113 | static Wiconnect* getInstance(); |
dan_ackme | 0:ea85c4bb5e1f | 114 | |
dan_ackme | 9:b6218dc218ad | 115 | /** |
dan_ackme | 9:b6218dc218ad | 116 | * @ingroup api_core_misc |
dan_ackme | 9:b6218dc218ad | 117 | * |
dan_ackme | 11:ea484e1b7fc4 | 118 | * @brief Initialize library and communication link with WiConnect WiFi module. |
dan_ackme | 9:b6218dc218ad | 119 | * |
dan_ackme | 9:b6218dc218ad | 120 | * @note This function is always blocking regardless of configured mode. |
dan_ackme | 9:b6218dc218ad | 121 | * |
dan_ackme | 9:b6218dc218ad | 122 | * @param[in] bringNetworkUp Flag indicating if the module should try to bring the network up upon initialization. |
dan_ackme | 9:b6218dc218ad | 123 | * @return Result of initialization. See @ref WiconnectResult |
dan_ackme | 9:b6218dc218ad | 124 | */ |
dan_ackme | 0:ea85c4bb5e1f | 125 | WiconnectResult init(bool bringNetworkUp); |
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 | 11:ea484e1b7fc4 | 130 | * @brief De-initialize library. |
dan_ackme | 9:b6218dc218ad | 131 | */ |
dan_ackme | 0:ea85c4bb5e1f | 132 | void deinit(); |
dan_ackme | 9:b6218dc218ad | 133 | |
dan_ackme | 9:b6218dc218ad | 134 | /** |
dan_ackme | 9:b6218dc218ad | 135 | * @ingroup api_core_misc |
dan_ackme | 9:b6218dc218ad | 136 | * |
dan_ackme | 11:ea484e1b7fc4 | 137 | * @brief Return TRUE if library is able to communicated with WiConnect WiFi module. |
dan_ackme | 9:b6218dc218ad | 138 | * FALSE else. |
dan_ackme | 9:b6218dc218ad | 139 | * |
dan_ackme | 9:b6218dc218ad | 140 | * @return TRUE if library can communicate with WiFi module, FALSE else. |
dan_ackme | 9:b6218dc218ad | 141 | */ |
dan_ackme | 0:ea85c4bb5e1f | 142 | bool isInitialized(); |
dan_ackme | 9:b6218dc218ad | 143 | |
dan_ackme | 9:b6218dc218ad | 144 | /** |
dan_ackme | 9:b6218dc218ad | 145 | * @ingroup api_core_misc |
dan_ackme | 9:b6218dc218ad | 146 | * |
dan_ackme | 11:ea484e1b7fc4 | 147 | * @brief Toggle the WiConnect WiFi module reset signal. |
dan_ackme | 9:b6218dc218ad | 148 | * |
dan_ackme | 9:b6218dc218ad | 149 | * @note This only resets the module if the library was instantiated with the 'reset' pin |
dan_ackme | 9:b6218dc218ad | 150 | * parameter in the Wiconnect::Wiconnect constructor. |
dan_ackme | 9:b6218dc218ad | 151 | * @note This method is always blocking. A small (1s) delay is added to ensure the module |
dan_ackme | 9:b6218dc218ad | 152 | * has returned from reset and ready. |
dan_ackme | 9:b6218dc218ad | 153 | * |
dan_ackme | 9:b6218dc218ad | 154 | * @return Result of method. See @ref WiconnectResult |
dan_ackme | 9:b6218dc218ad | 155 | */ |
dan_ackme | 0:ea85c4bb5e1f | 156 | WiconnectResult reset(); |
dan_ackme | 9:b6218dc218ad | 157 | |
dan_ackme | 9:b6218dc218ad | 158 | /** |
dan_ackme | 9:b6218dc218ad | 159 | * @ingroup api_core_misc |
dan_ackme | 9:b6218dc218ad | 160 | * |
dan_ackme | 11:ea484e1b7fc4 | 161 | * @brief Toggle the WiConnect WiFi moduel wakeup signal. |
dan_ackme | 9:b6218dc218ad | 162 | * |
dan_ackme | 9:b6218dc218ad | 163 | * @note This only wakes the module if the library was instantiated with the 'wake' pin |
dan_ackme | 9:b6218dc218ad | 164 | * parameter in the Wiconnect::Wiconnect constructor. |
dan_ackme | 9:b6218dc218ad | 165 | * @note This method is always blocking. |
dan_ackme | 9:b6218dc218ad | 166 | * |
dan_ackme | 9:b6218dc218ad | 167 | * @return Result of method. See @ref WiconnectResult |
dan_ackme | 9:b6218dc218ad | 168 | */ |
dan_ackme | 0:ea85c4bb5e1f | 169 | WiconnectResult wakeup(); |
dan_ackme | 9:b6218dc218ad | 170 | |
dan_ackme | 9:b6218dc218ad | 171 | /** |
dan_ackme | 9:b6218dc218ad | 172 | * @ingroup api_core_misc |
dan_ackme | 9:b6218dc218ad | 173 | * |
dan_ackme | 11:ea484e1b7fc4 | 174 | * @brief Flush any received data in serial RX buffer and terminate any commands on WiConnect WiFi module. |
dan_ackme | 9:b6218dc218ad | 175 | */ |
dan_ackme | 0:ea85c4bb5e1f | 176 | void flush(int delayMs = 500); |
dan_ackme | 0:ea85c4bb5e1f | 177 | |
dan_ackme | 9:b6218dc218ad | 178 | /** |
dan_ackme | 9:b6218dc218ad | 179 | * @ingroup api_core_misc |
dan_ackme | 9:b6218dc218ad | 180 | * |
dan_ackme | 11:ea484e1b7fc4 | 181 | * @brief Return current version of WiConnect WiFi module. |
dan_ackme | 9:b6218dc218ad | 182 | */ |
dan_ackme | 0:ea85c4bb5e1f | 183 | WiconnectResult getVersion(char *versionBuffer = NULL, int versionBufferSize = 0, const Callback &completeCallback = Callback()); |
dan_ackme | 0:ea85c4bb5e1f | 184 | |
dan_ackme | 11:ea484e1b7fc4 | 185 | |
dan_ackme | 11:ea484e1b7fc4 | 186 | // ------------------------------------------------------------------------ |
dan_ackme | 11:ea484e1b7fc4 | 187 | |
dan_ackme | 11:ea484e1b7fc4 | 188 | |
dan_ackme | 9:b6218dc218ad | 189 | /** |
dan_ackme | 9:b6218dc218ad | 190 | * @ingroup api_core_send_command |
dan_ackme | 9:b6218dc218ad | 191 | * |
dan_ackme | 9:b6218dc218ad | 192 | * @brief Send command to WiConnect WiFi module |
dan_ackme | 9:b6218dc218ad | 193 | * Refer to @ref send_command_desc for more info |
dan_ackme | 9:b6218dc218ad | 194 | */ |
dan_ackme | 0:ea85c4bb5e1f | 195 | WiconnectResult sendCommand(const Callback &completeCallback, char *responseBuffer, int responseBufferLen, |
dan_ackme | 0:ea85c4bb5e1f | 196 | int timeoutMs, const ReaderFunc &reader, void *user, const char *cmd, va_list vaList); |
dan_ackme | 9:b6218dc218ad | 197 | /** |
dan_ackme | 9:b6218dc218ad | 198 | * @ingroup api_core_send_command |
dan_ackme | 9:b6218dc218ad | 199 | * |
dan_ackme | 9:b6218dc218ad | 200 | * @brief Send command to WiConnect WiFi module |
dan_ackme | 9:b6218dc218ad | 201 | * Refer to @ref send_command_desc for more info |
dan_ackme | 9:b6218dc218ad | 202 | */ |
dan_ackme | 0:ea85c4bb5e1f | 203 | WiconnectResult sendCommand(char *responseBuffer, int responseBufferLen, int timeoutMs, const ReaderFunc &reader, |
dan_ackme | 0:ea85c4bb5e1f | 204 | void *user, const char *cmd, va_list vaList); |
dan_ackme | 9:b6218dc218ad | 205 | |
dan_ackme | 9:b6218dc218ad | 206 | /** |
dan_ackme | 9:b6218dc218ad | 207 | * @ingroup api_core_send_command |
dan_ackme | 9:b6218dc218ad | 208 | * |
dan_ackme | 9:b6218dc218ad | 209 | * @brief Send command to WiConnect WiFi module |
dan_ackme | 9:b6218dc218ad | 210 | * Refer to @ref send_command_desc for more info |
dan_ackme | 9:b6218dc218ad | 211 | * |
dan_ackme | 9:b6218dc218ad | 212 | * @note This method supports variable arguments |
dan_ackme | 9:b6218dc218ad | 213 | * |
dan_ackme | 9:b6218dc218ad | 214 | */ |
dan_ackme | 0:ea85c4bb5e1f | 215 | WiconnectResult sendCommand(char *responseBuffer, int responseBufferLen, int timeoutMs, const ReaderFunc &reader, |
dan_ackme | 0:ea85c4bb5e1f | 216 | 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( int timeoutMs, 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(const ReaderFunc &reader, void *user, 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(char *responseBuffer, int responseBufferLen, int timeoutMs, 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(const Callback &completeCallback, 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(char *responseBuffer, int responseBufferLen, 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 Callback &completeCallback, 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 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(const Callback &completeCallback, 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 | * @note This method supports variable arguments |
dan_ackme | 9:b6218dc218ad | 313 | * |
dan_ackme | 9:b6218dc218ad | 314 | */ |
dan_ackme | 0:ea85c4bb5e1f | 315 | WiconnectResult sendCommand(int timeoutMs, const char *cmd, ...); |
dan_ackme | 9:b6218dc218ad | 316 | |
dan_ackme | 9:b6218dc218ad | 317 | /** |
dan_ackme | 9:b6218dc218ad | 318 | * @ingroup api_core_send_command |
dan_ackme | 9:b6218dc218ad | 319 | * |
dan_ackme | 9:b6218dc218ad | 320 | * @brief Send command to WiConnect WiFi module |
dan_ackme | 9:b6218dc218ad | 321 | * Refer to @ref send_command_desc for more info |
dan_ackme | 9:b6218dc218ad | 322 | * |
dan_ackme | 9:b6218dc218ad | 323 | */ |
dan_ackme | 0:ea85c4bb5e1f | 324 | WiconnectResult sendCommand(const char *cmd, va_list vaList); |
dan_ackme | 0:ea85c4bb5e1f | 325 | |
dan_ackme | 9:b6218dc218ad | 326 | /** |
dan_ackme | 9:b6218dc218ad | 327 | * @ingroup api_core_send_command |
dan_ackme | 9:b6218dc218ad | 328 | * |
dan_ackme | 11:ea484e1b7fc4 | 329 | * @brief Check the status of the currently executing command. |
dan_ackme | 9:b6218dc218ad | 330 | * |
dan_ackme | 9:b6218dc218ad | 331 | * Refer to @ref WiconnectResult for more information about the return code. |
dan_ackme | 9:b6218dc218ad | 332 | * |
dan_ackme | 9:b6218dc218ad | 333 | * @note This command is only applicable for non-blocking mode. Refer to @ref setting_blocking_modes. |
dan_ackme | 9:b6218dc218ad | 334 | */ |
dan_ackme | 0:ea85c4bb5e1f | 335 | WiconnectResult checkCurrentCommand(); |
dan_ackme | 9:b6218dc218ad | 336 | |
dan_ackme | 9:b6218dc218ad | 337 | /** |
dan_ackme | 9:b6218dc218ad | 338 | * @ingroup api_core_send_command |
dan_ackme | 9:b6218dc218ad | 339 | * |
dan_ackme | 11:ea484e1b7fc4 | 340 | * @brief Stop the currently executing command. |
dan_ackme | 9:b6218dc218ad | 341 | * |
dan_ackme | 9:b6218dc218ad | 342 | * @note This command is only applicable for non-blocking mode. Refer to @ref setting_blocking_modes. |
dan_ackme | 9:b6218dc218ad | 343 | */ |
dan_ackme | 0:ea85c4bb5e1f | 344 | void stopCurrentCommand(); |
dan_ackme | 9:b6218dc218ad | 345 | |
dan_ackme | 11:ea484e1b7fc4 | 346 | |
dan_ackme | 11:ea484e1b7fc4 | 347 | |
dan_ackme | 11:ea484e1b7fc4 | 348 | // ------------------------------------------------------------------------ |
dan_ackme | 11:ea484e1b7fc4 | 349 | |
dan_ackme | 11:ea484e1b7fc4 | 350 | |
dan_ackme | 11:ea484e1b7fc4 | 351 | /** |
dan_ackme | 11:ea484e1b7fc4 | 352 | * @ingroup api_core_misc |
dan_ackme | 11:ea484e1b7fc4 | 353 | * |
dan_ackme | 11:ea484e1b7fc4 | 354 | * @brief When the WiConnect WiFi module returns a response, it contains a |
dan_ackme | 11:ea484e1b7fc4 | 355 | * response code in the header. This function converts the previous response code |
dan_ackme | 11:ea484e1b7fc4 | 356 | * to a readable string. |
dan_ackme | 11:ea484e1b7fc4 | 357 | */ |
dan_ackme | 11:ea484e1b7fc4 | 358 | const char* getLastCommandResponseCodeStr(); |
dan_ackme | 11:ea484e1b7fc4 | 359 | |
dan_ackme | 11:ea484e1b7fc4 | 360 | /** |
dan_ackme | 11:ea484e1b7fc4 | 361 | * @ingroup api_core_misc |
dan_ackme | 11:ea484e1b7fc4 | 362 | * |
dan_ackme | 11:ea484e1b7fc4 | 363 | * @brief Return the length in bytes of the previous response. |
dan_ackme | 11:ea484e1b7fc4 | 364 | */ |
dan_ackme | 11:ea484e1b7fc4 | 365 | uint16_t getLastCommandResponseLength(); |
dan_ackme | 11:ea484e1b7fc4 | 366 | |
dan_ackme | 11:ea484e1b7fc4 | 367 | /** |
dan_ackme | 11:ea484e1b7fc4 | 368 | * @ingroup api_core_misc |
dan_ackme | 11:ea484e1b7fc4 | 369 | * |
dan_ackme | 11:ea484e1b7fc4 | 370 | * @brief Return pointer to internal response buffer. |
dan_ackme | 11:ea484e1b7fc4 | 371 | */ |
dan_ackme | 11:ea484e1b7fc4 | 372 | char* getResponseBuffer(); |
dan_ackme | 11:ea484e1b7fc4 | 373 | |
dan_ackme | 11:ea484e1b7fc4 | 374 | /** |
dan_ackme | 11:ea484e1b7fc4 | 375 | * @ingroup api_core_misc |
dan_ackme | 11:ea484e1b7fc4 | 376 | * |
dan_ackme | 11:ea484e1b7fc4 | 377 | * @brief Helper method to convert previous response to uint32 |
dan_ackme | 11:ea484e1b7fc4 | 378 | */ |
dan_ackme | 11:ea484e1b7fc4 | 379 | WiconnectResult responseToUint32(uint32_t *uint32Ptr); |
dan_ackme | 11:ea484e1b7fc4 | 380 | |
dan_ackme | 11:ea484e1b7fc4 | 381 | /** |
dan_ackme | 11:ea484e1b7fc4 | 382 | * @ingroup api_core_misc |
dan_ackme | 11:ea484e1b7fc4 | 383 | * |
dan_ackme | 11:ea484e1b7fc4 | 384 | * @brief Helper method to convert previous response to int32 |
dan_ackme | 11:ea484e1b7fc4 | 385 | */ |
dan_ackme | 11:ea484e1b7fc4 | 386 | WiconnectResult responseToInt32(int32_t *int32Ptr); |
dan_ackme | 11:ea484e1b7fc4 | 387 | |
dan_ackme | 11:ea484e1b7fc4 | 388 | |
dan_ackme | 11:ea484e1b7fc4 | 389 | // ------------------------------------------------------------------------ |
dan_ackme | 11:ea484e1b7fc4 | 390 | |
dan_ackme | 11:ea484e1b7fc4 | 391 | |
dan_ackme | 9:b6218dc218ad | 392 | /** |
dan_ackme | 9:b6218dc218ad | 393 | * @ingroup api_core_settings |
dan_ackme | 9:b6218dc218ad | 394 | * |
dan_ackme | 11:ea484e1b7fc4 | 395 | * @brief Sets the default maximum time an API method may execute before |
dan_ackme | 9:b6218dc218ad | 396 | * terminating and return a timeout error code. |
dan_ackme | 9:b6218dc218ad | 397 | * |
dan_ackme | 9:b6218dc218ad | 398 | * @note All API method (execpt some sendCommand()) use this default value. |
dan_ackme | 9:b6218dc218ad | 399 | */ |
dan_ackme | 0:ea85c4bb5e1f | 400 | void setCommandDefaultTimeout(int timeoutMs); |
dan_ackme | 9:b6218dc218ad | 401 | |
dan_ackme | 9:b6218dc218ad | 402 | /** |
dan_ackme | 9:b6218dc218ad | 403 | * @ingroup api_core_settings |
dan_ackme | 9:b6218dc218ad | 404 | * |
dan_ackme | 11:ea484e1b7fc4 | 405 | * @brief Returns the current default maximum API execution time. |
dan_ackme | 9:b6218dc218ad | 406 | */ |
dan_ackme | 0:ea85c4bb5e1f | 407 | int getCommandDefaultTimeout(); |
dan_ackme | 0:ea85c4bb5e1f | 408 | |
dan_ackme | 9:b6218dc218ad | 409 | /** |
dan_ackme | 9:b6218dc218ad | 410 | * @ingroup api_core_settings |
dan_ackme | 9:b6218dc218ad | 411 | * |
dan_ackme | 11:ea484e1b7fc4 | 412 | * @brief Sets a mapping function used to convert from a host Pin to WiConnect WiFi module GPIO. |
dan_ackme | 9:b6218dc218ad | 413 | */ |
dan_ackme | 0:ea85c4bb5e1f | 414 | void setPinToGpioMapper(PinToGpioMapper mapper); |
dan_ackme | 0:ea85c4bb5e1f | 415 | |
dan_ackme | 9:b6218dc218ad | 416 | /** |
dan_ackme | 9:b6218dc218ad | 417 | * @ingroup api_core_settings |
dan_ackme | 9:b6218dc218ad | 418 | * |
dan_ackme | 11:ea484e1b7fc4 | 419 | * @brief Sets callback function used to debug WiConnect WiFi module RX/TX serial data. |
dan_ackme | 9:b6218dc218ad | 420 | */ |
dan_ackme | 0:ea85c4bb5e1f | 421 | void setDebugLogger(LogFunc logFunc); |
dan_ackme | 9:b6218dc218ad | 422 | |
dan_ackme | 9:b6218dc218ad | 423 | /** |
dan_ackme | 9:b6218dc218ad | 424 | * @ingroup api_core_settings |
dan_ackme | 9:b6218dc218ad | 425 | * |
dan_ackme | 11:ea484e1b7fc4 | 426 | * @brief Sets callback used when Wiconnect Library hits and internal assertion. |
dan_ackme | 9:b6218dc218ad | 427 | * |
dan_ackme | 9:b6218dc218ad | 428 | * @note This is mainly for debugging. There's nothing the callback can do to fix the assertion. |
dan_ackme | 9:b6218dc218ad | 429 | */ |
dan_ackme | 6:8a87a59d0d21 | 430 | void setAssertLogger(LogFunc assertLogFunc); |
dan_ackme | 0:ea85c4bb5e1f | 431 | |
dan_ackme | 11:ea484e1b7fc4 | 432 | |
dan_ackme | 11:ea484e1b7fc4 | 433 | // ------------------------------------------------------------------------ |
dan_ackme | 11:ea484e1b7fc4 | 434 | |
dan_ackme | 11:ea484e1b7fc4 | 435 | |
dan_ackme | 0:ea85c4bb5e1f | 436 | #ifdef WICONNECT_ASYNC_TIMER_ENABLED |
dan_ackme | 9:b6218dc218ad | 437 | /** |
dan_ackme | 9:b6218dc218ad | 438 | * @ingroup api_core_send_command |
dan_ackme | 9:b6218dc218ad | 439 | * |
dan_ackme | 11:ea484e1b7fc4 | 440 | * @brief Add user command to be executed asynchronously. |
dan_ackme | 9:b6218dc218ad | 441 | * |
dan_ackme | 9:b6218dc218ad | 442 | */ |
dan_ackme | 0:ea85c4bb5e1f | 443 | WiconnectResult enqueueCommand(QueuedCommand *command, const Callback &commandCompleteHandler = Callback()); |
dan_ackme | 9:b6218dc218ad | 444 | |
dan_ackme | 9:b6218dc218ad | 445 | /** |
dan_ackme | 9:b6218dc218ad | 446 | * @ingroup api_core_settings |
dan_ackme | 9:b6218dc218ad | 447 | * |
dan_ackme | 11:ea484e1b7fc4 | 448 | * @brief Set the period at which an asynchronous command should be processed. |
dan_ackme | 9:b6218dc218ad | 449 | */ |
dan_ackme | 0:ea85c4bb5e1f | 450 | void setCommandProcessingPeriod(uint32_t periodMs); |
dan_ackme | 0:ea85c4bb5e1f | 451 | #endif |
dan_ackme | 0:ea85c4bb5e1f | 452 | |
dan_ackme | 9:b6218dc218ad | 453 | |
dan_ackme | 9:b6218dc218ad | 454 | /** |
dan_ackme | 9:b6218dc218ad | 455 | * @ingroup conversion_util |
dan_ackme | 9:b6218dc218ad | 456 | * |
dan_ackme | 11:ea484e1b7fc4 | 457 | * @brief Converts a @ref WiconnectResult to string representation. |
dan_ackme | 9:b6218dc218ad | 458 | */ |
dan_ackme | 9:b6218dc218ad | 459 | static const char* getWiconnectResultStr(WiconnectResult wiconnectResult); |
dan_ackme | 9:b6218dc218ad | 460 | |
dan_ackme | 0:ea85c4bb5e1f | 461 | protected: |
dan_ackme | 0:ea85c4bb5e1f | 462 | |
dan_ackme | 0:ea85c4bb5e1f | 463 | #ifdef WICONNECT_ENABLE_MALLOC |
dan_ackme | 0:ea85c4bb5e1f | 464 | void* (*_malloc)(size_t); |
dan_ackme | 0:ea85c4bb5e1f | 465 | void (*_free)(void *); |
dan_ackme | 0:ea85c4bb5e1f | 466 | friend class QueuedCommand; |
dan_ackme | 0:ea85c4bb5e1f | 467 | friend class WiconnectSerial; |
dan_ackme | 0:ea85c4bb5e1f | 468 | friend class ScanResult; |
dan_ackme | 6:8a87a59d0d21 | 469 | friend class ScanResultList; |
dan_ackme | 0:ea85c4bb5e1f | 470 | friend class Socket; |
dan_ackme | 0:ea85c4bb5e1f | 471 | friend class File; |
dan_ackme | 0:ea85c4bb5e1f | 472 | #endif |
dan_ackme | 0:ea85c4bb5e1f | 473 | |
dan_ackme | 0:ea85c4bb5e1f | 474 | wiconnect::WiconnectSerial serial; |
dan_ackme | 0:ea85c4bb5e1f | 475 | wiconnect::Gpio resetGpio; |
dan_ackme | 0:ea85c4bb5e1f | 476 | wiconnect::Gpio wakeGpio; |
dan_ackme | 0:ea85c4bb5e1f | 477 | |
dan_ackme | 0:ea85c4bb5e1f | 478 | volatile bool commandExecuting; |
dan_ackme | 0:ea85c4bb5e1f | 479 | bool initialized; |
dan_ackme | 0:ea85c4bb5e1f | 480 | bool nonBlocking; |
dan_ackme | 0:ea85c4bb5e1f | 481 | |
dan_ackme | 0:ea85c4bb5e1f | 482 | PinToGpioMapper pinToGpioMapper; |
dan_ackme | 0:ea85c4bb5e1f | 483 | |
dan_ackme | 0:ea85c4bb5e1f | 484 | char *internalBuffer; |
dan_ackme | 0:ea85c4bb5e1f | 485 | int internalBufferSize; |
dan_ackme | 0:ea85c4bb5e1f | 486 | bool internalBufferAlloc; |
dan_ackme | 0:ea85c4bb5e1f | 487 | uint8_t internalProcessingState; |
dan_ackme | 0:ea85c4bb5e1f | 488 | void *currentCommandId; |
dan_ackme | 0:ea85c4bb5e1f | 489 | |
dan_ackme | 0:ea85c4bb5e1f | 490 | wiconnect::TimeoutTimer timeoutTimer; |
dan_ackme | 0:ea85c4bb5e1f | 491 | int defaultTimeoutMs; |
dan_ackme | 0:ea85c4bb5e1f | 492 | |
dan_ackme | 0:ea85c4bb5e1f | 493 | uint8_t commandHeaderBuffer[32]; |
dan_ackme | 0:ea85c4bb5e1f | 494 | char commandFormatBuffer[WICONNECT_MAX_CMD_SIZE]; |
dan_ackme | 0:ea85c4bb5e1f | 495 | uint8_t commandContext[96]; |
dan_ackme | 0:ea85c4bb5e1f | 496 | |
dan_ackme | 0:ea85c4bb5e1f | 497 | void prepare(void *internalBuffer, int internalBufferSize, bool nonBlocking); |
dan_ackme | 0:ea85c4bb5e1f | 498 | WiconnectResult inline receiveResponse(); |
dan_ackme | 0:ea85c4bb5e1f | 499 | WiconnectResult inline receivePacket(); |
dan_ackme | 0:ea85c4bb5e1f | 500 | void issueCommandCallback(WiconnectResult result); |
dan_ackme | 0:ea85c4bb5e1f | 501 | |
dan_ackme | 6:8a87a59d0d21 | 502 | LogFunc debugLogger; |
dan_ackme | 6:8a87a59d0d21 | 503 | LogFunc assertLogger; |
dan_ackme | 0:ea85c4bb5e1f | 504 | void debugLog(const char *msg, ...); |
dan_ackme | 0:ea85c4bb5e1f | 505 | |
dan_ackme | 0:ea85c4bb5e1f | 506 | #ifdef WICONNECT_ASYNC_TIMER_ENABLED |
dan_ackme | 0:ea85c4bb5e1f | 507 | wiconnect::PeriodicTimer commandProcessorTimer; |
dan_ackme | 0:ea85c4bb5e1f | 508 | uint32_t commandProcessingPeriod; |
dan_ackme | 0:ea85c4bb5e1f | 509 | CommandQueue commandQueue; |
dan_ackme | 0:ea85c4bb5e1f | 510 | wiconnect::QueuedCommand *currentQueuedCommand; |
dan_ackme | 0:ea85c4bb5e1f | 511 | |
dan_ackme | 0:ea85c4bb5e1f | 512 | void commandProcessingTimerHandler(void); |
dan_ackme | 0:ea85c4bb5e1f | 513 | void processNextQueuedCommand(); |
dan_ackme | 0:ea85c4bb5e1f | 514 | void checkQueuedCommandTimeout(); |
dan_ackme | 0:ea85c4bb5e1f | 515 | #endif |
dan_ackme | 0:ea85c4bb5e1f | 516 | |
dan_ackme | 0:ea85c4bb5e1f | 517 | friend class NetworkInterface; |
dan_ackme | 0:ea85c4bb5e1f | 518 | friend class SocketInterface; |
dan_ackme | 0:ea85c4bb5e1f | 519 | friend class FileInterface; |
dan_ackme | 0:ea85c4bb5e1f | 520 | }; |
dan_ackme | 0:ea85c4bb5e1f | 521 | |
dan_ackme | 0:ea85c4bb5e1f | 522 | } |