Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 40 additions & 6 deletions src/Platform/RepRap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,9 @@ DEFINE_GET_OBJECT_MODEL_TABLE(RepRap)
RepRap::RepRap() noexcept
: boardsSeq(0), directoriesSeq(0), fansSeq(0), heatSeq(0), inputsSeq(0), jobSeq(0), ledStripsSeq(0), moveSeq(0), globalSeq(0),
networkSeq(0), scannerSeq(0), sensorsSeq(0), spindlesSeq(0), stateSeq(0), toolsSeq(0), volumesSeq(0),
#if HAS_MASS_STORAGE || HAS_EMBEDDED_FILES
fileInfoResponseInUse(false), fileInfoResponseParsed(false),
#endif
lastWarningMillis(0),
ticksInSpinState(0), heatTaskIdleTicks(0),
beepFrequency(0), beepDuration(0), beepTimer(0),
Expand Down Expand Up @@ -2323,8 +2326,7 @@ GCodeResult RepRap::GetFileInfoResponse(const GCodeBuffer *_ecv_null gb, c_strin
{
const bool specificFile = (filename != nullptr && filename[0] != 0);
GCodeFileInfo info;
GlobalVariables vars; // if we asked for a specific file then this is the variable set that we fill in for customiNFO
const GlobalVariables *p_vars; // this will be a pointer to whatever GlobalVariables instance holds the customInfo
const GlobalVariables *p_vars = nullptr; // this will be a pointer to whatever GlobalVariables instance holds the customInfo
if (specificFile)
{
#if HAS_MASS_STORAGE || HAS_EMBEDDED_FILES
Expand All @@ -2334,12 +2336,30 @@ GCodeResult RepRap::GetFileInfoResponse(const GCodeBuffer *_ecv_null gb, c_strin
{
info.isValid = false;
}
else if (MassStorage::GetFileInfo(filePath.c_str(), info, quitEarly, &vars) == GCodeResult::notFinished)
else
{
// This may take a few runs...
return GCodeResult::notFinished;
if (!fileInfoResponseInUse || !fileInfoResponsePath.EqualsIgnoreCase(filePath.c_str()))
{
fileInfoResponsePath.copy(filePath.c_str());
fileInfoResponseInfo.Init();
fileInfoResponseCustomInfo.GetForWriting()->Clear();
fileInfoResponseInUse = true;
fileInfoResponseParsed = false;
}

if (!fileInfoResponseParsed)
{
if (MassStorage::GetFileInfo(filePath.c_str(), fileInfoResponseInfo, quitEarly, &fileInfoResponseCustomInfo) == GCodeResult::notFinished)
{
// This may take a few runs...
return GCodeResult::notFinished;
}
fileInfoResponseParsed = true;
}

info = fileInfoResponseInfo;
p_vars = &fileInfoResponseCustomInfo;
}
p_vars = &vars;
#else
return GCodeResult::warning;
#endif
Expand Down Expand Up @@ -2419,10 +2439,24 @@ GCodeResult RepRap::GetFileInfoResponse(const GCodeBuffer *_ecv_null gb, c_strin
response->catf("],\"generatedBy\":\"%.s\",\"customInfo\":", info.generatedBy.c_str());
p_vars->ReportAllAsJson(response);
response->cat("}\n");
#if HAS_MASS_STORAGE || HAS_EMBEDDED_FILES
if (specificFile)
{
fileInfoResponseInUse = false;
fileInfoResponseParsed = false;
}
#endif
return GCodeResult::ok;
}

response->catf("\"err\":1,\"fileName\":\"%.s\"}", ((specificFile) ? filename : printMonitor->GetPrintingFilename()));
#if HAS_MASS_STORAGE || HAS_EMBEDDED_FILES
if (specificFile)
{
fileInfoResponseInUse = false;
fileInfoResponseParsed = false;
}
#endif
return GCodeResult::warning;
}

Expand Down
9 changes: 9 additions & 0 deletions src/Platform/RepRap.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Licence: GPL
#include <ObjectModel/ObjectModel.h>
#include <RTOSIface/RTOSIface.h>
#include <General/function_ref.h>
#include <GCodes/GCodeFileInfo.h>
#include <ObjectModel/GlobalVariables.h>
#include "MessageBox.h"

Expand Down Expand Up @@ -247,6 +248,14 @@ class RepRap final INHERIT_OBJECT_MODEL

GlobalVariables globalVariables;

#if HAS_MASS_STORAGE || HAS_EMBEDDED_FILES
String<MaxFilenameLength> fileInfoResponsePath;
GCodeFileInfo fileInfoResponseInfo;
GlobalVariables fileInfoResponseCustomInfo;
bool fileInfoResponseInUse;
bool fileInfoResponseParsed;
#endif

uint32_t lastWarningMillis; // when we last sent a warning message for things that can happen very often

uint16_t ticksInSpinState;
Expand Down
Loading