diff options
author | David Crocker <dcrocker@eschertech.com> | 2022-02-08 12:52:27 +0300 |
---|---|---|
committer | David Crocker <dcrocker@eschertech.com> | 2022-02-08 12:52:27 +0300 |
commit | f18cca69ce1222aa63aad5a55b26afafc6bd08e0 (patch) | |
tree | f070104bdae20c6e6e70930927dffb68cc80aa9b | |
parent | 5adb96401f7d8f6e79658ff8211a18785a73cb36 (diff) |
Increased thumbnail chunk size in HTTP API
-rw-r--r-- | src/Platform/RepRap.cpp | 19 | ||||
-rw-r--r-- | src/Platform/RepRap.h | 2 |
2 files changed, 12 insertions, 9 deletions
diff --git a/src/Platform/RepRap.cpp b/src/Platform/RepRap.cpp index afedce45..25f00c47 100644 --- a/src/Platform/RepRap.cpp +++ b/src/Platform/RepRap.cpp @@ -2268,10 +2268,12 @@ OutputBuffer *RepRap::GetFilelistResponse(const char *dir, unsigned int startAt) // It is up to the caller to get the offset right, however we must fail gracefully if the caller passes us a bad offset. // The offset should always be either the initial offset or the 'next' value passed in a previous call, so it should always be the start of a line. // 'encapsulateThumbnail' defines whether the thumbnail shall be encapsulated as a "thumbnail" property of the root object -OutputBuffer *RepRap::GetThumbnailResponse(const char *filename, FilePosition offset, bool encapsulateThumbnail) noexcept +OutputBuffer *RepRap::GetThumbnailResponse(const char *filename, FilePosition offset, bool forM31point1) noexcept { - constexpr unsigned int ThumbnailMaxDataSize = 1024; - static_assert(ThumbnailMaxDataSize % 4 == 0, "must be a multiple of to guarantee base64 alignment"); + constexpr unsigned int ThumbnailMaxDataSizeM31 = 1024; // small enough for PanelDue to buffer + constexpr unsigned int ThumbnailMaxDataSizeRr = 2600; // about two TCP messages + static_assert(ThumbnailMaxDataSizeM31 % 4 == 0, "must be a multiple of to guarantee base64 alignment"); + static_assert(ThumbnailMaxDataSizeRr % 4 == 0, "must be a multiple of to guarantee base64 alignment"); // Need something to write to... OutputBuffer *response; @@ -2280,7 +2282,7 @@ OutputBuffer *RepRap::GetThumbnailResponse(const char *filename, FilePosition of return nullptr; } - if (encapsulateThumbnail) + if (forM31point1) { response->cat("{\"thumbnail\":"); } @@ -2294,7 +2296,8 @@ OutputBuffer *RepRap::GetThumbnailResponse(const char *filename, FilePosition of { response->cat("\"data\":\""); - for (unsigned int charsWrittenThisCall = 0; charsWrittenThisCall < ThumbnailMaxDataSize; ) + const unsigned int thumbnailMaxDataSize = (forM31point1) ? ThumbnailMaxDataSizeM31 : ThumbnailMaxDataSizeRr; + for (unsigned int charsWrittenThisCall = 0; charsWrittenThisCall < thumbnailMaxDataSize; ) { // Read a line char lineBuffer[GCODE_LENGTH]; @@ -2333,7 +2336,7 @@ OutputBuffer *RepRap::GetThumbnailResponse(const char *filename, FilePosition of const unsigned int charsSkipped = p - lineBuffer; const unsigned int charsAvailable = charsRead - charsSkipped; unsigned int charsWrittenFromThisLine; - if (charsAvailable <= ThumbnailMaxDataSize - charsWrittenThisCall) + if (charsAvailable <= thumbnailMaxDataSize - charsWrittenThisCall) { // Write all the data in this line charsWrittenFromThisLine = charsAvailable; @@ -2341,7 +2344,7 @@ OutputBuffer *RepRap::GetThumbnailResponse(const char *filename, FilePosition of else { // Write just enough characters to fill the buffer - charsWrittenFromThisLine = ThumbnailMaxDataSize - charsWrittenThisCall; + charsWrittenFromThisLine = thumbnailMaxDataSize - charsWrittenThisCall; offset = posOld + charsSkipped + charsWrittenFromThisLine; } @@ -2359,7 +2362,7 @@ OutputBuffer *RepRap::GetThumbnailResponse(const char *filename, FilePosition of err = 1; } - response->catf(encapsulateThumbnail ? "\"err\":%u}}\n" : "\"err\":%u}\n", err); + response->catf(forM31point1 ? "\"err\":%u}}\n" : "\"err\":%u}\n", err); return response; } diff --git a/src/Platform/RepRap.h b/src/Platform/RepRap.h index d620d811..b380bb51 100644 --- a/src/Platform/RepRap.h +++ b/src/Platform/RepRap.h @@ -148,7 +148,7 @@ public: #if HAS_MASS_STORAGE || HAS_EMBEDDED_FILES OutputBuffer *GetFilesResponse(const char* dir, unsigned int startAt, bool flagsDirs) noexcept; OutputBuffer *GetFilelistResponse(const char* dir, unsigned int startAt) noexcept; - OutputBuffer *GetThumbnailResponse(const char *filename, FilePosition offset, bool encapsulateThumbnail) noexcept; + OutputBuffer *GetThumbnailResponse(const char *filename, FilePosition offset, bool forM31point1) noexcept; #endif GCodeResult GetFileInfoResponse(const char *filename, OutputBuffer *&response, bool quitEarly) noexcept; |