23
23
#include " Arduino.h"
24
24
#include " Stream.h"
25
25
26
- #define PARSE_TIMEOUT 5 // default number of seconds to wait
26
+ #define PARSE_TIMEOUT 1000 // default number of milli- seconds to wait
27
27
#define NO_SKIP_CHAR 1 // a magic char not found in a valid ASCII numeric field
28
28
29
29
// private method to read stream with timeout
30
30
int Stream::timedRead ()
31
31
{
32
32
// Serial.println(_timeout);
33
33
this ->_startMillis = millis ();
34
- while (millis () - this ->_startMillis < ( this ->_timeout * 1000L ) )
34
+ while (millis () - this ->_startMillis < this ->_timeout )
35
35
{
36
36
if (this ->available () > 0 ) {
37
37
return this ->read ();
@@ -58,7 +58,7 @@ return c;
58
58
// Public Methods
59
59
// ////////////////////////////////////////////////////////////
60
60
61
- void Stream::setTimeout ( long timeout) // sets the maximum number of seconds to wait
61
+ void Stream::setTimeout ( long timeout) // sets the maximum number of milliseconds to wait
62
62
{
63
63
this ->_timeout = timeout;
64
64
}
@@ -200,17 +200,17 @@ float Stream::parseFloat(char skipChar){
200
200
// read characters from stream into buffer
201
201
// terminates if length characters have been read, null is detected or timeout (see setTimeout)
202
202
// returns the number of characters placed in the buffer (0 means no valid data found)
203
- int Stream::readChars ( char *buffer, size_t length)
203
+ int Stream::readBytes ( char *buffer, size_t length)
204
204
{
205
- return readCharsUntil ( 0 , buffer, length);
205
+ return readBytesUntil ( 0 , buffer, length);
206
206
}
207
207
208
208
209
- // as readChars with terminator character
209
+ // as readBytes with terminator character
210
210
// terminates if length characters have been read, timeout, or if the terminator character detected
211
211
// returns the number of characters placed in the buffer (0 means no valid data found)
212
212
213
- int Stream::readCharsUntil ( char terminator, char *buffer, size_t length)
213
+ int Stream::readBytesUntil ( char terminator, char *buffer, size_t length)
214
214
{
215
215
int index = 0 ;
216
216
*buffer = 0 ;
@@ -231,14 +231,3 @@ int Stream::readCharsUntil( char terminator, char *buffer, size_t length)
231
231
return index; // here if buffer is full before detecting the terminator
232
232
}
233
233
234
-
235
- // read characters found between pre_string and terminator into a buffer
236
- // terminated when the terminator character is matched or the buffer is full
237
- // returns the number of bytes placed in the buffer (0 means no valid data found)
238
- int Stream::readCharsBetween ( char *pre_string, char terminator, char *buffer, size_t length)
239
- {
240
- if ( find ( pre_string) ){
241
- return readCharsUntil (terminator, buffer, length);
242
- }
243
- return 0 ; // failed to find the prestring
244
- }
0 commit comments