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