Fix task and added timings for write
This commit is contained in:
@@ -6,9 +6,16 @@
|
||||
#include <string>
|
||||
#include <functional>
|
||||
#include <cstdio>
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/queue.h>
|
||||
#include <freertos/task.h>
|
||||
#include <freertos/semphr.h>
|
||||
|
||||
#define FS_MAX_CHUNK_SIZE (1024*64)
|
||||
#define FS_MAX_CHUNK_SIZE (1024 * 64)
|
||||
#define FS_TRANSFER_TIMEOUT_MS 30000
|
||||
#define FS_WRITE_QUEUE_SIZE 4
|
||||
#define FS_WRITER_TASK_STACK_SIZE 4096
|
||||
#define FS_WRITER_TASK_PRIORITY 5
|
||||
|
||||
namespace FileSystemWS {
|
||||
|
||||
@@ -29,6 +36,7 @@ struct UploadState {
|
||||
uint32_t fileSize;
|
||||
uint32_t totalChunks;
|
||||
uint32_t chunksReceived;
|
||||
uint32_t chunksWritten;
|
||||
uint32_t bytesReceived;
|
||||
uint32_t lastActivityTime;
|
||||
int clientId;
|
||||
@@ -36,6 +44,14 @@ struct UploadState {
|
||||
std::string errorMessage;
|
||||
};
|
||||
|
||||
struct WriteRequest {
|
||||
uint32_t transferId;
|
||||
uint8_t* data;
|
||||
size_t size;
|
||||
uint32_t chunkIndex;
|
||||
bool isLastChunk;
|
||||
};
|
||||
|
||||
using SendMetadataCallback = std::function<void(const socket_message_FSDownloadMetadata&, int clientId)>;
|
||||
using SendCallback = std::function<void(const socket_message_FSDownloadData&, int clientId)>;
|
||||
using SendCompleteCallback = std::function<void(const socket_message_FSDownloadComplete&, int clientId)>;
|
||||
@@ -44,6 +60,10 @@ using SendUploadCompleteCallback = std::function<void(const socket_message_FSUpl
|
||||
class FileSystemHandler {
|
||||
public:
|
||||
FileSystemHandler();
|
||||
~FileSystemHandler();
|
||||
|
||||
void startWriterTask();
|
||||
void stopWriterTask();
|
||||
|
||||
void setSendCallbacks(SendMetadataCallback sendMetadata, SendCallback sendData, SendCompleteCallback sendComplete,
|
||||
SendUploadCompleteCallback sendUploadComplete);
|
||||
@@ -63,6 +83,12 @@ class FileSystemHandler {
|
||||
std::map<uint32_t, UploadState> uploads_;
|
||||
uint32_t transferIdCounter_;
|
||||
|
||||
// Async writer task
|
||||
QueueHandle_t writeQueue_;
|
||||
TaskHandle_t writerTaskHandle_;
|
||||
SemaphoreHandle_t uploadsMutex_;
|
||||
volatile bool writerTaskRunning_;
|
||||
|
||||
inline uint32_t generateTransferId() { return ++transferIdCounter_; }
|
||||
|
||||
SendMetadataCallback sendMetadataCallback_;
|
||||
@@ -74,6 +100,8 @@ class FileSystemHandler {
|
||||
bool deleteRecursive(const std::string& path);
|
||||
bool sendNextDownloadChunk(uint32_t transferId);
|
||||
void finalizeUpload(uint32_t transferId, bool success, const std::string& error = "");
|
||||
void processWriteRequest(const WriteRequest& req);
|
||||
static void writerTaskFunc(void* param);
|
||||
};
|
||||
|
||||
extern FileSystemHandler fsHandler;
|
||||
|
||||
Reference in New Issue
Block a user