forked from arduinocamp/gsm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWideTextFinder.h
94 lines (75 loc) · 3.29 KB
/
WideTextFinder.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/**
* Copyright (C) 2011 Madefree Electronics <[email protected]>
* Daniele Sdei, Marco Antonini
* http://www.madefree.eu
*
* This file is part of BeeGSM.
*
* BeeGSM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* BeeGSM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with BeeGSM. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef WideTextFinder_h
#define WideTextFinder_h
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#include <SoftwareSerial.h>
#else
#include "WProgram.h"
#include <NewSoftSerial.h>
#endif
class WideTextFinder {
private:
#if defined(ARDUINO) && ARDUINO >= 100
SoftwareSerial* nSerialStream;
#else
NewSoftSerial* nSerialStream;
#endif
unsigned long timeout; // number of seconds to wait for the next char before aborting read
unsigned long startMillis; // used for timeout measurement
boolean debug;
char read(); // private function to read from the stream
public:
// constructor:
// default timeout is 5 seconds
#if defined(ARDUINO) && ARDUINO >= 100
WideTextFinder(SoftwareSerial &stream, int timeout = 5); // Ethernet constructor
#else
WideTextFinder(NewSoftSerial &stream, int timeout = 5); // Ethernet constructor
#endif
// Manage debug
void setDebug(boolean d);
// find methods - these seek through the data but do not return anything
// they are useful to skip past unwanted data
//
boolean find(char *target); // reads data from the stream until the target string is found
// returns true if target string is found
boolean findUntil(char *target, char *terminate); // as above but search ends if the terminate string is found
// get methods - these get a numeric value or string from the data stream
//
long getValue(); // returns the first valid (long) integer value from the current position.
// initial characters that are not digits (or the minus sign) are skipped
// integer is terminated by the first character that is not a digit.
long getValue(char skipChar); // as above but the given skipChar is ignored
// this allows format characters (typically commas) in values to be ignored
float getFloat(); // float version of getValue
float getFloat(char skipChar); // as above but the given skipChar is ignored
int getString( char *pre_string, char *post_string, char *buffer, int length); //puts string found between given delimiters in buffer
// string will be truncated to fit the buffer length
// end of string determined by a match of a character to the first char of close delimiter
// returns the number of characters placed in the buffer (0 means no valid data found)
unsigned long getTimeout(); // returns the number of seconds to wait for the next char before aborting read
// set methods
//
void setTimeout(unsigned long timeout); // set a new value for the wait timeout
};
#endif