MCPcopy Create free account
hub / github.com/Duet3D/RepRapFirmware / GetFileInfoResponse

Method GetFileInfoResponse

src/Platform/RepRap.cpp:2322–2427  ·  view source on GitHub ↗

Get information for the specified file, or the currently printing file (if 'filename' is null or empty), in JSON format Return GCodeResult::Warning if the file doesn't exist, else GCodeResult::ok or GCodeResult::notFinished

Source from the content-addressed store, hash-verified

2320// Get information for the specified file, or the currently printing file (if 'filename' is null or empty), in JSON format
2321// Return GCodeResult::Warning if the file doesn't exist, else GCodeResult::ok or GCodeResult::notFinished
2322GCodeResult RepRap::GetFileInfoResponse(const GCodeBuffer *_ecv_null gb, c_string _ecv_null filename, OutputBuffer *_ecv_null &response, bool quitEarly) noexcept
2323{
2324 const bool specificFile = (filename != nullptr && filename[0] != 0);
2325 GCodeFileInfo info;
2326 GlobalVariables vars; // if we asked for a specific file then this is the variable set that we fill in for customiNFO
2327 const GlobalVariables *p_vars; // this will be a pointer to whatever GlobalVariables instance holds the customInfo
2328 if (specificFile)
2329 {
2330#if HAS_MASS_STORAGE || HAS_EMBEDDED_FILES
2331 // Poll file info for a specific file
2332 String<MaxFilenameLength> filePath;
2333 if (!MassStorage::CombineName(filePath.GetRef(), Platform::GetGCodeDir(), filename))
2334 {
2335 info.isValid = false;
2336 }
2337 else if (MassStorage::GetFileInfo(filePath.c_str(), info, quitEarly, &vars) == GCodeResult::notFinished)
2338 {
2339 // This may take a few runs...
2340 return GCodeResult::notFinished;
2341 }
2342 p_vars = &vars;
2343#else
2344 return GCodeResult::warning;
2345#endif
2346 }
2347 else if (!printMonitor->GetPrintingFileInfo(info, p_vars))
2348 {
2349 return GCodeResult::notFinished;
2350 }
2351
2352 if (!OutputBuffer::Allocate(response, false))
2353 {
2354 return GCodeResult::notFinished;
2355 }
2356
2357 StartJsonResponse(gb, response);
2358 if (info.isValid)
2359 {
2360 response->catf("\"err\":0,\"fileName\":\"%.s\",\"size\":%lu,", ((specificFile) ? filename : printMonitor->GetPrintingFilename()), info.fileSize);
2361 tm timeInfo;
2362 gmtime_r(&info.lastModifiedTime, &timeInfo);
2363 if (timeInfo.tm_year > /*19*/80)
2364 {
2365 response->catf("\"lastModified\":\"%04u-%02u-%02uT%02u:%02u:%02u\",",
2366 timeInfo.tm_year + 1900, timeInfo.tm_mon + 1, timeInfo.tm_mday, timeInfo.tm_hour, timeInfo.tm_min, timeInfo.tm_sec);
2367 }
2368
2369 response->catf("\"height\":%.2f,\"layerHeight\":%.2f,\"numLayers\":%u,", (double)info.objectHeight, (double)info.layerHeight, info.numLayers);
2370 if (info.printTime != 0)
2371 {
2372 response->catf("\"printTime\":%" PRIu32 ",", info.printTime);
2373 }
2374 if (info.simulatedTime != 0)
2375 {
2376 response->catf("\"simulatedTime\":%" PRIu32 ",", info.simulatedTime);
2377 }
2378
2379 response->cat("\"filament\":");

Callers 2

SendFileInfoMethod · 0.80
GCodes2.cppFile · 0.80

Calls 5

GetPrintingFileInfoMethod · 0.80
catfMethod · 0.80
catMethod · 0.80
GetPrintDurationMethod · 0.80
IsValidMethod · 0.45

Tested by

no test coverage detected