Nathan Yonkee
/
Nucleo_sinewave_output_copy
init
mbed-os/platform/ATCmdParser.h@9:d58e77ebd769, 2018-03-02 (annotated)
- Committer:
- Nathan Yonkee
- Date:
- Fri Mar 02 07:12:37 2018 -0700
- Revision:
- 9:d58e77ebd769
add mbed-os library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Nathan Yonkee |
9:d58e77ebd769 | 1 | /* Copyright (c) 2017 ARM Limited |
Nathan Yonkee |
9:d58e77ebd769 | 2 | * |
Nathan Yonkee |
9:d58e77ebd769 | 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
Nathan Yonkee |
9:d58e77ebd769 | 4 | * you may not use this file except in compliance with the License. |
Nathan Yonkee |
9:d58e77ebd769 | 5 | * You may obtain a copy of the License at |
Nathan Yonkee |
9:d58e77ebd769 | 6 | * |
Nathan Yonkee |
9:d58e77ebd769 | 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
Nathan Yonkee |
9:d58e77ebd769 | 8 | * |
Nathan Yonkee |
9:d58e77ebd769 | 9 | * Unless required by applicable law or agreed to in writing, software |
Nathan Yonkee |
9:d58e77ebd769 | 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
Nathan Yonkee |
9:d58e77ebd769 | 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Nathan Yonkee |
9:d58e77ebd769 | 12 | * See the License for the specific language governing permissions and |
Nathan Yonkee |
9:d58e77ebd769 | 13 | * limitations under the License. |
Nathan Yonkee |
9:d58e77ebd769 | 14 | * |
Nathan Yonkee |
9:d58e77ebd769 | 15 | * @section DESCRIPTION |
Nathan Yonkee |
9:d58e77ebd769 | 16 | * |
Nathan Yonkee |
9:d58e77ebd769 | 17 | * Parser for the AT command syntax |
Nathan Yonkee |
9:d58e77ebd769 | 18 | * |
Nathan Yonkee |
9:d58e77ebd769 | 19 | */ |
Nathan Yonkee |
9:d58e77ebd769 | 20 | #ifndef MBED_ATCMDPARSER_H |
Nathan Yonkee |
9:d58e77ebd769 | 21 | #define MBED_ATCMDPARSER_H |
Nathan Yonkee |
9:d58e77ebd769 | 22 | |
Nathan Yonkee |
9:d58e77ebd769 | 23 | #include "mbed.h" |
Nathan Yonkee |
9:d58e77ebd769 | 24 | #include <cstdarg> |
Nathan Yonkee |
9:d58e77ebd769 | 25 | #include "Callback.h" |
Nathan Yonkee |
9:d58e77ebd769 | 26 | |
Nathan Yonkee |
9:d58e77ebd769 | 27 | namespace mbed { |
Nathan Yonkee |
9:d58e77ebd769 | 28 | |
Nathan Yonkee |
9:d58e77ebd769 | 29 | /** \addtogroup platform */ |
Nathan Yonkee |
9:d58e77ebd769 | 30 | /** @{*/ |
Nathan Yonkee |
9:d58e77ebd769 | 31 | /** |
Nathan Yonkee |
9:d58e77ebd769 | 32 | * \defgroup platform_ATCmdParser ATCmdParser class |
Nathan Yonkee |
9:d58e77ebd769 | 33 | * @{ |
Nathan Yonkee |
9:d58e77ebd769 | 34 | */ |
Nathan Yonkee |
9:d58e77ebd769 | 35 | |
Nathan Yonkee |
9:d58e77ebd769 | 36 | /** |
Nathan Yonkee |
9:d58e77ebd769 | 37 | * Parser class for parsing AT commands |
Nathan Yonkee |
9:d58e77ebd769 | 38 | * |
Nathan Yonkee |
9:d58e77ebd769 | 39 | * Here are some examples: |
Nathan Yonkee |
9:d58e77ebd769 | 40 | * @code |
Nathan Yonkee |
9:d58e77ebd769 | 41 | * UARTSerial serial = UARTSerial(D1, D0); |
Nathan Yonkee |
9:d58e77ebd769 | 42 | * ATCmdParser at = ATCmdParser(&serial, "\r\n"); |
Nathan Yonkee |
9:d58e77ebd769 | 43 | * int value; |
Nathan Yonkee |
9:d58e77ebd769 | 44 | * char buffer[100]; |
Nathan Yonkee |
9:d58e77ebd769 | 45 | * |
Nathan Yonkee |
9:d58e77ebd769 | 46 | * at.send("AT") && at.recv("OK"); |
Nathan Yonkee |
9:d58e77ebd769 | 47 | * at.send("AT+CWMODE=%d", 3) && at.recv("OK"); |
Nathan Yonkee |
9:d58e77ebd769 | 48 | * at.send("AT+CWMODE?") && at.recv("+CWMODE:%d\r\nOK", &value); |
Nathan Yonkee |
9:d58e77ebd769 | 49 | * at.recv("+IPD,%d:", &value); |
Nathan Yonkee |
9:d58e77ebd769 | 50 | * at.read(buffer, value); |
Nathan Yonkee |
9:d58e77ebd769 | 51 | * at.recv("OK"); |
Nathan Yonkee |
9:d58e77ebd769 | 52 | * @endcode |
Nathan Yonkee |
9:d58e77ebd769 | 53 | */ |
Nathan Yonkee |
9:d58e77ebd769 | 54 | |
Nathan Yonkee |
9:d58e77ebd769 | 55 | class ATCmdParser : private NonCopyable<ATCmdParser> |
Nathan Yonkee |
9:d58e77ebd769 | 56 | { |
Nathan Yonkee |
9:d58e77ebd769 | 57 | private: |
Nathan Yonkee |
9:d58e77ebd769 | 58 | // File handle |
Nathan Yonkee |
9:d58e77ebd769 | 59 | // Not owned by ATCmdParser |
Nathan Yonkee |
9:d58e77ebd769 | 60 | FileHandle *_fh; |
Nathan Yonkee |
9:d58e77ebd769 | 61 | |
Nathan Yonkee |
9:d58e77ebd769 | 62 | int _buffer_size; |
Nathan Yonkee |
9:d58e77ebd769 | 63 | char *_buffer; |
Nathan Yonkee |
9:d58e77ebd769 | 64 | int _timeout; |
Nathan Yonkee |
9:d58e77ebd769 | 65 | |
Nathan Yonkee |
9:d58e77ebd769 | 66 | // Parsing information |
Nathan Yonkee |
9:d58e77ebd769 | 67 | const char *_output_delimiter; |
Nathan Yonkee |
9:d58e77ebd769 | 68 | int _output_delim_size; |
Nathan Yonkee |
9:d58e77ebd769 | 69 | char _in_prev; |
Nathan Yonkee |
9:d58e77ebd769 | 70 | bool _dbg_on; |
Nathan Yonkee |
9:d58e77ebd769 | 71 | bool _aborted; |
Nathan Yonkee |
9:d58e77ebd769 | 72 | |
Nathan Yonkee |
9:d58e77ebd769 | 73 | struct oob { |
Nathan Yonkee |
9:d58e77ebd769 | 74 | unsigned len; |
Nathan Yonkee |
9:d58e77ebd769 | 75 | const char *prefix; |
Nathan Yonkee |
9:d58e77ebd769 | 76 | mbed::Callback<void()> cb; |
Nathan Yonkee |
9:d58e77ebd769 | 77 | oob *next; |
Nathan Yonkee |
9:d58e77ebd769 | 78 | }; |
Nathan Yonkee |
9:d58e77ebd769 | 79 | oob *_oobs; |
Nathan Yonkee |
9:d58e77ebd769 | 80 | |
Nathan Yonkee |
9:d58e77ebd769 | 81 | public: |
Nathan Yonkee |
9:d58e77ebd769 | 82 | |
Nathan Yonkee |
9:d58e77ebd769 | 83 | /** |
Nathan Yonkee |
9:d58e77ebd769 | 84 | * Constructor |
Nathan Yonkee |
9:d58e77ebd769 | 85 | * |
Nathan Yonkee |
9:d58e77ebd769 | 86 | * @param fh A FileHandle to a digital interface to use for AT commands |
Nathan Yonkee |
9:d58e77ebd769 | 87 | * @param output_delimiter end of command line termination |
Nathan Yonkee |
9:d58e77ebd769 | 88 | * @param buffer_size size of internal buffer for transaction |
Nathan Yonkee |
9:d58e77ebd769 | 89 | * @param timeout timeout of the connection |
Nathan Yonkee |
9:d58e77ebd769 | 90 | * @param debug turns on/off debug output for AT commands |
Nathan Yonkee |
9:d58e77ebd769 | 91 | */ |
Nathan Yonkee |
9:d58e77ebd769 | 92 | ATCmdParser(FileHandle *fh, const char *output_delimiter = "\r", |
Nathan Yonkee |
9:d58e77ebd769 | 93 | int buffer_size = 256, int timeout = 8000, bool debug = false) |
Nathan Yonkee |
9:d58e77ebd769 | 94 | : _fh(fh), _buffer_size(buffer_size), _in_prev(0), _oobs(NULL) |
Nathan Yonkee |
9:d58e77ebd769 | 95 | { |
Nathan Yonkee |
9:d58e77ebd769 | 96 | _buffer = new char[buffer_size]; |
Nathan Yonkee |
9:d58e77ebd769 | 97 | set_timeout(timeout); |
Nathan Yonkee |
9:d58e77ebd769 | 98 | set_delimiter(output_delimiter); |
Nathan Yonkee |
9:d58e77ebd769 | 99 | debug_on(debug); |
Nathan Yonkee |
9:d58e77ebd769 | 100 | } |
Nathan Yonkee |
9:d58e77ebd769 | 101 | |
Nathan Yonkee |
9:d58e77ebd769 | 102 | /** |
Nathan Yonkee |
9:d58e77ebd769 | 103 | * Destructor |
Nathan Yonkee |
9:d58e77ebd769 | 104 | */ |
Nathan Yonkee |
9:d58e77ebd769 | 105 | ~ATCmdParser() |
Nathan Yonkee |
9:d58e77ebd769 | 106 | { |
Nathan Yonkee |
9:d58e77ebd769 | 107 | while (_oobs) { |
Nathan Yonkee |
9:d58e77ebd769 | 108 | struct oob *oob = _oobs; |
Nathan Yonkee |
9:d58e77ebd769 | 109 | _oobs = oob->next; |
Nathan Yonkee |
9:d58e77ebd769 | 110 | delete oob; |
Nathan Yonkee |
9:d58e77ebd769 | 111 | } |
Nathan Yonkee |
9:d58e77ebd769 | 112 | delete[] _buffer; |
Nathan Yonkee |
9:d58e77ebd769 | 113 | } |
Nathan Yonkee |
9:d58e77ebd769 | 114 | |
Nathan Yonkee |
9:d58e77ebd769 | 115 | /** |
Nathan Yonkee |
9:d58e77ebd769 | 116 | * Allows timeout to be changed between commands |
Nathan Yonkee |
9:d58e77ebd769 | 117 | * |
Nathan Yonkee |
9:d58e77ebd769 | 118 | * @param timeout timeout of the connection |
Nathan Yonkee |
9:d58e77ebd769 | 119 | */ |
Nathan Yonkee |
9:d58e77ebd769 | 120 | void set_timeout(int timeout) |
Nathan Yonkee |
9:d58e77ebd769 | 121 | { |
Nathan Yonkee |
9:d58e77ebd769 | 122 | _timeout = timeout; |
Nathan Yonkee |
9:d58e77ebd769 | 123 | } |
Nathan Yonkee |
9:d58e77ebd769 | 124 | |
Nathan Yonkee |
9:d58e77ebd769 | 125 | /** |
Nathan Yonkee |
9:d58e77ebd769 | 126 | * For backwards compatibility. |
Nathan Yonkee |
9:d58e77ebd769 | 127 | * |
Nathan Yonkee |
9:d58e77ebd769 | 128 | * Please use set_timeout(int) API only from now on. |
Nathan Yonkee |
9:d58e77ebd769 | 129 | * Allows timeout to be changed between commands |
Nathan Yonkee |
9:d58e77ebd769 | 130 | * |
Nathan Yonkee |
9:d58e77ebd769 | 131 | * @param timeout timeout of the connection |
Nathan Yonkee |
9:d58e77ebd769 | 132 | */ |
Nathan Yonkee |
9:d58e77ebd769 | 133 | MBED_DEPRECATED_SINCE("mbed-os-5.5.0", "Replaced with set_timeout for consistency") |
Nathan Yonkee |
9:d58e77ebd769 | 134 | void setTimeout(int timeout) |
Nathan Yonkee |
9:d58e77ebd769 | 135 | { |
Nathan Yonkee |
9:d58e77ebd769 | 136 | set_timeout(timeout); |
Nathan Yonkee |
9:d58e77ebd769 | 137 | } |
Nathan Yonkee |
9:d58e77ebd769 | 138 | |
Nathan Yonkee |
9:d58e77ebd769 | 139 | /** |
Nathan Yonkee |
9:d58e77ebd769 | 140 | * Sets string of characters to use as line delimiters |
Nathan Yonkee |
9:d58e77ebd769 | 141 | * |
Nathan Yonkee |
9:d58e77ebd769 | 142 | * @param output_delimiter string of characters to use as line delimiters |
Nathan Yonkee |
9:d58e77ebd769 | 143 | */ |
Nathan Yonkee |
9:d58e77ebd769 | 144 | void set_delimiter(const char *output_delimiter) |
Nathan Yonkee |
9:d58e77ebd769 | 145 | { |
Nathan Yonkee |
9:d58e77ebd769 | 146 | _output_delimiter = output_delimiter; |
Nathan Yonkee |
9:d58e77ebd769 | 147 | _output_delim_size = strlen(output_delimiter); |
Nathan Yonkee |
9:d58e77ebd769 | 148 | } |
Nathan Yonkee |
9:d58e77ebd769 | 149 | |
Nathan Yonkee |
9:d58e77ebd769 | 150 | /** |
Nathan Yonkee |
9:d58e77ebd769 | 151 | * For backwards compatibility. |
Nathan Yonkee |
9:d58e77ebd769 | 152 | * |
Nathan Yonkee |
9:d58e77ebd769 | 153 | * Please use set_delimiter(const char *) API only from now on. |
Nathan Yonkee |
9:d58e77ebd769 | 154 | * Sets string of characters to use as line delimiters |
Nathan Yonkee |
9:d58e77ebd769 | 155 | * |
Nathan Yonkee |
9:d58e77ebd769 | 156 | * @param output_delimiter string of characters to use as line delimiters |
Nathan Yonkee |
9:d58e77ebd769 | 157 | */ |
Nathan Yonkee |
9:d58e77ebd769 | 158 | MBED_DEPRECATED_SINCE("mbed-os-5.5.0", "Replaced with set_delimiter for consistency") |
Nathan Yonkee |
9:d58e77ebd769 | 159 | void setDelimiter(const char *output_delimiter) |
Nathan Yonkee |
9:d58e77ebd769 | 160 | { |
Nathan Yonkee |
9:d58e77ebd769 | 161 | set_delimiter(output_delimiter); |
Nathan Yonkee |
9:d58e77ebd769 | 162 | } |
Nathan Yonkee |
9:d58e77ebd769 | 163 | |
Nathan Yonkee |
9:d58e77ebd769 | 164 | /** |
Nathan Yonkee |
9:d58e77ebd769 | 165 | * Allows traces from modem to be turned on or off |
Nathan Yonkee |
9:d58e77ebd769 | 166 | * |
Nathan Yonkee |
9:d58e77ebd769 | 167 | * @param on set as 1 to turn on traces and vice versa. |
Nathan Yonkee |
9:d58e77ebd769 | 168 | */ |
Nathan Yonkee |
9:d58e77ebd769 | 169 | void debug_on(uint8_t on) |
Nathan Yonkee |
9:d58e77ebd769 | 170 | { |
Nathan Yonkee |
9:d58e77ebd769 | 171 | _dbg_on = (on) ? 1 : 0; |
Nathan Yonkee |
9:d58e77ebd769 | 172 | } |
Nathan Yonkee |
9:d58e77ebd769 | 173 | |
Nathan Yonkee |
9:d58e77ebd769 | 174 | /** |
Nathan Yonkee |
9:d58e77ebd769 | 175 | * For backwards compatibility. |
Nathan Yonkee |
9:d58e77ebd769 | 176 | * |
Nathan Yonkee |
9:d58e77ebd769 | 177 | * Allows traces from modem to be turned on or off |
Nathan Yonkee |
9:d58e77ebd769 | 178 | * |
Nathan Yonkee |
9:d58e77ebd769 | 179 | * @param on set as 1 to turn on traces and vice versa. |
Nathan Yonkee |
9:d58e77ebd769 | 180 | */ |
Nathan Yonkee |
9:d58e77ebd769 | 181 | MBED_DEPRECATED_SINCE("mbed-os-5.5.0", "Replaced with debug_on for consistency") |
Nathan Yonkee |
9:d58e77ebd769 | 182 | void debugOn(uint8_t on) |
Nathan Yonkee |
9:d58e77ebd769 | 183 | { |
Nathan Yonkee |
9:d58e77ebd769 | 184 | debug_on(on); |
Nathan Yonkee |
9:d58e77ebd769 | 185 | } |
Nathan Yonkee |
9:d58e77ebd769 | 186 | |
Nathan Yonkee |
9:d58e77ebd769 | 187 | /** |
Nathan Yonkee |
9:d58e77ebd769 | 188 | * Sends an AT command |
Nathan Yonkee |
9:d58e77ebd769 | 189 | * |
Nathan Yonkee |
9:d58e77ebd769 | 190 | * Sends a formatted command using printf style formatting |
Nathan Yonkee |
9:d58e77ebd769 | 191 | * @see printf |
Nathan Yonkee |
9:d58e77ebd769 | 192 | * |
Nathan Yonkee |
9:d58e77ebd769 | 193 | * @param command printf-like format string of command to send which |
Nathan Yonkee |
9:d58e77ebd769 | 194 | * is appended with a newline |
Nathan Yonkee |
9:d58e77ebd769 | 195 | * @param ... all printf-like arguments to insert into command |
Nathan Yonkee |
9:d58e77ebd769 | 196 | * @return true only if command is successfully sent |
Nathan Yonkee |
9:d58e77ebd769 | 197 | */ |
Nathan Yonkee |
9:d58e77ebd769 | 198 | bool send(const char *command, ...) MBED_PRINTF_METHOD(1,2); |
Nathan Yonkee |
9:d58e77ebd769 | 199 | |
Nathan Yonkee |
9:d58e77ebd769 | 200 | bool vsend(const char *command, va_list args); |
Nathan Yonkee |
9:d58e77ebd769 | 201 | |
Nathan Yonkee |
9:d58e77ebd769 | 202 | /** |
Nathan Yonkee |
9:d58e77ebd769 | 203 | * Receive an AT response |
Nathan Yonkee |
9:d58e77ebd769 | 204 | * |
Nathan Yonkee |
9:d58e77ebd769 | 205 | * Receives a formatted response using scanf style formatting |
Nathan Yonkee |
9:d58e77ebd769 | 206 | * @see scanf |
Nathan Yonkee |
9:d58e77ebd769 | 207 | * |
Nathan Yonkee |
9:d58e77ebd769 | 208 | * Responses are parsed line at a time. |
Nathan Yonkee |
9:d58e77ebd769 | 209 | * Any received data that does not match the response is ignored until |
Nathan Yonkee |
9:d58e77ebd769 | 210 | * a timeout occurs. |
Nathan Yonkee |
9:d58e77ebd769 | 211 | * |
Nathan Yonkee |
9:d58e77ebd769 | 212 | * @param response scanf-like format string of response to expect |
Nathan Yonkee |
9:d58e77ebd769 | 213 | * @param ... all scanf-like arguments to extract from response |
Nathan Yonkee |
9:d58e77ebd769 | 214 | * @return true only if response is successfully matched |
Nathan Yonkee |
9:d58e77ebd769 | 215 | */ |
Nathan Yonkee |
9:d58e77ebd769 | 216 | bool recv(const char *response, ...) MBED_SCANF_METHOD(1,2); |
Nathan Yonkee |
9:d58e77ebd769 | 217 | |
Nathan Yonkee |
9:d58e77ebd769 | 218 | bool vrecv(const char *response, va_list args); |
Nathan Yonkee |
9:d58e77ebd769 | 219 | |
Nathan Yonkee |
9:d58e77ebd769 | 220 | /** |
Nathan Yonkee |
9:d58e77ebd769 | 221 | * Write a single byte to the underlying stream |
Nathan Yonkee |
9:d58e77ebd769 | 222 | * |
Nathan Yonkee |
9:d58e77ebd769 | 223 | * @param c The byte to write |
Nathan Yonkee |
9:d58e77ebd769 | 224 | * @return The byte that was written or -1 during a timeout |
Nathan Yonkee |
9:d58e77ebd769 | 225 | */ |
Nathan Yonkee |
9:d58e77ebd769 | 226 | int putc(char c); |
Nathan Yonkee |
9:d58e77ebd769 | 227 | |
Nathan Yonkee |
9:d58e77ebd769 | 228 | /** |
Nathan Yonkee |
9:d58e77ebd769 | 229 | * Get a single byte from the underlying stream |
Nathan Yonkee |
9:d58e77ebd769 | 230 | * |
Nathan Yonkee |
9:d58e77ebd769 | 231 | * @return The byte that was read or -1 during a timeout |
Nathan Yonkee |
9:d58e77ebd769 | 232 | */ |
Nathan Yonkee |
9:d58e77ebd769 | 233 | int getc(); |
Nathan Yonkee |
9:d58e77ebd769 | 234 | |
Nathan Yonkee |
9:d58e77ebd769 | 235 | /** |
Nathan Yonkee |
9:d58e77ebd769 | 236 | * Write an array of bytes to the underlying stream |
Nathan Yonkee |
9:d58e77ebd769 | 237 | * |
Nathan Yonkee |
9:d58e77ebd769 | 238 | * @param data the array of bytes to write |
Nathan Yonkee |
9:d58e77ebd769 | 239 | * @param size number of bytes to write |
Nathan Yonkee |
9:d58e77ebd769 | 240 | * @return number of bytes written or -1 on failure |
Nathan Yonkee |
9:d58e77ebd769 | 241 | */ |
Nathan Yonkee |
9:d58e77ebd769 | 242 | int write(const char *data, int size); |
Nathan Yonkee |
9:d58e77ebd769 | 243 | |
Nathan Yonkee |
9:d58e77ebd769 | 244 | /** |
Nathan Yonkee |
9:d58e77ebd769 | 245 | * Read an array of bytes from the underlying stream |
Nathan Yonkee |
9:d58e77ebd769 | 246 | * |
Nathan Yonkee |
9:d58e77ebd769 | 247 | * @param data the destination for the read bytes |
Nathan Yonkee |
9:d58e77ebd769 | 248 | * @param size number of bytes to read |
Nathan Yonkee |
9:d58e77ebd769 | 249 | * @return number of bytes read or -1 on failure |
Nathan Yonkee |
9:d58e77ebd769 | 250 | */ |
Nathan Yonkee |
9:d58e77ebd769 | 251 | int read(char *data, int size); |
Nathan Yonkee |
9:d58e77ebd769 | 252 | |
Nathan Yonkee |
9:d58e77ebd769 | 253 | /** |
Nathan Yonkee |
9:d58e77ebd769 | 254 | * Direct printf to underlying stream |
Nathan Yonkee |
9:d58e77ebd769 | 255 | * @see printf |
Nathan Yonkee |
9:d58e77ebd769 | 256 | * |
Nathan Yonkee |
9:d58e77ebd769 | 257 | * @param format format string to pass to printf |
Nathan Yonkee |
9:d58e77ebd769 | 258 | * @param ... arguments to printf |
Nathan Yonkee |
9:d58e77ebd769 | 259 | * @return number of bytes written or -1 on failure |
Nathan Yonkee |
9:d58e77ebd769 | 260 | */ |
Nathan Yonkee |
9:d58e77ebd769 | 261 | int printf(const char *format, ...) MBED_PRINTF_METHOD(1,2); |
Nathan Yonkee |
9:d58e77ebd769 | 262 | |
Nathan Yonkee |
9:d58e77ebd769 | 263 | int vprintf(const char *format, va_list args); |
Nathan Yonkee |
9:d58e77ebd769 | 264 | |
Nathan Yonkee |
9:d58e77ebd769 | 265 | /** |
Nathan Yonkee |
9:d58e77ebd769 | 266 | * Direct scanf on underlying stream |
Nathan Yonkee |
9:d58e77ebd769 | 267 | * @see scanf |
Nathan Yonkee |
9:d58e77ebd769 | 268 | * |
Nathan Yonkee |
9:d58e77ebd769 | 269 | * @param format format string to pass to scanf |
Nathan Yonkee |
9:d58e77ebd769 | 270 | * @param ... arguments to scanf |
Nathan Yonkee |
9:d58e77ebd769 | 271 | * @return number of bytes read or -1 on failure |
Nathan Yonkee |
9:d58e77ebd769 | 272 | */ |
Nathan Yonkee |
9:d58e77ebd769 | 273 | int scanf(const char *format, ...) MBED_SCANF_METHOD(1,2); |
Nathan Yonkee |
9:d58e77ebd769 | 274 | |
Nathan Yonkee |
9:d58e77ebd769 | 275 | int vscanf(const char *format, va_list args); |
Nathan Yonkee |
9:d58e77ebd769 | 276 | |
Nathan Yonkee |
9:d58e77ebd769 | 277 | /** |
Nathan Yonkee |
9:d58e77ebd769 | 278 | * Attach a callback for out-of-band data |
Nathan Yonkee |
9:d58e77ebd769 | 279 | * |
Nathan Yonkee |
9:d58e77ebd769 | 280 | * @param prefix string on when to initiate callback |
Nathan Yonkee |
9:d58e77ebd769 | 281 | * @param func callback to call when string is read |
Nathan Yonkee |
9:d58e77ebd769 | 282 | * @note out-of-band data is only processed during a scanf call |
Nathan Yonkee |
9:d58e77ebd769 | 283 | */ |
Nathan Yonkee |
9:d58e77ebd769 | 284 | void oob(const char *prefix, mbed::Callback<void()> func); |
Nathan Yonkee |
9:d58e77ebd769 | 285 | |
Nathan Yonkee |
9:d58e77ebd769 | 286 | /** |
Nathan Yonkee |
9:d58e77ebd769 | 287 | * Flushes the underlying stream |
Nathan Yonkee |
9:d58e77ebd769 | 288 | */ |
Nathan Yonkee |
9:d58e77ebd769 | 289 | void flush(); |
Nathan Yonkee |
9:d58e77ebd769 | 290 | |
Nathan Yonkee |
9:d58e77ebd769 | 291 | /** |
Nathan Yonkee |
9:d58e77ebd769 | 292 | * Abort current recv |
Nathan Yonkee |
9:d58e77ebd769 | 293 | * |
Nathan Yonkee |
9:d58e77ebd769 | 294 | * Can be called from oob handler to interrupt the current |
Nathan Yonkee |
9:d58e77ebd769 | 295 | * recv operation. |
Nathan Yonkee |
9:d58e77ebd769 | 296 | */ |
Nathan Yonkee |
9:d58e77ebd769 | 297 | void abort(); |
Nathan Yonkee |
9:d58e77ebd769 | 298 | |
Nathan Yonkee |
9:d58e77ebd769 | 299 | /** |
Nathan Yonkee |
9:d58e77ebd769 | 300 | * Process out-of-band data |
Nathan Yonkee |
9:d58e77ebd769 | 301 | * |
Nathan Yonkee |
9:d58e77ebd769 | 302 | * Process out-of-band data in the receive buffer. This function |
Nathan Yonkee |
9:d58e77ebd769 | 303 | * returns immediately if there is no data to process. |
Nathan Yonkee |
9:d58e77ebd769 | 304 | * |
Nathan Yonkee |
9:d58e77ebd769 | 305 | * @return true if oob data processed, false otherwise |
Nathan Yonkee |
9:d58e77ebd769 | 306 | */ |
Nathan Yonkee |
9:d58e77ebd769 | 307 | bool process_oob(void); |
Nathan Yonkee |
9:d58e77ebd769 | 308 | }; |
Nathan Yonkee |
9:d58e77ebd769 | 309 | |
Nathan Yonkee |
9:d58e77ebd769 | 310 | /**@}*/ |
Nathan Yonkee |
9:d58e77ebd769 | 311 | |
Nathan Yonkee |
9:d58e77ebd769 | 312 | /**@}*/ |
Nathan Yonkee |
9:d58e77ebd769 | 313 | |
Nathan Yonkee |
9:d58e77ebd769 | 314 | } //namespace mbed |
Nathan Yonkee |
9:d58e77ebd769 | 315 | |
Nathan Yonkee |
9:d58e77ebd769 | 316 | #endif //MBED_ATCMDPARSER_H |