From e9167525ec232ced638aa474957bb99b21311d86 Mon Sep 17 00:00:00 2001 From: Pawel Jalocha Date: Fri, 16 Oct 2020 00:16:57 +0100 Subject: [PATCH] Sort positions in time, as the APRS data can be mixed in time --- utils/aprs2igc.cc | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/utils/aprs2igc.cc b/utils/aprs2igc.cc index 03230b6..3675d58 100644 --- a/utils/aprs2igc.cc +++ b/utils/aprs2igc.cc @@ -4,6 +4,9 @@ #include #include +#include +#include + #include "format.h" static int APRS2IGC(char *Out, const char *Inp, int GeoidSepar) // convert APRS positon message into IGC B-record @@ -40,6 +43,8 @@ static int APRS2IGC(char *Out, const char *Inp, int GeoidSepar) // convert Len+=5; Out[Len]=0; return Len; } + static bool Earlier(const char *Line1, const char *Line2) { return strcmp(Line1, Line2)<0; } + static int Verbose = 1; static int GeoidSepar = 40; @@ -52,32 +57,39 @@ int main(int argc, char *argv[]) const char *OwnAcft = argv[1]; int OwnAcftLen = strlen(OwnAcft); char OutFileName[32]; strcpy(OutFileName, OwnAcft); strcat(OutFileName, ".IGC"); - OutFile=fopen(OutFileName, "wt"); - if(OutFile==0) { printf("Cannot open %s for write\n", OutFileName); return 0; } const char *InpFileName = argv[2]; - FILE *InpFile=fopen(InpFileName, "rt"); if(InpFile==0) { printf("Cannot open %s for read\n", InpFileName); return 0; } + std::vector OutLine; char InpLine[256]; - char OutLine[256]; + // char OutLine[256]; int InpLines=0; - int OutLines=0; + // int OutLines=0; + char *Out=0; for( ; ; ) { if(fgets(InpLine, 256, InpFile)==0) break; char *EOL = strchr(InpLine, '\n'); if(EOL==0) break; *EOL = 0; InpLines++; if(memcmp(InpLine, OwnAcft, OwnAcftLen)) continue; - int OutLen=APRS2IGC(OutLine, InpLine, GeoidSepar); + if(Out==0) Out = (char *)malloc(60); + int OutLen=APRS2IGC(Out, InpLine, GeoidSepar); if(OutLen>0) - { if(Verbose) printf("%s => %s [%d]\n", InpLine, OutLine, OutLen); - fprintf(OutFile, "%s\n", OutLine); OutLines++; } + { if(Verbose) printf("%s => %s [%d]\n", InpLine, Out, OutLen); + OutLine.push_back(Out); Out=0; } } + if(Out) { free(Out); Out=0; } fclose(InpFile); printf("%d lines from %s\n", InpLines, InpFileName); + + std::sort(OutLine.begin(), OutLine.end(), Earlier); + OutFile=fopen(OutFileName, "wt"); + if(OutFile==0) { printf("Cannot open %s for write\n", OutFileName); return 0; } + for(int Idx=0; Idx