Update Packages' Patches

This commit is contained in:
Khoi Hoang
2022-11-09 23:44:57 -05:00
committed by GitHub
parent d78618d4b4
commit 89acc339e0
53 changed files with 9768 additions and 4553 deletions
@@ -28,65 +28,65 @@
// private method to read stream with timeout
int Stream::timedRead()
{
int c;
unsigned long startMillis = millis();
int c;
unsigned long startMillis = millis();
do
{
c = read();
do
{
c = read();
if (c >= 0)
return c;
if (c >= 0)
return c;
yield();
} while (millis() - startMillis < _timeout);
yield();
} while (millis() - startMillis < _timeout);
Serial.print(("timedRead timeout = "));
Serial.println(_timeout);
Serial.print(("timedRead timeout = "));
Serial.println(_timeout);
return -1; // -1 indicates timeout
return -1; // -1 indicates timeout
}
// private method to peek stream with timeout
int Stream::timedPeek()
{
int c;
unsigned long startMillis = millis();
int c;
unsigned long startMillis = millis();
do
{
c = peek();
do
{
c = peek();
if (c >= 0)
return c;
if (c >= 0)
return c;
yield();
} while (millis() - startMillis < _timeout);
yield();
} while (millis() - startMillis < _timeout);
return -1; // -1 indicates timeout
return -1; // -1 indicates timeout
}
// returns peek of the next digit in the stream or -1 if timeout
// discards non-numeric characters
int Stream::peekNextDigit()
{
int c;
int c;
while (1)
{
c = timedPeek();
while (1)
{
c = timedPeek();
if (c < 0)
return c; // timeout
if (c < 0)
return c; // timeout
if (c == '-')
return c;
if (c == '-')
return c;
if (c >= '0' && c <= '9')
return c;
if (c >= '0' && c <= '9')
return c;
read(); // discard non-numeric
}
read(); // discard non-numeric
}
}
// Public Methods
@@ -94,31 +94,31 @@ int Stream::peekNextDigit()
void Stream::setTimeout(unsigned long timeout) // sets the maximum number of milliseconds to wait
{
_timeout = timeout;
_timeout = timeout;
}
// find returns true if the target string is found
bool Stream::find(const char *target)
{
return findUntil(target, NULL);
return findUntil(target, NULL);
}
// reads data from the stream until the target string of given length is found
// returns true if target string is found, false if timed out
bool Stream::find(const char *target, size_t length)
{
return findUntil(target, length, NULL, 0);
return findUntil(target, length, NULL, 0);
}
// as find but search ends if the terminator string is found
bool Stream::findUntil(const char *target, const char *terminator)
{
if (target == nullptr)
return true;
if (target == nullptr)
return true;
size_t tlen = (terminator == nullptr) ? 0 : strlen(terminator);
size_t tlen = (terminator == nullptr) ? 0 : strlen(terminator);
return findUntil(target, strlen(target), terminator, tlen);
return findUntil(target, strlen(target), terminator, tlen);
}
// reads data from the stream until the target string of the given length is found
@@ -126,45 +126,45 @@ bool Stream::findUntil(const char *target, const char *terminator)
// returns true if target string is found, false if terminated or timed out
bool Stream::findUntil(const char *target, size_t targetLen, const char *terminator, size_t termLen)
{
size_t index = 0; // maximum target string length is 64k bytes!
size_t termIndex = 0;
int c;
size_t index = 0; // maximum target string length is 64k bytes!
size_t termIndex = 0;
int c;
if ( target == nullptr)
return true;
if ( target == nullptr)
return true;
if ( *target == 0)
return true; // return true if target is a null string
if ( *target == 0)
return true; // return true if target is a null string
if (terminator == nullptr)
termLen = 0;
if (terminator == nullptr)
termLen = 0;
while ( (c = timedRead()) > 0)
{
if ( c == target[index])
{
//////Serial.print("found "); Serial.write(c); Serial.print("index now"); Serial.println(index+1);
if (++index >= targetLen)
{
// return true if all chars in the target match
return true;
}
}
else
{
index = 0; // reset index if any char does not match
}
while ( (c = timedRead()) > 0)
{
if ( c == target[index])
{
//////Serial.print("found "); Serial.write(c); Serial.print("index now"); Serial.println(index+1);
if (++index >= targetLen)
{
// return true if all chars in the target match
return true;
}
}
else
{
index = 0; // reset index if any char does not match
}
if (termLen > 0 && c == terminator[termIndex])
{
if (++termIndex >= termLen)
return false; // return false if terminate string found before target string
}
else
termIndex = 0;
}
if (termLen > 0 && c == terminator[termIndex])
{
if (++termIndex >= termLen)
return false; // return false if terminate string found before target string
}
else
termIndex = 0;
}
return false;
return false;
}
@@ -173,93 +173,93 @@ bool Stream::findUntil(const char *target, size_t targetLen, const char *termina
// function is terminated by the first character that is not a digit.
long Stream::parseInt()
{
return parseInt(NO_SKIP_CHAR); // terminate on first non-digit character (or timeout)
return parseInt(NO_SKIP_CHAR); // terminate on first non-digit character (or timeout)
}
// as above but a given skipChar is ignored
// this allows format characters (typically commas) in values to be ignored
long Stream::parseInt(char skipChar)
{
boolean isNegative = false;
long value = 0;
int c;
boolean isNegative = false;
long value = 0;
int c;
c = peekNextDigit();
c = peekNextDigit();
// ignore non numeric leading characters
if (c < 0)
return 0; // zero returned if timeout
// ignore non numeric leading characters
if (c < 0)
return 0; // zero returned if timeout
do
{
if (c == skipChar)
; // ignore this charactor
else if (c == '-')
isNegative = true;
else if (c >= '0' && c <= '9') // is c a digit?
value = value * 10 + c - '0';
do
{
if (c == skipChar)
; // ignore this charactor
else if (c == '-')
isNegative = true;
else if (c >= '0' && c <= '9') // is c a digit?
value = value * 10 + c - '0';
read(); // consume the character we got with peek
c = timedPeek();
} while ( (c >= '0' && c <= '9') || c == skipChar );
read(); // consume the character we got with peek
c = timedPeek();
} while ( (c >= '0' && c <= '9') || c == skipChar );
if (isNegative)
value = -value;
if (isNegative)
value = -value;
return value;
return value;
}
// as parseInt but returns a floating point value
float Stream::parseFloat()
{
return parseFloat(NO_SKIP_CHAR);
return parseFloat(NO_SKIP_CHAR);
}
// as above but the given skipChar is ignored
// this allows format characters (typically commas) in values to be ignored
float Stream::parseFloat(char skipChar)
{
boolean isNegative = false;
boolean isFraction = false;
long value = 0;
int c;
float fraction = 1.0;
boolean isNegative = false;
boolean isFraction = false;
long value = 0;
int c;
float fraction = 1.0;
c = peekNextDigit();
c = peekNextDigit();
// ignore non numeric leading characters
if (c < 0)
return 0; // zero returned if timeout
// ignore non numeric leading characters
if (c < 0)
return 0; // zero returned if timeout
do
{
if (c == skipChar)
; // ignore
else if (c == '-')
isNegative = true;
else if (c == '.')
isFraction = true;
else if (c >= '0' && c <= '9')
{
// is c a digit?
value = value * 10 + c - '0';
do
{
if (c == skipChar)
; // ignore
else if (c == '-')
isNegative = true;
else if (c == '.')
isFraction = true;
else if (c >= '0' && c <= '9')
{
// is c a digit?
value = value * 10 + c - '0';
if (isFraction)
fraction *= 0.1f;
}
if (isFraction)
fraction *= 0.1f;
}
read(); // consume the character we got with peek
c = timedPeek();
} while ( (c >= '0' && c <= '9') || c == '.' || c == skipChar );
read(); // consume the character we got with peek
c = timedPeek();
} while ( (c >= '0' && c <= '9') || c == '.' || c == skipChar );
if (isNegative)
value = -value;
if (isNegative)
value = -value;
if (isFraction)
return value * fraction;
else
return value;
if (isFraction)
return value * fraction;
else
return value;
}
// read characters from stream into buffer
@@ -269,26 +269,26 @@ float Stream::parseFloat(char skipChar)
//
size_t Stream::readBytes(char *buffer, size_t length)
{
if (buffer == nullptr)
return 0;
if (buffer == nullptr)
return 0;
size_t count = 0;
size_t count = 0;
while (count < length)
{
int c = timedRead();
while (count < length)
{
int c = timedRead();
if (c < 0)
{
setReadError();
break;
}
if (c < 0)
{
setReadError();
break;
}
*buffer++ = (char)c;
count++;
}
*buffer++ = (char)c;
count++;
}
return count;
return count;
}
@@ -298,34 +298,34 @@ size_t Stream::readBytes(char *buffer, size_t length)
size_t Stream::readBytesUntil(char terminator, char *buffer, size_t length)
{
if (buffer == nullptr)
return 0;
if (buffer == nullptr)
return 0;
if (length < 1)
return 0;
if (length < 1)
return 0;
length--;
size_t index = 0;
length--;
size_t index = 0;
while (index < length)
{
int c = timedRead();
while (index < length)
{
int c = timedRead();
if (c == terminator)
break;
if (c == terminator)
break;
if (c < 0)
{
setReadError();
break;
}
if (c < 0)
{
setReadError();
break;
}
*buffer++ = (char)c;
index++;
}
*buffer++ = (char)c;
index++;
}
*buffer = 0;
return index; // return number of characters, not including null terminator
*buffer = 0;
return index; // return number of characters, not including null terminator
}
#if 1
@@ -333,112 +333,112 @@ size_t Stream::readBytesUntil(char terminator, char *buffer, size_t length)
String Stream::readString(size_t max)
{
String ret;
int c = timedRead();
String ret;
int c = timedRead();
while (c >= 0)
{
ret += (char)c;
c = timedRead();
}
while (c >= 0)
{
ret += (char)c;
c = timedRead();
}
return ret;
return ret;
}
char readStringBuffer[2048];
char* Stream::readCharsUntil(char terminator, size_t max)
{
uint16_t offset = 0;
uint16_t offset = 0;
int c = timedRead();
int c = timedRead();
readStringBuffer[offset++] = c;
readStringBuffer[offset++] = c;
while (c >= 0 && c != terminator)
{
c = timedRead();
while (c >= 0 && c != terminator)
{
c = timedRead();
readStringBuffer[offset++] = c;
}
readStringBuffer[offset++] = c;
}
readStringBuffer[offset] = 0;
readStringBuffer[offset] = 0;
return readStringBuffer;
return readStringBuffer;
}
String Stream::readStringUntil(char terminator, size_t max)
{
String ret;
uint16_t offset = 0;
String ret;
uint16_t offset = 0;
int c = timedRead();
int c = timedRead();
readStringBuffer[offset++] = c;
readStringBuffer[offset++] = c;
while (c >= 0 && c != terminator)
{
c = timedRead();
while (c >= 0 && c != terminator)
{
c = timedRead();
readStringBuffer[offset++] = c;
}
readStringBuffer[offset++] = c;
}
readStringBuffer[offset] = 0;
readStringBuffer[offset] = 0;
ret = String(readStringBuffer);
ret = String(readStringBuffer);
return String(readStringBuffer);
return String(readStringBuffer);
}
#else
String Stream::readString(size_t max)
{
String str;
size_t length = 0;
String str;
size_t length = 0;
while (length < max)
{
int c = timedRead();
while (length < max)
{
int c = timedRead();
if (c < 0)
{
setReadError();
break; // timeout
}
if (c < 0)
{
setReadError();
break; // timeout
}
if (c == 0)
break;
if (c == 0)
break;
str += (char)c;
length++;
}
str += (char)c;
length++;
}
return str;
return str;
}
String Stream::readStringUntil(char terminator, size_t max)
{
String str;
size_t length = 0;
String str;
size_t length = 0;
while (length < max)
{
int c = timedRead();
while (length < max)
{
int c = timedRead();
if (c < 0)
{
setReadError();
break; // timeout
}
if (c < 0)
{
setReadError();
break; // timeout
}
if (c == 0 || c == terminator)
break;
if (c == 0 || c == terminator)
break;
str += (char)c;
length++;
}
str += (char)c;
length++;
}
return str;
return str;
}
#endif
@@ -25,124 +25,124 @@
class Stream : public Print
{
public:
constexpr Stream() : _timeout(1000), read_error(0) {}
virtual int available() = 0;
virtual int read() = 0;
virtual int peek() = 0;
public:
constexpr Stream() : _timeout(1000), read_error(0) {}
virtual int available() = 0;
virtual int read() = 0;
virtual int peek() = 0;
void setTimeout(unsigned long timeout);
bool find(const char *target);
void setTimeout(unsigned long timeout);
bool find(const char *target);
bool find(const uint8_t *target)
{
return find ((const char *)target);
}
bool find(const uint8_t *target)
{
return find ((const char *)target);
}
bool find(const String &target)
{
return find(target.c_str());
}
bool find(const String &target)
{
return find(target.c_str());
}
bool find(const char *target, size_t length);
bool find(const char *target, size_t length);
bool find(const uint8_t *target, size_t length)
{
return find ((const char *)target, length);
}
bool find(const uint8_t *target, size_t length)
{
return find ((const char *)target, length);
}
bool find(const String &target, size_t length)
{
return find(target.c_str(), length);
}
bool find(const String &target, size_t length)
{
return find(target.c_str(), length);
}
bool findUntil(const char *target, const char *terminator);
bool findUntil(const char *target, const char *terminator);
bool findUntil(const uint8_t *target, const char *terminator)
{
return findUntil((const char *)target, terminator);
}
bool findUntil(const uint8_t *target, const char *terminator)
{
return findUntil((const char *)target, terminator);
}
bool findUntil(const String &target, const char *terminator)
{
return findUntil(target.c_str(), terminator);
}
bool findUntil(const String &target, const char *terminator)
{
return findUntil(target.c_str(), terminator);
}
bool findUntil(const char *target, const String &terminator)
{
return findUntil(target, terminator.c_str());
}
bool findUntil(const char *target, const String &terminator)
{
return findUntil(target, terminator.c_str());
}
bool findUntil(const String &target, const String &terminator)
{
return findUntil(target.c_str(), terminator.c_str());
}
bool findUntil(const String &target, const String &terminator)
{
return findUntil(target.c_str(), terminator.c_str());
}
bool findUntil(const char *target, size_t targetLen, const char *terminate, size_t termLen);
bool findUntil(const char *target, size_t targetLen, const char *terminate, size_t termLen);
bool findUntil(const uint8_t *target, size_t targetLen, const char *terminate, size_t termLen)
{
return findUntil((const char *)target, targetLen, terminate, termLen);
}
bool findUntil(const uint8_t *target, size_t targetLen, const char *terminate, size_t termLen)
{
return findUntil((const char *)target, targetLen, terminate, termLen);
}
bool findUntil(const String &target, size_t targetLen, const char *terminate, size_t termLen);
bool findUntil(const char *target, size_t targetLen, const String &terminate, size_t termLen);
bool findUntil(const String &target, size_t targetLen, const String &terminate, size_t termLen);
bool findUntil(const String &target, size_t targetLen, const char *terminate, size_t termLen);
bool findUntil(const char *target, size_t targetLen, const String &terminate, size_t termLen);
bool findUntil(const String &target, size_t targetLen, const String &terminate, size_t termLen);
long parseInt();
long parseInt(char skipChar);
long parseInt();
long parseInt(char skipChar);
float parseFloat();
float parseFloat(char skipChar);
float parseFloat();
float parseFloat(char skipChar);
size_t readBytes(char *buffer, size_t length);
size_t readBytes(char *buffer, size_t length);
size_t readBytes(uint8_t *buffer, size_t length)
{
return readBytes((char *)buffer, length);
}
size_t readBytes(uint8_t *buffer, size_t length)
{
return readBytes((char *)buffer, length);
}
size_t readBytesUntil(char terminator, char *buffer, size_t length);
size_t readBytesUntil(char terminator, char *buffer, size_t length);
size_t readBytesUntil(char terminator, uint8_t *buffer, size_t length)
{
return readBytesUntil(terminator, (char *)buffer, length);
}
size_t readBytesUntil(char terminator, uint8_t *buffer, size_t length)
{
return readBytesUntil(terminator, (char *)buffer, length);
}
////////////////////////////////////////////////////////////
String readString(size_t max = 512);
String readStringUntil(char terminator, size_t max = 512);
////////////////////////////////////////////////////////////
String readString(size_t max = 512);
String readStringUntil(char terminator, size_t max = 512);
// KH, to not use String
char* readCharsUntil(char terminator, size_t max = 512);
////////////////////////////////////////////////////////////
// KH, to not use String
char* readCharsUntil(char terminator, size_t max = 512);
////////////////////////////////////////////////////////////
int getReadError()
{
return read_error;
}
int getReadError()
{
return read_error;
}
void clearReadError()
{
setReadError(0);
}
void clearReadError()
{
setReadError(0);
}
protected:
void setReadError(int err = 1)
{
read_error = err;
}
protected:
void setReadError(int err = 1)
{
read_error = err;
}
unsigned long _timeout;
unsigned long _timeout;
// KH
int timedRead();
int timedPeek();
int peekNextDigit();
//////
// KH
int timedRead();
int timedPeek();
int peekNextDigit();
//////
private:
char read_error;
private:
char read_error;
};
#endif
@@ -28,65 +28,65 @@
// private method to read stream with timeout
int Stream::timedRead()
{
int c;
unsigned long startMillis = millis();
int c;
unsigned long startMillis = millis();
do
{
c = read();
do
{
c = read();
if (c >= 0)
return c;
if (c >= 0)
return c;
yield();
} while (millis() - startMillis < _timeout);
yield();
} while (millis() - startMillis < _timeout);
Serial.print(("timedRead timeout = "));
Serial.println(_timeout);
Serial.print(("timedRead timeout = "));
Serial.println(_timeout);
return -1; // -1 indicates timeout
return -1; // -1 indicates timeout
}
// private method to peek stream with timeout
int Stream::timedPeek()
{
int c;
unsigned long startMillis = millis();
int c;
unsigned long startMillis = millis();
do
{
c = peek();
do
{
c = peek();
if (c >= 0)
return c;
if (c >= 0)
return c;
yield();
} while (millis() - startMillis < _timeout);
yield();
} while (millis() - startMillis < _timeout);
return -1; // -1 indicates timeout
return -1; // -1 indicates timeout
}
// returns peek of the next digit in the stream or -1 if timeout
// discards non-numeric characters
int Stream::peekNextDigit()
{
int c;
int c;
while (1)
{
c = timedPeek();
while (1)
{
c = timedPeek();
if (c < 0)
return c; // timeout
if (c < 0)
return c; // timeout
if (c == '-')
return c;
if (c == '-')
return c;
if (c >= '0' && c <= '9')
return c;
if (c >= '0' && c <= '9')
return c;
read(); // discard non-numeric
}
read(); // discard non-numeric
}
}
// Public Methods
@@ -94,31 +94,31 @@ int Stream::peekNextDigit()
void Stream::setTimeout(unsigned long timeout) // sets the maximum number of milliseconds to wait
{
_timeout = timeout;
_timeout = timeout;
}
// find returns true if the target string is found
bool Stream::find(const char *target)
{
return findUntil(target, NULL);
return findUntil(target, NULL);
}
// reads data from the stream until the target string of given length is found
// returns true if target string is found, false if timed out
bool Stream::find(const char *target, size_t length)
{
return findUntil(target, length, NULL, 0);
return findUntil(target, length, NULL, 0);
}
// as find but search ends if the terminator string is found
bool Stream::findUntil(const char *target, const char *terminator)
{
if (target == nullptr)
return true;
if (target == nullptr)
return true;
size_t tlen = (terminator == nullptr) ? 0 : strlen(terminator);
size_t tlen = (terminator == nullptr) ? 0 : strlen(terminator);
return findUntil(target, strlen(target), terminator, tlen);
return findUntil(target, strlen(target), terminator, tlen);
}
// reads data from the stream until the target string of the given length is found
@@ -126,45 +126,45 @@ bool Stream::findUntil(const char *target, const char *terminator)
// returns true if target string is found, false if terminated or timed out
bool Stream::findUntil(const char *target, size_t targetLen, const char *terminator, size_t termLen)
{
size_t index = 0; // maximum target string length is 64k bytes!
size_t termIndex = 0;
int c;
size_t index = 0; // maximum target string length is 64k bytes!
size_t termIndex = 0;
int c;
if ( target == nullptr)
return true;
if ( target == nullptr)
return true;
if ( *target == 0)
return true; // return true if target is a null string
if ( *target == 0)
return true; // return true if target is a null string
if (terminator == nullptr)
termLen = 0;
if (terminator == nullptr)
termLen = 0;
while ( (c = timedRead()) > 0)
{
if ( c == target[index])
{
//////Serial.print("found "); Serial.write(c); Serial.print("index now"); Serial.println(index+1);
if (++index >= targetLen)
{
// return true if all chars in the target match
return true;
}
}
else
{
index = 0; // reset index if any char does not match
}
while ( (c = timedRead()) > 0)
{
if ( c == target[index])
{
//////Serial.print("found "); Serial.write(c); Serial.print("index now"); Serial.println(index+1);
if (++index >= targetLen)
{
// return true if all chars in the target match
return true;
}
}
else
{
index = 0; // reset index if any char does not match
}
if (termLen > 0 && c == terminator[termIndex])
{
if (++termIndex >= termLen)
return false; // return false if terminate string found before target string
}
else
termIndex = 0;
}
if (termLen > 0 && c == terminator[termIndex])
{
if (++termIndex >= termLen)
return false; // return false if terminate string found before target string
}
else
termIndex = 0;
}
return false;
return false;
}
@@ -173,93 +173,93 @@ bool Stream::findUntil(const char *target, size_t targetLen, const char *termina
// function is terminated by the first character that is not a digit.
long Stream::parseInt()
{
return parseInt(NO_SKIP_CHAR); // terminate on first non-digit character (or timeout)
return parseInt(NO_SKIP_CHAR); // terminate on first non-digit character (or timeout)
}
// as above but a given skipChar is ignored
// this allows format characters (typically commas) in values to be ignored
long Stream::parseInt(char skipChar)
{
boolean isNegative = false;
long value = 0;
int c;
boolean isNegative = false;
long value = 0;
int c;
c = peekNextDigit();
c = peekNextDigit();
// ignore non numeric leading characters
if (c < 0)
return 0; // zero returned if timeout
// ignore non numeric leading characters
if (c < 0)
return 0; // zero returned if timeout
do
{
if (c == skipChar)
; // ignore this charactor
else if (c == '-')
isNegative = true;
else if (c >= '0' && c <= '9') // is c a digit?
value = value * 10 + c - '0';
do
{
if (c == skipChar)
; // ignore this charactor
else if (c == '-')
isNegative = true;
else if (c >= '0' && c <= '9') // is c a digit?
value = value * 10 + c - '0';
read(); // consume the character we got with peek
c = timedPeek();
} while ( (c >= '0' && c <= '9') || c == skipChar );
read(); // consume the character we got with peek
c = timedPeek();
} while ( (c >= '0' && c <= '9') || c == skipChar );
if (isNegative)
value = -value;
if (isNegative)
value = -value;
return value;
return value;
}
// as parseInt but returns a floating point value
float Stream::parseFloat()
{
return parseFloat(NO_SKIP_CHAR);
return parseFloat(NO_SKIP_CHAR);
}
// as above but the given skipChar is ignored
// this allows format characters (typically commas) in values to be ignored
float Stream::parseFloat(char skipChar)
{
boolean isNegative = false;
boolean isFraction = false;
long value = 0;
int c;
float fraction = 1.0;
boolean isNegative = false;
boolean isFraction = false;
long value = 0;
int c;
float fraction = 1.0;
c = peekNextDigit();
c = peekNextDigit();
// ignore non numeric leading characters
if (c < 0)
return 0; // zero returned if timeout
// ignore non numeric leading characters
if (c < 0)
return 0; // zero returned if timeout
do
{
if (c == skipChar)
; // ignore
else if (c == '-')
isNegative = true;
else if (c == '.')
isFraction = true;
else if (c >= '0' && c <= '9')
{
// is c a digit?
value = value * 10 + c - '0';
do
{
if (c == skipChar)
; // ignore
else if (c == '-')
isNegative = true;
else if (c == '.')
isFraction = true;
else if (c >= '0' && c <= '9')
{
// is c a digit?
value = value * 10 + c - '0';
if (isFraction)
fraction *= 0.1f;
}
if (isFraction)
fraction *= 0.1f;
}
read(); // consume the character we got with peek
c = timedPeek();
} while ( (c >= '0' && c <= '9') || c == '.' || c == skipChar );
read(); // consume the character we got with peek
c = timedPeek();
} while ( (c >= '0' && c <= '9') || c == '.' || c == skipChar );
if (isNegative)
value = -value;
if (isNegative)
value = -value;
if (isFraction)
return value * fraction;
else
return value;
if (isFraction)
return value * fraction;
else
return value;
}
// read characters from stream into buffer
@@ -269,26 +269,26 @@ float Stream::parseFloat(char skipChar)
//
size_t Stream::readBytes(char *buffer, size_t length)
{
if (buffer == nullptr)
return 0;
if (buffer == nullptr)
return 0;
size_t count = 0;
size_t count = 0;
while (count < length)
{
int c = timedRead();
while (count < length)
{
int c = timedRead();
if (c < 0)
{
setReadError();
break;
}
if (c < 0)
{
setReadError();
break;
}
*buffer++ = (char)c;
count++;
}
*buffer++ = (char)c;
count++;
}
return count;
return count;
}
@@ -298,34 +298,34 @@ size_t Stream::readBytes(char *buffer, size_t length)
size_t Stream::readBytesUntil(char terminator, char *buffer, size_t length)
{
if (buffer == nullptr)
return 0;
if (buffer == nullptr)
return 0;
if (length < 1)
return 0;
if (length < 1)
return 0;
length--;
size_t index = 0;
length--;
size_t index = 0;
while (index < length)
{
int c = timedRead();
while (index < length)
{
int c = timedRead();
if (c == terminator)
break;
if (c == terminator)
break;
if (c < 0)
{
setReadError();
break;
}
if (c < 0)
{
setReadError();
break;
}
*buffer++ = (char)c;
index++;
}
*buffer++ = (char)c;
index++;
}
*buffer = 0;
return index; // return number of characters, not including null terminator
*buffer = 0;
return index; // return number of characters, not including null terminator
}
#if 1
@@ -333,112 +333,112 @@ size_t Stream::readBytesUntil(char terminator, char *buffer, size_t length)
String Stream::readString(size_t max)
{
String ret;
int c = timedRead();
String ret;
int c = timedRead();
while (c >= 0)
{
ret += (char)c;
c = timedRead();
}
while (c >= 0)
{
ret += (char)c;
c = timedRead();
}
return ret;
return ret;
}
char readStringBuffer[2048];
char* Stream::readCharsUntil(char terminator, size_t max)
{
uint16_t offset = 0;
uint16_t offset = 0;
int c = timedRead();
int c = timedRead();
readStringBuffer[offset++] = c;
readStringBuffer[offset++] = c;
while (c >= 0 && c != terminator)
{
c = timedRead();
while (c >= 0 && c != terminator)
{
c = timedRead();
readStringBuffer[offset++] = c;
}
readStringBuffer[offset++] = c;
}
readStringBuffer[offset] = 0;
readStringBuffer[offset] = 0;
return readStringBuffer;
return readStringBuffer;
}
String Stream::readStringUntil(char terminator, size_t max)
{
String ret;
uint16_t offset = 0;
String ret;
uint16_t offset = 0;
int c = timedRead();
int c = timedRead();
readStringBuffer[offset++] = c;
readStringBuffer[offset++] = c;
while (c >= 0 && c != terminator)
{
c = timedRead();
while (c >= 0 && c != terminator)
{
c = timedRead();
readStringBuffer[offset++] = c;
}
readStringBuffer[offset++] = c;
}
readStringBuffer[offset] = 0;
readStringBuffer[offset] = 0;
ret = String(readStringBuffer);
ret = String(readStringBuffer);
return String(readStringBuffer);
return String(readStringBuffer);
}
#else
String Stream::readString(size_t max)
{
String str;
size_t length = 0;
String str;
size_t length = 0;
while (length < max)
{
int c = timedRead();
while (length < max)
{
int c = timedRead();
if (c < 0)
{
setReadError();
break; // timeout
}
if (c < 0)
{
setReadError();
break; // timeout
}
if (c == 0)
break;
if (c == 0)
break;
str += (char)c;
length++;
}
str += (char)c;
length++;
}
return str;
return str;
}
String Stream::readStringUntil(char terminator, size_t max)
{
String str;
size_t length = 0;
String str;
size_t length = 0;
while (length < max)
{
int c = timedRead();
while (length < max)
{
int c = timedRead();
if (c < 0)
{
setReadError();
break; // timeout
}
if (c < 0)
{
setReadError();
break; // timeout
}
if (c == 0 || c == terminator)
break;
if (c == 0 || c == terminator)
break;
str += (char)c;
length++;
}
str += (char)c;
length++;
}
return str;
return str;
}
#endif
@@ -25,124 +25,124 @@
class Stream : public Print
{
public:
constexpr Stream() : _timeout(1000), read_error(0) {}
virtual int available() = 0;
virtual int read() = 0;
virtual int peek() = 0;
public:
constexpr Stream() : _timeout(1000), read_error(0) {}
virtual int available() = 0;
virtual int read() = 0;
virtual int peek() = 0;
void setTimeout(unsigned long timeout);
bool find(const char *target);
void setTimeout(unsigned long timeout);
bool find(const char *target);
bool find(const uint8_t *target)
{
return find ((const char *)target);
}
bool find(const uint8_t *target)
{
return find ((const char *)target);
}
bool find(const String &target)
{
return find(target.c_str());
}
bool find(const String &target)
{
return find(target.c_str());
}
bool find(const char *target, size_t length);
bool find(const char *target, size_t length);
bool find(const uint8_t *target, size_t length)
{
return find ((const char *)target, length);
}
bool find(const uint8_t *target, size_t length)
{
return find ((const char *)target, length);
}
bool find(const String &target, size_t length)
{
return find(target.c_str(), length);
}
bool find(const String &target, size_t length)
{
return find(target.c_str(), length);
}
bool findUntil(const char *target, const char *terminator);
bool findUntil(const char *target, const char *terminator);
bool findUntil(const uint8_t *target, const char *terminator)
{
return findUntil((const char *)target, terminator);
}
bool findUntil(const uint8_t *target, const char *terminator)
{
return findUntil((const char *)target, terminator);
}
bool findUntil(const String &target, const char *terminator)
{
return findUntil(target.c_str(), terminator);
}
bool findUntil(const String &target, const char *terminator)
{
return findUntil(target.c_str(), terminator);
}
bool findUntil(const char *target, const String &terminator)
{
return findUntil(target, terminator.c_str());
}
bool findUntil(const char *target, const String &terminator)
{
return findUntil(target, terminator.c_str());
}
bool findUntil(const String &target, const String &terminator)
{
return findUntil(target.c_str(), terminator.c_str());
}
bool findUntil(const String &target, const String &terminator)
{
return findUntil(target.c_str(), terminator.c_str());
}
bool findUntil(const char *target, size_t targetLen, const char *terminate, size_t termLen);
bool findUntil(const char *target, size_t targetLen, const char *terminate, size_t termLen);
bool findUntil(const uint8_t *target, size_t targetLen, const char *terminate, size_t termLen)
{
return findUntil((const char *)target, targetLen, terminate, termLen);
}
bool findUntil(const uint8_t *target, size_t targetLen, const char *terminate, size_t termLen)
{
return findUntil((const char *)target, targetLen, terminate, termLen);
}
bool findUntil(const String &target, size_t targetLen, const char *terminate, size_t termLen);
bool findUntil(const char *target, size_t targetLen, const String &terminate, size_t termLen);
bool findUntil(const String &target, size_t targetLen, const String &terminate, size_t termLen);
bool findUntil(const String &target, size_t targetLen, const char *terminate, size_t termLen);
bool findUntil(const char *target, size_t targetLen, const String &terminate, size_t termLen);
bool findUntil(const String &target, size_t targetLen, const String &terminate, size_t termLen);
long parseInt();
long parseInt(char skipChar);
long parseInt();
long parseInt(char skipChar);
float parseFloat();
float parseFloat(char skipChar);
float parseFloat();
float parseFloat(char skipChar);
size_t readBytes(char *buffer, size_t length);
size_t readBytes(char *buffer, size_t length);
size_t readBytes(uint8_t *buffer, size_t length)
{
return readBytes((char *)buffer, length);
}
size_t readBytes(uint8_t *buffer, size_t length)
{
return readBytes((char *)buffer, length);
}
size_t readBytesUntil(char terminator, char *buffer, size_t length);
size_t readBytesUntil(char terminator, char *buffer, size_t length);
size_t readBytesUntil(char terminator, uint8_t *buffer, size_t length)
{
return readBytesUntil(terminator, (char *)buffer, length);
}
size_t readBytesUntil(char terminator, uint8_t *buffer, size_t length)
{
return readBytesUntil(terminator, (char *)buffer, length);
}
////////////////////////////////////////////////////////////
String readString(size_t max = 512);
String readStringUntil(char terminator, size_t max = 512);
////////////////////////////////////////////////////////////
String readString(size_t max = 512);
String readStringUntil(char terminator, size_t max = 512);
// KH, to not use String
char* readCharsUntil(char terminator, size_t max = 512);
////////////////////////////////////////////////////////////
// KH, to not use String
char* readCharsUntil(char terminator, size_t max = 512);
////////////////////////////////////////////////////////////
int getReadError()
{
return read_error;
}
int getReadError()
{
return read_error;
}
void clearReadError()
{
setReadError(0);
}
void clearReadError()
{
setReadError(0);
}
protected:
void setReadError(int err = 1)
{
read_error = err;
}
protected:
void setReadError(int err = 1)
{
read_error = err;
}
unsigned long _timeout;
unsigned long _timeout;
// KH
int timedRead();
int timedPeek();
int peekNextDigit();
//////
// KH
int timedRead();
int timedPeek();
int peekNextDigit();
//////
private:
char read_error;
private:
char read_error;
};
#endif
@@ -28,65 +28,65 @@
// private method to read stream with timeout
int Stream::timedRead()
{
int c;
unsigned long startMillis = millis();
int c;
unsigned long startMillis = millis();
do
{
c = read();
do
{
c = read();
if (c >= 0)
return c;
if (c >= 0)
return c;
yield();
} while (millis() - startMillis < _timeout);
yield();
} while (millis() - startMillis < _timeout);
Serial.print(("timedRead timeout = "));
Serial.println(_timeout);
Serial.print(("timedRead timeout = "));
Serial.println(_timeout);
return -1; // -1 indicates timeout
return -1; // -1 indicates timeout
}
// private method to peek stream with timeout
int Stream::timedPeek()
{
int c;
unsigned long startMillis = millis();
int c;
unsigned long startMillis = millis();
do
{
c = peek();
do
{
c = peek();
if (c >= 0)
return c;
if (c >= 0)
return c;
yield();
} while (millis() - startMillis < _timeout);
yield();
} while (millis() - startMillis < _timeout);
return -1; // -1 indicates timeout
return -1; // -1 indicates timeout
}
// returns peek of the next digit in the stream or -1 if timeout
// discards non-numeric characters
int Stream::peekNextDigit()
{
int c;
int c;
while (1)
{
c = timedPeek();
while (1)
{
c = timedPeek();
if (c < 0)
return c; // timeout
if (c < 0)
return c; // timeout
if (c == '-')
return c;
if (c == '-')
return c;
if (c >= '0' && c <= '9')
return c;
if (c >= '0' && c <= '9')
return c;
read(); // discard non-numeric
}
read(); // discard non-numeric
}
}
// Public Methods
@@ -94,31 +94,31 @@ int Stream::peekNextDigit()
void Stream::setTimeout(unsigned long timeout) // sets the maximum number of milliseconds to wait
{
_timeout = timeout;
_timeout = timeout;
}
// find returns true if the target string is found
bool Stream::find(const char *target)
{
return findUntil(target, NULL);
return findUntil(target, NULL);
}
// reads data from the stream until the target string of given length is found
// returns true if target string is found, false if timed out
bool Stream::find(const char *target, size_t length)
{
return findUntil(target, length, NULL, 0);
return findUntil(target, length, NULL, 0);
}
// as find but search ends if the terminator string is found
bool Stream::findUntil(const char *target, const char *terminator)
{
if (target == nullptr)
return true;
if (target == nullptr)
return true;
size_t tlen = (terminator == nullptr) ? 0 : strlen(terminator);
size_t tlen = (terminator == nullptr) ? 0 : strlen(terminator);
return findUntil(target, strlen(target), terminator, tlen);
return findUntil(target, strlen(target), terminator, tlen);
}
// reads data from the stream until the target string of the given length is found
@@ -126,45 +126,45 @@ bool Stream::findUntil(const char *target, const char *terminator)
// returns true if target string is found, false if terminated or timed out
bool Stream::findUntil(const char *target, size_t targetLen, const char *terminator, size_t termLen)
{
size_t index = 0; // maximum target string length is 64k bytes!
size_t termIndex = 0;
int c;
size_t index = 0; // maximum target string length is 64k bytes!
size_t termIndex = 0;
int c;
if ( target == nullptr)
return true;
if ( target == nullptr)
return true;
if ( *target == 0)
return true; // return true if target is a null string
if ( *target == 0)
return true; // return true if target is a null string
if (terminator == nullptr)
termLen = 0;
if (terminator == nullptr)
termLen = 0;
while ( (c = timedRead()) > 0)
{
if ( c == target[index])
{
//////Serial.print("found "); Serial.write(c); Serial.print("index now"); Serial.println(index+1);
if (++index >= targetLen)
{
// return true if all chars in the target match
return true;
}
}
else
{
index = 0; // reset index if any char does not match
}
while ( (c = timedRead()) > 0)
{
if ( c == target[index])
{
//////Serial.print("found "); Serial.write(c); Serial.print("index now"); Serial.println(index+1);
if (++index >= targetLen)
{
// return true if all chars in the target match
return true;
}
}
else
{
index = 0; // reset index if any char does not match
}
if (termLen > 0 && c == terminator[termIndex])
{
if (++termIndex >= termLen)
return false; // return false if terminate string found before target string
}
else
termIndex = 0;
}
if (termLen > 0 && c == terminator[termIndex])
{
if (++termIndex >= termLen)
return false; // return false if terminate string found before target string
}
else
termIndex = 0;
}
return false;
return false;
}
@@ -173,93 +173,93 @@ bool Stream::findUntil(const char *target, size_t targetLen, const char *termina
// function is terminated by the first character that is not a digit.
long Stream::parseInt()
{
return parseInt(NO_SKIP_CHAR); // terminate on first non-digit character (or timeout)
return parseInt(NO_SKIP_CHAR); // terminate on first non-digit character (or timeout)
}
// as above but a given skipChar is ignored
// this allows format characters (typically commas) in values to be ignored
long Stream::parseInt(char skipChar)
{
boolean isNegative = false;
long value = 0;
int c;
boolean isNegative = false;
long value = 0;
int c;
c = peekNextDigit();
c = peekNextDigit();
// ignore non numeric leading characters
if (c < 0)
return 0; // zero returned if timeout
// ignore non numeric leading characters
if (c < 0)
return 0; // zero returned if timeout
do
{
if (c == skipChar)
; // ignore this charactor
else if (c == '-')
isNegative = true;
else if (c >= '0' && c <= '9') // is c a digit?
value = value * 10 + c - '0';
do
{
if (c == skipChar)
; // ignore this charactor
else if (c == '-')
isNegative = true;
else if (c >= '0' && c <= '9') // is c a digit?
value = value * 10 + c - '0';
read(); // consume the character we got with peek
c = timedPeek();
} while ( (c >= '0' && c <= '9') || c == skipChar );
read(); // consume the character we got with peek
c = timedPeek();
} while ( (c >= '0' && c <= '9') || c == skipChar );
if (isNegative)
value = -value;
if (isNegative)
value = -value;
return value;
return value;
}
// as parseInt but returns a floating point value
float Stream::parseFloat()
{
return parseFloat(NO_SKIP_CHAR);
return parseFloat(NO_SKIP_CHAR);
}
// as above but the given skipChar is ignored
// this allows format characters (typically commas) in values to be ignored
float Stream::parseFloat(char skipChar)
{
boolean isNegative = false;
boolean isFraction = false;
long value = 0;
int c;
float fraction = 1.0;
boolean isNegative = false;
boolean isFraction = false;
long value = 0;
int c;
float fraction = 1.0;
c = peekNextDigit();
c = peekNextDigit();
// ignore non numeric leading characters
if (c < 0)
return 0; // zero returned if timeout
// ignore non numeric leading characters
if (c < 0)
return 0; // zero returned if timeout
do
{
if (c == skipChar)
; // ignore
else if (c == '-')
isNegative = true;
else if (c == '.')
isFraction = true;
else if (c >= '0' && c <= '9')
{
// is c a digit?
value = value * 10 + c - '0';
do
{
if (c == skipChar)
; // ignore
else if (c == '-')
isNegative = true;
else if (c == '.')
isFraction = true;
else if (c >= '0' && c <= '9')
{
// is c a digit?
value = value * 10 + c - '0';
if (isFraction)
fraction *= 0.1f;
}
if (isFraction)
fraction *= 0.1f;
}
read(); // consume the character we got with peek
c = timedPeek();
} while ( (c >= '0' && c <= '9') || c == '.' || c == skipChar );
read(); // consume the character we got with peek
c = timedPeek();
} while ( (c >= '0' && c <= '9') || c == '.' || c == skipChar );
if (isNegative)
value = -value;
if (isNegative)
value = -value;
if (isFraction)
return value * fraction;
else
return value;
if (isFraction)
return value * fraction;
else
return value;
}
// read characters from stream into buffer
@@ -269,26 +269,26 @@ float Stream::parseFloat(char skipChar)
//
size_t Stream::readBytes(char *buffer, size_t length)
{
if (buffer == nullptr)
return 0;
if (buffer == nullptr)
return 0;
size_t count = 0;
size_t count = 0;
while (count < length)
{
int c = timedRead();
while (count < length)
{
int c = timedRead();
if (c < 0)
{
setReadError();
break;
}
if (c < 0)
{
setReadError();
break;
}
*buffer++ = (char)c;
count++;
}
*buffer++ = (char)c;
count++;
}
return count;
return count;
}
@@ -298,34 +298,34 @@ size_t Stream::readBytes(char *buffer, size_t length)
size_t Stream::readBytesUntil(char terminator, char *buffer, size_t length)
{
if (buffer == nullptr)
return 0;
if (buffer == nullptr)
return 0;
if (length < 1)
return 0;
if (length < 1)
return 0;
length--;
size_t index = 0;
length--;
size_t index = 0;
while (index < length)
{
int c = timedRead();
while (index < length)
{
int c = timedRead();
if (c == terminator)
break;
if (c == terminator)
break;
if (c < 0)
{
setReadError();
break;
}
if (c < 0)
{
setReadError();
break;
}
*buffer++ = (char)c;
index++;
}
*buffer++ = (char)c;
index++;
}
*buffer = 0;
return index; // return number of characters, not including null terminator
*buffer = 0;
return index; // return number of characters, not including null terminator
}
#if 1
@@ -333,112 +333,112 @@ size_t Stream::readBytesUntil(char terminator, char *buffer, size_t length)
String Stream::readString(size_t max)
{
String ret;
int c = timedRead();
String ret;
int c = timedRead();
while (c >= 0)
{
ret += (char)c;
c = timedRead();
}
while (c >= 0)
{
ret += (char)c;
c = timedRead();
}
return ret;
return ret;
}
char readStringBuffer[2048];
char* Stream::readCharsUntil(char terminator, size_t max)
{
uint16_t offset = 0;
uint16_t offset = 0;
int c = timedRead();
int c = timedRead();
readStringBuffer[offset++] = c;
readStringBuffer[offset++] = c;
while (c >= 0 && c != terminator)
{
c = timedRead();
while (c >= 0 && c != terminator)
{
c = timedRead();
readStringBuffer[offset++] = c;
}
readStringBuffer[offset++] = c;
}
readStringBuffer[offset] = 0;
readStringBuffer[offset] = 0;
return readStringBuffer;
return readStringBuffer;
}
String Stream::readStringUntil(char terminator, size_t max)
{
String ret;
uint16_t offset = 0;
String ret;
uint16_t offset = 0;
int c = timedRead();
int c = timedRead();
readStringBuffer[offset++] = c;
readStringBuffer[offset++] = c;
while (c >= 0 && c != terminator)
{
c = timedRead();
while (c >= 0 && c != terminator)
{
c = timedRead();
readStringBuffer[offset++] = c;
}
readStringBuffer[offset++] = c;
}
readStringBuffer[offset] = 0;
readStringBuffer[offset] = 0;
ret = String(readStringBuffer);
ret = String(readStringBuffer);
return String(readStringBuffer);
return String(readStringBuffer);
}
#else
String Stream::readString(size_t max)
{
String str;
size_t length = 0;
String str;
size_t length = 0;
while (length < max)
{
int c = timedRead();
while (length < max)
{
int c = timedRead();
if (c < 0)
{
setReadError();
break; // timeout
}
if (c < 0)
{
setReadError();
break; // timeout
}
if (c == 0)
break;
if (c == 0)
break;
str += (char)c;
length++;
}
str += (char)c;
length++;
}
return str;
return str;
}
String Stream::readStringUntil(char terminator, size_t max)
{
String str;
size_t length = 0;
String str;
size_t length = 0;
while (length < max)
{
int c = timedRead();
while (length < max)
{
int c = timedRead();
if (c < 0)
{
setReadError();
break; // timeout
}
if (c < 0)
{
setReadError();
break; // timeout
}
if (c == 0 || c == terminator)
break;
if (c == 0 || c == terminator)
break;
str += (char)c;
length++;
}
str += (char)c;
length++;
}
return str;
return str;
}
#endif
@@ -25,124 +25,124 @@
class Stream : public Print
{
public:
constexpr Stream() : _timeout(1000), read_error(0) {}
virtual int available() = 0;
virtual int read() = 0;
virtual int peek() = 0;
public:
constexpr Stream() : _timeout(1000), read_error(0) {}
virtual int available() = 0;
virtual int read() = 0;
virtual int peek() = 0;
void setTimeout(unsigned long timeout);
bool find(const char *target);
void setTimeout(unsigned long timeout);
bool find(const char *target);
bool find(const uint8_t *target)
{
return find ((const char *)target);
}
bool find(const uint8_t *target)
{
return find ((const char *)target);
}
bool find(const String &target)
{
return find(target.c_str());
}
bool find(const String &target)
{
return find(target.c_str());
}
bool find(const char *target, size_t length);
bool find(const char *target, size_t length);
bool find(const uint8_t *target, size_t length)
{
return find ((const char *)target, length);
}
bool find(const uint8_t *target, size_t length)
{
return find ((const char *)target, length);
}
bool find(const String &target, size_t length)
{
return find(target.c_str(), length);
}
bool find(const String &target, size_t length)
{
return find(target.c_str(), length);
}
bool findUntil(const char *target, const char *terminator);
bool findUntil(const char *target, const char *terminator);
bool findUntil(const uint8_t *target, const char *terminator)
{
return findUntil((const char *)target, terminator);
}
bool findUntil(const uint8_t *target, const char *terminator)
{
return findUntil((const char *)target, terminator);
}
bool findUntil(const String &target, const char *terminator)
{
return findUntil(target.c_str(), terminator);
}
bool findUntil(const String &target, const char *terminator)
{
return findUntil(target.c_str(), terminator);
}
bool findUntil(const char *target, const String &terminator)
{
return findUntil(target, terminator.c_str());
}
bool findUntil(const char *target, const String &terminator)
{
return findUntil(target, terminator.c_str());
}
bool findUntil(const String &target, const String &terminator)
{
return findUntil(target.c_str(), terminator.c_str());
}
bool findUntil(const String &target, const String &terminator)
{
return findUntil(target.c_str(), terminator.c_str());
}
bool findUntil(const char *target, size_t targetLen, const char *terminate, size_t termLen);
bool findUntil(const char *target, size_t targetLen, const char *terminate, size_t termLen);
bool findUntil(const uint8_t *target, size_t targetLen, const char *terminate, size_t termLen)
{
return findUntil((const char *)target, targetLen, terminate, termLen);
}
bool findUntil(const uint8_t *target, size_t targetLen, const char *terminate, size_t termLen)
{
return findUntil((const char *)target, targetLen, terminate, termLen);
}
bool findUntil(const String &target, size_t targetLen, const char *terminate, size_t termLen);
bool findUntil(const char *target, size_t targetLen, const String &terminate, size_t termLen);
bool findUntil(const String &target, size_t targetLen, const String &terminate, size_t termLen);
bool findUntil(const String &target, size_t targetLen, const char *terminate, size_t termLen);
bool findUntil(const char *target, size_t targetLen, const String &terminate, size_t termLen);
bool findUntil(const String &target, size_t targetLen, const String &terminate, size_t termLen);
long parseInt();
long parseInt(char skipChar);
long parseInt();
long parseInt(char skipChar);
float parseFloat();
float parseFloat(char skipChar);
float parseFloat();
float parseFloat(char skipChar);
size_t readBytes(char *buffer, size_t length);
size_t readBytes(char *buffer, size_t length);
size_t readBytes(uint8_t *buffer, size_t length)
{
return readBytes((char *)buffer, length);
}
size_t readBytes(uint8_t *buffer, size_t length)
{
return readBytes((char *)buffer, length);
}
size_t readBytesUntil(char terminator, char *buffer, size_t length);
size_t readBytesUntil(char terminator, char *buffer, size_t length);
size_t readBytesUntil(char terminator, uint8_t *buffer, size_t length)
{
return readBytesUntil(terminator, (char *)buffer, length);
}
size_t readBytesUntil(char terminator, uint8_t *buffer, size_t length)
{
return readBytesUntil(terminator, (char *)buffer, length);
}
////////////////////////////////////////////////////////////
String readString(size_t max = 512);
String readStringUntil(char terminator, size_t max = 512);
////////////////////////////////////////////////////////////
String readString(size_t max = 512);
String readStringUntil(char terminator, size_t max = 512);
// KH, to not use String
char* readCharsUntil(char terminator, size_t max = 512);
////////////////////////////////////////////////////////////
// KH, to not use String
char* readCharsUntil(char terminator, size_t max = 512);
////////////////////////////////////////////////////////////
int getReadError()
{
return read_error;
}
int getReadError()
{
return read_error;
}
void clearReadError()
{
setReadError(0);
}
void clearReadError()
{
setReadError(0);
}
protected:
void setReadError(int err = 1)
{
read_error = err;
}
protected:
void setReadError(int err = 1)
{
read_error = err;
}
unsigned long _timeout;
unsigned long _timeout;
// KH
int timedRead();
int timedPeek();
int peekNextDigit();
//////
// KH
int timedRead();
int timedPeek();
int peekNextDigit();
//////
private:
char read_error;
private:
char read_error;
};
#endif