mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
модифицированна функция записи файла
This commit is contained in:
@@ -2,7 +2,8 @@
|
|||||||
#include "EspFileSystem.h"
|
#include "EspFileSystem.h"
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
|
|
||||||
extern void writeFileUint8(const String& filename, uint8_t*& payload, size_t length, size_t headerLenth);
|
extern void writeFileUint8tFromBuf(const String& filename, uint8_t*& payload, size_t length, size_t headerLenth, size_t bufSize);
|
||||||
|
extern void writeFileUint8tByByte(const String& filename, uint8_t*& payload, size_t length, size_t headerLenth);
|
||||||
extern File seekFile(const String& filename, size_t position = 0);
|
extern File seekFile(const String& filename, size_t position = 0);
|
||||||
extern const String writeFile(const String& filename, const String& str);
|
extern const String writeFile(const String& filename, const String& str);
|
||||||
extern const String readFile(const String& filename, size_t max_size);
|
extern const String readFile(const String& filename, size_t max_size);
|
||||||
|
|||||||
@@ -226,7 +226,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (headerStr == "/gifnoc") {
|
if (headerStr == "/gifnoc") {
|
||||||
writeFileUint8("config.json", payload, length, headerLenth);
|
writeFileUint8tFromBuf("config.json", payload, length, headerLenth, 256);
|
||||||
}
|
}
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
|
|||||||
@@ -1,10 +1,32 @@
|
|||||||
#include "Utils/FileUtils.h"
|
#include "Utils/FileUtils.h"
|
||||||
|
|
||||||
void writeFileUint8(const String& filename, uint8_t*& payload, size_t length, size_t headerLenth) {
|
//данная функция записывает файл из длинного массива uint8_t через буфер
|
||||||
|
void writeFileUint8tFromBuf(const String& filename, uint8_t*& big_buf, size_t length, size_t headerLenth, size_t bufSize) {
|
||||||
String path = filepath(filename);
|
String path = filepath(filename);
|
||||||
auto file = FileFS.open(path, "w");
|
auto file = FileFS.open(path, "w");
|
||||||
if (!file) {
|
if (!file) {
|
||||||
Serial.println(F("failed write file uint8"));
|
Serial.println(F("failed write file uint8tFromBuf"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
size_t written{headerLenth};
|
||||||
|
while (length > written) {
|
||||||
|
size_t size = length - written;
|
||||||
|
if (size > bufSize) size = bufSize;
|
||||||
|
uint8_t* p = &big_buf[written];
|
||||||
|
size_t res = file.write(p, size);
|
||||||
|
if (size != res) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
written += res;
|
||||||
|
}
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
void writeFileUint8tByByte(const String& filename, uint8_t*& payload, size_t length, size_t headerLenth) {
|
||||||
|
String path = filepath(filename);
|
||||||
|
auto file = FileFS.open(path, "w");
|
||||||
|
if (!file) {
|
||||||
|
Serial.println(F("failed write file uint8tByByte"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
size_t every = 0;
|
size_t every = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user