diff --git a/cores/esp8266/StreamString.cpp b/cores/esp8266/StreamString.cpp index f50b6825b5..24cfe0dd1a 100644 --- a/cores/esp8266/StreamString.cpp +++ b/cores/esp8266/StreamString.cpp @@ -32,6 +32,7 @@ size_t StreamString::write(const uint8_t *data, size_t size) { *(wbuffer() + newlen) = 0x00; // add null for string end return size; } + DEBUGV(":stream2string: OOM (%d->%d)\n", length(), newlen+1); } return 0; } diff --git a/cores/esp8266/WString.cpp b/cores/esp8266/WString.cpp index aee4b1c94b..048704074f 100644 --- a/cores/esp8266/WString.cpp +++ b/cores/esp8266/WString.cpp @@ -185,7 +185,7 @@ unsigned char String::changeBuffer(unsigned int maxStrLen) { size_t oldSize = capacity() + 1; // include NULL. if (isSSO()) { // Copy the SSO buffer into allocated space - memmove(newbuffer, sso.buff, sizeof(sso.buff)); + memmove_P(newbuffer, sso.buff, sizeof(sso.buff)); } if (newSize > oldSize) { @@ -210,7 +210,7 @@ String & String::copy(const char *cstr, unsigned int length) { return *this; } setLen(length); - memmove(wbuffer(), cstr, length + 1); + memmove_P(wbuffer(), cstr, length + 1); return *this; } @@ -228,7 +228,7 @@ String & String::copy(const __FlashStringHelper *pstr, unsigned int length) { void String::move(String &rhs) { if(buffer()) { if(capacity() >= rhs.len()) { - memmove(wbuffer(), rhs.buffer(), rhs.length() + 1); + memmove_P(wbuffer(), rhs.buffer(), rhs.length() + 1); setLen(rhs.len()); rhs.invalidate(); return; @@ -241,7 +241,7 @@ void String::move(String &rhs) { } if (rhs.isSSO()) { setSSO(true); - memmove(sso.buff, rhs.sso.buff, sizeof(sso.buff)); + memmove_P(sso.buff, rhs.sso.buff, sizeof(sso.buff)); } else { setSSO(false); setBuffer(rhs.wbuffer()); @@ -313,7 +313,7 @@ unsigned char String::concat(const String &s) { return 1; if (!reserve(newlen)) return 0; - memmove(wbuffer() + len(), buffer(), len()); + memmove_P(wbuffer() + len(), buffer(), len()); setLen(newlen); wbuffer()[len()] = 0; return 1; @@ -330,12 +330,7 @@ unsigned char String::concat(const char *cstr, unsigned int length) { return 1; if(!reserve(newlen)) return 0; - if (cstr >= wbuffer() && cstr < wbuffer() + len()) - // compatible with SSO in ram #6155 (case "x += x.c_str()") - memmove(wbuffer() + len(), cstr, length + 1); - else - // compatible with source in flash #6367 - memcpy_P(wbuffer() + len(), cstr, length + 1); + memmove_P(wbuffer() + len(), cstr, length + 1); setLen(newlen); return 1; } @@ -739,21 +734,21 @@ void String::replace(const String& find, const String& replace) { char *foundAt; if(diff == 0) { while((foundAt = strstr(readFrom, find.buffer())) != NULL) { - memmove(foundAt, replace.buffer(), replace.len()); + memmove_P(foundAt, replace.buffer(), replace.len()); readFrom = foundAt + replace.len(); } } else if(diff < 0) { char *writeTo = wbuffer(); while((foundAt = strstr(readFrom, find.buffer())) != NULL) { unsigned int n = foundAt - readFrom; - memmove(writeTo, readFrom, n); + memmove_P(writeTo, readFrom, n); writeTo += n; - memmove(writeTo, replace.buffer(), replace.len()); + memmove_P(writeTo, replace.buffer(), replace.len()); writeTo += replace.len(); readFrom = foundAt + find.len(); setLen(len() + diff); } - memmove(writeTo, readFrom, strlen(readFrom)+1); + memmove_P(writeTo, readFrom, strlen(readFrom)+1); } else { unsigned int size = len(); // compute size needed for result while((foundAt = strstr(readFrom, find.buffer())) != NULL) { @@ -767,9 +762,9 @@ void String::replace(const String& find, const String& replace) { int index = len() - 1; while(index >= 0 && (index = lastIndexOf(find, index)) >= 0) { readFrom = wbuffer() + index + find.len(); - memmove(readFrom + diff, readFrom, len() - (readFrom - buffer())); + memmove_P(readFrom + diff, readFrom, len() - (readFrom - buffer())); int newLen = len() + diff; - memmove(wbuffer() + index, replace.buffer(), replace.len()); + memmove_P(wbuffer() + index, replace.buffer(), replace.len()); setLen(newLen); wbuffer()[newLen] = 0; index--; @@ -797,7 +792,7 @@ void String::remove(unsigned int index, unsigned int count) { char *writeTo = wbuffer() + index; unsigned int newlen = len() - count; setLen(newlen); - memmove(writeTo, wbuffer() + index + count, newlen - index); + memmove_P(writeTo, wbuffer() + index + count, newlen - index); wbuffer()[newlen] = 0; } @@ -829,7 +824,7 @@ void String::trim(void) { unsigned int newlen = end + 1 - begin; setLen(newlen); if(begin > buffer()) - memmove(wbuffer(), begin, newlen); + memmove_P(wbuffer(), begin, newlen); wbuffer()[newlen] = 0; } diff --git a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp index 55608f0d3b..6503ea839e 100644 --- a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp +++ b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp @@ -1007,7 +1007,7 @@ const String& HTTPClient::getString(void) _payload.reset(new StreamString()); - if(_size) { + if(_size > 0) { // try to reserve needed memmory if(!_payload->reserve((_size + 1))) { DEBUG_HTTPCLIENT("[HTTP-Client][getString] not enough memory to reserve a string! need: %d\n", (_size + 1)); @@ -1456,10 +1456,10 @@ int HTTPClient::writeToStreamDataBlock(Stream * stream, int size) free(buff); - DEBUG_HTTPCLIENT("[HTTP-Client][writeToStreamDataBlock] connection closed or file end (written: %d).\n", bytesWritten); + DEBUG_HTTPCLIENT("[HTTP-Client][writeToStreamDataBlock] end of chunk or data (transferred: %d).\n", bytesWritten); if((size > 0) && (size != bytesWritten)) { - DEBUG_HTTPCLIENT("[HTTP-Client][writeToStreamDataBlock] bytesWritten %d and size %d mismatch!.\n", bytesWritten, size); + DEBUG_HTTPCLIENT("[HTTP-Client][writeToStreamDataBlock] transferred size %d and request size %d mismatch!.\n", bytesWritten, size); return HTTPC_ERROR_STREAM_WRITE; } diff --git a/package/package_esp8266com_index.template.json b/package/package_esp8266com_index.template.json index 3c96a2e1cf..cc4e3f866d 100644 --- a/package/package_esp8266com_index.template.json +++ b/package/package_esp8266com_index.template.json @@ -138,7 +138,7 @@ "tools": [ { "version": "3.7.2-post1", - "name": "python", + "name": "python3", "systems": [ { "host": "x86_64-mingw32", diff --git a/platform.txt b/platform.txt index e11d4c3fe2..25c14c97e8 100644 --- a/platform.txt +++ b/platform.txt @@ -85,7 +85,8 @@ compiler.elf2hex.extra_flags= ## generate file with git version number ## needs git recipe.hooks.sketch.prebuild.pattern="{runtime.tools.python3.path}/python3" "{runtime.tools.signing}" --mode header --publickey "{build.source.path}/public.key" --out "{build.path}/core/Updater_Signing.h" -recipe.hooks.core.prebuild.pattern="{runtime.tools.python3.path}/python3" "{runtime.tools.makecorever}" --build_path "{build.path}" --platform_path "{runtime.platform.path}" --version "unix-{version}" +# This is quite a working hack. This form of prebuild hook, while intuitive, is not explicitly documented. +recipe.hooks.prebuild.10.pattern="{runtime.tools.python3.path}/python3" "{runtime.tools.makecorever}" --build_path "{build.path}" --platform_path "{runtime.platform.path}" --version "unix-{version}" ## Build the app.ld linker file recipe.hooks.linking.prelink.1.pattern="{compiler.path}{compiler.c.cmd}" -CC -E -P {build.vtable_flags} "{runtime.platform.path}/tools/sdk/ld/eagle.app.v6.common.ld.h" -o "{build.path}/local.eagle.app.v6.common.ld" diff --git a/tests/host/common/ArduinoMain.cpp b/tests/host/common/ArduinoMain.cpp index 7fdf4b22f5..565c7942d0 100644 --- a/tests/host/common/ArduinoMain.cpp +++ b/tests/host/common/ArduinoMain.cpp @@ -129,24 +129,26 @@ void help (const char* argv0, int exitcode) " -b - blocking tty/mocked-uart (default: not blocking tty)\n" " -S - spiffs size in KBytes (default: %zd)\n" " -L - littlefs size in KBytes (default: %zd)\n" - " -v - mock verbose\n" - " (negative value will force mismatched size)\n" + "\t (spiffs, littlefs: negative value will force mismatched size)\n" + " -T - show timestamp on output\n" + " -v - verbose\n" , argv0, MOCK_PORT_SHIFTER, spiffs_kb, littlefs_kb); exit(exitcode); } static struct option options[] = { - { "help", no_argument, NULL, 'h' }, - { "fast", no_argument, NULL, 'f' }, - { "local", no_argument, NULL, 'l' }, - { "sigint", no_argument, NULL, 'c' }, - { "blockinguart", no_argument, NULL, 'b' }, - { "verbose", no_argument, NULL, 'v' }, - { "interface", required_argument, NULL, 'i' }, - { "spiffskb", required_argument, NULL, 'S' }, - { "littlefskb", required_argument, NULL, 'L' }, - { "portshifter", required_argument, NULL, 's' }, + { "help", no_argument, NULL, 'h' }, + { "fast", no_argument, NULL, 'f' }, + { "local", no_argument, NULL, 'l' }, + { "sigint", no_argument, NULL, 'c' }, + { "blockinguart", no_argument, NULL, 'b' }, + { "verbose", no_argument, NULL, 'v' }, + { "timestamp", no_argument, NULL, 'T' }, + { "interface", required_argument, NULL, 'i' }, + { "spiffskb", required_argument, NULL, 'S' }, + { "littlefskb", required_argument, NULL, 'L' }, + { "portshifter", required_argument, NULL, 's' }, }; void cleanup () @@ -182,7 +184,7 @@ int main (int argc, char* const argv []) for (;;) { - int n = getopt_long(argc, argv, "hlcfbvi:S:s:L:", options, NULL); + int n = getopt_long(argc, argv, "hlcfbvTi:S:s:L:", options, NULL); if (n < 0) break; switch (n) @@ -217,6 +219,9 @@ int main (int argc, char* const argv []) case 'v': mockdebug = true; break; + case 'T': + serial_timestamp = true; + break; default: help(argv[0], EXIT_FAILURE); } diff --git a/tests/host/common/MockUART.cpp b/tests/host/common/MockUART.cpp index 6c6a54ab35..67af7ed2cc 100644 --- a/tests/host/common/MockUART.cpp +++ b/tests/host/common/MockUART.cpp @@ -29,6 +29,8 @@ */ #include // write +#include // gettimeofday +#include // localtime #include "Arduino.h" #include "uart.h" @@ -59,13 +61,35 @@ struct uart_ struct uart_rx_buffer_ * rx_buffer; }; +bool serial_timestamp = false; + // write one byte to the emulated UART static void uart_do_write_char(const int uart_nr, char c) { + static bool w = false; + if (uart_nr >= UART0 && uart_nr <= UART1) - if (1 != write(uart_nr + 1, &c, 1)) - fprintf(stderr, "Unable to write character to emulated UART stream: %d\n", c); + { + if (serial_timestamp && (c == '\n' || c == '\r')) + { + if (w) + { + FILE* out = uart_nr == UART0? stdout: stderr; + timeval tv; + gettimeofday(&tv, nullptr); + const tm* tm = localtime(&tv.tv_sec); + fprintf(out, "\r\n%d:%02d:%02d.%06d: ", tm->tm_hour, tm->tm_min, tm->tm_sec, (int)tv.tv_usec); + fflush(out); + w = false; + } + } + else + { + write(uart_nr + 1, &c, 1); + w = true; + } + } } // write a new byte into the RX FIFO buffer diff --git a/tests/host/common/mock.h b/tests/host/common/mock.h index e616167374..a908b2aba4 100644 --- a/tests/host/common/mock.h +++ b/tests/host/common/mock.h @@ -85,7 +85,7 @@ int ets_printf (const char* fmt, ...) __attribute__ ((format (printf, 1, 2))); int mockverbose (const char* fmt, ...) __attribute__ ((format (printf, 1, 2))); extern const char* host_interface; // cmdline parameter - +extern bool serial_timestamp; extern int mock_port_shifter; #define NO_GLOBAL_BINDING 0xffffffff diff --git a/tests/host/sys/pgmspace.h b/tests/host/sys/pgmspace.h index be5046bd92..1b357d2e37 100644 --- a/tests/host/sys/pgmspace.h +++ b/tests/host/sys/pgmspace.h @@ -60,6 +60,7 @@ inline size_t strlen_P(const char *s) { return strlen(s); } inline int vsnprintf_P(char *str, size_t size, const char *format, va_list ap) { return vsnprintf(str, size, format, ap); } #define memcpy_P memcpy +#define memmove_P memmove #define strncpy_P strncpy #define strcmp_P strcmp #define memccpy_P memccpy diff --git a/tools/sdk/libc/xtensa-lx106-elf/include/sys/string.h b/tools/sdk/libc/xtensa-lx106-elf/include/sys/string.h index 159b2d8027..e19c3d8434 100644 --- a/tools/sdk/libc/xtensa-lx106-elf/include/sys/string.h +++ b/tools/sdk/libc/xtensa-lx106-elf/include/sys/string.h @@ -25,6 +25,7 @@ extern "C" { int _EXFUN(memcmp_P,(const _PTR, const _PTR, size_t)); _PTR _EXFUN(memmem_P, (const _PTR, size_t, const _PTR, size_t)); _PTR _EXFUN(memcpy_P,(_PTR __restrict, const _PTR __restrict, size_t)); +_PTR _EXFUN(memmove_P,(_PTR __restrict, const _PTR __restrict, size_t)); _PTR _EXFUN(memccpy_P,(_PTR __restrict, const _PTR __restrict, int, size_t)); _PTR _EXFUN(memchr_P,(const _PTR, int, size_t)); diff --git a/tools/sdk/libc/xtensa-lx106-elf/lib/libc.a b/tools/sdk/libc/xtensa-lx106-elf/lib/libc.a index aa8a59bd91..9c879cdeb5 100644 Binary files a/tools/sdk/libc/xtensa-lx106-elf/lib/libc.a and b/tools/sdk/libc/xtensa-lx106-elf/lib/libc.a differ