From b6c62373e8b76082dcb3da70613a4fc551d36a51 Mon Sep 17 00:00:00 2001 From: slaff Date: Tue, 6 Mar 2018 08:03:17 +0100 Subject: [PATCH 01/10] Fixed memory leak in HttpRequest. (#1342) --- Sming/SmingCore/Network/Http/HttpRequest.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sming/SmingCore/Network/Http/HttpRequest.cpp b/Sming/SmingCore/Network/Http/HttpRequest.cpp index 84c616d1f1..d18c6aaa92 100644 --- a/Sming/SmingCore/Network/Http/HttpRequest.cpp +++ b/Sming/SmingCore/Network/Http/HttpRequest.cpp @@ -52,8 +52,10 @@ HttpRequest& HttpRequest::operator = (const HttpRequest& rhs) { HttpRequest::~HttpRequest() { delete queryParams; delete stream; + delete responseStream; queryParams = NULL; stream = NULL; + responseStream = NULL; } HttpRequest* HttpRequest::setURL(const URL& uri) { From 31828f0d846b58f2e764c8985c085fc69cc1439f Mon Sep 17 00:00:00 2001 From: slaff Date: Thu, 8 Mar 2018 09:30:21 +0100 Subject: [PATCH 02/10] Better support for libraries that rely on Adafruit_Sensor. (#1344) --- Sming/Makefile-project.mk | 3 ++- Sming/Makefile-rboot.mk | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Sming/Makefile-project.mk b/Sming/Makefile-project.mk index 31bd35b751..cbb7170e4f 100644 --- a/Sming/Makefile-project.mk +++ b/Sming/Makefile-project.mk @@ -212,7 +212,8 @@ else ifeq ($(ENABLE_CUSTOM_LWIP), 2) endif EXTRA_INCDIR += $(SMING_HOME)/include $(SMING_HOME)/ $(LWIP_INCDIR) $(SMING_HOME)/system/include \ - $(SMING_HOME)/Wiring $(SMING_HOME)/Libraries $(SMING_HOME)/Libraries/Adafruit_GFX \ + $(SMING_HOME)/Wiring $(SMING_HOME)/Libraries \ + $(SMING_HOME)/Libraries/Adafruit_GFX $(SMING_HOME)/Libraries/Adafruit_Sensor \ $(SMING_HOME)/SmingCore $(SMING_HOME)/Services/SpifFS $(SDK_BASE)/../include \ $(THIRD_PARTY_DIR)/rboot $(THIRD_PARTY_DIR)/rboot/appcode $(THIRD_PARTY_DIR)/spiffs/src diff --git a/Sming/Makefile-rboot.mk b/Sming/Makefile-rboot.mk index 8ec37f3c3d..783504bd26 100644 --- a/Sming/Makefile-rboot.mk +++ b/Sming/Makefile-rboot.mk @@ -227,7 +227,8 @@ else ifeq ($(ENABLE_CUSTOM_LWIP), 2) endif EXTRA_INCDIR += $(SMING_HOME)/include $(SMING_HOME)/ $(LWIP_INCDIR) $(SMING_HOME)/system/include \ - $(SMING_HOME)/Wiring $(SMING_HOME)/Libraries $(SMING_HOME)/Libraries/Adafruit_GFX \ + $(SMING_HOME)/Wiring $(SMING_HOME)/Libraries \ + $(SMING_HOME)/Libraries/Adafruit_GFX $(SMING_HOME)/Libraries/Adafruit_Sensor \ $(SMING_HOME)/SmingCore $(SMING_HOME)/Services/SpifFS $(SDK_BASE)/../include \ $(THIRD_PARTY_DIR)/rboot $(THIRD_PARTY_DIR)/rboot/appcode $(THIRD_PARTY_DIR)/spiffs/src From 19f783200a7652d2f42d8564047897770a665b4d Mon Sep 17 00:00:00 2001 From: frankdownunder Date: Mon, 12 Mar 2018 18:35:30 +1100 Subject: [PATCH 03/10] Fixes to the digitalPinToInterrupt definition (#1346) --- Sming/SmingCore/Interrupts.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sming/SmingCore/Interrupts.h b/Sming/SmingCore/Interrupts.h index 4c6db9b465..aae2f4608f 100644 --- a/Sming/SmingCore/Interrupts.h +++ b/Sming/SmingCore/Interrupts.h @@ -100,7 +100,7 @@ void noInterrupts(); */ void interrupts(); -#define digitalPinToInterrupt(pin) ( (p) < ESP_MAX_INTERRUPTS ? (p) : -1 ) +#define digitalPinToInterrupt(pin) ( (pin) < ESP_MAX_INTERRUPTS ? (pin) : -1 ) #define cli() noInterrupts() #define sei() interrupts() From 958d41eef493bc5ccbc86da6d1cfdb53f071498f Mon Sep 17 00:00:00 2001 From: verybadsoldier Date: Mon, 19 Mar 2018 09:33:14 +0100 Subject: [PATCH 04/10] Fixed reading of http body from stream. (#1349) --- Sming/SmingCore/Network/Http/HttpRequest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sming/SmingCore/Network/Http/HttpRequest.cpp b/Sming/SmingCore/Network/Http/HttpRequest.cpp index d18c6aaa92..cbf99a865b 100644 --- a/Sming/SmingCore/Network/Http/HttpRequest.cpp +++ b/Sming/SmingCore/Network/Http/HttpRequest.cpp @@ -157,7 +157,7 @@ String HttpRequest::getBody() if(stream->available() != -1 && stream->getStreamType() == eSST_Memory) { MemoryDataStream *memory = (MemoryDataStream *)stream; char buf[1024]; - for(int i=0; i< stream->available(); i += 1024) { + while(stream->available() > 0) { int available = memory->readMemoryBlock(buf, 1024); memory->seek(max(available, 0)); ret += String(buf, available); From aee6a401f8510708603da610dc3cf7dbb6d65818 Mon Sep 17 00:00:00 2001 From: slaff Date: Mon, 9 Apr 2018 18:27:39 +0200 Subject: [PATCH 05/10] Updated the Http parser to its latest version. (#1350) --- Sming/third-party/.patches/http-parser.patch | 304 +++++++++++++++++-- Sming/third-party/http-parser | 2 +- 2 files changed, 276 insertions(+), 30 deletions(-) diff --git a/Sming/third-party/.patches/http-parser.patch b/Sming/third-party/.patches/http-parser.patch index 2e340f410e..9650d4f0e7 100644 --- a/Sming/third-party/.patches/http-parser.patch +++ b/Sming/third-party/.patches/http-parser.patch @@ -1,9 +1,9 @@ diff --git a/bench.c b/bench.c deleted file mode 100644 -index 5b452fa..0000000 +index 678f555..0000000 --- a/bench.c +++ /dev/null -@@ -1,111 +0,0 @@ +@@ -1,128 +0,0 @@ -/* Copyright Fedor Indutny. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy @@ -26,10 +26,14 @@ index 5b452fa..0000000 - */ -#include "http_parser.h" -#include +-#include -#include -#include -#include - +-/* 8 gb */ +-static const int64_t kBytes = 8LL << 30; +- -static const char data[] = - "POST /joyent/http-parser HTTP/1.1\r\n" - "Host: github.com\r\n" @@ -44,7 +48,7 @@ index 5b452fa..0000000 - "Referer: https://github.com/joyent/http-parser\r\n" - "Connection: keep-alive\r\n" - "Transfer-Encoding: chunked\r\n" -- "Cache-Control: max-age=0\r\n\r\nb\r\nhello world\r\n0\r\n\r\n"; +- "Cache-Control: max-age=0\r\n\r\nb\r\nhello world\r\n0\r\n"; -static const size_t data_len = sizeof(data) - 1; - -static int on_info(http_parser* p) { @@ -73,13 +77,13 @@ index 5b452fa..0000000 - int err; - struct timeval start; - struct timeval end; -- float rps; - - if (!silent) { - err = gettimeofday(&start, NULL); - assert(err == 0); - } - +- fprintf(stderr, "req_len=%d\n", (int) data_len); - for (i = 0; i < iter_count; i++) { - size_t parsed; - http_parser_init(&parser, HTTP_REQUEST); @@ -89,17 +93,27 @@ index 5b452fa..0000000 - } - - if (!silent) { +- double elapsed; +- double bw; +- double total; +- - err = gettimeofday(&end, NULL); - assert(err == 0); - - fprintf(stdout, "Benchmark result:\n"); - -- rps = (float) (end.tv_sec - start.tv_sec) + -- (end.tv_usec - start.tv_usec) * 1e-6f; -- fprintf(stdout, "Took %f seconds to run\n", rps); +- elapsed = (double) (end.tv_sec - start.tv_sec) + +- (end.tv_usec - start.tv_usec) * 1e-6f; +- +- total = (double) iter_count * data_len; +- bw = (double) total / elapsed; +- +- fprintf(stdout, "%.2f mb | %.2f mb/s | %.2f req/sec | %.2f s\n", +- (double) total / (1024 * 1024), +- bw / (1024 * 1024), +- (double) iter_count / elapsed, +- elapsed); - -- rps = (float) iter_count / rps; -- fprintf(stdout, "%f req/sec\n", rps); - fflush(stdout); - } - @@ -107,45 +121,47 @@ index 5b452fa..0000000 -} - -int main(int argc, char** argv) { +- int64_t iterations; +- +- iterations = kBytes / (int64_t) data_len; - if (argc == 2 && strcmp(argv[1], "infinite") == 0) { - for (;;) -- bench(5000000, 1); +- bench(iterations, 1); - return 0; - } else { -- return bench(5000000, 0); +- return bench(iterations, 0); - } -} diff --git a/http_parser.c b/http_parser.c -index 895bf0c..050d0b7 100644 +index 5b5657b..e7a2b3d 100644 --- a/http_parser.c +++ b/http_parser.c -@@ -22,13 +22,23 @@ +@@ -19,12 +19,22 @@ * IN THE SOFTWARE. */ #include "http_parser.h" -#include -#include +#ifdef __ets__ -+ #include ++ #include +#endif #include - #include #include #include +#ifdef __ets__ -+ #include -+ #include "m_printf.h" -+ #undef assert -+ #define assert(condition) if (!(condition)) m_printf("ASSERT: %s %d", __FUNCTION__, __LINE__) ++ #include ++ #include "m_printf.h" ++ #undef assert ++ #define assert(condition) if (!(condition)) m_printf("ASSERT: %s %d", __FUNCTION__, __LINE__) +#else -+ #include ++ #include +#endif + #ifndef ULLONG_MAX # define ULLONG_MAX ((uint64_t) -1) /* 2^64-1 */ #endif -@@ -186,7 +196,7 @@ static const char *method_strings[] = +@@ -182,7 +192,7 @@ static const char *method_strings[] = * | "/" | "[" | "]" | "?" | "=" * | "{" | "}" | SP | HT */ @@ -154,7 +170,7 @@ index 895bf0c..050d0b7 100644 /* 0 nul 1 soh 2 stx 3 etx 4 eot 5 enq 6 ack 7 bel */ 0, 0, 0, 0, 0, 0, 0, 0, /* 8 bs 9 ht 10 nl 11 vt 12 np 13 cr 14 so 15 si */ -@@ -221,7 +231,7 @@ static const char tokens[256] = { +@@ -217,7 +227,7 @@ static const char tokens[256] = { 'x', 'y', 'z', 0, '|', 0, '~', 0 }; @@ -163,7 +179,7 @@ index 895bf0c..050d0b7 100644 {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 ,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 ,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 -@@ -240,7 +250,7 @@ static const int8_t unhex[256] = +@@ -236,7 +246,7 @@ static const int8_t unhex[256] = #endif @@ -174,10 +190,10 @@ index 895bf0c..050d0b7 100644 /* 8 bs 9 ht 10 nl 11 vt 12 np 13 cr 14 so 15 si */ diff --git a/test.c b/test.c deleted file mode 100644 -index f5744aa..0000000 +index bc4e664..0000000 --- a/test.c +++ /dev/null -@@ -1,4226 +0,0 @@ +@@ -1,4456 +0,0 @@ -/* Copyright Joyent, Inc. and other Node contributors. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy @@ -258,6 +274,7 @@ index f5744aa..0000000 - int message_begin_cb_called; - int headers_complete_cb_called; - int message_complete_cb_called; +- int status_cb_called; - int message_complete_on_eof; - int body_is_final; -}; @@ -1311,7 +1328,7 @@ index f5744aa..0000000 - } - -#define UNLINK_REQUEST 41 --, {.name = "link request" +-, {.name = "unlink request" - ,.type= HTTP_REQUEST - ,.raw= "UNLINK /images/my_dog.jpg HTTP/1.1\r\n" - "Host: example.com\r\n" @@ -1333,6 +1350,26 @@ index f5744aa..0000000 - ,.body= "" - } - +-#define SOURCE_REQUEST 42 +-, {.name = "source request" +- ,.type= HTTP_REQUEST +- ,.raw= "SOURCE /music/sweet/music HTTP/1.1\r\n" +- "Host: example.com\r\n" +- "\r\n" +- ,.should_keep_alive= TRUE +- ,.message_complete_on_eof= FALSE +- ,.http_major= 1 +- ,.http_minor= 1 +- ,.method= HTTP_SOURCE +- ,.request_path= "/music/sweet/music" +- ,.request_url= "/music/sweet/music" +- ,.query_string= "" +- ,.fragment= "" +- ,.num_headers= 1 +- ,.headers= { { "Host", "example.com" } } +- ,.body= "" +- } +- -, {.name= NULL } /* sentinel */ -}; - @@ -1951,6 +1988,167 @@ index f5744aa..0000000 - ,.chunk_lengths= { 2 } - } - +-#define HTTP_101_RESPONSE_WITH_UPGRADE_HEADER 22 +-, {.name= "HTTP 101 response with Upgrade header" +- ,.type= HTTP_RESPONSE +- ,.raw= "HTTP/1.1 101 Switching Protocols\r\n" +- "Connection: upgrade\r\n" +- "Upgrade: h2c\r\n" +- "\r\n" +- "proto" +- ,.should_keep_alive= TRUE +- ,.message_complete_on_eof= FALSE +- ,.http_major= 1 +- ,.http_minor= 1 +- ,.status_code= 101 +- ,.response_status= "Switching Protocols" +- ,.upgrade= "proto" +- ,.num_headers= 2 +- ,.headers= +- { { "Connection", "upgrade" } +- , { "Upgrade", "h2c" } +- } +- } +- +-#define HTTP_101_RESPONSE_WITH_UPGRADE_HEADER_AND_CONTENT_LENGTH 23 +-, {.name= "HTTP 101 response with Upgrade and Content-Length header" +- ,.type= HTTP_RESPONSE +- ,.raw= "HTTP/1.1 101 Switching Protocols\r\n" +- "Connection: upgrade\r\n" +- "Upgrade: h2c\r\n" +- "Content-Length: 4\r\n" +- "\r\n" +- "body" +- "proto" +- ,.should_keep_alive= TRUE +- ,.message_complete_on_eof= FALSE +- ,.http_major= 1 +- ,.http_minor= 1 +- ,.status_code= 101 +- ,.response_status= "Switching Protocols" +- ,.body= "body" +- ,.upgrade= "proto" +- ,.num_headers= 3 +- ,.headers= +- { { "Connection", "upgrade" } +- , { "Upgrade", "h2c" } +- , { "Content-Length", "4" } +- } +- } +- +-#define HTTP_101_RESPONSE_WITH_UPGRADE_HEADER_AND_TRANSFER_ENCODING 24 +-, {.name= "HTTP 101 response with Upgrade and Transfer-Encoding header" +- ,.type= HTTP_RESPONSE +- ,.raw= "HTTP/1.1 101 Switching Protocols\r\n" +- "Connection: upgrade\r\n" +- "Upgrade: h2c\r\n" +- "Transfer-Encoding: chunked\r\n" +- "\r\n" +- "2\r\n" +- "bo\r\n" +- "2\r\n" +- "dy\r\n" +- "0\r\n" +- "\r\n" +- "proto" +- ,.should_keep_alive= TRUE +- ,.message_complete_on_eof= FALSE +- ,.http_major= 1 +- ,.http_minor= 1 +- ,.status_code= 101 +- ,.response_status= "Switching Protocols" +- ,.body= "body" +- ,.upgrade= "proto" +- ,.num_headers= 3 +- ,.headers= +- { { "Connection", "upgrade" } +- , { "Upgrade", "h2c" } +- , { "Transfer-Encoding", "chunked" } +- } +- ,.num_chunks_complete= 3 +- ,.chunk_lengths= { 2, 2 } +- } +- +-#define HTTP_200_RESPONSE_WITH_UPGRADE_HEADER 25 +-, {.name= "HTTP 200 response with Upgrade header" +- ,.type= HTTP_RESPONSE +- ,.raw= "HTTP/1.1 200 OK\r\n" +- "Connection: upgrade\r\n" +- "Upgrade: h2c\r\n" +- "\r\n" +- "body" +- ,.should_keep_alive= FALSE +- ,.message_complete_on_eof= TRUE +- ,.http_major= 1 +- ,.http_minor= 1 +- ,.status_code= 200 +- ,.response_status= "OK" +- ,.body= "body" +- ,.upgrade= NULL +- ,.num_headers= 2 +- ,.headers= +- { { "Connection", "upgrade" } +- , { "Upgrade", "h2c" } +- } +- } +- +-#define HTTP_200_RESPONSE_WITH_UPGRADE_HEADER_AND_CONTENT_LENGTH 26 +-, {.name= "HTTP 200 response with Upgrade and Content-Length header" +- ,.type= HTTP_RESPONSE +- ,.raw= "HTTP/1.1 200 OK\r\n" +- "Connection: upgrade\r\n" +- "Upgrade: h2c\r\n" +- "Content-Length: 4\r\n" +- "\r\n" +- "body" +- ,.should_keep_alive= TRUE +- ,.message_complete_on_eof= FALSE +- ,.http_major= 1 +- ,.http_minor= 1 +- ,.status_code= 200 +- ,.response_status= "OK" +- ,.num_headers= 3 +- ,.body= "body" +- ,.upgrade= NULL +- ,.headers= +- { { "Connection", "upgrade" } +- , { "Upgrade", "h2c" } +- , { "Content-Length", "4" } +- } +- } +- +-#define HTTP_200_RESPONSE_WITH_UPGRADE_HEADER_AND_TRANSFER_ENCODING 27 +-, {.name= "HTTP 200 response with Upgrade and Transfer-Encoding header" +- ,.type= HTTP_RESPONSE +- ,.raw= "HTTP/1.1 200 OK\r\n" +- "Connection: upgrade\r\n" +- "Upgrade: h2c\r\n" +- "Transfer-Encoding: chunked\r\n" +- "\r\n" +- "2\r\n" +- "bo\r\n" +- "2\r\n" +- "dy\r\n" +- "0\r\n" +- "\r\n" +- ,.should_keep_alive= TRUE +- ,.message_complete_on_eof= FALSE +- ,.http_major= 1 +- ,.http_minor= 1 +- ,.status_code= 200 +- ,.response_status= "OK" +- ,.num_headers= 3 +- ,.body= "body" +- ,.upgrade= NULL +- ,.headers= +- { { "Connection", "upgrade" } +- , { "Upgrade", "h2c" } +- , { "Transfer-Encoding", "chunked" } +- } +- ,.num_chunks_complete= 3 +- ,.chunk_lengths= { 2, 2 } +- } +- -, {.name= NULL } /* sentinel */ -}; - @@ -2161,6 +2359,9 @@ index f5744aa..0000000 -response_status_cb (http_parser *p, const char *buf, size_t len) -{ - assert(p == parser); +- +- messages[num_messages].status_cb_called = TRUE; +- - strlncat(messages[num_messages].response_status, - sizeof(messages[num_messages].response_status), - buf, @@ -2585,6 +2786,7 @@ index f5744aa..0000000 - } else { - MESSAGE_CHECK_NUM_EQ(expected, m, status_code); - MESSAGE_CHECK_STR_EQ(expected, m, response_status); +- assert(m->status_cb_called); - } - - if (!connect) { @@ -2656,7 +2858,9 @@ index f5744aa..0000000 - if (!r) return 0; - } - -- MESSAGE_CHECK_STR_EQ(expected, m, upgrade); +- if (!connect) { +- MESSAGE_CHECK_STR_EQ(expected, m, upgrade); +- } - - return 1; -} @@ -3493,9 +3697,11 @@ index f5744aa..0000000 -} - -void --test_simple (const char *buf, enum http_errno err_expected) +-test_simple_type (const char *buf, +- enum http_errno err_expected, +- enum http_parser_type type) -{ -- parser_init(HTTP_REQUEST); +- parser_init(type); - - enum http_errno err; - @@ -3520,6 +3726,12 @@ index f5744aa..0000000 -} - -void +-test_simple (const char *buf, enum http_errno err_expected) +-{ +- test_simple_type(buf, err_expected, HTTP_REQUEST); +-} +- +-void -test_invalid_header_content (int req, const char* str) -{ - http_parser parser; @@ -3669,6 +3881,30 @@ index f5744aa..0000000 -} - -void +-test_no_overflow_parse_url (void) +-{ +- int rv; +- struct http_parser_url u; +- +- http_parser_url_init(&u); +- rv = http_parser_parse_url("http://example.com:8001", 22, 0, &u); +- +- if (rv != 0) { +- fprintf(stderr, +- "\n*** test_no_overflow_parse_url invalid return value=%d\n", +- rv); +- abort(); +- } +- +- if (u.port != 800) { +- fprintf(stderr, +- "\n*** test_no_overflow_parse_url invalid port number=%d\n", +- u.port); +- abort(); +- } +-} +- +-void -test_header_overflow_error (int req) -{ - http_parser parser; @@ -4103,6 +4339,7 @@ index f5744aa..0000000 - test_header_nread_value(); - - //// OVERFLOW CONDITIONS +- test_no_overflow_parse_url(); - - test_header_overflow_error(HTTP_REQUEST); - test_no_overflow_long_body(HTTP_REQUEST, 1000); @@ -4129,6 +4366,12 @@ index f5744aa..0000000 - - //// RESPONSES - +- test_simple_type("HTP/1.1 200 OK\r\n\r\n", HPE_INVALID_VERSION, HTTP_RESPONSE); +- test_simple_type("HTTP/01.1 200 OK\r\n\r\n", HPE_INVALID_VERSION, HTTP_RESPONSE); +- test_simple_type("HTTP/11.1 200 OK\r\n\r\n", HPE_INVALID_VERSION, HTTP_RESPONSE); +- test_simple_type("HTTP/1.01 200 OK\r\n\r\n", HPE_INVALID_VERSION, HTTP_RESPONSE); +- test_simple_type("HTTP/1.1\t200 OK\r\n\r\n", HPE_INVALID_VERSION, HTTP_RESPONSE); +- - for (i = 0; i < response_count; i++) { - test_message(&responses[i]); - } @@ -4206,6 +4449,9 @@ index f5744aa..0000000 - /// REQUESTS - - test_simple("GET / HTP/1.1\r\n\r\n", HPE_INVALID_VERSION); +- test_simple("GET / HTTP/01.1\r\n\r\n", HPE_INVALID_VERSION); +- test_simple("GET / HTTP/11.1\r\n\r\n", HPE_INVALID_VERSION); +- test_simple("GET / HTTP/1.01\r\n\r\n", HPE_INVALID_VERSION); - - // Extended characters - see nodejs/test/parallel/test-http-headers-obstext.js - test_simple("GET / HTTP/1.1\r\n" diff --git a/Sming/third-party/http-parser b/Sming/third-party/http-parser index 335850f6b8..edeedb1b4d 160000 --- a/Sming/third-party/http-parser +++ b/Sming/third-party/http-parser @@ -1 +1 @@ -Subproject commit 335850f6b868d3411968cbf5a4d59fe619dee36f +Subproject commit edeedb1b4d2f34e4c7d8045ac8b92adbc35e7ed7 From 6f3bf3e6ce914ab0b3416f8ec7a636e0f646f4d0 Mon Sep 17 00:00:00 2001 From: slaff Date: Tue, 10 Apr 2018 11:25:06 +0200 Subject: [PATCH 06/10] Prevent "already-freed" error from happening. (#1359) Fixes #1357. --- Sming/SmingCore/Network/Http/HttpConnection.cpp | 1 + Sming/SmingCore/Network/Http/HttpServerConnection.cpp | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Sming/SmingCore/Network/Http/HttpConnection.cpp b/Sming/SmingCore/Network/Http/HttpConnection.cpp index a1b378ac54..883fcbf3b0 100644 --- a/Sming/SmingCore/Network/Http/HttpConnection.cpp +++ b/Sming/SmingCore/Network/Http/HttpConnection.cpp @@ -225,6 +225,7 @@ int HttpConnection::staticOnMessageComplete(http_parser* parser) if(connection->incomingRequest->responseStream != NULL) { connection->incomingRequest->responseStream->close(); delete connection->incomingRequest->responseStream; + connection->incomingRequest->responseStream = NULL; } delete connection->incomingRequest; diff --git a/Sming/SmingCore/Network/Http/HttpServerConnection.cpp b/Sming/SmingCore/Network/Http/HttpServerConnection.cpp index c7c0e7fd0c..9d5919634d 100644 --- a/Sming/SmingCore/Network/Http/HttpServerConnection.cpp +++ b/Sming/SmingCore/Network/Http/HttpServerConnection.cpp @@ -90,7 +90,8 @@ int HttpServerConnection::staticOnMessageBegin(http_parser* parser) return 0; } -int HttpServerConnection::staticOnPath(http_parser *parser, const char *at, size_t length) { +int HttpServerConnection::staticOnPath(http_parser *parser, const char *at, size_t length) +{ HttpServerConnection *connection = (HttpServerConnection*)parser->data; if(connection == NULL) { // something went wrong @@ -150,6 +151,7 @@ int HttpServerConnection::staticOnMessageComplete(http_parser* parser) if(connection->request.responseStream != NULL) { connection->request.responseStream->close(); delete connection->request.responseStream; + connection->request.responseStream = NULL; } return hasError; @@ -175,7 +177,7 @@ int HttpServerConnection::staticOnHeadersComplete(http_parser* parser) * chunked' headers that indicate the presence of a body. * * Returning `2` from on_headers_complete will tell parser that it should not - * expect neither a body nor any futher responses on this connection. This is + * expect neither a body nor any further responses on this connection. This is * useful for handling responses to a CONNECT request which may not contain * `Upgrade` or `Connection: upgrade` headers. */ @@ -509,7 +511,8 @@ bool HttpServerConnection::sendResponseBody(HttpResponse *response) } -void HttpServerConnection::onError(err_t err) { +void HttpServerConnection::onError(err_t err) +{ TcpClient::onError(err); } From ed0ca30a9e7a70e996892b35526e2729fed095d3 Mon Sep 17 00:00:00 2001 From: slaff Date: Wed, 11 Apr 2018 12:10:46 +0200 Subject: [PATCH 07/10] Small changes allowing the use of C++11 std::function. (#1353) * Small changes allowing the use of C++11 std::function. --- Sming/Libraries/ArduCAM/ArduCAMStream.cpp | 2 +- Sming/Libraries/I2Cdev/I2Cdev.cpp | 2 +- Sming/SmingCore/SPI.cpp | 2 +- Sming/SmingCore/SmingCore.h | 5 +++++ Sming/Wiring/WConstants.h | 4 ++++ Sming/appinit/user_main.cpp | 7 +++++++ 6 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Sming/Libraries/ArduCAM/ArduCAMStream.cpp b/Sming/Libraries/ArduCAM/ArduCAMStream.cpp index 5dad79555b..91564aa79c 100644 --- a/Sming/Libraries/ArduCAM/ArduCAMStream.cpp +++ b/Sming/Libraries/ArduCAM/ArduCAMStream.cpp @@ -99,7 +99,7 @@ uint16_t ArduCAMStream::readMemoryBlock(char* data, int bufSize) { } - int bytesread = min(len, bufSize); + int bytesread = min(len, (unsigned int)bufSize); ACAM_DEBUG("ArduCAMStream::readMemoryBlock [%d] (%d bytes) remaining (%d bytes)\n", bcount++, bytesread, len); diff --git a/Sming/Libraries/I2Cdev/I2Cdev.cpp b/Sming/Libraries/I2Cdev/I2Cdev.cpp index 3e65697ad3..25d9db0ca6 100644 --- a/Sming/Libraries/I2Cdev/I2Cdev.cpp +++ b/Sming/Libraries/I2Cdev/I2Cdev.cpp @@ -273,7 +273,7 @@ int8_t I2Cdev::readBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8 // I2C/TWI subsystem uses internal buffer that breaks with large data requests // so if user requests more than BUFFER_LENGTH bytes, we have to do it in // smaller chunks instead of all at once - for (uint8_t k = 0; k < length; k += min(length, BUFFER_LENGTH)) { + for (uint8_t k = 0; k < length; k += min((unsigned int)length, (unsigned int)BUFFER_LENGTH)) { Wire.beginTransmission(devAddr); Wire.write(regAddr); Wire.endTransmission(); diff --git a/Sming/SmingCore/SPI.cpp b/Sming/SmingCore/SPI.cpp index b3f1787485..48b75efd01 100644 --- a/Sming/SmingCore/SPI.cpp +++ b/Sming/SmingCore/SPI.cpp @@ -197,7 +197,7 @@ void SPIClass::transfer(uint8 *buffer, size_t numberBytes) { while (blocks--) { // get full BLOCKSIZE or number of remaining bytes - bufLenght = min(numberBytes-bufIndx, BLOCKSIZE); + bufLenght = min(numberBytes-bufIndx, (unsigned int)BLOCKSIZE); #ifdef SPI_DEBUG debugf("Write/Read Block %d total %d bytes", total-blocks, bufLenght); diff --git a/Sming/SmingCore/SmingCore.h b/Sming/SmingCore/SmingCore.h index e44f7a510b..7e48c8b663 100644 --- a/Sming/SmingCore/SmingCore.h +++ b/Sming/SmingCore/SmingCore.h @@ -10,6 +10,11 @@ #define SMING_VERSION "3.5.1" // Major Minor Sub +#include + +#define min(A, B) std::min(A, B) +#define max(A, B) std::max(A, B) + #include "../Wiring/WiringFrameworkIncludes.h" #include "Delegate.h" diff --git a/Sming/Wiring/WConstants.h b/Sming/Wiring/WConstants.h index 1b431d8398..30d6936283 100644 --- a/Sming/Wiring/WConstants.h +++ b/Sming/Wiring/WConstants.h @@ -114,8 +114,12 @@ #define sq(x) ((x)*(x)) //#define abs(x) ((x)>0?(x):-(x)) +#ifndef min #define min(a,b) ((a)<(b)?(a):(b)) +#endif +#ifndef max #define max(a,b) ((a)>(b)?(a):(b)) +#endif //#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5)) #define radians(deg) ((deg)*DEG_TO_RAD) #define degrees(rad) ((rad)*RAD_TO_DEG) diff --git a/Sming/appinit/user_main.cpp b/Sming/appinit/user_main.cpp index 8e57fe8eec..ae1b7918cd 100644 --- a/Sming/appinit/user_main.cpp +++ b/Sming/appinit/user_main.cpp @@ -68,3 +68,10 @@ extern "C" uint32 ICACHE_FLASH_ATTR __attribute__((weak)) user_rf_cal_sector_se return rf_cal_sec; } + +namespace std { + void __attribute__((weak)) __throw_bad_function_call() + { + while(1); + }; +} From 78da89e21a2f43bc5b2061bd3619e563ff5daf2f Mon Sep 17 00:00:00 2001 From: slaff Date: Thu, 12 Apr 2018 09:00:41 +0200 Subject: [PATCH 08/10] Updated PWM to its latest version. (#1360) --- Sming/third-party/.patches/pwm.patch | 12 +++++++----- Sming/third-party/pwm | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Sming/third-party/.patches/pwm.patch b/Sming/third-party/.patches/pwm.patch index bd2b382c65..26fb1037ad 100644 --- a/Sming/third-party/.patches/pwm.patch +++ b/Sming/third-party/.patches/pwm.patch @@ -1,5 +1,5 @@ diff --git a/pwm.c b/pwm.c -index 5e7f218..0386a06 100644 +index 6df21ac..d039908 100644 --- a/pwm.c +++ b/pwm.c @@ -16,6 +16,8 @@ @@ -11,12 +11,14 @@ index 5e7f218..0386a06 100644 /* Set the following three defines to your needs */ #ifndef SDK_PWM_PERIOD_COMPAT_MODE -@@ -109,7 +111,7 @@ struct timer_regs { +@@ -109,8 +111,8 @@ struct timer_regs { }; - static struct timer_regs* timer = (void*)(0x60000600); + static struct timer_regs* timer = (struct timer_regs*)(0x60000600); --static void pwm_intr_handler(void) -+static void pwm_intr_handler(void* param) +-static void ICACHE_RAM_ATTR +-pwm_intr_handler(void) ++static void IRAM_ATTR ++pwm_intr_handler(void* param) { if ((pwm_state.current_set[pwm_state.current_phase].off_mask == 0) && (pwm_state.current_set[pwm_state.current_phase].on_mask == 0)) { diff --git a/Sming/third-party/pwm b/Sming/third-party/pwm index e1c1d0fc59..19cb69e9ce 160000 --- a/Sming/third-party/pwm +++ b/Sming/third-party/pwm @@ -1 +1 @@ -Subproject commit e1c1d0fc59941bbbf45d520f04c953b97450ead0 +Subproject commit 19cb69e9ce5071686d0e2a28962fd06e11d03a61 From cd7a1d36e4cd138531658e28c39633be5eab91db Mon Sep 17 00:00:00 2001 From: slaff Date: Wed, 18 Apr 2018 12:32:49 +0200 Subject: [PATCH 09/10] Added missing Eclipse .project and .cporject files for some samples. (#1364) --- samples/Basic_APA102/.cproject | 151 ++++++++++++++++++++++++++++ samples/Basic_APA102/.project | 28 ++++++ samples/Basic_Ssl/.cproject | 151 ++++++++++++++++++++++++++++ samples/Gesture_APDS-9960/.cproject | 151 ++++++++++++++++++++++++++++ samples/Gesture_APDS-9960/.project | 28 ++++++ samples/IR_lib/.cproject | 151 ++++++++++++++++++++++++++++ samples/IR_lib/.project | 28 ++++++ samples/ScreenTFT_ST7735/.cproject | 151 ++++++++++++++++++++++++++++ samples/ScreenTFT_ST7735/.project | 28 ++++++ 9 files changed, 867 insertions(+) create mode 100644 samples/Basic_APA102/.cproject create mode 100644 samples/Basic_APA102/.project create mode 100644 samples/Basic_Ssl/.cproject create mode 100644 samples/Gesture_APDS-9960/.cproject create mode 100644 samples/Gesture_APDS-9960/.project create mode 100644 samples/IR_lib/.cproject create mode 100644 samples/IR_lib/.project create mode 100644 samples/ScreenTFT_ST7735/.cproject create mode 100644 samples/ScreenTFT_ST7735/.project diff --git a/samples/Basic_APA102/.cproject b/samples/Basic_APA102/.cproject new file mode 100644 index 0000000000..e1450b6031 --- /dev/null +++ b/samples/Basic_APA102/.cproject @@ -0,0 +1,151 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + make + -f ${ProjDirPath}/Makefile + all + true + true + true + + + make + -f ${ProjDirPath}/Makefile + clean + true + true + true + + + make + -f ${ProjDirPath}/Makefile + flash + true + true + true + + + make + -f ${ProjDirPath}/Makefile + flashonefile + true + true + true + + + make + -f ${ProjDirPath}/Makefile + flashinit + true + true + true + + + make + -f ${ProjDirPath}/Makefile + flashboot + true + true + true + + + make + -f ${ProjDirPath}/Makefile + rebuild + true + true + true + + + + + + + + + + + + + + + + + + + + diff --git a/samples/Basic_APA102/.project b/samples/Basic_APA102/.project new file mode 100644 index 0000000000..97036b7c8e --- /dev/null +++ b/samples/Basic_APA102/.project @@ -0,0 +1,28 @@ + + + Basic_APA102 + + + SmingFramework + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + diff --git a/samples/Basic_Ssl/.cproject b/samples/Basic_Ssl/.cproject new file mode 100644 index 0000000000..e1450b6031 --- /dev/null +++ b/samples/Basic_Ssl/.cproject @@ -0,0 +1,151 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + make + -f ${ProjDirPath}/Makefile + all + true + true + true + + + make + -f ${ProjDirPath}/Makefile + clean + true + true + true + + + make + -f ${ProjDirPath}/Makefile + flash + true + true + true + + + make + -f ${ProjDirPath}/Makefile + flashonefile + true + true + true + + + make + -f ${ProjDirPath}/Makefile + flashinit + true + true + true + + + make + -f ${ProjDirPath}/Makefile + flashboot + true + true + true + + + make + -f ${ProjDirPath}/Makefile + rebuild + true + true + true + + + + + + + + + + + + + + + + + + + + diff --git a/samples/Gesture_APDS-9960/.cproject b/samples/Gesture_APDS-9960/.cproject new file mode 100644 index 0000000000..e1450b6031 --- /dev/null +++ b/samples/Gesture_APDS-9960/.cproject @@ -0,0 +1,151 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + make + -f ${ProjDirPath}/Makefile + all + true + true + true + + + make + -f ${ProjDirPath}/Makefile + clean + true + true + true + + + make + -f ${ProjDirPath}/Makefile + flash + true + true + true + + + make + -f ${ProjDirPath}/Makefile + flashonefile + true + true + true + + + make + -f ${ProjDirPath}/Makefile + flashinit + true + true + true + + + make + -f ${ProjDirPath}/Makefile + flashboot + true + true + true + + + make + -f ${ProjDirPath}/Makefile + rebuild + true + true + true + + + + + + + + + + + + + + + + + + + + diff --git a/samples/Gesture_APDS-9960/.project b/samples/Gesture_APDS-9960/.project new file mode 100644 index 0000000000..0784e87605 --- /dev/null +++ b/samples/Gesture_APDS-9960/.project @@ -0,0 +1,28 @@ + + + Gesture_APDS-9960 + + + SmingFramework + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + diff --git a/samples/IR_lib/.cproject b/samples/IR_lib/.cproject new file mode 100644 index 0000000000..e1450b6031 --- /dev/null +++ b/samples/IR_lib/.cproject @@ -0,0 +1,151 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + make + -f ${ProjDirPath}/Makefile + all + true + true + true + + + make + -f ${ProjDirPath}/Makefile + clean + true + true + true + + + make + -f ${ProjDirPath}/Makefile + flash + true + true + true + + + make + -f ${ProjDirPath}/Makefile + flashonefile + true + true + true + + + make + -f ${ProjDirPath}/Makefile + flashinit + true + true + true + + + make + -f ${ProjDirPath}/Makefile + flashboot + true + true + true + + + make + -f ${ProjDirPath}/Makefile + rebuild + true + true + true + + + + + + + + + + + + + + + + + + + + diff --git a/samples/IR_lib/.project b/samples/IR_lib/.project new file mode 100644 index 0000000000..27f9d0781b --- /dev/null +++ b/samples/IR_lib/.project @@ -0,0 +1,28 @@ + + + IR_lib + + + SmingFramework + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + diff --git a/samples/ScreenTFT_ST7735/.cproject b/samples/ScreenTFT_ST7735/.cproject new file mode 100644 index 0000000000..e1450b6031 --- /dev/null +++ b/samples/ScreenTFT_ST7735/.cproject @@ -0,0 +1,151 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + make + -f ${ProjDirPath}/Makefile + all + true + true + true + + + make + -f ${ProjDirPath}/Makefile + clean + true + true + true + + + make + -f ${ProjDirPath}/Makefile + flash + true + true + true + + + make + -f ${ProjDirPath}/Makefile + flashonefile + true + true + true + + + make + -f ${ProjDirPath}/Makefile + flashinit + true + true + true + + + make + -f ${ProjDirPath}/Makefile + flashboot + true + true + true + + + make + -f ${ProjDirPath}/Makefile + rebuild + true + true + true + + + + + + + + + + + + + + + + + + + + diff --git a/samples/ScreenTFT_ST7735/.project b/samples/ScreenTFT_ST7735/.project new file mode 100644 index 0000000000..4a2668bcb8 --- /dev/null +++ b/samples/ScreenTFT_ST7735/.project @@ -0,0 +1,28 @@ + + + ScreenTFT_ST7735 + + + SmingFramework + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + From ff7fb1e5e50e386031e14792d154b70cb3c204c4 Mon Sep 17 00:00:00 2001 From: slaff Date: Tue, 24 Apr 2018 15:31:12 +0200 Subject: [PATCH 10/10] In C++ use std::max and std::min instead of the max() and min() macros. (#1368) The old Arduino libs can still continue to use the macros. --- Sming/SmingCore/ArduinoCompat.h | 9 +++++++++ Sming/SmingCore/DataSourceStream.cpp | 7 ++++--- Sming/SmingCore/Network/Http/HttpRequest.cpp | 4 +++- .../Network/Http/Stream/HttpChunkedStream.cpp | 4 +++- Sming/SmingCore/Network/MqttClient.cpp | 4 ++-- Sming/SmingCore/Network/TcpConnection.cpp | 6 ++++-- Sming/SmingCore/SPI.cpp | 4 ++-- Sming/SmingCore/SmingCore.h | 3 --- Sming/Wiring/WConstants.h | 12 ++++++------ 9 files changed, 33 insertions(+), 20 deletions(-) diff --git a/Sming/SmingCore/ArduinoCompat.h b/Sming/SmingCore/ArduinoCompat.h index 02ce660e25..fae1491513 100644 --- a/Sming/SmingCore/ArduinoCompat.h +++ b/Sming/SmingCore/ArduinoCompat.h @@ -19,6 +19,15 @@ extern "C" { #endif +#define abs(x) ((x)>0?(x):-(x)) +#ifndef min +#define min(a,b) ((a)<(b)?(a):(b)) +#endif +#ifndef max +#define max(a,b) ((a)>(b)?(a):(b)) +#endif +#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5)) + void yield(); #ifdef __cplusplus diff --git a/Sming/SmingCore/DataSourceStream.cpp b/Sming/SmingCore/DataSourceStream.cpp index 23f68bbb0a..9b44e43e6c 100644 --- a/Sming/SmingCore/DataSourceStream.cpp +++ b/Sming/SmingCore/DataSourceStream.cpp @@ -6,6 +6,7 @@ ****/ #include "../SmingCore/DataSourceStream.h" +#include int IDataSourceStream::read() { @@ -91,7 +92,7 @@ size_t MemoryDataStream::write(const uint8_t* data, size_t len) uint16_t MemoryDataStream::readMemoryBlock(char* data, int bufSize) { - int available = min(size - (pos - buf), bufSize); + int available = std::min(size - (pos - buf), bufSize); memcpy(data, pos, available); return available; } @@ -154,7 +155,7 @@ FileStream::~FileStream() uint16_t FileStream::readMemoryBlock(char* data, int bufSize) { - int len = min(bufSize, size - pos); + int len = std::min(bufSize, size - pos); int available = fileRead(handle, data, len); fileSeek(handle, pos, eSO_FileStart); // Don't move cursor now (waiting seek) if(available < 0) { @@ -250,7 +251,7 @@ uint16_t TemplateFileStream::readMemoryBlock(char* data, int bufSize) debug_d("var %s not found", varName.c_str()); state = eTES_Wait; int len = FileStream::readMemoryBlock(data, bufSize); - return min(len, skipBlockSize); + return std::min(len, skipBlockSize); } } else if (state == eTES_SendingVar) diff --git a/Sming/SmingCore/Network/Http/HttpRequest.cpp b/Sming/SmingCore/Network/Http/HttpRequest.cpp index cbf99a865b..70d517432f 100644 --- a/Sming/SmingCore/Network/Http/HttpRequest.cpp +++ b/Sming/SmingCore/Network/Http/HttpRequest.cpp @@ -12,6 +12,8 @@ #include "HttpRequest.h" +#include + HttpRequest::HttpRequest(const URL& uri) { this->uri = uri; } @@ -159,7 +161,7 @@ String HttpRequest::getBody() char buf[1024]; while(stream->available() > 0) { int available = memory->readMemoryBlock(buf, 1024); - memory->seek(max(available, 0)); + memory->seek(std::max(available, 0)); ret += String(buf, available); if(available < 1024) { break; diff --git a/Sming/SmingCore/Network/Http/Stream/HttpChunkedStream.cpp b/Sming/SmingCore/Network/Http/Stream/HttpChunkedStream.cpp index cd29889270..28761b03f5 100644 --- a/Sming/SmingCore/Network/Http/Stream/HttpChunkedStream.cpp +++ b/Sming/SmingCore/Network/Http/Stream/HttpChunkedStream.cpp @@ -1,5 +1,7 @@ #include "HttpChunkedStream.h" +#include + HttpChunkedStream::HttpChunkedStream(ReadWriteStream *stream) { this->stream = stream; @@ -43,7 +45,7 @@ uint16_t HttpChunkedStream::readMemoryBlock(char* data, int bufSize) int len = readSize; char buffer[len]; len = stream->readMemoryBlock(buffer, len); - stream->seek(max(len, 0)); + stream->seek(std::max(len, 0)); if(len < 1) { return 0; } diff --git a/Sming/SmingCore/Network/MqttClient.cpp b/Sming/SmingCore/Network/MqttClient.cpp index 4a05259f6d..60b9bdcc3a 100644 --- a/Sming/SmingCore/Network/MqttClient.cpp +++ b/Sming/SmingCore/Network/MqttClient.cpp @@ -47,7 +47,7 @@ void MqttClient::setPingRepeatTime(int seconds) { if (PingRepeatTime > keepAlive) PingRepeatTime = keepAlive; - else + else PingRepeatTime = seconds; } @@ -239,7 +239,7 @@ err_t MqttClient::onReceive(pbuf *buf) continue; } - int available = min(waitingSize, buf->tot_len - received); + int available = std::min(waitingSize, buf->tot_len - received); waitingSize -= available; if (current != NULL) { diff --git a/Sming/SmingCore/Network/TcpConnection.cpp b/Sming/SmingCore/Network/TcpConnection.cpp index e2d27829b8..faf70a116a 100644 --- a/Sming/SmingCore/Network/TcpConnection.cpp +++ b/Sming/SmingCore/Network/TcpConnection.cpp @@ -13,6 +13,8 @@ #include "../Wiring/WString.h" #include "../Wiring/IPAddress.h" +#include + TcpConnection::TcpConnection(bool autoDestruct) : autoSelfDestruct(autoDestruct), sleep(0), canSend(true), timeOut(70) { @@ -265,7 +267,7 @@ int TcpConnection::write(IDataSourceStream* stream) do { pushCount++; - int read = min(NETWORK_SEND_BUFFER_SIZE, getAvailableWriteSize()); + int read = std::min((uint16_t)NETWORK_SEND_BUFFER_SIZE, getAvailableWriteSize()); if (read > 0) available = stream->readMemoryBlock(buffer, read); else @@ -275,7 +277,7 @@ int TcpConnection::write(IDataSourceStream* stream) { int written = write(buffer, available, TCP_WRITE_FLAG_COPY | TCP_WRITE_FLAG_MORE); total += written; - stream->seek(max(written, 0)); + stream->seek(std::max(written, 0)); debug_d("Written: %d, Available: %d, isFinished: %d, PushCount: %d [TcpBuf: %d]", written, available, (stream->isFinished()?1:0), pushCount, tcp_sndbuf(tcp)); repeat = written == available && !stream->isFinished() && pushCount < 25; } diff --git a/Sming/SmingCore/SPI.cpp b/Sming/SmingCore/SPI.cpp index 48b75efd01..3d97c7c606 100644 --- a/Sming/SmingCore/SPI.cpp +++ b/Sming/SmingCore/SPI.cpp @@ -197,7 +197,7 @@ void SPIClass::transfer(uint8 *buffer, size_t numberBytes) { while (blocks--) { // get full BLOCKSIZE or number of remaining bytes - bufLenght = min(numberBytes-bufIndx, (unsigned int)BLOCKSIZE); + bufLenght = std::min(numberBytes-bufIndx, (unsigned int)BLOCKSIZE); #ifdef SPI_DEBUG debugf("Write/Read Block %d total %d bytes", total-blocks, bufLenght); @@ -453,7 +453,7 @@ void SPIClass::setFrequency(int freq) { return; } - freq = min(freq, _CPU_freq/2); + freq = std::min(freq, _CPU_freq/2); _SPISettings._speed = freq; diff --git a/Sming/SmingCore/SmingCore.h b/Sming/SmingCore/SmingCore.h index 7e48c8b663..5c27fadeab 100644 --- a/Sming/SmingCore/SmingCore.h +++ b/Sming/SmingCore/SmingCore.h @@ -12,9 +12,6 @@ #include -#define min(A, B) std::min(A, B) -#define max(A, B) std::max(A, B) - #include "../Wiring/WiringFrameworkIncludes.h" #include "Delegate.h" diff --git a/Sming/Wiring/WConstants.h b/Sming/Wiring/WConstants.h index 30d6936283..4e461f9caf 100644 --- a/Sming/Wiring/WConstants.h +++ b/Sming/Wiring/WConstants.h @@ -114,12 +114,12 @@ #define sq(x) ((x)*(x)) //#define abs(x) ((x)>0?(x):-(x)) -#ifndef min -#define min(a,b) ((a)<(b)?(a):(b)) -#endif -#ifndef max -#define max(a,b) ((a)>(b)?(a):(b)) -#endif +//#ifndef min +//#define min(a,b) ((a)<(b)?(a):(b)) +//#endif +//#ifndef max +//#define max(a,b) ((a)>(b)?(a):(b)) +//#endif //#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5)) #define radians(deg) ((deg)*DEG_TO_RAD) #define degrees(rad) ((rad)*RAD_TO_DEG)