Skip to content

Commit

Permalink
Fix hold state blocked and check cached hashes when in motion (#1370)
Browse files Browse the repository at this point in the history
  • Loading branch information
michmela44 authored Nov 4, 2024
1 parent 3c58324 commit b69dd39
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 27 deletions.
4 changes: 2 additions & 2 deletions FluidNC/src/HashFS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string, std::string>::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;
Expand Down
2 changes: 1 addition & 1 deletion FluidNC/src/HashFS.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
};
38 changes: 15 additions & 23 deletions FluidNC/src/WebUI/WebServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -675,23 +684,6 @@ namespace WebUI {

"</body></html>");
}
// 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",
"<!DOCTYPE html><html><body>"
"<h3>GCode Program is Paused (in Feedhold state)</h3>"

"<button onclick='window.location.replace(\"/cyclestart_reload\")'>Resume</button>"
"&nbsp;Resume the GCode program with cyclestart<br><br>"

"<button onclick='window.location.replace(\"/restart_reload\")'>Stop</button>"
"&nbsp;Stop the GCode Program with reset<br><br>"

"</body></html>");
}
void Web_Server::handleDidRestart() {
_webserver->send(503,
"text/html",
Expand Down
1 change: 0 additions & 1 deletion FluidNC/src/WebUI/WebServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit b69dd39

Please sign in to comment.