Rolling 20220921

This commit is contained in:
jomjol
2022-09-21 21:49:09 +02:00
parent 6756b6d741
commit efc800c223
14 changed files with 184 additions and 606 deletions

View File

@@ -52,6 +52,7 @@ extern "C" {
#define MAX_FILE_SIZE (2000*1024) // 200 KB
#define MAX_FILE_SIZE_STR "2000KB"
/* Scratch buffer size */
#define SCRATCH_BUFSIZE 8192
@@ -72,6 +73,9 @@ static const char *TAG_FILESERVER = "file_server";
using namespace std;
string SUFFIX_ZW = "_0xge";
esp_err_t get_tflite_file_handler(httpd_req_t *req)
{
// DIR *verzeichnis;
@@ -780,12 +784,20 @@ std::string unzip_new(std::string _in_zip_file, std::string _target_zip, std::st
}
printf("Filename to extract: %s", zw.c_str());
DeleteFile(zw);
FILE* fpTargetFile = OpenFileAndWait(zw.c_str(), "wb");
string filename_zw = zw + SUFFIX_ZW;
printf("Filename to extract: %s, Zwischenfilename: %s", zw.c_str(), filename_zw.c_str());
// extrahieren in zwischendatei
DeleteFile(filename_zw);
FILE* fpTargetFile = OpenFileAndWait(filename_zw.c_str(), "wb");
fwrite(p, 1, (uint)uncomp_size, fpTargetFile);
fclose(fpTargetFile);
DeleteFile(zw);
RenameFile(filename_zw, zw);
DeleteFile(filename_zw);
printf("Successfully extracted file \"%s\", size %u\n", archive_filename, (uint)uncomp_size);
// printf("File data: \"%s\"\n", (const char*)p);

View File

@@ -358,24 +358,19 @@ esp_err_t handler_ota_update(httpd_req_t *req)
{
std::string in, out, outbin, zw, retfirmware;
// in = "/sdcard/firmware/html.zip";
out = "/sdcard/html";
outbin = "/sdcard/firmware";
// delete_all_in_directory(out);
retfirmware = unzip_new(fn, out+"/", outbin+"/");
if (retfirmware.length() > 0)
{
filetype = "BIN";
fn = retfirmware;
zw = "HTML Update Successfull!<br><br>Additioal firmware found in ZIP file.\n";
httpd_resp_sendstr_chunk(req, zw.c_str());
}
else
{
zw = "HTML Update Successfull!<br><br>No reboot necessary.\n";
zw = "HTML Update Successfull! No reboot necessary.\n";
httpd_resp_sendstr_chunk(req, zw.c_str());
httpd_resp_sendstr_chunk(req, NULL);
return ESP_OK;
@@ -385,21 +380,20 @@ esp_err_t handler_ota_update(httpd_req_t *req)
if (filetype == "BIN")
{
const char* resp_str;
const char* resp_str;
KillTFliteTasks();
gpio_handler_deinit();
if (ota_update_task(fn))
{
// resp_str = "rebooting - Firmware Update Successfull!<br><br>You can restart now.";
// httpd_resp_send(req, resp_str, strlen(resp_str));
// httpd_resp_sendstr_chunk(req, NULL);
return handler_reboot(req);
}
else
{
resp_str = "Error during Firmware Update!!!<br><br>Please check output of console.";
std::string zw = "reboot\n";
httpd_resp_sendstr_chunk(req, zw.c_str());
httpd_resp_sendstr_chunk(req, NULL);
printf("Send reboot\n");
return ESP_OK;
}
resp_str = "Error during Firmware Update!!!\nPlease check output of console.";
httpd_resp_send(req, resp_str, strlen(resp_str));
#ifdef DEBUG_DETAIL_ON
@@ -428,7 +422,7 @@ esp_err_t handler_ota_update(httpd_req_t *req)
delete_all_in_directory(out);
unzip(in, out+"/");
zw = "HTML Update Successfull!<br><br>No reboot necessary";
zw = "HTML Update Successfull!\nNo reboot necessary";
httpd_resp_send(req, zw.c_str(), strlen(zw.c_str()));
httpd_resp_sendstr_chunk(req, NULL);
return ESP_OK;

View File

@@ -209,6 +209,23 @@ size_t findDelimiterPos(string input, string delimiter)
return pos;
}
void RenameFile(string from, string to)
{
// ESP_LOGI(logTag, "Deleting file : %s", fn.c_str());
/* Delete file */
FILE* fpSourceFile = OpenFileAndWait(from.c_str(), "rb");
if (!fpSourceFile) // Sourcefile existiert nicht sonst gibt es einen Fehler beim Kopierversuch!
{
printf("DeleteFile: File %s existiert nicht!\n", from.c_str());
return;
}
fclose(fpSourceFile);
rename(from.c_str(), to.c_str());
}
void DeleteFile(string fn)
{
// ESP_LOGI(logTag, "Deleting file : %s", fn.c_str());

View File

@@ -11,6 +11,8 @@ void FindReplace(std::string& line, std::string& oldString, std::string& newStri
void CopyFile(string input, string output);
void DeleteFile(string fn);
void RenameFile(string from, string to);
FILE* OpenFileAndWait(const char* nm, const char* _mode, int _waitsec = 1);