|
|
@@ -60,12 +60,14 @@
|
|
|
#include "FS.h"
|
|
|
#include <LittleFS.h>
|
|
|
#include <Update.h>
|
|
|
+#include <ESPmDNS.h>
|
|
|
|
|
|
//=============================================================
|
|
|
// WiFi / UI
|
|
|
//=============================================================
|
|
|
const char* ssid = "alfred";
|
|
|
const char* password = "alfred16";
|
|
|
+const char* hostname = "modulos-dsp";
|
|
|
const char* version = "VER: 260304_13";
|
|
|
|
|
|
#define I2C_SDA 13
|
|
|
@@ -119,6 +121,8 @@ static uint8_t dataBuffer[50 * 1024];
|
|
|
#define CMD_WRITE 0x09
|
|
|
#define CMD_READ 0x0A
|
|
|
|
|
|
+#define TCP_IDLE_TIMEOUT_MS 30000 // drop session if silent for 30 s
|
|
|
+
|
|
|
constexpr int WRITE_HDR_LEN = 10;
|
|
|
constexpr int READ_HDR_LEN = 8;
|
|
|
|
|
|
@@ -318,8 +322,9 @@ static void printWifiInfo()
|
|
|
{
|
|
|
Serial.println();
|
|
|
Serial.println("WiFi connected.");
|
|
|
- Serial.print("WiFi IP: "); Serial.println(WiFi.localIP());
|
|
|
- Serial.print("MAC: "); Serial.println(WiFi.macAddress());
|
|
|
+ Serial.print("WiFi IP: "); Serial.println(WiFi.localIP());
|
|
|
+ Serial.printf("Hostname: http://%s.local/\n", hostname);
|
|
|
+ Serial.print("MAC: "); Serial.println(WiFi.macAddress());
|
|
|
Serial.println("Modulos AudioDSP");
|
|
|
Serial.println(version);
|
|
|
if (s_lcdOk) {
|
|
|
@@ -443,6 +448,22 @@ static void handleUploadStream() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+//=============================================================
|
|
|
+// HTTP DSP reset handler
|
|
|
+//=============================================================
|
|
|
+static void handleDspReset() {
|
|
|
+ Serial.println("DSP soft reset requested");
|
|
|
+ // Stop DSP execution, brief pause, restart. Program and parameter RAM
|
|
|
+ // are preserved — this restarts execution without reloading from EEPROM.
|
|
|
+ uint8_t stop[2] = { 0x00, 0x00 };
|
|
|
+ uint8_t run[2] = { 0x00, 0x01 };
|
|
|
+ DSPWriter::writeRegister(dspRegister::CoreRegister, sizeof(stop), stop);
|
|
|
+ delay(100);
|
|
|
+ DSPWriter::writeRegister(dspRegister::CoreRegister, sizeof(run), run);
|
|
|
+ Serial.println("DSP soft reset complete");
|
|
|
+ httpServer.send(200, "text/plain", "DSP soft reset complete.");
|
|
|
+}
|
|
|
+
|
|
|
//=============================================================
|
|
|
// HTTP OTA handlers
|
|
|
//=============================================================
|
|
|
@@ -532,6 +553,13 @@ void setup() {
|
|
|
delay(5000); ESP.restart();
|
|
|
}
|
|
|
|
|
|
+ if (MDNS.begin(hostname)) {
|
|
|
+ MDNS.addService("http", "tcp", 80);
|
|
|
+ Serial.printf("mDNS: http://%s.local/\n", hostname);
|
|
|
+ } else {
|
|
|
+ Serial.println("mDNS start failed");
|
|
|
+ }
|
|
|
+
|
|
|
if (!LittleFS.begin(false)) {
|
|
|
Serial.println("LittleFS mount failed, formatting...");
|
|
|
if (!LittleFS.begin(true)) { Serial.println("LittleFS mount failed even after format"); return; }
|
|
|
@@ -548,6 +576,7 @@ void setup() {
|
|
|
httpServer.on("/upload", HTTP_POST, handleUploadDone, handleUploadStream);
|
|
|
httpServer.on("/ota", HTTP_GET, handleOtaPage);
|
|
|
httpServer.on("/ota_do", HTTP_POST, handleOtaDone, handleOtaStream);
|
|
|
+ httpServer.on("/dsp_reset", HTTP_POST, handleDspReset);
|
|
|
httpServer.onNotFound([]() {
|
|
|
String uri = httpServer.uri();
|
|
|
if (streamFromFS(uri)) return;
|
|
|
@@ -578,10 +607,11 @@ static void handleTcpBridgeClient(WiFiClient& client)
|
|
|
Serial.println("TCP new connection");
|
|
|
DSPWriter::resetSafeload();
|
|
|
|
|
|
- int writeIndex = 0; // next free slot in dataBuffer
|
|
|
- int readIndex = 0; // start of current unprocessed command
|
|
|
- int receivedByteCount = 0; // total bytes written into dataBuffer
|
|
|
- int currentState = STATE_START;
|
|
|
+ int writeIndex = 0; // next free slot in dataBuffer
|
|
|
+ int readIndex = 0; // start of current unprocessed command
|
|
|
+ int receivedByteCount = 0; // total bytes written into dataBuffer
|
|
|
+ int currentState = STATE_START;
|
|
|
+ uint32_t lastActivityMs = millis(); // idle watchdog
|
|
|
|
|
|
while (client.connected()) {
|
|
|
|
|
|
@@ -603,6 +633,7 @@ static void handleTcpBridgeClient(WiFiClient& client)
|
|
|
if (b < 0) break;
|
|
|
dataBuffer[writeIndex++] = (uint8_t)b;
|
|
|
receivedByteCount++;
|
|
|
+ lastActivityMs = millis();
|
|
|
}
|
|
|
|
|
|
// ------------------------------------------------------------------
|
|
|
@@ -752,10 +783,14 @@ static void handleTcpBridgeClient(WiFiClient& client)
|
|
|
}
|
|
|
} // end process loop
|
|
|
|
|
|
- // No idle timeout — stay connected until SigmaStudio disconnects.
|
|
|
- // client.connected() will return false when the TCP connection drops.
|
|
|
+ // Idle path — no data waiting, no command in progress.
|
|
|
if (currentState == STATE_START && receivedByteCount == readIndex) {
|
|
|
if (!client.available()) {
|
|
|
+ if (millis() - lastActivityMs > TCP_IDLE_TIMEOUT_MS) {
|
|
|
+ Serial.println("TCP idle timeout — closing session");
|
|
|
+ ledErrorFlash();
|
|
|
+ break;
|
|
|
+ }
|
|
|
httpServer.handleClient();
|
|
|
delay(10);
|
|
|
}
|
|
|
@@ -789,6 +824,8 @@ static void maintainWifi()
|
|
|
WiFi.reconnect();
|
|
|
} else if (s_wifiLost) {
|
|
|
Serial.print("WiFi reconnected, IP: "); Serial.println(WiFi.localIP());
|
|
|
+ MDNS.begin(hostname);
|
|
|
+ MDNS.addService("http", "tcp", 80);
|
|
|
tcpServer.begin(); // re-register listening socket with recovered stack
|
|
|
printWifiInfo(); // update LCD with current IP
|
|
|
s_wifiLost = false;
|