diff --git a/main/gps.cpp b/main/gps.cpp index 3f8ee35..3231916 100644 --- a/main/gps.cpp +++ b/main/gps.cpp @@ -116,6 +116,7 @@ static uint32_t RndID_TimeToChange = 0; void FlightProcess(void) { bool PrevInFlight=Flight.inFlight(); + GPS_Position &GPS = GPS_Pos[GPS_PosIdx]; Flight.Process(GPS_Pos[GPS_PosIdx]); GPS.InFlight=Flight.inFlight(); if(Parameters.AddrType!=0) return; diff --git a/main/sdlog.cpp b/main/sdlog.cpp index 3939a75..378beaa 100644 --- a/main/sdlog.cpp +++ b/main/sdlog.cpp @@ -105,7 +105,7 @@ static uint32_t IGC_SaveTime=0; uint16_t IGC_FlightNum=0; // flight counter static uint32_t IGC_AcftID=0; // to keep trackof possibly changing aircraft radio ID -static SHA256 IGC_SHA256; // +static SHA256 IGC_SHA256, IGC_SHA256_bck; // const int IGC_Digest_Size = 32; static uint8_t IGC_Digest[IGC_Digest_Size]; // @@ -263,13 +263,33 @@ static int IGC_Log(const GPS_Position &Pos) // log GPS p if(Written!=Len) IGC_Close(); // if not all data written then close the log return Written; } // return number of bytes written or (negative) error +static void IGC_Sig(const uint8_t *Dig, int DigLen, const uint8_t *Sig, int SigLen, bool Partial=0) +{ int Len=0; + if(Partial) Line[Len++]='L'; + Line[Len++]='G'; // produce G-record with SH256 + for(int Idx=0; Idx=IGC_SavePeriod) // - { IGC_Reopen(); } // re-open IGC thus close it and open it back to save the current data + { IGC_SHA256_bck.Clone(IGC_SHA256); + IGC_SHA256_bck.Finish(IGC_Digest); // complete SHA256 digest + uint8_t *Sig = (uint8_t *)Line+256; // space to write the SHA and signature + int SigLen = IGC_SignKey.Sign_MD5_SHA256(Sig, IGC_Digest, IGC_Digest_Size); // produce signature + IGC_Sig(IGC_Digest, IGC_Digest_Size, Sig, SigLen, 1); + IGC_Reopen(); } // re-open IGC thus close it and open it back to save the current data } } else // if IGC file is not open - { if(inFlight) // and in-flight - { for(int Try=0; Try<8; Try++) - { int Err=IGC_Open(); if(Err!=(-2)) break; } // try to open a new IGC file but don't overwrite the old ones - if(IGC_File) // if open succesfully - { IGC_SHA256.Start(); // start the SHA256 calculation - IGC_Header(GPS_Pos[PosIdx]); // then write header - IGC_ID(); IGC_AcftID=Parameters.AcftID; - IGC_MAC(); - IGC_Log(GPS_Pos[PosIdx]); } // log first B-record - } + { for(int Try=0; Try<8; Try++) + { int Err=IGC_Open(); if(Err!=(-2)) break; } // try to open a new IGC file but don't overwrite the old ones + if(IGC_File) // if open succesfully + { IGC_SHA256.Start(); // start the SHA256 calculation + IGC_Header(GPS_Pos[PosIdx]); // then write header + IGC_ID(); IGC_AcftID=Parameters.AcftID; + IGC_MAC(); + IGC_Log(GPS_Pos[PosIdx]); } // log first B-record } } @@ -389,6 +402,7 @@ extern "C" // xSemaphoreGive(CONS_Mutex); IGC_SHA256.Init(); + IGC_SHA256_bck.Init(); Log_FIFO.Clear();