jomjol hace 5 años
padre
commit
f5c28107d4

+ 7 - 2
README.md

@@ -25,11 +25,16 @@ A 3d-printable housing can be found here: https://www.thingiverse.com/thing:4571
 
 **General remark:** Beside the `firmware.bin`, typically also the content of `/html` needs to be updated!
 
-##### Rolling - (2020-12-06)
+##### Rolling - (2020-12-07)
+
+* Improvement: internal file handling
+
+
+2020-12-06
 
 * Option for fixed IP settings in `wlan.ini` - description see inside file
 
-* based on v5.0.05 (2020-12-06)
+* based on v5.0.0 (2020-12-06)
 
   
 

+ 2 - 2
code/components/connect_wlan/connect_wlan.cpp

@@ -232,7 +232,7 @@ void LoadWlanFromFile(std::string fn, std::string &_ssid, std::string &_passphra
 
     FILE* pFile;
     fn = FormatFileName(fn);
-    pFile = fopen(fn.c_str(), "r");
+    pFile = OpenFileAndWait(fn.c_str(), "r");
 
     printf("file loaded\n");
 
@@ -326,7 +326,7 @@ void LoadNetConfigFromFile(std::string fn, std::string &_ip, std::string &_gw, s
 
     FILE* pFile;
     fn = FormatFileName(fn);
-    pFile = fopen(fn.c_str(), "r");
+    pFile = OpenFileAndWait(fn.c_str(), "r");
 
     printf("file loaded\n");
 

+ 1 - 1
code/components/jomjol_controlcamera/ClassControllCamera.cpp

@@ -255,7 +255,7 @@ esp_err_t CCamera::CaptureToFile(std::string nm, int delay)
         }
     }
 
-    FILE * fp = fopen(nm.c_str(), "wb");
+    FILE * fp = OpenFileAndWait(nm.c_str(), "wb");
     if (fp == NULL)  /* If an error occurs during the file creation */
     {
         fprintf(stderr, "fopen() failed for '%s'\n", nm.c_str());

+ 5 - 5
code/components/jomjol_fileserver_ota/server_file.cpp

@@ -121,7 +121,7 @@ static esp_err_t http_resp_dir_html(httpd_req_t *req, const char *dirpath, const
 
 /////////////////////////////////////////////////
     if (!readonly) {
-        FILE *fd = fopen("/sdcard/html/upload_script.html", "r");
+        FILE *fd = OpenFileAndWait("/sdcard/html/upload_script.html", "r");
         char *chunk = ((struct file_server_data *)req->user_ctx)->scratch;
         size_t chunksize;
         do {
@@ -231,7 +231,7 @@ static esp_err_t logfileact_get_handler(httpd_req_t *req)
     std::string currentfilename = LogFile.GetCurrentFileName();
 
 
-    fd = fopen(currentfilename.c_str(), "r");
+    fd = OpenFileAndWait(currentfilename.c_str(), "r");
     if (!fd) {
         ESP_LOGE(TAG, "Failed to read existing file : %s", filepath);
         /* Respond with 500 Internal Server Error */
@@ -337,7 +337,7 @@ static esp_err_t download_get_handler(httpd_req_t *req)
         return ESP_FAIL;
     }
 
-    fd = fopen(filepath, "r");
+    fd = OpenFileAndWait(filepath, "r");
     if (!fd) {
         ESP_LOGE(TAG, "Failed to read existing file : %s", filepath);
         /* Respond with 500 Internal Server Error */
@@ -424,7 +424,7 @@ static esp_err_t upload_post_handler(httpd_req_t *req)
         return ESP_FAIL;
     }
 
-    fd = fopen(filepath, "w");
+    fd = OpenFileAndWait(filepath, "w");
     if (!fd) {
         ESP_LOGE(TAG, "Failed to create file : %s", filepath);
         /* Respond with 500 Internal Server Error */
@@ -710,7 +710,7 @@ void unzip(std::string _in_zip_file, std::string _target_directory){
             zw = std::string(archive_filename);
             zw = _target_directory + zw;
             printf("Filename to extract: %s", zw.c_str());
-            FILE* fpTargetFile = fopen(zw.c_str(), "wb");
+            FILE* fpTargetFile = OpenFileAndWait(zw.c_str(), "wb");
             fwrite(p, 1, (uint)uncomp_size, fpTargetFile);
             fclose(fpTargetFile);
 

+ 3 - 1
code/components/jomjol_fileserver_ota/server_help.cpp

@@ -10,6 +10,8 @@
 #include "esp_err.h"
 #include "esp_log.h"
 
+#include "Helper.h"
+
 #include "esp_http_server.h"
 
 
@@ -25,7 +27,7 @@ char scratch[SCRATCH_BUFSIZE];
 
 esp_err_t send_file(httpd_req_t *req, std::string filename,  struct stat * file_stat)
 {
-    FILE *fd = fopen(filename.c_str(), "r");
+    FILE *fd = OpenFileAndWait(filename.c_str(), "r");
     if (!fd) {
         ESP_LOGE(TAG, "Failed to read existing file : %s", filename.c_str());
         /* Respond with 500 Internal Server Error */

+ 3 - 1
code/components/jomjol_fileserver_ota/server_ota.cpp

@@ -31,6 +31,8 @@
 
 #include "ClassLogFile.h"
 
+#include "Helper.h"
+
 
 
 #define BUFFSIZE 1024
@@ -89,7 +91,7 @@ static bool ota_example_task(std::string fn)
 
     int data_read;     
 
-    FILE* f = fopen(fn.c_str(), "rb");     // vorher  nur "r"
+    FILE* f = OpenFileAndWait(fn.c_str(), "rb");     // vorher  nur "r"
     data_read = fread(ota_write_data, 1, BUFFSIZE, f);
 
     while (data_read > 0) {

+ 1 - 1
code/components/jomjol_flowcontroll/ClassFlowControll.cpp

@@ -122,7 +122,7 @@ void ClassFlowControll::InitFlow(std::string config)
     ClassFlow* cfc;
     FILE* pFile;
     config = FormatFileName(config);
-    pFile = fopen(config.c_str(), "r");
+    pFile = OpenFileAndWait(config.c_str(), "r");
 
     line = "";
 

+ 1 - 1
code/components/jomjol_helper/CMakeLists.txt

@@ -2,6 +2,6 @@ FILE(GLOB_RECURSE app_sources ${CMAKE_CURRENT_SOURCE_DIR}/*.*)
 
 idf_component_register(SRCS ${app_sources}
                     INCLUDE_DIRS "."
-                    REQUIRES tfmicro)
+                    REQUIRES tfmicro jomjol_logfile)
 
 

+ 27 - 2
code/components/jomjol_helper/Helper.cpp

@@ -1,5 +1,8 @@
 //#pragma warning(disable : 4996)
 
+#include "freertos/FreeRTOS.h"
+#include "freertos/task.h"
+
 #include "Helper.h"
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -7,11 +10,33 @@
 #include <string.h>
 #include <esp_log.h>
 
+#include "ClassLogFile.h"
+//#include "ClassLogFile.h"
+
 //#define ISWINDOWS_TRUE
 #define PATH_MAX_STRING_SIZE 256
 
 using namespace std;
 
+
+FILE* OpenFileAndWait(const char* nm, char* _mode, int _waitsec)
+{
+	FILE *pfile = fopen(nm, _mode);
+
+	if (pfile == NULL)
+	{
+		TickType_t xDelay;
+		xDelay = _waitsec * 1000 / portTICK_PERIOD_MS;
+		std::string zw = "File is locked: " + std::string(nm) + " - wait for " + std::to_string(_waitsec);
+	    printf(zw.c_str());
+		printf("\n");
+		LogFile.WriteToFile(zw);      
+		vTaskDelay( xDelay );
+		pfile = fopen(nm, _mode);
+	}
+	return pfile;
+}
+
 std::string FormatFileName(std::string input)
 {
 #ifdef ISWINDOWS_TRUE
@@ -126,14 +151,14 @@ void CopyFile(string input, string output)
 	}
 
 	char cTemp;
-	FILE* fpSourceFile = fopen(input.c_str(), "rb");
+	FILE* fpSourceFile = OpenFileAndWait(input.c_str(), "rb");
 	if (!fpSourceFile)	// Sourcefile existiert nicht sonst gibt es einen Fehler beim Kopierversuch!
 	{
 		printf("File %s existiert nicht!\n", input.c_str());
 		return;
 	}
 
-	FILE* fpTargetFile = fopen(output.c_str(), "wb");
+	FILE* fpTargetFile = OpenFileAndWait(output.c_str(), "wb");
 
 	// Code Section
 

+ 2 - 0
code/components/jomjol_helper/Helper.h

@@ -10,6 +10,8 @@ void FindReplace(std::string& line, std::string& oldString, std::string& newStri
 
 void CopyFile(string input, string output);
 
+FILE* OpenFileAndWait(const char* nm, char* _mode, int _waitsec = 10);
+
 size_t findDelimiterPos(string input, string delimiter);
 //string trim(string istring);
 string trim(string istring, string adddelimiter = "");

+ 2 - 1
code/components/jomjol_logfile/ClassLogFile.cpp

@@ -19,7 +19,8 @@ void ClassLogFile::WriteToDedicatedFile(std::string _fn, std::string info, bool
         return;
     }
 
-    pFile = fopen(_fn.c_str(), "a+");
+    pFile = OpenFileAndWait(_fn.c_str(), "a+");
+
     if (pFile!=NULL) {
         if (_time)
         {

+ 1 - 1
code/components/jomjol_tfliteclass/CMakeLists.txt

@@ -2,6 +2,6 @@ FILE(GLOB_RECURSE app_sources ${CMAKE_CURRENT_SOURCE_DIR}/*.*)
 
 idf_component_register(SRCS ${app_sources}
                     INCLUDE_DIRS "."
-                    REQUIRES jomjol_image_proc jomjol_logfile esp_http_server esp32-camera-master jomjol_controlcamera jomjol_flowcontroll)
+                    REQUIRES jomjol_image_proc jomjol_logfile esp_http_server esp32-camera-master jomjol_controlcamera jomjol_flowcontroll jomjol_helper)
 
 

+ 3 - 1
code/components/jomjol_tfliteclass/CTfLiteClass.cpp

@@ -4,6 +4,8 @@
 
 #include "ClassLogFile.h"
 
+#include "Helper.h"
+
 #include <sys/stat.h>
 
 bool debugdetailtflite = false;
@@ -199,7 +201,7 @@ unsigned char* CTfLiteClass::ReadFileToCharArray(std::string _fn)
   
 	if(result != NULL) {
 //		printf("\nSpeicher ist reserviert\n");
-        FILE* f = fopen(_fn.c_str(), "rb");     // vorher  nur "r"
+        FILE* f = OpenFileAndWait(_fn.c_str(), "rb");     // vorher  nur "r"
         fread(result, 1, size, f);
         fclose(f);        
 	}else {

+ 2 - 2
code/main/version.cpp

@@ -1,4 +1,4 @@
-const char* GIT_REV="a8fb2e3";
+const char* GIT_REV="793f928";
 const char* GIT_TAG="";
 const char* GIT_BRANCH="rolling";
-const char* BUILD_TIME="2020-12-06 21:10";
+const char* BUILD_TIME="2020-12-07 20:40";

+ 2 - 2
code/version.cpp

@@ -1,4 +1,4 @@
-const char* GIT_REV="a8fb2e3";
+const char* GIT_REV="793f928";
 const char* GIT_TAG="";
 const char* GIT_BRANCH="rolling";
-const char* BUILD_TIME="2020-12-06 21:10";
+const char* BUILD_TIME="2020-12-07 20:40";

BIN
firmware/bootloader.bin


BIN
firmware/firmware.bin