Parser for AT commands and similar protocols
Diff: ATParser.h
- Revision:
- 1:66a14afe650a
- Parent:
- 0:c741e144517c
- Child:
- 2:4d68f546861c
--- a/ATParser.h Wed Jul 15 22:39:25 2015 +0000 +++ b/ATParser.h Thu Jul 16 20:42:44 2015 +0000 @@ -19,6 +19,9 @@ */ #include "mbed.h" +#include <stdarg.h> + +#include "BufferedSerial.h" /** @@ -27,7 +30,7 @@ class ATParser { private: // Serial information - RawSerial *_serial; + BufferedSerial *_serial; int _buffer_size; char *_buffer; int _timeout; @@ -42,16 +45,18 @@ // Helper methods for reading/writing lines with // timeout and buffer limitations bool _putline(const char *line); - bool _getline(int size, char *line); + bool _getline(char *line, int size); public: /** * Constructor * * @param serial serial interface to use for AT commands + * @param buffer_size size of internal buffer for transaction * @param timeout timeout of the connection + * @param echo flag to indicate if an echo of sent characters should be expected */ - ATParser(RawSerial *serial, int buffer_size = 256, int timeout = 3000) : + ATParser(BufferedSerial *serial, int buffer_size = 256, int timeout = 3000) : _serial(serial), _buffer_size(buffer_size), _timeout(timeout) { @@ -76,13 +81,21 @@ /** * Issue AT commands with specified command and expected response + * Uses printf/scanf like format strings to be able to parse the results + * + * Here are some examples: + * @code + * at.command("AT", "OK"); + * at.command("AT+CWMODE=%d", "OK", 3); + * at.command("AT+CWMODE?", "+CWMODE:%d OK", &result); + * @endcode * * @param command printf-like format string of command to send * @param response scanf-like format string of response to parse * @param ... all printf-like arguments to insert into command followed by * all scanf-like pointers to destinations for response values - * @return true if response is successfully matched + * @return true only if response is successfully matched */ bool command(const char *command, const char *response, ...); }; - \ No newline at end of file +