Skip to content

Commit

Permalink
More changes to stabilize FPP File transfers
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinMueller2003 committed Jan 5, 2025
1 parent 430bf6b commit ff681dc
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/FileMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1457,9 +1457,15 @@ void c_FileMgr::CloseSdFile (FileId& FileHandle, bool LockStatus)
{
if(!FileList[FileListIndex].Paused)
{
// DEBUG_V("Close the file");
delay(10);
FileList[FileListIndex].fsFile.close ();
}
else
{
// DEBUG_V("File is paused. Not closing");
}

FileList[FileListIndex].IsOpen = false;
FileList[FileListIndex].handle = INVALID_FILE_HANDLE;
FileList[FileListIndex].Paused = false;
Expand All @@ -1468,6 +1474,7 @@ void c_FileMgr::CloseSdFile (FileId& FileHandle, bool LockStatus)
{
if(FileList[FileListIndex].buffer.DataBuffer != OutputMgr.GetBufferAddress())
{
// only free the buffer if it is not malloc'd
free(FileList[FileListIndex].buffer.DataBuffer);
}
}
Expand Down Expand Up @@ -1708,19 +1715,19 @@ void c_FileMgr::BuildFseqList(bool LockStatus)
ESP_SD.chdir(); // Set to sd root
if(!InputFile.open ("/", O_READ))
{
logcon(F("ERROR: Could not open SD card."));
logcon(F("ERROR: Could not open SD card for Reading FSEQ List."));
break;
}

// open output file, erase old data
ESP_SD.chdir(); // Set to sd root
DeleteSdFile(String(FSEQFILELIST), true);
DeleteSdFile(String(F(FSEQFILELIST)), true);

FsFile OutputFile;
if(!OutputFile.open (String(F(FSEQFILELIST)).c_str(), O_WRITE | O_CREAT))
{
InputFile.close();
logcon(F("ERROR: Could not Open SD file list."));
logcon(F("ERROR: Could not open SD card for writting FSEQ List."));
break;
}
OutputFile.print("{");
Expand Down Expand Up @@ -1864,6 +1871,7 @@ bool c_FileMgr::handleFileUpload (
// DEBUG_V("New File");
handleFileUploadNewFile (filename);
expectedIndex = 0;
LOG_PORT.println(".");
}

if (index != expectedIndex)
Expand All @@ -1875,6 +1883,7 @@ bool c_FileMgr::handleFileUpload (
CloseSdFile(fsUploadFileHandle, false);
DeleteSdFile (fsUploadFileName, false);
fsUploadFileHandle = INVALID_FILE_HANDLE;
delay(1000);
BuildFseqList(false);
expectedIndex = 0;
fsUploadFileName = emptyString;
Expand All @@ -1894,7 +1903,8 @@ bool c_FileMgr::handleFileUpload (
// DEBUG_V ("UploadWrite: " + String (len) + String (" bytes"));
bytesWritten = WriteSdFileBuf (fsUploadFileHandle, data, len, false);
// DEBUG_V (String ("Writing bytes: ") + String (index));
// LOG_PORT.print (".");
LOG_PORT.println(String("\033[Fprogress: ") + String(expectedIndex));
LOG_PORT.flush();
}
// PauseSdFile(fsUploadFile);

Expand All @@ -1904,6 +1914,7 @@ bool c_FileMgr::handleFileUpload (
CloseSdFile(fsUploadFileHandle, false);
DeleteSdFile (fsUploadFileName, false);
fsUploadFileHandle = INVALID_FILE_HANDLE;
delay(1000);
BuildFseqList(false);
expectedIndex = 0;
fsUploadFileName = emptyString;
Expand All @@ -1927,7 +1938,11 @@ bool c_FileMgr::handleFileUpload (
F(" Bytes out of ") + String(totalLen) +
F(" bytes. FileLen: ") + GetSdFileSize(filename, false));

delay(1000);
FeedWDT();

expectedIndex = 0;
delay(1000);
BuildFseqList(false);

// DEBUG_V(String("Expected: ") + String(totalLen));
Expand Down

0 comments on commit ff681dc

Please sign in to comment.