mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-30 16:24:09 +03:00
Merge branch 'master' into master
This commit is contained in:
@ -725,7 +725,7 @@ int HTTPClient::writeToStream(Stream * stream)
|
||||
int ret = 0;
|
||||
|
||||
if(_transferEncoding == HTTPC_TE_IDENTITY) {
|
||||
if(len > 0) {
|
||||
if(len > 0 || len == -1) {
|
||||
ret = writeToStreamDataBlock(stream, len);
|
||||
|
||||
// have we an error?
|
||||
@ -1184,6 +1184,12 @@ int HTTPClient::writeToStreamDataBlock(Stream * stream, int size)
|
||||
if(readBytes > buff_size) {
|
||||
readBytes = buff_size;
|
||||
}
|
||||
|
||||
// len == -1 or len > what is available, read only what is available
|
||||
int av = _client->available();
|
||||
if (readBytes < 0 || readBytes > av) {
|
||||
readBytes = av;
|
||||
}
|
||||
|
||||
// read data
|
||||
int bytesRead = _client->readBytes(buff, readBytes);
|
||||
|
@ -246,7 +246,7 @@ protected:
|
||||
bool _parseForm(ClientType& client, const String& boundary, uint32_t len);
|
||||
bool _parseFormUploadAborted();
|
||||
void _uploadWriteByte(uint8_t b);
|
||||
uint8_t _uploadReadByte(ClientType& client);
|
||||
int _uploadReadByte(ClientType& client);
|
||||
void _prepareHeader(String& response, int code, const char* content_type, size_t contentLength);
|
||||
bool _collectHeader(const char* headerName, const char* headerValue);
|
||||
|
||||
|
@ -347,14 +347,14 @@ void ESP8266WebServerTemplate<ServerType>::_uploadWriteByte(uint8_t b){
|
||||
}
|
||||
|
||||
template <typename ServerType>
|
||||
uint8_t ESP8266WebServerTemplate<ServerType>::_uploadReadByte(ClientType& client){
|
||||
int ESP8266WebServerTemplate<ServerType>::_uploadReadByte(ClientType& client){
|
||||
int res = client.read();
|
||||
if(res == -1){
|
||||
while(!client.available() && client.connected())
|
||||
yield();
|
||||
res = client.read();
|
||||
}
|
||||
return (uint8_t)res;
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
@ -444,45 +444,34 @@ bool ESP8266WebServerTemplate<ServerType>::_parseForm(ClientType& client, const
|
||||
_currentHandler->upload(*this, _currentUri, *_currentUpload);
|
||||
_currentUpload->status = UPLOAD_FILE_WRITE;
|
||||
|
||||
int bLen = boundary.length();
|
||||
uint8_t boundBuf[2 + bLen + 1]; // "--" + boundary + null terminator
|
||||
boundBuf[2 + bLen] = '\0';
|
||||
uint8_t argByte;
|
||||
bool first = true;
|
||||
while (1) {
|
||||
//attempt to fill up boundary buffer with length of boundary string
|
||||
int i;
|
||||
for (i = 0; i < 2 + bLen; i++) {
|
||||
if (!client.connected()) return _parseFormUploadAborted();
|
||||
argByte = _uploadReadByte(client);
|
||||
if (argByte == '\r')
|
||||
int fastBoundaryLen = 4 /* \r\n-- */ + boundary.length() + 1 /* \0 */;
|
||||
char fastBoundary[ fastBoundaryLen ];
|
||||
snprintf(fastBoundary, fastBoundaryLen, "\r\n--%s", boundary.c_str());
|
||||
int boundaryPtr = 0;
|
||||
while ( true ) {
|
||||
int ret = _uploadReadByte(client);
|
||||
if (ret < 0) {
|
||||
// Unexpected, we should have had data available per above
|
||||
return _parseFormUploadAborted();
|
||||
}
|
||||
char in = (char) ret;
|
||||
if (in == fastBoundary[ boundaryPtr ]) {
|
||||
// The input matched the current expected character, advance and possibly exit this file
|
||||
boundaryPtr++;
|
||||
if (boundaryPtr == fastBoundaryLen - 1) {
|
||||
// We read the whole boundary line, we're done here!
|
||||
break;
|
||||
boundBuf[i] = argByte;
|
||||
}
|
||||
if ((strncmp((const char*)boundBuf, "--", 2) == 0) && (strcmp((const char*)(boundBuf + 2), boundary.c_str()) == 0))
|
||||
break; //found the boundary, done parsing this file
|
||||
if (first) first = false; //only add newline characters after the first line
|
||||
else {
|
||||
_uploadWriteByte('\r');
|
||||
_uploadWriteByte('\n');
|
||||
}
|
||||
// current line does not contain boundary, upload all bytes in boundary buffer
|
||||
for (int j = 0; j < i; j++)
|
||||
_uploadWriteByte(boundBuf[j]);
|
||||
// the initial pass (filling up the boundary buffer) did not reach the end of the line. Upload the rest of the line now
|
||||
if (i >= 2 + bLen) {
|
||||
if (!client.connected()) return _parseFormUploadAborted();
|
||||
argByte = _uploadReadByte(client);
|
||||
while (argByte != '\r') {
|
||||
if (!client.connected()) return _parseFormUploadAborted();
|
||||
_uploadWriteByte(argByte);
|
||||
argByte = _uploadReadByte(client);
|
||||
}
|
||||
} else {
|
||||
// The char doesn't match what we want, so dump whatever matches we had, the read in char, and reset ptr to start
|
||||
for (int i = 0; i < boundaryPtr; i++) {
|
||||
_uploadWriteByte( fastBoundary[ i ] );
|
||||
}
|
||||
_uploadWriteByte( in );
|
||||
boundaryPtr = 0;
|
||||
}
|
||||
if (!client.connected()) return _parseFormUploadAborted();
|
||||
_uploadReadByte(client); // '\n'
|
||||
}
|
||||
//Found the boundary string, finish processing this file upload
|
||||
// Found the boundary string, finish processing this file upload
|
||||
if (_currentHandler && _currentHandler->canUpload(_currentUri))
|
||||
_currentHandler->upload(*this, _currentUri, *_currentUpload);
|
||||
_currentUpload->totalSize += _currentUpload->currentSize;
|
||||
|
@ -69,8 +69,13 @@ uint8_t Servo::attach(int pin, uint16_t minUs, uint16_t maxUs)
|
||||
uint8_t Servo::attach(int pin, uint16_t minUs, uint16_t maxUs, int value)
|
||||
{
|
||||
if (!_attached) {
|
||||
#ifdef WAVEFORM_LOCKED_PHASE
|
||||
pinMode(pin, OUTPUT);
|
||||
digitalWrite(pin, LOW);
|
||||
#else
|
||||
digitalWrite(pin, LOW);
|
||||
pinMode(pin, OUTPUT);
|
||||
#endif
|
||||
_pin = pin;
|
||||
_attached = true;
|
||||
}
|
||||
@ -90,7 +95,11 @@ void Servo::detach()
|
||||
{
|
||||
if (_attached) {
|
||||
_servoMap &= ~(1 << _pin);
|
||||
#ifdef WAVEFORM_LOCKED_PHASE
|
||||
startWaveform(_pin, 0, REFRESH_INTERVAL, 1);
|
||||
#else
|
||||
// TODO - timeHigh == 0 is illegal in _PWM code branch. Do nothing for now.
|
||||
#endif
|
||||
delay(REFRESH_INTERVAL / 1000); // long enough to complete active period under all circumstances.
|
||||
stopWaveform(_pin);
|
||||
_attached = false;
|
||||
@ -115,7 +124,14 @@ void Servo::writeMicroseconds(int value)
|
||||
_valueUs = value;
|
||||
if (_attached) {
|
||||
_servoMap &= ~(1 << _pin);
|
||||
if (startWaveform(_pin, _valueUs, REFRESH_INTERVAL - _valueUs, 0)) {
|
||||
#ifdef WAVEFORM_LOCKED_PHASE
|
||||
// Find the first GPIO being generated by checking GCC's find-first-set (returns 1 + the bit of the first 1 in an int32_t)
|
||||
int phaseReference = __builtin_ffs(_servoMap) - 1;
|
||||
if (startWaveform(_pin, _valueUs, REFRESH_INTERVAL - _valueUs, 0, phaseReference))
|
||||
#else
|
||||
if (startWaveform(_pin, _valueUs, REFRESH_INTERVAL - _valueUs, 0))
|
||||
#endif
|
||||
{
|
||||
_servoMap |= (1 << _pin);
|
||||
}
|
||||
}
|
||||
|
Submodule libraries/SoftwareSerial updated: 4c08ee8d2c...6d520c259c
Reference in New Issue
Block a user