From 079adb708c7246c670c15c6f30c5b318f52b4f60 Mon Sep 17 00:00:00 2001 From: David Crocker Date: Tue, 9 Apr 2024 10:26:29 +0100 Subject: [PATCH] Fix issue with remote FMs sending live data too often, still 3.5.0-rc.4 --- src/FilamentMonitors/FilamentMonitor.cpp | 17 ++++++++++++++--- src/FilamentMonitors/FilamentMonitor.h | 1 + src/Platform/RepRap.cpp | 2 +- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/FilamentMonitors/FilamentMonitor.cpp b/src/FilamentMonitors/FilamentMonitor.cpp index 16af434cd5..8c7f259583 100644 --- a/src/FilamentMonitors/FilamentMonitor.cpp +++ b/src/FilamentMonitors/FilamentMonitor.cpp @@ -303,7 +303,7 @@ static uint32_t checkCalls = 0, clearCalls = 0; //TEMP DEBUG size_t slotIndex = 0; size_t firstDriveNotSent = NumDirectDrivers; Bitmap driversReported; - bool forceSend = false; + bool forceSend = false, haveLiveData = false; #endif { @@ -363,11 +363,15 @@ static uint32_t checkCalls = 0, clearCalls = 0; //TEMP DEBUG auto& slot = msg->data[slotIndex]; slot.status = fst.ToBaseType(); fs.GetLiveData(slot); - if (fst != fs.lastStatus || slot.hasLiveData) + if (fst != fs.lastStatus) { forceSend = true; fs.lastStatus = fst; } + else if (slot.hasLiveData) + { + haveLiveData = true; + } driversReported.SetBit(drv); ++slotIndex; } @@ -409,7 +413,14 @@ static uint32_t checkCalls = 0, clearCalls = 0; //TEMP DEBUG #if SUPPORT_REMOTE_COMMANDS if (CanInterface::InExpansionMode()) { - if (slotIndex != 0 && (forceSend || millis() - whenStatusLastSent >= StatusUpdateInterval)) + uint32_t now; + if ( slotIndex != 0 + && ( forceSend + || (now = millis()) - whenStatusLastSent >= StatusUpdateInterval + || (haveLiveData && now - whenStatusLastSent >= LiveStatusUpdateInterval) + + ) + ) { msg->SetStandardFields(driversReported); buf.dataLength = msg->GetActualDataLength(); diff --git a/src/FilamentMonitors/FilamentMonitor.h b/src/FilamentMonitors/FilamentMonitor.h index 2352f13910..f212c21fd3 100644 --- a/src/FilamentMonitors/FilamentMonitor.h +++ b/src/FilamentMonitors/FilamentMonitor.h @@ -176,6 +176,7 @@ class FilamentMonitor INHERIT_OBJECT_MODEL #if SUPPORT_REMOTE_COMMANDS static constexpr uint32_t StatusUpdateInterval = 2000; // how often we send status reports when there isn't a change + static constexpr uint32_t LiveStatusUpdateInterval = 250; // how often we report live status static uint32_t whenStatusLastSent; static size_t firstDriveToSend; #endif diff --git a/src/Platform/RepRap.cpp b/src/Platform/RepRap.cpp index ade57b9470..7a2906ad68 100644 --- a/src/Platform/RepRap.cpp +++ b/src/Platform/RepRap.cpp @@ -2417,7 +2417,7 @@ size_t RepRap::GetStatusIndex() const noexcept : (gCodes->IsCancellingPrint()) ? 7 // Cancelling : (printMonitor->IsPrinting()) ? ((gCodes->IsSimulating()) ? 8 // Simulating - : 9 // Printing + : 9 // Printing ) : (gCodes->IsDoingToolChange()) ? 10 // Changing tool : (gCodes->DoingFileMacro() || !move->NoLiveMovement() ||