kopia lustrzana https://github.com/pjalocha/esp32-ogn-tracker
Record to internal flash only when flying
rodzic
196589f2dc
commit
916765929b
56
main/log.cpp
56
main/log.cpp
|
@ -30,13 +30,13 @@ static const uint32_t FlashLog_MaxTime = 3600; // 1 hour max. per single log
|
||||||
static const uint32_t FlashLog_MaxSize = 0x10000; // 64KB max. per single log file
|
static const uint32_t FlashLog_MaxSize = 0x10000; // 64KB max. per single log file
|
||||||
#ifdef WITH_SPIFFS_FAT
|
#ifdef WITH_SPIFFS_FAT
|
||||||
static const uint32_t FlashLog_SavePeriod = 30; // [sec] reopen the file every 30sec
|
static const uint32_t FlashLog_SavePeriod = 30; // [sec] reopen the file every 30sec
|
||||||
static const uint32_t FlashLog_SaveSize = 4096; // [bytes] reopen the file every 4KB
|
static const uint32_t FlashLog_SaveSize = 4096; // [bytes] reopen the file every 4KB
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool FlashLog_SaveReq=0; // request to save the log right away, like after landing or before shutdown
|
bool FlashLog_SaveReq=0; // request to save the log right away, like after landing or before shutdown
|
||||||
uint32_t FlashLog_FileTime=0; // [sec] UTC time corresponding to the log file
|
uint32_t FlashLog_FileTime=0; // [sec] UTC time corresponding to the log file
|
||||||
char FlashLog_FileName[32]; // current log file name if open
|
char FlashLog_FileName[32]; // current log file name if open
|
||||||
static FILE *FlashLog_File=0; // current log file if open
|
static FILE * FlashLog_File=0; // current log file if open
|
||||||
static uint32_t FlashLog_FileFlush=0; // track where the log file has been forced to be written to flash
|
static uint32_t FlashLog_FileFlush=0; // track where the log file has been forced to be written to flash
|
||||||
|
|
||||||
FIFO<OGN_LogPacket<OGN_Packet>, 32> FlashLog_FIFO;
|
FIFO<OGN_LogPacket<OGN_Packet>, 32> FlashLog_FIFO;
|
||||||
|
@ -292,12 +292,12 @@ static int FlashLog_Open(uint32_t Time) // open a new
|
||||||
if(FlashLog_File==0) FlashLog_Clean(0, 4); // if the file cannot be open clean again
|
if(FlashLog_File==0) FlashLog_Clean(0, 4); // if the file cannot be open clean again
|
||||||
return FlashLog_File!=0; } // 1=success, 0=failure: new log file could not be open
|
return FlashLog_File!=0; } // 1=success, 0=failure: new log file could not be open
|
||||||
|
|
||||||
static void FlashLog_Reopen(void)
|
static void FlashLog_Reopen(void) // force close and re-open the current log file
|
||||||
{ if(FlashLog_File)
|
{ if(FlashLog_File) // if log File is open
|
||||||
{ fclose(FlashLog_File);
|
{ fclose(FlashLog_File); // close it
|
||||||
FlashLog_File = fopen(FlashLog_FileName, "ab");
|
FlashLog_File = fopen(FlashLog_FileName, "ab"); // open it again for append with same filename
|
||||||
FlashLog_FileFlush = ftell(FlashLog_File); }
|
FlashLog_FileFlush = ftell(FlashLog_File); } // track how much has been pysically written
|
||||||
FlashLog_SaveReq=0; }
|
FlashLog_SaveReq=0; } // clear q possible request to save the file
|
||||||
|
|
||||||
static int FlashLog_Record(OGN_LogPacket<OGN_Packet> *Packet, int Packets, uint32_t Time) // log a batch of OGN packets
|
static int FlashLog_Record(OGN_LogPacket<OGN_Packet> *Packet, int Packets, uint32_t Time) // log a batch of OGN packets
|
||||||
{ if(FlashLog_File) // if log file already open
|
{ if(FlashLog_File) // if log file already open
|
||||||
|
@ -381,27 +381,23 @@ void vTaskLOG(void* pvParameters)
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
TickType_t PrevTick = 0;
|
TickType_t PrevTick = 0; // [ms] Time when packets stored the last time
|
||||||
for( ; ; )
|
for( ; ; )
|
||||||
{ // vTaskDelay(200); // wait idle 0.2sec
|
{ vTaskDelay(1);
|
||||||
if(FlashLog_SaveReq) FlashLog_Reopen(); // if requested then save the current log (close + reopen)
|
bool Flying = Flight.inFlight(); // if the aircraft flying ?
|
||||||
TickType_t Tick=xTaskGetTickCount(); // system tick count now
|
|
||||||
size_t Packets = FlashLog_FIFO.Full(); // how many packets in the queue ?
|
size_t Packets = FlashLog_FIFO.Full(); // how many packets in the queue ?
|
||||||
// #ifdef DEBUG_PRINT
|
if(Flying) // when flying
|
||||||
// xSemaphoreTake(CONS_Mutex, portMAX_DELAY);
|
{ if(FlashLog_SaveReq) FlashLog_Reopen(); // if requested then save the current log (close + reopen)
|
||||||
// Format_String(CONS_UART_Write, "TaskLOG() ");
|
TickType_t Tick=xTaskGetTickCount(); // system tick count now
|
||||||
// Format_UnsDec(CONS_UART_Write, Tick, 4, 3);
|
if(Packets==0) { PrevTick=Tick; vTaskDelay(100); continue; } // if none: then give up
|
||||||
// Format_String(CONS_UART_Write, "(");
|
if(Packets>=8) { Copy(); PrevTick=Tick; continue; } // if 8 or more packets then copy them to the log file
|
||||||
// Format_UnsDec(CONS_UART_Write, PrevTick, 4, 3);
|
TickType_t Diff = Tick-PrevTick; // time since last log action
|
||||||
// Format_String(CONS_UART_Write, ")s: ");
|
if(Diff>=8000) { Copy(); PrevTick=Tick; continue; } // if more than 8.0sec than copy the packets
|
||||||
// Format_UnsDec(CONS_UART_Write, Packets);
|
} else // when not flying
|
||||||
// Format_String(CONS_UART_Write, " packets\n");
|
{ if(FlashLog_File) { fclose(FlashLog_File); FlashLog_File=0; } // if file open then close it
|
||||||
// xSemaphoreGive(CONS_Mutex);
|
while(FlashLog_FIFO.Full()>=FlashLog_FIFO.Len/2) // flush the packet queue but keep it half-full
|
||||||
// #endif
|
{ FlashLog_FIFO.Read(); vTaskDelay(1); }
|
||||||
if(Packets==0) { PrevTick=Tick; vTaskDelay(100); continue; } // if none: then give up
|
}
|
||||||
if(Packets>=8) { Copy(); PrevTick=Tick; continue; } // if 8 or more packets then copy them to the log file
|
|
||||||
TickType_t Diff = Tick-PrevTick; // time since last log action
|
|
||||||
if(Diff>=8000) { Copy(); PrevTick=Tick; continue; } // if more than 8.0sec than copy the packets
|
|
||||||
vTaskDelay(100); }
|
vTaskDelay(100); }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue