Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Duet3D/RepRapFirmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Hammacher <bmasterc@gmail.com>2022-02-06 17:08:21 +0300
committerChristian Hammacher <bmasterc@gmail.com>2022-02-06 17:08:21 +0300
commit21df0021ca2c915318d983f182aaa815bca2fb1d (patch)
tree6dc7adf93c9d21f47fae50d4e1f5edd40ccd5ac9
parent43dbde5e47a99b8ab6ba3eb2169df71e49184186 (diff)
Improvements for fileinfo detection
Added support for num_layers detection to fileinfo requests numLayers is reported again as part of fileinfo responses and set by SBC Bug fix: rr_thumbnail could hang up the network task when invalid parameters were passed
-rw-r--r--src/GCodes/GCodeFileInfo.cpp1
-rw-r--r--src/GCodes/GCodeFileInfo.h1
-rw-r--r--src/Networking/HttpResponder.cpp2
-rw-r--r--src/Platform/RepRap.cpp2
-rw-r--r--src/SBC/DataTransfer.cpp1
-rw-r--r--src/SBC/SbcMessageFormats.h2
-rw-r--r--src/Storage/FileInfoParser.cpp56
-rw-r--r--src/Storage/FileInfoParser.h1
8 files changed, 63 insertions, 3 deletions
diff --git a/src/GCodes/GCodeFileInfo.cpp b/src/GCodes/GCodeFileInfo.cpp
index e52d0f8e..10992833 100644
--- a/src/GCodes/GCodeFileInfo.cpp
+++ b/src/GCodes/GCodeFileInfo.cpp
@@ -13,6 +13,7 @@ void GCodeFileInfo::Init() noexcept
incomplete = true;
objectHeight = 0.0;
layerHeight = 0.0;
+ numLayers = 0;
printTime = simulatedTime = 0;
numFilaments = 0;
lastModifiedTime = 0;
diff --git a/src/GCodes/GCodeFileInfo.h b/src/GCodes/GCodeFileInfo.h
index 95a0b04a..190c0489 100644
--- a/src/GCodes/GCodeFileInfo.h
+++ b/src/GCodes/GCodeFileInfo.h
@@ -34,6 +34,7 @@ struct GCodeFileInfo
FilePosition fileSize;
time_t lastModifiedTime;
float layerHeight;
+ unsigned int numLayers;
float objectHeight;
float filamentNeeded[MaxExtruders];
uint32_t printTime;
diff --git a/src/Networking/HttpResponder.cpp b/src/Networking/HttpResponder.cpp
index 11a5988d..e7d77150 100644
--- a/src/Networking/HttpResponder.cpp
+++ b/src/Networking/HttpResponder.cpp
@@ -590,12 +590,12 @@ bool HttpResponder::GetJsonResponse(const char *_ecv_array request, OutputBuffer
}
else if (StringEqualsIgnoreCase(request, "thumbnail"))
{
- OutputBuffer::ReleaseAll(response);
const char* const nameVal = GetKeyValue("name");
const char* const offsetVal = GetKeyValue("offset");
FilePosition offset;
if (nameVal != nullptr && offsetVal != nullptr && (offset = StrToU32(offsetVal)) != 0)
{
+ OutputBuffer::ReleaseAll(response);
response = reprap.GetThumbnailResponse(nameVal, offset);
}
else
diff --git a/src/Platform/RepRap.cpp b/src/Platform/RepRap.cpp
index afb76727..1da497d2 100644
--- a/src/Platform/RepRap.cpp
+++ b/src/Platform/RepRap.cpp
@@ -2404,7 +2404,7 @@ GCodeResult RepRap::GetFileInfoResponse(const char *filename, OutputBuffer *&res
timeInfo.tm_year + 1900, timeInfo.tm_mon + 1, timeInfo.tm_mday, timeInfo.tm_hour, timeInfo.tm_min, timeInfo.tm_sec);
}
- response->catf("\"height\":%.2f,\"layerHeight\":%.2f,", (double)info.objectHeight, (double)info.layerHeight);
+ response->catf("\"height\":%.2f,\"layerHeight\":%.2f,\"numLayers\":%u,", (double)info.objectHeight, (double)info.layerHeight, info.numLayers);
if (info.printTime != 0)
{
response->catf("\"printTime\":%" PRIu32 ",", info.printTime);
diff --git a/src/SBC/DataTransfer.cpp b/src/SBC/DataTransfer.cpp
index 967134f4..2e023190 100644
--- a/src/SBC/DataTransfer.cpp
+++ b/src/SBC/DataTransfer.cpp
@@ -566,6 +566,7 @@ void DataTransfer::ReadPrintStartedInfo(size_t packetLength, const StringRef& fi
const PrintStartedHeader *header = ReadDataHeader<PrintStartedHeader>();
info.isValid = true;
info.numFilaments = header->numFilaments;
+ info.numLayers = header->numLayers;
info.lastModifiedTime = header->lastModifiedTime;
info.fileSize = header->fileSize;
info.layerHeight = header->layerHeight;
diff --git a/src/SBC/SbcMessageFormats.h b/src/SBC/SbcMessageFormats.h
index a053e1f8..ed16706f 100644
--- a/src/SBC/SbcMessageFormats.h
+++ b/src/SBC/SbcMessageFormats.h
@@ -363,7 +363,7 @@ struct PrintStartedHeader
uint32_t numFilaments;
time_t lastModifiedTime;
uint32_t fileSize;
- float firstLayerHeight;
+ uint32_t numLayers;
float layerHeight;
float objectHeight;
uint32_t printTime;
diff --git a/src/Storage/FileInfoParser.cpp b/src/Storage/FileInfoParser.cpp
index 991fe4df..83e0be83 100644
--- a/src/Storage/FileInfoParser.cpp
+++ b/src/Storage/FileInfoParser.cpp
@@ -299,6 +299,13 @@ GCodeResult FileInfoParser::GetFileInfo(const char *filePath, GCodeFileInfo& inf
}
}
+ // Search for number of layers
+ if (parsedFileInfo.numLayers == 0)
+ {
+ // Number of layers should come before the object height
+ (void)FindNumLayers(buf, sizeToScan);
+ }
+
// Look for print time
if (parsedFileInfo.printTime == 0)
{
@@ -331,6 +338,10 @@ GCodeResult FileInfoParser::GetFileInfo(const char *filePath, GCodeFileInfo& inf
}
parseState = notParsing;
fileBeingParsed->Close();
+ if (parsedFileInfo.numLayers == 0 && parsedFileInfo.layerHeight > 0.0 && parsedFileInfo.objectHeight > 0.0)
+ {
+ parsedFileInfo.numLayers = lrintf(parsedFileInfo.objectHeight / parsedFileInfo.layerHeight);
+ }
parsedFileInfo.incomplete = false;
info = parsedFileInfo;
return GCodeResult::ok;
@@ -476,6 +487,51 @@ bool FileInfoParser::FindHeight(const char* bufp, size_t len) noexcept
return foundHeight;
}
+// Scan the buffer for th total number of layers. The buffer is null-terminated.
+bool FileInfoParser::FindNumLayers(const char* bufp, size_t len) noexcept
+{
+ static const char* const numLayerStrings[] =
+ {
+ "num_layers",
+ "NUM_LAYERS"
+ };
+
+ if (*bufp != 0)
+ {
+ ++bufp; // make sure we can look back 1 character after we find a match
+ for (const char * lhStr : numLayerStrings) // search for each string in turn
+ {
+ const char *pos = bufp;
+ for(;;) // loop until success or strstr returns null
+ {
+ pos = strstr(pos, lhStr);
+ if (pos == nullptr)
+ {
+ break; // didn't find this string in the buffer, so try the next string
+ }
+
+ const char c = pos[-1]; // fetch the previous character
+ pos += strlen(lhStr); // skip the string we matched
+ if (c == ' ' || c == ';' || c == '\t') // check we are not in the middle of a word
+ {
+ while (strchr(" \t=:,", *pos) != nullptr) // skip the possible separators
+ {
+ ++pos;
+ }
+ const unsigned int val = StrToU32(pos);
+ if (val > 0)
+ {
+ parsedFileInfo.numLayers = val;
+ return true;
+ }
+ }
+ }
+ }
+ }
+
+ return false;
+}
+
// Scan the buffer for the layer height. The buffer is null-terminated.
bool FileInfoParser::FindLayerHeight(const char *bufp) noexcept
{
diff --git a/src/Storage/FileInfoParser.h b/src/Storage/FileInfoParser.h
index 24ff5576..d906d055 100644
--- a/src/Storage/FileInfoParser.h
+++ b/src/Storage/FileInfoParser.h
@@ -53,6 +53,7 @@ private:
// G-Code parser methods
bool FindHeight(const char *_ecv_array bufp, size_t len) noexcept;
+ bool FindNumLayers(const char *_ecv_array bufp, size_t len) noexcept;
bool FindLayerHeight(const char *_ecv_array bufp) noexcept;
bool FindSlicerInfo(const char *_ecv_array bufp) noexcept;
bool FindPrintTime(const char *_ecv_array bufp) noexcept;