15
15
You should have received a copy of the GNU Lesser General Public
16
16
License along with this library; if not, write to the Free Software
17
17
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
parsing functions based on TextFinder library by Michael Margolis
23
25
#include <inttypes.h>
28
// compatability macros for testing
30
#define getInt() parseInt()
31
#define getInt(skipChar) parseInt(skipchar)
32
#define getFloat() parseFloat()
33
#define getFloat(skipChar) parseFloat(skipChar)
34
#define getString( pre_string, post_string, buffer, length)
35
readBytesBetween( pre_string, terminator, buffer, length)
26
38
class Stream : public Print
41
unsigned long _timeout; // number of milliseconds to wait for the next char before aborting timed read
42
unsigned long _startMillis; // used for timeout measurement
43
int timedRead(); // private method to read stream with timeout
44
int timedPeek(); // private method to peek stream with timeout
45
int peekNextDigit(); // returns the next numeric digit in the stream or -1 if timeout
29
48
virtual int available() = 0;
30
49
virtual int read() = 0;
31
50
virtual int peek() = 0;
32
51
virtual void flush() = 0;
53
Stream() {_timeout=1000;}
57
void setTimeout(unsigned long timeout); // sets maximum milliseconds to wait for stream data, default is 1 second
59
bool find(char *target); // reads data from the stream until the target string is found
60
// returns true if target string is found, false if timed out (see setTimeout)
62
bool find(char *target, size_t length); // reads data from the stream until the target string of given length is found
63
// returns true if target string is found, false if timed out
65
bool findUntil(char *target, char *terminator); // as find but search ends if the terminator string is found
67
bool findUntil(char *target, size_t targetLen, char *terminate, size_t termLen); // as above but search ends if the terminate string is found
70
long parseInt(); // returns the first valid (long) integer value from the current position.
71
// initial characters that are not digits (or the minus sign) are skipped
72
// integer is terminated by the first character that is not a digit.
74
float parseFloat(); // float version of parseInt
76
size_t readBytes( char *buffer, size_t length); // read chars from stream into buffer
77
// terminates if length characters have been read or timeout (see setTimeout)
78
// returns the number of characters placed in the buffer (0 means no valid data found)
80
size_t readBytesUntil( char terminator, char *buffer, size_t length); // as readBytes with terminator character
81
// terminates if length characters have been read, timeout, or if the terminator character detected
82
// returns the number of characters placed in the buffer (0 means no valid data found)
84
// Arduino String functions to be added here
87
long parseInt(char skipChar); // as above but the given skipChar is ignored
88
// as above but the given skipChar is ignored
89
// this allows format characters (typically commas) in values to be ignored
91
float parseFloat(char skipChar); // as above but the given skipChar is ignored