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){
|
||||
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;
|
||||
|
||||
void Buffer::saveFs(){
|
||||
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);
|
||||
if (!file) {
|
||||
Serial.println(text02+fileName+"'");
|
||||
//useSD = false;
|
||||
return;
|
||||
}
|
||||
|
||||
saving = true;
|
||||
writing = false;
|
||||
|
||||
if(useA){
|
||||
|
||||
if(bufSizeB > 0){
|
||||
file.write(bufB, bufSizeB);
|
||||
bufSizeB = 0;
|
||||
}
|
||||
|
||||
if(bufSizeA > 0){
|
||||
file.write(bufA, bufSizeA);
|
||||
bufSizeA = 0;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
if(bufSizeA > 0){
|
||||
file.write(bufA, bufSizeA);
|
||||
bufSizeA = 0;
|
||||
}
|
||||
|
||||
if(bufSizeB > 0){
|
||||
file.write(bufB, bufSizeB);
|
||||
bufSizeB = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
file.close();
|
||||
|
||||
//Serial.printf("saved %u bytes\n",len);
|
||||
|
||||
saving = false;
|
||||
writing = true;
|
||||
}
|
||||
|
||||
void Buffer::forceSaveSerial() {
|
||||
uint32_t len = bufSizeA + bufSizeB;
|
||||
if(len == 0) return;
|
||||
|
||||
saving = true;
|
||||
writing = false;
|
||||
|
||||
void Buffer::saveSerial() {
|
||||
if(useA){
|
||||
if(bufSizeB > 0){
|
||||
Serial1.write(bufB, bufSizeB);
|
||||
bufSizeB = 0;
|
||||
}
|
||||
if(bufSizeA > 0){
|
||||
Serial1.write(bufA, bufSizeA);
|
||||
bufSizeA = 0;
|
||||
}
|
||||
} else {
|
||||
if(bufSizeA > 0){
|
||||
Serial1.write(bufA, bufSizeA);
|
||||
bufSizeA = 0;
|
||||
}
|
||||
if(bufSizeB > 0){
|
||||
Serial1.write(bufB, bufSizeB);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
writing = true;
|
||||
|
||||
@@ -22,9 +22,7 @@ class Buffer {
|
||||
void logOpen(String file_name, fs::FS* fs, bool serial);
|
||||
void pcapAdd(wifi_promiscuous_pkt_t *packet, int len);
|
||||
void logAdd(String log);
|
||||
void save(fs::FS* fs);
|
||||
void forceSave(fs::FS* fs);
|
||||
void forceSaveSerial();
|
||||
void save();
|
||||
private:
|
||||
void createFile(String name, bool is_pcap);
|
||||
void open(bool is_pcap);
|
||||
@@ -34,6 +32,8 @@ class Buffer {
|
||||
void write(uint32_t n);
|
||||
void write(uint16_t n);
|
||||
void write(const uint8_t* buf, uint32_t len);
|
||||
void saveFs();
|
||||
void saveSerial();
|
||||
|
||||
uint8_t* bufA;
|
||||
uint8_t* bufB;
|
||||
|
||||
@@ -276,11 +276,7 @@ bool SDInterface::checkDetectPin() {
|
||||
}
|
||||
|
||||
void SDInterface::main() {
|
||||
if (this->supported) {
|
||||
//Serial.println("Saving packet...");
|
||||
buffer_obj.forceSave(&SD);
|
||||
}
|
||||
else {
|
||||
if (!this->supported) {
|
||||
if (checkDetectPin()) {
|
||||
delay(100);
|
||||
this->initSD();
|
||||
|
||||
@@ -46,7 +46,6 @@ class SDInterface {
|
||||
void runUpdate();
|
||||
void performUpdate(Stream &updateSource, size_t updateSize);
|
||||
void main();
|
||||
//void savePacket(uint8_t* buf, uint32_t len);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -418,14 +418,14 @@ void loop()
|
||||
gps_obj.main();
|
||||
#endif
|
||||
|
||||
#ifdef WRITE_PACKETS_SERIAL
|
||||
buffer_obj.forceSaveSerial();
|
||||
#elif defined(HAS_SD)
|
||||
// Detect SD card
|
||||
#if defined(HAS_SD)
|
||||
sd_obj.main();
|
||||
#else
|
||||
return;
|
||||
#endif
|
||||
|
||||
// Save buffer to SD and/or serial
|
||||
buffer_obj.save();
|
||||
|
||||
#ifdef HAS_BATTERY
|
||||
battery_obj.main(currentTime);
|
||||
//temp_obj.main(currentTime);
|
||||
|
||||
Reference in New Issue
Block a user