This commit is contained in:
jomjol
2020-12-07 21:38:43 +01:00
parent 793f928e6e
commit f5c28107d4
17 changed files with 62 additions and 23 deletions

View File

@@ -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! **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 * 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)

View File

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

View File

@@ -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 */ if (fp == NULL) /* If an error occurs during the file creation */
{ {
fprintf(stderr, "fopen() failed for '%s'\n", nm.c_str()); fprintf(stderr, "fopen() failed for '%s'\n", nm.c_str());

View File

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

View File

@@ -10,6 +10,8 @@
#include "esp_err.h" #include "esp_err.h"
#include "esp_log.h" #include "esp_log.h"
#include "Helper.h"
#include "esp_http_server.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) 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) { if (!fd) {
ESP_LOGE(TAG, "Failed to read existing file : %s", filename.c_str()); ESP_LOGE(TAG, "Failed to read existing file : %s", filename.c_str());
/* Respond with 500 Internal Server Error */ /* Respond with 500 Internal Server Error */

View File

@@ -31,6 +31,8 @@
#include "ClassLogFile.h" #include "ClassLogFile.h"
#include "Helper.h"
#define BUFFSIZE 1024 #define BUFFSIZE 1024
@@ -89,7 +91,7 @@ static bool ota_example_task(std::string fn)
int data_read; 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); data_read = fread(ota_write_data, 1, BUFFSIZE, f);
while (data_read > 0) { while (data_read > 0) {

View File

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

View File

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

View File

@@ -1,5 +1,8 @@
//#pragma warning(disable : 4996) //#pragma warning(disable : 4996)
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "Helper.h" #include "Helper.h"
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
@@ -7,11 +10,33 @@
#include <string.h> #include <string.h>
#include <esp_log.h> #include <esp_log.h>
#include "ClassLogFile.h"
//#include "ClassLogFile.h"
//#define ISWINDOWS_TRUE //#define ISWINDOWS_TRUE
#define PATH_MAX_STRING_SIZE 256 #define PATH_MAX_STRING_SIZE 256
using namespace std; 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) std::string FormatFileName(std::string input)
{ {
#ifdef ISWINDOWS_TRUE #ifdef ISWINDOWS_TRUE
@@ -126,14 +151,14 @@ void CopyFile(string input, string output)
} }
char cTemp; 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! if (!fpSourceFile) // Sourcefile existiert nicht sonst gibt es einen Fehler beim Kopierversuch!
{ {
printf("File %s existiert nicht!\n", input.c_str()); printf("File %s existiert nicht!\n", input.c_str());
return; return;
} }
FILE* fpTargetFile = fopen(output.c_str(), "wb"); FILE* fpTargetFile = OpenFileAndWait(output.c_str(), "wb");
// Code Section // Code Section

View File

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

View File

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

View File

@@ -2,6 +2,6 @@ FILE(GLOB_RECURSE app_sources ${CMAKE_CURRENT_SOURCE_DIR}/*.*)
idf_component_register(SRCS ${app_sources} idf_component_register(SRCS ${app_sources}
INCLUDE_DIRS "." 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)

View File

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

View File

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

View File

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

Binary file not shown.

Binary file not shown.