2016-10-06 14:21:30 +03:00
|
|
|
/*
|
|
|
|
|
Stream.h - base class for character-based streams.
|
|
|
|
|
Copyright (c) 2010 David A. Mellis. All right reserved.
|
|
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This library 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
|
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
License along with this library; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
|
|
|
|
|
|
parsing functions based on TextFinder library by Michael Margolis
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef Stream_h
|
|
|
|
|
#define Stream_h
|
|
|
|
|
|
|
|
|
|
#include <inttypes.h>
|
|
|
|
|
#include "Print.h"
|
|
|
|
|
|
|
|
|
|
// compatability macros for testing
|
|
|
|
|
/*
|
|
|
|
|
#define getInt() parseInt()
|
|
|
|
|
#define getInt(skipChar) parseInt(skipchar)
|
|
|
|
|
#define getFloat() parseFloat()
|
|
|
|
|
#define getFloat(skipChar) parseFloat(skipChar)
|
|
|
|
|
#define getString( pre_string, post_string, buffer, length)
|
|
|
|
|
readBytesBetween( pre_string, terminator, buffer, length)
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
class Stream: public Print
|
|
|
|
|
{
|
|
|
|
|
protected:
|
|
|
|
|
unsigned long _timeout; // number of milliseconds to wait for the next char before aborting timed read
|
|
|
|
|
unsigned long _startMillis; // used for timeout measurement
|
|
|
|
|
int timedRead(); // private method to read stream with timeout
|
|
|
|
|
int timedPeek(); // private method to peek stream with timeout
|
|
|
|
|
int peekNextDigit(); // returns the next numeric digit in the stream or -1 if timeout
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
virtual int available() = 0;
|
|
|
|
|
virtual int read() = 0;
|
|
|
|
|
virtual int peek() = 0;
|
|
|
|
|
virtual void flush() = 0;
|
|
|
|
|
|
|
|
|
|
Stream():_startMillis(0)
|
|
|
|
|
{
|
|
|
|
|
_timeout = 1000;
|
|
|
|
|
}
|
|
|
|
|
virtual ~Stream() {}
|
|
|
|
|
|
|
|
|
|
// parsing methods
|
|
|
|
|
|
|
|
|
|
void setTimeout(unsigned long timeout); // sets maximum milliseconds to wait for stream data, default is 1 second
|
2019-04-12 06:45:35 -04:00
|
|
|
unsigned long getTimeout(void);
|
Corrections of Stream.Find, FindUntil and added FindMulti - like AVR-Core Libraries (#3442)
* Corrections of Find, FindUntil and FindMulti
Find has some bug that is not working with Ethernet.find() so, I copied code from Stream.h and Stream.cpp in AVR-CORE library and now it's working perfectly.
I don't know where was the error, but an Ethernet.find compiled to MEGA2560 was working but not working when compiled to esp32, after corrections of code (copy of AVR-Core libraries) it's working perfect.
So probably has some error on original ESP32-Core library.
Below is part of code that was working with MEGA2560 and not with ESP32 libraries.
client.find never return TRUE with ESP32 original library and with AVR it's works.
boolean esp32_fw_update(EthernetClient &client, DecodedHeader &header, const String &field_filename, const String &field_crc) {
char bound[header.boundary.length()+3];
char term[]="\r\n";
strcpy(bound,header.boundary.c_str());
strcat(bound,term);
while (client.find(bound)) {
String line=client.readStringUntil('\r');
* Update Stream.h
* Update Stream.cpp
Co-authored-by: Me No Dev <me-no-dev@users.noreply.github.com>
2020-10-14 09:20:40 -03:00
|
|
|
|
|
|