From b69dd39c3071ba2134768c136d0b3fa05a9ddc47 Mon Sep 17 00:00:00 2001 From: Mike M Date: Mon, 4 Nov 2024 10:28:19 -0600 Subject: [PATCH] Fix hold state blocked and check cached hashes when in motion (#1370) --- FluidNC/src/HashFS.cpp | 4 ++-- FluidNC/src/HashFS.h | 2 +- FluidNC/src/WebUI/WebServer.cpp | 38 +++++++++++++-------------------- FluidNC/src/WebUI/WebServer.h | 1 - 4 files changed, 18 insertions(+), 27 deletions(-) diff --git a/FluidNC/src/HashFS.cpp b/FluidNC/src/HashFS.cpp index 8fc67f9b6..a3d77b81c 100644 --- a/FluidNC/src/HashFS.cpp +++ b/FluidNC/src/HashFS.cpp @@ -107,14 +107,14 @@ void HashFS::hash_all() { } } } -std::string HashFS::hash(const std::filesystem::path& path) { +std::string HashFS::hash(const std::filesystem::path& path, bool useCacheOnly /*= false*/) { if (file_is_hashable(path)) { std::map::const_iterator it; it = localFsHashes.find(path.filename()); if (it != localFsHashes.end()) { return it->second; } - } else { + } else if (!useCacheOnly) { std::string theHash; hashFile(path, theHash); return theHash; diff --git a/FluidNC/src/HashFS.h b/FluidNC/src/HashFS.h index 9c9143c6b..8853ea13d 100644 --- a/FluidNC/src/HashFS.h +++ b/FluidNC/src/HashFS.h @@ -14,7 +14,7 @@ class HashFS { static void hash_all(); static void report_change(); - static std::string hash(const std::filesystem::path& path); + static std::string hash(const std::filesystem::path& path, bool useCacheOnly = false); private: }; diff --git a/FluidNC/src/WebUI/WebServer.cpp b/FluidNC/src/WebUI/WebServer.cpp index 5919ce646..fe6ff3eef 100644 --- a/FluidNC/src/WebUI/WebServer.cpp +++ b/FluidNC/src/WebUI/WebServer.cpp @@ -233,6 +233,8 @@ namespace WebUI { return false; } + std::string hash; + // If you load or reload WebUI while a program is running, there is a high // risk of stalling the motion because serving a file from // the local FLASH filesystem takes away a lot of CPU cycles. If we get @@ -241,17 +243,24 @@ namespace WebUI { // This can make it hard to debug ISR IRAM problems, because the easiest // way to trigger such problems is to refresh WebUI during motion. if (http_block_during_motion->get() && inMotionState()) { + // Check to see if we have a cached hash of the file that can be retrieved without accessing FLASH + hash = HashFS::hash(fpath, true); + if (!hash.length()) { + std::filesystem::path gzpath(fpath); + gzpath += ".gz"; + hash = HashFS::hash(gzpath, true); + } + + if (hash.length() && std::string(_webserver->header("If-None-Match").c_str()) == hash) { + _webserver->send(304); + return true; + } + Web_Server::handleReloadBlocked(); return true; } - if (state_is(State::Hold)) { - Web_Server::handleFeedholdBlocked(); - return true; - } - std::string hash; // Check for brower cache match - hash = HashFS::hash(fpath); if (!hash.length()) { std::filesystem::path gzpath(fpath); @@ -675,23 +684,6 @@ namespace WebUI { ""); } - // This page is used when you try to reload WebUI during feedhold state. - // Reload will not work because commands cannot be executed in feedhold, - // so things like ESP800 will hang. - void Web_Server::handleFeedholdBlocked() { - _webserver->send(503, - "text/html", - "" - "

GCode Program is Paused (in Feedhold state)

" - - "" - " Resume the GCode program with cyclestart

" - - "" - " Stop the GCode Program with reset

" - - ""); - } void Web_Server::handleDidRestart() { _webserver->send(503, "text/html", diff --git a/FluidNC/src/WebUI/WebServer.h b/FluidNC/src/WebUI/WebServer.h index 74cc82293..0d1227a00 100644 --- a/FluidNC/src/WebUI/WebServer.h +++ b/FluidNC/src/WebUI/WebServer.h @@ -86,7 +86,6 @@ namespace WebUI { static void handle_Websocket_Event(uint8_t num, uint8_t type, uint8_t* payload, size_t length); static void handle_Websocketv3_Event(uint8_t num, uint8_t type, uint8_t* payload, size_t length); static void handleReloadBlocked(); - static void handleFeedholdBlocked(); static void handleFeedholdReload(); static void handleCyclestartReload(); static void handleRestartReload();