diff --git a/utils/makefile b/utils/makefile index 28dfe44..b49757d 100644 --- a/utils/makefile +++ b/utils/makefile @@ -4,6 +4,9 @@ read_log: read_log.cc aprs2igc: aprs2igc.cc g++ -Wall -Wno-misleading-indentation -O2 -o aprs2igc aprs2igc.cc format.cpp -clean: - rm read_log aprs2igc +serial_dump: serial_dump.cc + g++ -Wall -Wno-misleading-indentation -O2 -o serial_dump serial_dump.cc format.cpp + +clean: + rm read_log aprs2igc serial_dump diff --git a/utils/serial_dump.cc b/utils/serial_dump.cc new file mode 100644 index 0000000..a15b470 --- /dev/null +++ b/utils/serial_dump.cc @@ -0,0 +1,53 @@ +#include +#include +#include +#include +#include +#include +#include + +#include "serial.h" +#include "ogn.h" + +static double getTime(void) // read the system time at this very moment +{ struct timespec now; clock_gettime(CLOCK_REALTIME, &now); return now.tv_sec + 1e-9*now.tv_nsec; } + +SerialPort Port; + +int main(int argc, char *argv[]) +{ const int MaxLineLen = 256; + char Line[MaxLineLen]; + int LineIdx; + + const char *PortName = "/dev/ttyUSB0"; // default serial port name + int BaudRate = 115200; // default baud rate on the serial port + + if(argc>=2) + { char *Colon = strchr(argv[1],':'); + if(Colon) { Colon[0]=0; BaudRate=atoi(Colon+1); } + PortName = argv[1]; } + + if(Port.Open(PortName, BaudRate)<0) { printf("Can't open %s at %dbps\n", PortName, BaudRate); return -1; } + + uint8_t Index[20]; + LineIdx=0; // line byte index/counter + double Start=getTime(); // line start time + for( ; ; ) + { char Byte; + if(Port.Read(Byte)<=0) { usleep(1000); continue; } // if no new bytes on the serial port sleep a little + if(LineIdx==0) Start=getTime(); // if this is the first byte on the line: note the time + if(Byte<' ') // if a control (non-printable) character + { if(LineIdx==0) { printf("<%02X>", Byte); continue; } // if this is the first byte on the line + printf("\n"); + Line[LineIdx]=0; // if more bytes on this line: add NL at the end of the line + int8_t Err=GPS_Position::IndexNMEA(Index, Line); + uint32_t Time=(uint32_t)floor(Start); + double Frac=Start-Time; + printf("%06.3f [%3d] [%2d] %s<%02X>", (Time%60)+Frac, LineIdx, Err, Line, Byte); // print the time, line length and the line itself + LineIdx=0; // reset line byte index/counter + continue; } + if(LineIdx