kopia lustrzana https://github.com/pjalocha/esp32-ogn-tracker
Spearate APRS2IGC so it can be used elsewhere
rodzic
09870a8f95
commit
bf5f77a000
|
@ -8,42 +8,9 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#include "format.h"
|
#include "format.h"
|
||||||
|
#include "ognconv.h"
|
||||||
|
|
||||||
static int APRS2IGC(char *Out, const char *Inp, int GeoidSepar) // convert APRS positon message into IGC B-record
|
static bool Earlier(const char *Line1, const char *Line2) { return strcmp(Line1, Line2)<0; }
|
||||||
{ int Len=0;
|
|
||||||
const char *Msg = strchr(Inp, ':'); if(Msg==0) return 0; // colon: separates header and message
|
|
||||||
Msg++; // where message starts
|
|
||||||
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 *ExtPos = strstr(Pos+18, " !W"); if(ExtPos[5]=='!') ExtPos+=3; else ExtPos=0;
|
|
||||||
Out[Len++]='B'; // B-record
|
|
||||||
memcpy(Out+Len, Msg+1, 6); Len+=6; // copy UTC time
|
|
||||||
memcpy(Out+Len, Pos, 4); Len+=4; // copy DDMM
|
|
||||||
memcpy(Out+Len, Pos+5, 2); Len+=2; // copy fractional MM
|
|
||||||
Out[Len++] = ExtPos?ExtPos[0]:'0'; // extended precision
|
|
||||||
Out[Len++] = Pos[7]; // copy N/S sign
|
|
||||||
memcpy(Out+Len, Pos+9, 5); Len+=5; // copy DDMM
|
|
||||||
memcpy(Out+Len, Pos+15,2); Len+=2; // copy fractional MM
|
|
||||||
Out[Len++] = ExtPos?ExtPos[1]:'0'; // extended precision
|
|
||||||
Out[Len++] = Pos[17]; // copy E/W sign
|
|
||||||
Out[Len++] = 'A';
|
|
||||||
memcpy(Out+Len, " ", 10);
|
|
||||||
const char *FL = strstr(Pos+18, " FL");
|
|
||||||
if(FL) // pressure altitude
|
|
||||||
{ float PressAlt=atof(FL+3); PressAlt*=30.4; int32_t Alt=floor(PressAlt+0.5);
|
|
||||||
if(Alt<0) { Alt = (-Alt); Out[Len] = '-'; Format_UnsDec(Out+Len+1, (uint32_t)Alt, 4); }
|
|
||||||
else { Format_UnsDec(Out+Len, (uint32_t)Alt, 5); }
|
|
||||||
}
|
|
||||||
Len+=5;
|
|
||||||
if(Pos[27]=='A' && Pos[28]=='=') // geometrical altitude
|
|
||||||
{ int32_t Alt=atol(Pos+29); Alt=(Alt*3+5)/10; Alt+=GeoidSepar; // convert to meters and add GeoidSepar for HAE
|
|
||||||
if(Alt<0) { Alt = (-Alt); Out[Len] = '-'; Format_UnsDec(Out+Len+1, (uint32_t)Alt, 4); }
|
|
||||||
else { Format_UnsDec(Out+Len, (uint32_t)Alt, 5); }
|
|
||||||
}
|
|
||||||
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 Verbose = 1;
|
||||||
static int GeoidSepar = 40;
|
static int GeoidSepar = 40;
|
||||||
|
@ -91,9 +58,9 @@ int main(int argc, char *argv[])
|
||||||
std::sort(OutLine.begin(), OutLine.end(), Earlier);
|
std::sort(OutLine.begin(), OutLine.end(), Earlier);
|
||||||
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(int Idx=0; Idx<OutLine.size(); Idx++)
|
for(size_t Idx=0; Idx<OutLine.size(); Idx++)
|
||||||
{ fprintf(OutFile, "%s\n", OutLine[Idx]); }
|
{ fprintf(OutFile, "%s\n", OutLine[Idx]); }
|
||||||
fclose(OutFile);
|
fclose(OutFile);
|
||||||
printf("%d lines to %s\n", OutLine.size(), OutFileName);
|
printf("%lu lines to %s\n", OutLine.size(), OutFileName);
|
||||||
|
|
||||||
return 0; }
|
return 0; }
|
||||||
|
|
|
@ -2,7 +2,7 @@ read_log: read_log.cc
|
||||||
g++ -Wall -Wno-misleading-indentation -O2 -o read_log read_log.cc format.cpp
|
g++ -Wall -Wno-misleading-indentation -O2 -o read_log read_log.cc format.cpp
|
||||||
|
|
||||||
aprs2igc: aprs2igc.cc
|
aprs2igc: aprs2igc.cc
|
||||||
g++ -Wall -Wno-misleading-indentation -O2 -o aprs2igc aprs2igc.cc format.cpp
|
g++ -Wall -Wno-misleading-indentation -O2 -o aprs2igc aprs2igc.cc format.cpp ognconv.cpp
|
||||||
|
|
||||||
aprs2igc.exe: aprs2igc.cc
|
aprs2igc.exe: aprs2igc.cc
|
||||||
x86_64-w64-mingw32-g++ -Wall -Wno-misleading-indentation -O2 -static -o aprs2igc.exe aprs2igc.cc format.cpp
|
x86_64-w64-mingw32-g++ -Wall -Wno-misleading-indentation -O2 -static -o aprs2igc.exe aprs2igc.cc format.cpp
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
#include "format.h"
|
||||||
#include "ognconv.h"
|
#include "ognconv.h"
|
||||||
|
|
||||||
// ==============================================================================================
|
// ==============================================================================================
|
||||||
|
@ -269,3 +273,38 @@ uint8_t DecodeAscii85(uint32_t &Word, const char *Ascii)
|
||||||
|
|
||||||
// ==============================================================================================
|
// ==============================================================================================
|
||||||
|
|
||||||
|
int APRS2IGC(char *Out, const char *Inp, int GeoidSepar) // convert APRS positon message into IGC B-record
|
||||||
|
{ int Len=0;
|
||||||
|
const char *Msg = strchr(Inp, ':'); if(Msg==0) return 0; // colon: separates header and message
|
||||||
|
Msg++; // where message starts
|
||||||
|
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 *ExtPos = strstr(Pos+18, " !W"); if(ExtPos[5]=='!') ExtPos+=3; else ExtPos=0;
|
||||||
|
Out[Len++]='B'; // B-record
|
||||||
|
memcpy(Out+Len, Msg+1, 6); Len+=6; // copy UTC time
|
||||||
|
memcpy(Out+Len, Pos, 4); Len+=4; // copy DDMM
|
||||||
|
memcpy(Out+Len, Pos+5, 2); Len+=2; // copy fractional MM
|
||||||
|
Out[Len++] = ExtPos?ExtPos[0]:'0'; // extended precision
|
||||||
|
Out[Len++] = Pos[7]; // copy N/S sign
|
||||||
|
memcpy(Out+Len, Pos+9, 5); Len+=5; // copy DDMM
|
||||||
|
memcpy(Out+Len, Pos+15,2); Len+=2; // copy fractional MM
|
||||||
|
Out[Len++] = ExtPos?ExtPos[1]:'0'; // extended precision
|
||||||
|
Out[Len++] = Pos[17]; // copy E/W sign
|
||||||
|
Out[Len++] = 'A';
|
||||||
|
memcpy(Out+Len, " ", 10);
|
||||||
|
const char *FL = strstr(Pos+18, " FL");
|
||||||
|
if(FL) // pressure altitude
|
||||||
|
{ float PressAlt=atof(FL+3); PressAlt*=30.4; int32_t Alt=floor(PressAlt+0.5);
|
||||||
|
if(Alt<0) { Alt = (-Alt); Out[Len] = '-'; Format_UnsDec(Out+Len+1, (uint32_t)Alt, 4); }
|
||||||
|
else { Format_UnsDec(Out+Len, (uint32_t)Alt, 5); }
|
||||||
|
}
|
||||||
|
Len+=5;
|
||||||
|
if(Pos[27]=='A' && Pos[28]=='=') // geometrical altitude
|
||||||
|
{ int32_t Alt=atol(Pos+29); Alt=(Alt*3+5)/10; Alt+=GeoidSepar; // convert to meters and add GeoidSepar for HAE
|
||||||
|
if(Alt<0) { Alt = (-Alt); Out[Len] = '-'; Format_UnsDec(Out+Len+1, (uint32_t)Alt, 4); }
|
||||||
|
else { Format_UnsDec(Out+Len, (uint32_t)Alt, 5); }
|
||||||
|
}
|
||||||
|
Len+=5;
|
||||||
|
Out[Len]=0; return Len; }
|
||||||
|
|
||||||
|
// ==============================================================================================
|
||||||
|
|
|
@ -82,4 +82,6 @@ void xorshift64(uint64_t &Seed);
|
||||||
uint8_t EncodeAscii85( char *Ascii, uint32_t Word ); // Encode 32-bit Word into 5-char Ascii-85 string
|
uint8_t EncodeAscii85( char *Ascii, uint32_t Word ); // Encode 32-bit Word into 5-char Ascii-85 string
|
||||||
uint8_t DecodeAscii85(uint32_t &Word, const char *Ascii); // Decode 5-char Ascii-85 to 32-bit Word
|
uint8_t DecodeAscii85(uint32_t &Word, const char *Ascii); // Decode 5-char Ascii-85 to 32-bit Word
|
||||||
|
|
||||||
|
int APRS2IGC(char *Out, const char *Inp, int GeoidSepar); // convert APRS message to IGC B-record
|
||||||
|
|
||||||
#endif // __OGNCONV_H__
|
#endif // __OGNCONV_H__
|
||||||
|
|
Ładowanie…
Reference in New Issue