From db6af0f2f4f826489a542d3f22153da788ffef09 Mon Sep 17 00:00:00 2001 From: Pawel Jalocha Date: Sun, 7 Aug 2022 05:01:03 +0100 Subject: [PATCH] Keep APRS messages within the IGC --- utils/aprs2igc.cc | 38 ++++++++++++++++++++++---------------- utils/ognconv.cpp | 2 +- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/utils/aprs2igc.cc b/utils/aprs2igc.cc index e6c1886..7ccbf26 100644 --- a/utils/aprs2igc.cc +++ b/utils/aprs2igc.cc @@ -12,9 +12,12 @@ 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; +const int MaxLineLen = 256; +const int MaxIGClen = 64; + static FILE *OutFile = 0; int main(int argc, char *argv[]) @@ -22,8 +25,8 @@ int main(int argc, char *argv[]) { printf("Usage: %s \n", argv[0]); return 0; } - const char *OwnAcft = argv[1]; int OwnAcftLen = strlen(OwnAcft); - char OutFileName[32]; strcpy(OutFileName, OwnAcft); strcat(OutFileName, ".IGC"); + const char *OwnAcft = argv[1]; int OwnAcftLen = strlen(OwnAcft); // target aircraft APRS name + char OutFileName[32]; strcpy(OutFileName, OwnAcft); strcat(OutFileName, ".IGC"); // create the IGC file name const char *InpFileName = argv[2]; 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; } } - std::vector OutLine; - char InpLine[256]; - // char OutLine[256]; + std::vector OutLine; // list of APRS lines for the selected aircraft + char InpLine[MaxLineLen]; + // char OutLine[MaxLineLen]; int InpLines=0; // int OutLines=0; - char *Out=0; + char *Out=0; // (new) IGC line allocated 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; *EOL = 0; InpLines++; - if(memcmp(InpLine, OwnAcft, OwnAcftLen)) continue; - if(Out==0) Out = (char *)malloc(60); - int OutLen=APRS2IGC(Out, InpLine, GeoidSepar); - if(OutLen>0) - { if(Verbose) printf("%s => %s [%d]\n", InpLine, Out, OutLen); - OutLine.push_back(Out); Out=0; } + if(memcmp(InpLine, OwnAcft, OwnAcftLen)) continue; // must start with the selected APRS name + if(Out==0) Out = (char *)malloc(MaxIGClen+MaxLineLen); // allocated (new) IGC line + int OutLen=APRS2IGC(Out, InpLine, GeoidSepar); // convert APRS to IGC B-record + if(OutLen>0) // if correct conversion + { // if(Verbose) printf("%s => %s [%d]\n", InpLine, Out, OutLen); + 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(InpFile!=stdin) fclose(InpFile); 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"); if(OutFile==0) { printf("Cannot open %s for write\n", OutFileName); return 0; } - for(size_t Idx=0; Idx