Keep track if the IGC log of the possibly changing aircraft radio ID

pull/46/head
Pawel Jalocha 2022-03-20 20:36:00 +00:00
rodzic 9c82d6e589
commit 4c1eb17e9e
5 zmienionych plików z 51 dodań i 26 usunięć

Wyświetl plik

@ -63,7 +63,7 @@
#define WITH_AP_BUTTON // only starts when button pressed at sartup
#define WITH_BT_SPP // Bluetooth serial port for smartphone/tablet link: can work together with WiFi Access point
// #define WITH_STRATUX // beta-code: connect to Stratux WiFi and serve as GPS and OGN transmitter/receiver
// #define WITH_APRS // alpha-code: attempt to connect to the wifi router for uploading the log files to APRS
#define WITH_APRS // alpha-code: attempt to connect to the wifi router for uploading the log files to APRS
#define WITH_HTTP // HTTP server, works with AP dna should work with Stratux as well

Wyświetl plik

@ -15,6 +15,7 @@
#include "sdlog.h"
#endif
#include "rf.h"
#include "ogn.h"
// #include "ctrl.h"
@ -108,7 +109,24 @@ uint8_t MAVLINK_BattCap = 0; // [%]
EventGroupHandle_t GPS_Event = 0;
// ----------------------------------------------------------------------------
FlightMonitor Flight;
static uint32_t RndID_TimeToChange = 0;
void FlightProcess(void)
{ bool PrevInFlight=Flight.inFlight();
Flight.Process(GPS_Pos[GPS_PosIdx]);
bool InFlight=Flight.inFlight();
if(Parameters.AddrType!=0) return;
if(RndID_TimeToChange==0)
{ if(Parameters.Stealth) RndID_TimeToChange=60; }
else
{ if(RndID_TimeToChange==1)
{ Parameters.Address = GPS_Random^RX_Random; }
RndID_TimeToChange--; }
if(PrevInFlight==1 && InFlight==0) RndID_TimeToChange+=20;
}
// ----------------------------------------------------------------------------
@ -563,7 +581,8 @@ static void GPS_BurstComplete(void) // wh
GPS_Pos[NextPosIdx].copyTime(GPS_Pos[GPS_PosIdx]); // copy time from current position
GPS_Pos[NextPosIdx].incrTimeFrac(GPS_PosPeriod); // increment time by the expected period
GPS_Pos[NextPosIdx].copyBaro(GPS_Pos[GPS_PosIdx], (int16_t)GPS_PosPeriod);
Flight.Process(GPS_Pos[GPS_PosIdx]);
if(GPS_Pos[GPS_PosIdx].Sec!=GPS_Pos[NextPosIdx].Sec) FlightProcess();
// Flight.Process(GPS_Pos[GPS_PosIdx]);
// GPS_Pos[NextPosIdx].copyDate(GPS_Pos[GPS_PosIdx]);
#ifdef DEBUG_PRINT
xSemaphoreTake(CONS_Mutex, portMAX_DELAY);

Wyświetl plik

@ -508,6 +508,8 @@ uint16_t StratuxPort;
Len+=Format_Hex(Line+Len, Address, 6);
Len+=Format_String(Line+Len, ",AddrType=");
Line[Len++]='0'+AddrType;
Len+=Format_String(Line+Len, ",Stealth=");
Line[Len++]='0'+Stealth;
Len+=Format_String(Line+Len, ",AcftType=0x");
Line[Len++]=HexDigit(AcftType);
Len+=Format_String(Line+Len, ",FreqPlan=");

Wyświetl plik

@ -345,12 +345,12 @@ static void ProcessRxPacket(OGN_RxPacket<OGN_Packet> *RxPacket, uint8_t RxPacket
if(MyOwnPacket) return; // don't process my own (relayed) packets
if(RxPacket->Packet.Header.Encrypted && RxPacket->RxErr<10) // here we attempt to relay encrypted packets
{ RxPacket->calcRelayRank(GPS_Altitude/10);
OGN_RxPacket<OGN_Packet> *PrevRxPacket = RelayQueue.addNew(RxPacketIdx);
OGN_RxPacket<OGN_Packet> *PrevRxPacket = RelayQueue.addNew(RxPacketIdx); // add to the relay queue and get the previous packet of same ID
return; }
bool DistOK = RxPacket->Packet.calcDistanceVector(LatDist, LonDist, GPS_Latitude, GPS_Longitude, GPS_LatCosine)>=0;
if(DistOK)
{ RxPacket->calcRelayRank(GPS_Altitude/10); // calculate the relay-rank (priority for relay)
OGN_RxPacket<OGN_Packet> *PrevRxPacket = RelayQueue.addNew(RxPacketIdx);
OGN_RxPacket<OGN_Packet> *PrevRxPacket = RelayQueue.addNew(RxPacketIdx); // add to the relay queue and get the previous packet of same ID
#ifdef WITH_POGNT
{ uint8_t Len=RxPacket->WritePOGNT(Line); // print on the console as $POGNT
if(Parameters.Verbose)
@ -388,15 +388,15 @@ static void ProcessRxPacket(OGN_RxPacket<OGN_Packet> *RxPacket, uint8_t RxPacket
#endif
#endif // WITH_LOOKOUT
bool Signif = PrevRxPacket!=0;
if(!Signif) Signif=OGN_isSignif(&(RxPacket->Packet), &(PrevRxPacket->Packet));
if(!Signif) Signif=OGN_isSignif(&(RxPacket->Packet), &(PrevRxPacket->Packet)); // compare against previous packet of same ID from the relay queue
#ifdef WITH_APRS
if(Signif) APRSrx_FIFO.Write(*RxPacket);
if(Signif) APRSrx_FIFO.Write(*RxPacket); // APRS queue for received packets
#endif
#ifdef WITH_LOG
if(Signif) FlashLog(RxPacket, RxTime); // log only significant packets
#endif
#ifdef WITH_PFLAA
if( Parameters.Verbose // print PFLAA on the console for received packets
if( Parameters.Verbose // print PFLAA on the console for received packets
#ifdef WITH_LOOKOUT
&& (!Tgt)
#endif

Wyświetl plik

@ -103,6 +103,7 @@ const uint32_t IGC_SavePeriod = 20;
static FILE *IGC_File=0; //
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; //
const int IGC_Digest_Size = 32;
@ -233,33 +234,34 @@ static int IGC_Header(const GPS_Position &Pos) // write the
#endif
return 0; }
int IGC_ID(void)
void IGC_ID(void)
{ uint32_t Time = TimeSync_Time();
int Len=Format_String(Line, "LOGN");
Len+=Format_HHMMSS(Line+Len, Time);
Len+=Format_String(Line+Len, "ID ");
Len+=Format_Hex(Line+Len, Parameters.AcftID);
Len+=Format_Hex(Line+Len, Parameters.AcftID); // Radio ID
Line[Len++]='\n'; Line[Len]=0;
IGC_LogLine(Line, Len);
IGC_LogLine(Line, Len); }
void IGC_MAC(void)
uint64_t MAC = getUniqueID();
Len=4+6;
Len+=Format_String(Line+Len, "MAC ");
Len+=Format_Hex(Line+Len, (uint16_t)(MAC>>32)); // ESP32 48-bit ID
Len+=Format_Hex(Line+Len, (uint32_t) MAC );
Line[Len++]='\n'; Line[Len]=0;
IGC_LogLine(Line, Len);
return 0; }
IGC_LogLine(Line, Len); }
static int IGC_Log(const GPS_Position &Pos) // log GPS position as B-record
{ int Len=Pos.WriteIGC(Line);
{ int Len=Pos.WriteIGC(Line); // write GPS position in the IGC format
#ifdef DEBUG_PRINT
xSemaphoreTake(CONS_Mutex, portMAX_DELAY);
Format_String(CONS_UART_Write, Line);
xSemaphoreGive(CONS_Mutex);
#endif
int Written=IGC_LogLine(Line, Len);
if(Written!=Len) IGC_Close();
return Written; }
int Written=IGC_LogLine(Line, Len); // write Line to the IGC log
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_Check(void) // check if new GPS position
{ static uint8_t PrevPosIdx=0;
@ -279,10 +281,11 @@ static void IGC_Check(void) // check if
xSemaphoreGive(CONS_Mutex);
#endif
if(IGC_File) // if IGC file already open
{ IGC_Log(GPS_Pos[PosIdx]); // log position
{ if(Parameters.AcftID!=IGC_AcftID) { IGC_ID(); IGC_AcftID=Parameters.AcftID; }
IGC_Log(GPS_Pos[PosIdx]); // log position
if(!inFlight) // if no longer in flight
{ IGC_SHA256.Finish(IGC_Digest);
uint8_t *Sig = (uint8_t *)Line+256;
{ IGC_SHA256.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);
int Len=0;
Line[Len++]='G'; // produce G-record with SH256
@ -296,10 +299,10 @@ static void IGC_Check(void) // check if
Line[Len++]='\n'; Line[Len]=0; // end-of-line, end-of-string
IGC_LogLine(Line, Len); // write to IGC
IGC_Close(); IGC_TimeStamp(); } // then close the IGC file
else
{ uint32_t Time=TimeSync_Time();
if(Time-IGC_SaveTime>=IGC_SavePeriod)
{ IGC_Reopen(); }
else // if (still) in flight
{ uint32_t Time=TimeSync_Time(); //
if(Time-IGC_SaveTime>=IGC_SavePeriod) //
{ IGC_Reopen(); } // re-open IGC thus close it and open it back to save the current data
}
}
else // if IGC file is not open
@ -309,7 +312,8 @@ static void IGC_Check(void) // check if
if(IGC_File) // if open succesfully
{ IGC_SHA256.Start(); // start the SHA256 calculation
IGC_Header(GPS_Pos[PosIdx]); // then write header
IGC_ID();
IGC_ID(); IGC_AcftID=Parameters.AcftID;
IGC_MAC();
IGC_Log(GPS_Pos[PosIdx]); } // log first B-record
}
}
@ -371,8 +375,8 @@ extern "C"
Format_String(CONS_UART_Write, "\n");
xSemaphoreGive(CONS_Mutex);
*/
uint32_t ID = getUniqueAddress();
IGC_Serial[2] = Flight.Code36(ID%36); ID/=36;
uint32_t ID = getUniqueAddress(); // ID of the tracker (from CPU serial)
IGC_Serial[2] = Flight.Code36(ID%36); ID/=36; // produce 3-char IGC serial for this tracker
IGC_Serial[1] = Flight.Code36(ID%36); ID/=36;
IGC_Serial[0] = Flight.Code36(ID%36);