From 02aaee0878812c70f1712893a5ef116b2f77230a Mon Sep 17 00:00:00 2001 From: Rune Harlyk Date: Fri, 30 Jan 2026 14:01:48 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Replace=20more=20arduino?= =?UTF-8?q?=20functions=20with=20native?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- esp32/include/filesystem_ws.h | 12 ++++------ esp32/include/peripherals/peripherals.h | 1 - esp32/src/filesystem_ws.cpp | 30 ++++++++++++------------- esp32/src/main.cpp | 2 -- 4 files changed, 18 insertions(+), 27 deletions(-) diff --git a/esp32/include/filesystem_ws.h b/esp32/include/filesystem_ws.h index f505c94..e34b89e 100644 --- a/esp32/include/filesystem_ws.h +++ b/esp32/include/filesystem_ws.h @@ -7,8 +7,8 @@ #include // Make sure that this aligns with socket_message.FSDownloadData.data max_size (and for upload) -#define FS_MAX_CHUNK_SIZE 16384 // ~= 16 kb -#define FS_TRANSFER_TIMEOUT 30000 // 30 seconds +#define FS_MAX_CHUNK_SIZE 16384 // ~= 16 kb +#define FS_TRANSFER_TIMEOUT_MS 30000 // 30 seconds namespace FileSystemWS { @@ -47,12 +47,8 @@ class FileSystemHandler { FileSystemHandler(); // Set callbacks for sending streaming data - void setSendCallbacks( - SendMetadataCallback sendMetadata, - SendCallback sendData, - SendCompleteCallback sendComplete, - SendUploadCompleteCallback sendUploadComplete - ); + void setSendCallbacks(SendMetadataCallback sendMetadata, SendCallback sendData, SendCompleteCallback sendComplete, + SendUploadCompleteCallback sendUploadComplete); // Delete file/directory socket_message_FSDeleteResponse handleDelete(const socket_message_FSDeleteRequest& req); diff --git a/esp32/include/peripherals/peripherals.h b/esp32/include/peripherals/peripherals.h index 490b6f3..f4c88b5 100644 --- a/esp32/include/peripherals/peripherals.h +++ b/esp32/include/peripherals/peripherals.h @@ -11,7 +11,6 @@ #include #include -#include #include #include diff --git a/esp32/src/filesystem_ws.cpp b/esp32/src/filesystem_ws.cpp index 4964c20..e15a18f 100644 --- a/esp32/src/filesystem_ws.cpp +++ b/esp32/src/filesystem_ws.cpp @@ -3,6 +3,7 @@ #include #include #include +#include static const char* TAG = "FileSystemWS"; @@ -12,12 +13,9 @@ FileSystemHandler fsHandler; FileSystemHandler::FileSystemHandler() : transferIdCounter_(0) {} -void FileSystemHandler::setSendCallbacks( - SendMetadataCallback sendMetadata, - SendCallback sendData, - SendCompleteCallback sendComplete, - SendUploadCompleteCallback sendUploadComplete -) { +void FileSystemHandler::setSendCallbacks(SendMetadataCallback sendMetadata, SendCallback sendData, + SendCompleteCallback sendComplete, + SendUploadCompleteCallback sendUploadComplete) { sendMetadataCallback_ = sendMetadata; sendDataCallback_ = sendData; sendCompleteCallback_ = sendComplete; @@ -25,11 +23,11 @@ void FileSystemHandler::setSendCallbacks( } void FileSystemHandler::cleanupExpiredTransfers() { - uint32_t now = millis(); + uint32_t now = esp_timer_get_time() / 1000; auto dlIt = downloads_.begin(); while (dlIt != downloads_.end()) { - if (now - dlIt->second.lastActivityTime > FS_TRANSFER_TIMEOUT) { + if (now - dlIt->second.lastActivityTime > FS_TRANSFER_TIMEOUT_MS) { if (dlIt->second.file) { dlIt->second.file.close(); } @@ -53,7 +51,7 @@ void FileSystemHandler::cleanupExpiredTransfers() { auto ulIt = uploads_.begin(); while (ulIt != uploads_.end()) { - if (now - ulIt->second.lastActivityTime > FS_TRANSFER_TIMEOUT) { + if (now - ulIt->second.lastActivityTime > FS_TRANSFER_TIMEOUT_MS) { if (ulIt->second.file) { ulIt->second.file.close(); } @@ -156,7 +154,8 @@ void FileSystemHandler::listDirectory(const std::string& path, socket_message_FS while (file && fileCount < 20 && dirCount < 20) { // Limit to match protobuf max_count if (file.isDirectory()) { if (dirCount < 20) { - strncpy(response.directories[dirCount].name, file.name(), sizeof(response.directories[dirCount].name) - 1); + strncpy(response.directories[dirCount].name, file.name(), + sizeof(response.directories[dirCount].name) - 1); dirCount++; } } else { @@ -248,13 +247,12 @@ void FileSystemHandler::handleDownloadRequest(const socket_message_FSDownloadReq state.chunkSize = chunkSize; state.totalChunks = totalChunks; state.chunksSent = 0; - state.lastActivityTime = millis(); + state.lastActivityTime = esp_timer_get_time() / 1000; state.clientId = clientId; downloads_[transferId] = state; - ESP_LOGI(TAG, "Download started: %s, size=%u, chunks=%u, id=%u", - path.c_str(), fileSize, totalChunks, transferId); + ESP_LOGI(TAG, "Download started: %s, size=%u, chunks=%u, id=%u", path.c_str(), fileSize, totalChunks, transferId); // Start streaming chunks immediately while (sendNextDownloadChunk(transferId)) { @@ -270,7 +268,7 @@ bool FileSystemHandler::sendNextDownloadChunk(uint32_t transferId) { } DownloadState& state = it->second; - state.lastActivityTime = millis(); + state.lastActivityTime = esp_timer_get_time() / 1000; if (state.chunksSent >= state.totalChunks) { if (sendCompleteCallback_) { @@ -378,7 +376,7 @@ socket_message_FSUploadStartResponse FileSystemHandler::handleUploadStart(const state.totalChunks = req.total_chunks; state.chunksReceived = 0; state.bytesReceived = 0; - state.lastActivityTime = millis(); + state.lastActivityTime = esp_timer_get_time() / 1000; state.clientId = clientId; state.hasError = false; @@ -402,7 +400,7 @@ void FileSystemHandler::handleUploadData(const socket_message_FSUploadData& req) } UploadState& state = it->second; - state.lastActivityTime = millis(); + state.lastActivityTime = esp_timer_get_time() / 1000; // Skip if we already have an error if (state.hasError) { diff --git a/esp32/src/main.cpp b/esp32/src/main.cpp index 58b8949..9fd5996 100644 --- a/esp32/src/main.cpp +++ b/esp32/src/main.cpp @@ -315,8 +315,6 @@ void IRAM_ATTR serviceLoopEntry(void *) { } void setup() { - Serial.begin(115200); - ESP_FS.begin(); ESP_LOGI("main", "Booting robot");