kopia lustrzana https://github.com/pjalocha/esp32-ogn-tracker
Keep APRS messages within the IGC
rodzic
a59e1ec30f
commit
db6af0f2f4
|
@ -12,9 +12,12 @@
|
||||||
|
|
||||||
static bool Earlier(const char *Line1, const char *Line2) { return strcmp(Line1, Line2)<0; }
|
static bool Earlier(const char *Line1, const char *Line2) { return strcmp(Line1, Line2)<0; }
|
||||||
|
|
||||||
static int Verbose = 1;
|
static int Verbose = 0;
|
||||||
static int GeoidSepar = 40;
|
static int GeoidSepar = 40;
|
||||||
|
|
||||||
|
const int MaxLineLen = 256;
|
||||||
|
const int MaxIGClen = 64;
|
||||||
|
|
||||||
static FILE *OutFile = 0;
|
static FILE *OutFile = 0;
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
|
@ -22,8 +25,8 @@ int main(int argc, char *argv[])
|
||||||
{ printf("Usage: %s <own-aircraft-APRS-call> <input-file.aprs>\n", argv[0]);
|
{ printf("Usage: %s <own-aircraft-APRS-call> <input-file.aprs>\n", argv[0]);
|
||||||
return 0; }
|
return 0; }
|
||||||
|
|
||||||
const char *OwnAcft = argv[1]; int OwnAcftLen = strlen(OwnAcft);
|
const char *OwnAcft = argv[1]; int OwnAcftLen = strlen(OwnAcft); // target aircraft APRS name
|
||||||
char OutFileName[32]; strcpy(OutFileName, OwnAcft); strcat(OutFileName, ".IGC");
|
char OutFileName[32]; strcpy(OutFileName, OwnAcft); strcat(OutFileName, ".IGC"); // create the IGC file name
|
||||||
|
|
||||||
const char *InpFileName = argv[2];
|
const char *InpFileName = argv[2];
|
||||||
FILE *InpFile;
|
FILE *InpFile;
|
||||||
|
@ -33,32 +36,35 @@ int main(int argc, char *argv[])
|
||||||
if(InpFile==0) { printf("Cannot open %s for read\n", InpFileName); return 0; }
|
if(InpFile==0) { printf("Cannot open %s for read\n", InpFileName); return 0; }
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<char *> OutLine;
|
std::vector<char *> OutLine; // list of APRS lines for the selected aircraft
|
||||||
char InpLine[256];
|
char InpLine[MaxLineLen];
|
||||||
// char OutLine[256];
|
// char OutLine[MaxLineLen];
|
||||||
int InpLines=0;
|
int InpLines=0;
|
||||||
// int OutLines=0;
|
// int OutLines=0;
|
||||||
char *Out=0;
|
char *Out=0; // (new) IGC line allocated
|
||||||
for( ; ; )
|
for( ; ; )
|
||||||
{ if(fgets(InpLine, 256, InpFile)==0) break;
|
{ if(fgets(InpLine, MaxLineLen, InpFile)==0) break; // read line from the input
|
||||||
char *EOL = strchr(InpLine, '\n'); if(EOL==0) break;
|
char *EOL = strchr(InpLine, '\n'); if(EOL==0) break;
|
||||||
*EOL = 0;
|
*EOL = 0;
|
||||||
InpLines++;
|
InpLines++;
|
||||||
if(memcmp(InpLine, OwnAcft, OwnAcftLen)) continue;
|
if(memcmp(InpLine, OwnAcft, OwnAcftLen)) continue; // must start with the selected APRS name
|
||||||
if(Out==0) Out = (char *)malloc(60);
|
if(Out==0) Out = (char *)malloc(MaxIGClen+MaxLineLen); // allocated (new) IGC line
|
||||||
int OutLen=APRS2IGC(Out, InpLine, GeoidSepar);
|
int OutLen=APRS2IGC(Out, InpLine, GeoidSepar); // convert APRS to IGC B-record
|
||||||
if(OutLen>0)
|
if(OutLen>0) // if correct conversion
|
||||||
{ if(Verbose) printf("%s => %s [%d]\n", InpLine, Out, OutLen);
|
{ // if(Verbose) printf("%s => %s [%d]\n", InpLine, Out, OutLen);
|
||||||
OutLine.push_back(Out); Out=0; }
|
OutLen += Format_String(Out+OutLen, "LGNE ");
|
||||||
|
OutLen += Format_String(Out+OutLen, InpLine);
|
||||||
|
Out[OutLen++] = '\n'; Out[OutLen] = 0;
|
||||||
|
OutLine.push_back(Out); Out=0; } // add the new IGC line to the list
|
||||||
}
|
}
|
||||||
if(Out) { free(Out); Out=0; }
|
if(Out) { free(Out); Out=0; }
|
||||||
if(InpFile!=stdin) fclose(InpFile);
|
if(InpFile!=stdin) fclose(InpFile);
|
||||||
printf("%d lines from %s\n", InpLines, InpFileName);
|
printf("%d lines from %s\n", InpLines, InpFileName);
|
||||||
|
|
||||||
std::sort(OutLine.begin(), OutLine.end(), Earlier);
|
std::sort(OutLine.begin(), OutLine.end(), Earlier); // sort the IGC B-record lines
|
||||||
OutFile=fopen(OutFileName, "wt");
|
OutFile=fopen(OutFileName, "wt");
|
||||||
if(OutFile==0) { printf("Cannot open %s for write\n", OutFileName); return 0; }
|
if(OutFile==0) { printf("Cannot open %s for write\n", OutFileName); return 0; }
|
||||||
for(size_t Idx=0; Idx<OutLine.size(); Idx++)
|
for(size_t Idx=0; Idx<OutLine.size(); Idx++) // look over (now sorted) IGC B-records
|
||||||
{ fprintf(OutFile, "%s", OutLine[Idx]); }
|
{ fprintf(OutFile, "%s", OutLine[Idx]); }
|
||||||
fclose(OutFile);
|
fclose(OutFile);
|
||||||
printf("%lu lines to %s\n", OutLine.size(), OutFileName);
|
printf("%lu lines to %s\n", OutLine.size(), OutFileName);
|
||||||
|
|
|
@ -277,7 +277,7 @@ int APRS2IGC(char *Out, const char *Inp, int GeoidSepar) // convert
|
||||||
Msg++; // where message starts
|
Msg++; // where message starts
|
||||||
if(Msg[0]!='/' || Msg[7]!='h') return 0;
|
if(Msg[0]!='/' || Msg[7]!='h') return 0;
|
||||||
const char *Pos = Msg+8; if(Pos[4]!='.' || Pos[14]!='.') return 0; // where position starts
|
const char *Pos = Msg+8; if(Pos[4]!='.' || Pos[14]!='.') return 0; // where position starts
|
||||||
const char *ExtPos = strstr(Pos+18, " !W"); if(ExtPos[5]=='!') ExtPos+=3; else ExtPos=0;
|
const char *ExtPos = strstr(Pos+18, " !W"); if(ExtPos && ExtPos[5]=='!') ExtPos+=3; else ExtPos=0;
|
||||||
Out[Len++]='B'; // B-record
|
Out[Len++]='B'; // B-record
|
||||||
memcpy(Out+Len, Msg+1, 6); Len+=6; // copy UTC time
|
memcpy(Out+Len, Msg+1, 6); Len+=6; // copy UTC time
|
||||||
memcpy(Out+Len, Pos, 4); Len+=4; // copy DDMM
|
memcpy(Out+Len, Pos, 4); Len+=4; // copy DDMM
|
||||||
|
|
Ładowanie…
Reference in New Issue