#include #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; } static const char *PortName = "/dev/ttyUSB0"; // default serial port name static int BaudRate = 115200; // default baud rate on the serial port static int ListOnly = 0; static uint32_t SelectFile = 0; static int Help = 0; static SerialPort Port; const int MaxLineLen = 512; static char Line[MaxLineLen]; static std::vector LogFileList; // list of log file start times static int List(void) { sleep(1); Port.Write(12); // send Ctrl-L to list the log files uint8_t Index[32]; int LineIdx=0; double Start=getTime(); // sart counting the time for( ; ; ) { char Byte; if(Port.Read(Byte)<=0) // get a byte from the serial port { double Now=getTime(); // if non, then check time if((Now-Start)>=5.0) break; // if idle for more than 4 sec then stop recording the log files usleep(1000); continue; } // if no new bytes on the serial port sleep a little // printf("%3d: %02X %c\n", LineIdx, Byte, Byte<=' '?' ':Byte); if(Byte<' ') // if a control (non-printable) character { Line[LineIdx]=0; // terminate the line and process it if(LineIdx<7) { LineIdx=0; continue; } // printf("%s\n", Line); if(memcmp(Line, "$POGNL,", 7)!=0) { LineIdx=0; continue; } // only take POGNL sentences int8_t Err=GPS_Position::IndexNMEA(Index, Line); // index the parameters if(Err<2) { LineIdx=0; continue; } // if less than two parameters, then skip this message if((Index[1]-Index[0])!=13) { LineIdx=0; continue; } // filename must be 13 characters long uint32_t UnixTime=0; if(Read_Hex(UnixTime, Line+Index[0])!=8) { LineIdx=0; continue; } // get the starting time: 8 hex characters time_t Time = UnixTime; struct tm *TM = gmtime(&Time); printf("%s (%d,%d) %02d:%02d:%02d %02d.%02d.%04d\n", Line, Err, Index[1]-Index[0], TM->tm_hour, TM->tm_min, TM->tm_sec, TM->tm_mday, TM->tm_mon+1, TM->tm_year+1900); Start=getTime(); // set new start time counter LogFileList.push_back(Time); LineIdx=0; continue; } if(LineIdx=4.0) break; usleep(1000); continue; } // if no new bytes on the serial port sleep a little if(Byte<' ') // if a control (non-printable) character { Line[LineIdx]=0; if(Line[0]=='$') { LineIdx=0; continue; } if(LineIdx<12) { LineIdx=0; continue; } printf("%s\n", Line); Start=getTime(); Records++; LineIdx=0; continue; } if(LineIdx\n\ Options: -h this help\n\ -l only list the log files stored in the OGN-Tracker\n\ -f download the selected file: use the UTC time\n\ ", argv[0]); return 0; } if(arg