kopia lustrzana https://github.com/pjalocha/esp32-ogn-tracker
Log more data to SD
rodzic
b30f589def
commit
771cdd3997
|
@ -18,7 +18,8 @@ static uint16_t LogDate = 0; // [~days] dat
|
|||
static TickType_t LogOpenTime; // [msec] when was the log file (re)open
|
||||
static const TickType_t LogReopen = 30000; // [msec] when to close and re-open the log file
|
||||
|
||||
static FIFO<char, 16384> Log_FIFO; // 16K buffer for SD-log
|
||||
const size_t FIFOsize = 16384;
|
||||
static FIFO<char, FIFOsize> Log_FIFO; // 16K buffer for SD-log
|
||||
SemaphoreHandle_t Log_Mutex; // Mutex for the FIFO to prevent mixing between threads
|
||||
|
||||
void Log_Write(char Byte) // write a byte into the log file buffer (FIFO)
|
||||
|
@ -59,13 +60,12 @@ static void Log_Check(void) // time check:
|
|||
utime(LogFileName, &LogTime); }
|
||||
}
|
||||
|
||||
|
||||
static int WriteLog(size_t MaxBlock=8192) // process the queue of lines to be written to the log
|
||||
static int WriteLog(size_t MaxBlock=FIFOsize/2) // process the queue of lines to be written to the log
|
||||
{ if(!LogFile) return 0;
|
||||
int Count=0;
|
||||
for( ; ; )
|
||||
{ char *Block; size_t Len=Log_FIFO.getReadBlock(Block); if(Len==0) break;
|
||||
if(Len>MaxBlock) Len=MaxBlock;
|
||||
if(Len>MaxBlock) Len/=2;
|
||||
int Write=fwrite(Block, 1, Len, LogFile);
|
||||
Log_FIFO.flushReadBlock(Len);
|
||||
if(Write!=Len) { fclose(LogFile); LogFile=0; return -1; }
|
||||
|
@ -83,10 +83,11 @@ extern "C"
|
|||
{ Log_Open();
|
||||
if(!LogFile) { SD_Unmount(); vTaskDelay(1000); continue; }
|
||||
}
|
||||
if(Log_FIFO.Full()<FIFOsize/4) { vTaskDelay(100); }
|
||||
int Write;
|
||||
do { Write=WriteLog(); } while(Write>0);
|
||||
if(Write<0) { SD_Unmount(); vTaskDelay(1000); continue; }
|
||||
if(Write==0) vTaskDelay(100);
|
||||
// if(Write==0) vTaskDelay(100);
|
||||
Log_Check(); }
|
||||
}
|
||||
|
||||
|
|
|
@ -101,8 +101,7 @@ static Delay<int32_t, 8> PressDelay; // 4-second delay for long-term clim
|
|||
static char Line[96]; // line to prepare the barometer NMEA sentence
|
||||
|
||||
static uint8_t InitBaro(void)
|
||||
{ // xSemaphoreTake(I2C_Mutex, portMAX_DELAY);
|
||||
Baro.Bus=BARO_I2C;
|
||||
{ Baro.Bus=BARO_I2C;
|
||||
uint8_t Err=Baro.CheckID();
|
||||
if(Err==0) Err=Baro.ReadCalib();
|
||||
#ifdef WITH_BMP180
|
||||
|
@ -113,7 +112,6 @@ static uint8_t InitBaro(void)
|
|||
if(Err==0) Err=Baro.Acquire();
|
||||
if(Err==0) { Baro.Calculate(); }
|
||||
#endif
|
||||
// xSemaphoreGive(I2C_Mutex);
|
||||
// if(Err) LED_BAT_On();
|
||||
return Err==0 ? Baro.ADDR:0; }
|
||||
|
||||
|
@ -129,22 +127,16 @@ static void ProcBaro(void)
|
|||
|
||||
#ifdef WITH_BMP180
|
||||
TickType_t Start=xTaskGetTickCount();
|
||||
// xSemaphoreTake(I2C_Mutex, portMAX_DELAY);
|
||||
uint8_t Err=Baro.AcquireRawTemperature(); // measure temperature
|
||||
// xSemaphoreGive(I2C_Mutex);
|
||||
if(Err==0) { Baro.CalcTemperature(); AverPress=0; AverCount=0; } // clear the average
|
||||
else { PipeCount=0;
|
||||
// xSemaphoreTake(I2C_Mutex, portMAX_DELAY);
|
||||
I2C_Restart(Baro.Bus);
|
||||
// xSemaphoreGive(I2C_Mutex);
|
||||
vTaskDelay(20);
|
||||
InitBaro(); // try to recover I2C bus and baro
|
||||
return; }
|
||||
|
||||
for(uint8_t Idx=0; Idx<16; Idx++)
|
||||
{ // xSemaphoreTake(I2C_Mutex, portMAX_DELAY);
|
||||
uint8_t Err=Baro.AcquireRawPressure(); // take pressure measurement
|
||||
// xSemaphoreGive(I2C_Mutex);
|
||||
{ uint8_t Err=Baro.AcquireRawPressure(); // take pressure measurement
|
||||
if(Err==0) { Baro.CalcPressure(); AverPress+=Baro.Pressure; AverCount++; } // sum-up average pressure
|
||||
TickType_t Time=xTaskGetTickCount()-Start; if(Time>=200) break; } // but no longer than 250ms to fit into 0.5 second slot
|
||||
|
||||
|
@ -161,12 +153,15 @@ static void ProcBaro(void)
|
|||
#endif
|
||||
#endif
|
||||
#if defined(WITH_BMP280) || defined(WITH_MS5607) || defined(WITH_BME280) || defined(WITH_MS5611)
|
||||
// xSemaphoreTake(I2C_Mutex, portMAX_DELAY);
|
||||
uint8_t Err=Baro.Acquire();
|
||||
// xSemaphoreGive(I2C_Mutex);
|
||||
if(Err==0) { Baro.Calculate(); }
|
||||
else { PipeCount=0; return; }
|
||||
AverPress = Baro.Pressure; // [0.25Pa]
|
||||
AverPress = Baro.Pressure;
|
||||
Err=Baro.Acquire();
|
||||
if(Err==0) { Baro.Calculate(); }
|
||||
else { PipeCount=0; return; }
|
||||
AverPress += Baro.Pressure;
|
||||
AverPress/=2; // [0.25Pa]
|
||||
#endif
|
||||
BaroPipe.Input(AverPress); // [0.25Pa]
|
||||
if(PipeCount<255) PipeCount++; // count data going to the slope fitting pipe
|
||||
|
@ -255,7 +250,7 @@ static void ProcBaro(void)
|
|||
#ifdef WITH_SDLOG
|
||||
if(Log_Free()>=128)
|
||||
{ xSemaphoreTake(Log_Mutex, portMAX_DELAY);
|
||||
Format_String(Log_Write, Line, Len, 0); // send NMEA sentence to the log file
|
||||
Format_String(Log_Write, Line, 0, Len); // send NMEA sentence to the log file
|
||||
xSemaphoreGive(Log_Mutex); }
|
||||
#endif
|
||||
|
||||
|
@ -270,6 +265,12 @@ static void ProcBaro(void)
|
|||
{ xSemaphoreTake(CONS_Mutex, portMAX_DELAY);
|
||||
Format_String(CONS_UART_Write, Line, 0, Len); // send NMEA sentence to the console (UART1)
|
||||
xSemaphoreGive(CONS_Mutex); }
|
||||
#ifdef WITH_SDLOG
|
||||
if(Log_Free()>=128)
|
||||
{ xSemaphoreTake(Log_Mutex, portMAX_DELAY);
|
||||
Format_String(Log_Write, Line, 0, Len); // send NMEA sentence to the log file
|
||||
xSemaphoreGive(Log_Mutex); }
|
||||
#endif
|
||||
|
||||
Len=0;
|
||||
Len+=Format_String(Line+Len, "$LK8EX1,");
|
||||
|
@ -288,6 +289,12 @@ static void ProcBaro(void)
|
|||
{ xSemaphoreTake(CONS_Mutex, portMAX_DELAY);
|
||||
Format_String(CONS_UART_Write, Line, 0, Len); // send NMEA sentence to the console (UART1)
|
||||
xSemaphoreGive(CONS_Mutex); }
|
||||
#ifdef WITH_SDLOG
|
||||
if(Log_Free()>=128)
|
||||
{ xSemaphoreTake(Log_Mutex, portMAX_DELAY);
|
||||
Format_String(Log_Write, Line, 0, Len); // send NMEA sentence to the log file
|
||||
xSemaphoreGive(Log_Mutex); }
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue