mirror of
https://github.com/justcallmekoko/ESP32Marauder.git
synced 2025-12-22 23:26:45 -08:00
Sd+Serial save() in buffer_obj / out of sd_obj
This commit is contained in:
@@ -153,126 +153,61 @@ void Buffer::write(const uint8_t* buf, uint32_t len){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Buffer::save(fs::FS* fs){
|
void Buffer::saveFs(){
|
||||||
if(saving) return; // makes sure the function isn't called simultaneously on different cores
|
|
||||||
|
|
||||||
// buffers are already emptied, therefor saving is unecessary
|
|
||||||
if((useA && bufSizeB == 0) || (!useA && bufSizeA == 0)){
|
|
||||||
//Serial.printf("useA: %s, bufA %u, bufB %u\n",useA ? "true" : "false",bufSizeA,bufSizeB); // for debug porpuses
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Serial.println("saving file");
|
|
||||||
|
|
||||||
uint32_t startTime = millis();
|
|
||||||
uint32_t finishTime;
|
|
||||||
|
|
||||||
file = fs->open(fileName, FILE_APPEND);
|
|
||||||
if (!file) {
|
|
||||||
Serial.println(text02 + fileName+"'");
|
|
||||||
//useSD = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
saving = true;
|
|
||||||
|
|
||||||
uint32_t len;
|
|
||||||
|
|
||||||
if(useA){
|
|
||||||
file.write(bufB, bufSizeB);
|
|
||||||
len = bufSizeB;
|
|
||||||
bufSizeB = 0;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
file.write(bufA, bufSizeA);
|
|
||||||
len = bufSizeA;
|
|
||||||
bufSizeA = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
file.close();
|
|
||||||
|
|
||||||
finishTime = millis() - startTime;
|
|
||||||
|
|
||||||
//Serial.printf("\n%u bytes written for %u ms\n", len, finishTime);
|
|
||||||
|
|
||||||
saving = false;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void Buffer::forceSave(fs::FS* fs){
|
|
||||||
uint32_t len = bufSizeA + bufSizeB;
|
|
||||||
if(len == 0) return;
|
|
||||||
|
|
||||||
file = fs->open(fileName, FILE_APPEND);
|
file = fs->open(fileName, FILE_APPEND);
|
||||||
if (!file) {
|
if (!file) {
|
||||||
Serial.println(text02+fileName+"'");
|
Serial.println(text02+fileName+"'");
|
||||||
//useSD = false;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
saving = true;
|
|
||||||
writing = false;
|
|
||||||
|
|
||||||
if(useA){
|
if(useA){
|
||||||
|
|
||||||
if(bufSizeB > 0){
|
if(bufSizeB > 0){
|
||||||
file.write(bufB, bufSizeB);
|
file.write(bufB, bufSizeB);
|
||||||
bufSizeB = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(bufSizeA > 0){
|
if(bufSizeA > 0){
|
||||||
file.write(bufA, bufSizeA);
|
file.write(bufA, bufSizeA);
|
||||||
bufSizeA = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if(bufSizeA > 0){
|
if(bufSizeA > 0){
|
||||||
file.write(bufA, bufSizeA);
|
file.write(bufA, bufSizeA);
|
||||||
bufSizeA = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(bufSizeB > 0){
|
if(bufSizeB > 0){
|
||||||
file.write(bufB, bufSizeB);
|
file.write(bufB, bufSizeB);
|
||||||
bufSizeB = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
//Serial.printf("saved %u bytes\n",len);
|
|
||||||
|
|
||||||
saving = false;
|
|
||||||
writing = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Buffer::forceSaveSerial() {
|
void Buffer::saveSerial() {
|
||||||
uint32_t len = bufSizeA + bufSizeB;
|
|
||||||
if(len == 0) return;
|
|
||||||
|
|
||||||
saving = true;
|
|
||||||
writing = false;
|
|
||||||
|
|
||||||
if(useA){
|
if(useA){
|
||||||
if(bufSizeB > 0){
|
if(bufSizeB > 0){
|
||||||
Serial1.write(bufB, bufSizeB);
|
Serial1.write(bufB, bufSizeB);
|
||||||
bufSizeB = 0;
|
|
||||||
}
|
}
|
||||||
if(bufSizeA > 0){
|
if(bufSizeA > 0){
|
||||||
Serial1.write(bufA, bufSizeA);
|
Serial1.write(bufA, bufSizeA);
|
||||||
bufSizeA = 0;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(bufSizeA > 0){
|
if(bufSizeA > 0){
|
||||||
Serial1.write(bufA, bufSizeA);
|
Serial1.write(bufA, bufSizeA);
|
||||||
bufSizeA = 0;
|
|
||||||
}
|
}
|
||||||
if(bufSizeB > 0){
|
if(bufSizeB > 0){
|
||||||
Serial1.write(bufB, bufSizeB);
|
Serial1.write(bufB, bufSizeB);
|
||||||
bufSizeB = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Buffer::save() {
|
||||||
|
if((bufSizeA + bufSizeB) == 0) return;
|
||||||
|
|
||||||
|
saving = true;
|
||||||
|
writing = false;
|
||||||
|
|
||||||
|
if(this->fs) saveFs();
|
||||||
|
if(this->serial) saveSerial();
|
||||||
|
|
||||||
|
bufSizeA = 0;
|
||||||
|
bufSizeB = 0;
|
||||||
|
|
||||||
saving = false;
|
saving = false;
|
||||||
writing = true;
|
writing = true;
|
||||||
|
|||||||
@@ -22,9 +22,7 @@ class Buffer {
|
|||||||
void logOpen(String file_name, fs::FS* fs, bool serial);
|
void logOpen(String file_name, fs::FS* fs, bool serial);
|
||||||
void pcapAdd(wifi_promiscuous_pkt_t *packet, int len);
|
void pcapAdd(wifi_promiscuous_pkt_t *packet, int len);
|
||||||
void logAdd(String log);
|
void logAdd(String log);
|
||||||
void save(fs::FS* fs);
|
void save();
|
||||||
void forceSave(fs::FS* fs);
|
|
||||||
void forceSaveSerial();
|
|
||||||
private:
|
private:
|
||||||
void createFile(String name, bool is_pcap);
|
void createFile(String name, bool is_pcap);
|
||||||
void open(bool is_pcap);
|
void open(bool is_pcap);
|
||||||
@@ -34,6 +32,8 @@ class Buffer {
|
|||||||
void write(uint32_t n);
|
void write(uint32_t n);
|
||||||
void write(uint16_t n);
|
void write(uint16_t n);
|
||||||
void write(const uint8_t* buf, uint32_t len);
|
void write(const uint8_t* buf, uint32_t len);
|
||||||
|
void saveFs();
|
||||||
|
void saveSerial();
|
||||||
|
|
||||||
uint8_t* bufA;
|
uint8_t* bufA;
|
||||||
uint8_t* bufB;
|
uint8_t* bufB;
|
||||||
|
|||||||
@@ -276,11 +276,7 @@ bool SDInterface::checkDetectPin() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SDInterface::main() {
|
void SDInterface::main() {
|
||||||
if (this->supported) {
|
if (!this->supported) {
|
||||||
//Serial.println("Saving packet...");
|
|
||||||
buffer_obj.forceSave(&SD);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (checkDetectPin()) {
|
if (checkDetectPin()) {
|
||||||
delay(100);
|
delay(100);
|
||||||
this->initSD();
|
this->initSD();
|
||||||
|
|||||||
@@ -46,7 +46,6 @@ class SDInterface {
|
|||||||
void runUpdate();
|
void runUpdate();
|
||||||
void performUpdate(Stream &updateSource, size_t updateSize);
|
void performUpdate(Stream &updateSource, size_t updateSize);
|
||||||
void main();
|
void main();
|
||||||
//void savePacket(uint8_t* buf, uint32_t len);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -418,14 +418,14 @@ void loop()
|
|||||||
gps_obj.main();
|
gps_obj.main();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef WRITE_PACKETS_SERIAL
|
// Detect SD card
|
||||||
buffer_obj.forceSaveSerial();
|
#if defined(HAS_SD)
|
||||||
#elif defined(HAS_SD)
|
|
||||||
sd_obj.main();
|
sd_obj.main();
|
||||||
#else
|
|
||||||
return;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Save buffer to SD and/or serial
|
||||||
|
buffer_obj.save();
|
||||||
|
|
||||||
#ifdef HAS_BATTERY
|
#ifdef HAS_BATTERY
|
||||||
battery_obj.main(currentTime);
|
battery_obj.main(currentTime);
|
||||||
//temp_obj.main(currentTime);
|
//temp_obj.main(currentTime);
|
||||||
|
|||||||
Reference in New Issue
Block a user