Jelajahi Sumber

fix safeload on disconnect

Benjamin Harris 1 bulan lalu
induk
melakukan
85864aaff8
3 mengubah file dengan 14 tambahan dan 4 penghapusan
  1. 9 1
      DSPWriter.cpp
  2. 4 3
      DSPWriter.h
  3. 1 0
      ModulosDSP_101.ino

+ 9 - 1
DSPWriter.cpp

@@ -70,12 +70,20 @@ void DSPWriter::writeRegister(uint16_t memoryAddress, uint8_t length, const uint
 // ---------------------------------------------------------------
 // Safeload counter — static so it survives across DSPWriter
 // instances, but exposed via resetSafeload() so the TCP bridge
-// can reset it cleanly at the start of each session.
+// can flush and reset cleanly on session start and disconnect.
 // ---------------------------------------------------------------
 static uint8_t s_safeload_count = 0;
 
 void DSPWriter::resetSafeload()
 {
+    // If the session ended mid-safeload, the DSP still has its own internal
+    // safeload counter pointing at those stale slots. Triggering IST here
+    // commits whatever is pending to parameter RAM so the DSP counter resets
+    // to zero before the next session writes new safeload data.
+    if (s_safeload_count > 0) {
+        uint8_t ist[2] = { 0x00, 0x3C };
+        DSPWriter::writeRegister(dspRegister::CoreRegister, sizeof(ist), ist);
+    }
     s_safeload_count = 0;
 }
 

+ 4 - 3
DSPWriter.h

@@ -90,9 +90,10 @@ public:
 
     /***************************************
     Function: resetSafeload()
-    Purpose:  Resets the internal safeload counter. Must be called at the
-              start of each TCP session to prevent counter corruption from
-              a previously interrupted safeload sequence.
+    Purpose:  Flushes any pending safeload slots by triggering IST (if the
+              counter is non-zero), then resets the counter to zero. Call at
+              both session start and session end to keep the DSP's internal
+              safeload counter in sync with ours.
     ***************************************/
     static void resetSafeload();
 

+ 1 - 0
ModulosDSP_101.ino

@@ -692,6 +692,7 @@ static void handleTcpBridgeClient(WiFiClient& client)
 
   } // end main while loop
 
+  DSPWriter::resetSafeload();  // flush any mid-session safeload before disconnect
   client.stop();
   Serial.println("TCP disconnected");
   ledOff();