kopia lustrzana https://github.com/pjalocha/esp32-ogn-tracker
Fix IGC file creation issues
rodzic
ff20127a6a
commit
44cce4a19a
|
@ -76,6 +76,10 @@ void Format_Hex( void (*Output)(char), uint32_t Word )
|
||||||
{ Format_Hex(Output, (uint8_t)(Word>>24)); Format_Hex(Output, (uint8_t)(Word>>16));
|
{ Format_Hex(Output, (uint8_t)(Word>>24)); Format_Hex(Output, (uint8_t)(Word>>16));
|
||||||
Format_Hex(Output, (uint8_t)(Word>>8)); Format_Hex(Output, (uint8_t)Word); }
|
Format_Hex(Output, (uint8_t)(Word>>8)); Format_Hex(Output, (uint8_t)Word); }
|
||||||
|
|
||||||
|
void Format_Hex( void (*Output)(char), uint64_t Word )
|
||||||
|
{ Format_Hex(Output, (uint32_t)(Word>>32));
|
||||||
|
Format_Hex(Output, (uint32_t)(Word )); }
|
||||||
|
|
||||||
void Format_MAC( void (*Output)(char), uint8_t *MAC, uint8_t Len)
|
void Format_MAC( void (*Output)(char), uint8_t *MAC, uint8_t Len)
|
||||||
{ for(uint8_t Idx=0; Idx<Len; Idx++)
|
{ for(uint8_t Idx=0; Idx<Len; Idx++)
|
||||||
{ if(Idx) (*Output)(':');
|
{ if(Idx) (*Output)(':');
|
||||||
|
@ -284,11 +288,16 @@ int16_t Read_Dec3(const char *Inp) // convert three digit decimal nu
|
||||||
int8_t Low=Read_Dec1(Inp[2]); if(Low<0) return -1;
|
int8_t Low=Read_Dec1(Inp[2]); if(Low<0) return -1;
|
||||||
return (int16_t)Low + (int16_t)10*(int16_t)Mid + (int16_t)100*(int16_t)High; }
|
return (int16_t)Low + (int16_t)10*(int16_t)Mid + (int16_t)100*(int16_t)High; }
|
||||||
|
|
||||||
int16_t Read_Dec4(const char *Inp) // convert three digit decimal number into an integer
|
int16_t Read_Dec4(const char *Inp) // convert four digit decimal number into an integer
|
||||||
{ int16_t High=Read_Dec2(Inp ); if(High<0) return -1;
|
{ int16_t High=Read_Dec2(Inp ); if(High<0) return -1;
|
||||||
int16_t Low =Read_Dec2(Inp+2); if(Low<0) return -1;
|
int16_t Low =Read_Dec2(Inp+2); if(Low<0) return -1;
|
||||||
return Low + (int16_t)100*(int16_t)High; }
|
return Low + (int16_t)100*(int16_t)High; }
|
||||||
|
|
||||||
|
int32_t Read_Dec5(const char *Inp) // convert four digit decimal number into an integer
|
||||||
|
{ int16_t High=Read_Dec2(Inp ); if(High<0) return -1;
|
||||||
|
int16_t Low =Read_Dec3(Inp+2); if(Low<0) return -1;
|
||||||
|
return (int32_t)Low + (int32_t)1000*(int32_t)High; }
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
int8_t Read_Coord(int32_t &Lat, const char *Inp)
|
int8_t Read_Coord(int32_t &Lat, const char *Inp)
|
||||||
|
|
|
@ -16,6 +16,7 @@ void Format_String( void (*Output)(char), const char *String, uint8_t MinLen,
|
||||||
void Format_Hex( void (*Output)(char), uint8_t Byte );
|
void Format_Hex( void (*Output)(char), uint8_t Byte );
|
||||||
void Format_Hex( void (*Output)(char), uint16_t Word );
|
void Format_Hex( void (*Output)(char), uint16_t Word );
|
||||||
void Format_Hex( void (*Output)(char), uint32_t Word );
|
void Format_Hex( void (*Output)(char), uint32_t Word );
|
||||||
|
void Format_Hex( void (*Output)(char), uint64_t Word );
|
||||||
// void Format_Hex( void (*Output)(char), uint32_t Word, uint8_t Digits);
|
// void Format_Hex( void (*Output)(char), uint32_t Word, uint8_t Digits);
|
||||||
void Format_MAC( void (*Output)(char), const uint8_t *MAC, uint8_t Len=6);
|
void Format_MAC( void (*Output)(char), const uint8_t *MAC, uint8_t Len=6);
|
||||||
|
|
||||||
|
@ -78,7 +79,8 @@ int8_t Read_Dec1(char Digit); // convert single digit into an
|
||||||
inline int8_t Read_Dec1(const char *Inp) { return Read_Dec1(Inp[0]); }
|
inline int8_t Read_Dec1(const char *Inp) { return Read_Dec1(Inp[0]); }
|
||||||
int8_t Read_Dec2(const char *Inp); // convert two digit decimal number into an integer
|
int8_t Read_Dec2(const char *Inp); // convert two digit decimal number into an integer
|
||||||
int16_t Read_Dec3(const char *Inp); // convert three digit decimal number into an integer
|
int16_t Read_Dec3(const char *Inp); // convert three digit decimal number into an integer
|
||||||
int16_t Read_Dec4(const char *Inp); // convert three digit decimal number into an integer
|
int16_t Read_Dec4(const char *Inp); // convert four digit decimal number into an integer
|
||||||
|
int32_t Read_Dec5(const char *Inp); // convert five digit decimal number into an integer
|
||||||
|
|
||||||
template <class Type>
|
template <class Type>
|
||||||
int8_t Read_Hex(Type &Int, const char *Inp, uint8_t MaxDig=0) // convert variable number of digits hexadecimal number into an integer
|
int8_t Read_Hex(Type &Int, const char *Inp, uint8_t MaxDig=0) // convert variable number of digits hexadecimal number into an integer
|
||||||
|
@ -120,7 +122,8 @@ template <class Type>
|
||||||
{ Dig=Read_UnsDec(Value, Inp+Len); }
|
{ Dig=Read_UnsDec(Value, Inp+Len); }
|
||||||
if(Dig<=0) return Dig;
|
if(Dig<=0) return Dig;
|
||||||
Len+=Dig;
|
Len+=Dig;
|
||||||
if(Sign=='-') Value=(-Value); return Len; }
|
if(Sign=='-') Value=(-Value);
|
||||||
|
return Len; }
|
||||||
|
|
||||||
template <class Type>
|
template <class Type>
|
||||||
int8_t Read_Float1(Type &Value, const char *Inp) // read floating point, take just one digit after decimal point
|
int8_t Read_Float1(Type &Value, const char *Inp) // read floating point, take just one digit after decimal point
|
||||||
|
|
|
@ -125,7 +125,8 @@ static void IGC_Close(void)
|
||||||
Format_String(CONS_UART_Write, IGC_FileName);
|
Format_String(CONS_UART_Write, IGC_FileName);
|
||||||
Format_String(CONS_UART_Write, "\n");
|
Format_String(CONS_UART_Write, "\n");
|
||||||
xSemaphoreGive(CONS_Mutex);
|
xSemaphoreGive(CONS_Mutex);
|
||||||
fclose(IGC_File); IGC_File=0; IGC_FlightNum++; }
|
fclose(IGC_File); IGC_File=0;
|
||||||
|
IGC_FlightNum++; }
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
IGC_SaveTime = TimeSync_Time();
|
IGC_SaveTime = TimeSync_Time();
|
||||||
|
@ -146,11 +147,14 @@ static int IGC_Open(const GPS_Position &GPS)
|
||||||
IGC_FileName[IGC_PathLen]='/'; // slash after the path
|
IGC_FileName[IGC_PathLen]='/'; // slash after the path
|
||||||
Flight.ShortName(IGC_FileName+IGC_PathLen+1, GPS, IGC_FlightNum, IGC_Serial); // full name
|
Flight.ShortName(IGC_FileName+IGC_PathLen+1, GPS, IGC_FlightNum, IGC_Serial); // full name
|
||||||
IGC_File=fopen(IGC_FileName, "rt"); // attempt to open for read, just to try if the file is already there
|
IGC_File=fopen(IGC_FileName, "rt"); // attempt to open for read, just to try if the file is already there
|
||||||
if(IGC_File) { IGC_Close(); return -2; } // -2 => file already exists
|
// Format_String(CONS_UART_Write, "IGC_Open() (1)\n");
|
||||||
|
if(IGC_File) { fclose(IGC_File); IGC_File=0; IGC_FlightNum++; return -2; } // -2 => file already exists
|
||||||
IGC_File=fopen(IGC_FileName, "wt"); // open for write
|
IGC_File=fopen(IGC_FileName, "wt"); // open for write
|
||||||
|
// Format_String(CONS_UART_Write, "IGC_Open() (2)\n");
|
||||||
if(IGC_File==0) // failed: maybe sub-dir does not exist ?
|
if(IGC_File==0) // failed: maybe sub-dir does not exist ?
|
||||||
{ if(mkdir(IGC_Path, 0777)<0) return -3; // -3 => can't create sub-dir
|
{ if(mkdir(IGC_Path, 0777)<0) return -3; // -3 => can't create sub-dir
|
||||||
IGC_File=fopen(IGC_FileName, "wt"); } // retry to open for write
|
IGC_File=fopen(IGC_FileName, "wt"); } // retry to open for write
|
||||||
|
// Format_String(CONS_UART_Write, "IGC_Open() (3)\n");
|
||||||
if(IGC_File)
|
if(IGC_File)
|
||||||
{ IGC_SaveTime = TimeSync_Time();
|
{ IGC_SaveTime = TimeSync_Time();
|
||||||
xSemaphoreTake(CONS_Mutex, portMAX_DELAY);
|
xSemaphoreTake(CONS_Mutex, portMAX_DELAY);
|
||||||
|
@ -368,13 +372,13 @@ static void IGC_CheckGPS(void) // check if new
|
||||||
{ static uint8_t PrevPosIdx=0;
|
{ static uint8_t PrevPosIdx=0;
|
||||||
if(GPS_PosIdx==PrevPosIdx) return;
|
if(GPS_PosIdx==PrevPosIdx) return;
|
||||||
PrevPosIdx=GPS_PosIdx;
|
PrevPosIdx=GPS_PosIdx;
|
||||||
const uint8_t PosPipeIdxMask = GPS_PosPipeSize-1; // get the GPS position just before in the pipe
|
const uint8_t PosPipeIdxMask = GPS_PosPipeSize-1; // get the GPS position just before in the pipe
|
||||||
uint8_t PosIdx = GPS_PosIdx-1; PosIdx&=PosPipeIdxMask;
|
uint8_t PosIdx = GPS_PosIdx-1; PosIdx&=PosPipeIdxMask;
|
||||||
static bool PrevInFlight=0;
|
static bool PrevInFlight=0;
|
||||||
const GPS_Position &GPS = GPS_Pos[PosIdx];
|
const GPS_Position &GPS = GPS_Pos[PosIdx];
|
||||||
bool inFlight = GPS.InFlight; // in-flight or on-the-ground ?
|
bool inFlight = GPS.InFlight; // in-flight or on-the-ground ?
|
||||||
bool StopFile = PrevInFlight && !inFlight;
|
bool StopFile = PrevInFlight && !inFlight; // decide to stop the file when InFlight switches from 1 to 0
|
||||||
PrevInFlight = inFlight;;
|
PrevInFlight = inFlight;
|
||||||
#ifdef DEBUG_PRINT
|
#ifdef DEBUG_PRINT
|
||||||
GPS.PrintLine(Line);
|
GPS.PrintLine(Line);
|
||||||
xSemaphoreTake(CONS_Mutex, portMAX_DELAY);
|
xSemaphoreTake(CONS_Mutex, portMAX_DELAY);
|
||||||
|
|
Ładowanie…
Reference in New Issue