diff --git a/Makefile b/Makefile index 884c31f..a008e1b 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,7 @@ endif CHEAT_ARG := $(shell ./update-git-hash-if-necessary) PROGRAMS = navparse ubxtool navnexus navcat navrecv navdump testrunner navdisplay tlecatch reporter sp3feed \ - galmonmon rinreport rtcmtool + galmonmon rinreport rtcmtool gndate all: navmon.pb.cc $(PROGRAMS) @@ -127,5 +127,9 @@ ubxtool: navmon.pb.o ubxtool.o ubx.o bits.o ext/fmt-6.1.2/src/format.o galileo.o testrunner: navmon.pb.o testrunner.o ubx.o bits.o ext/fmt-6.1.2/src/format.o galileo.o gps.o beidou.o ephemeris.o sp3.o osen.o navmon.o rinex.o githash.o $(CXX) -std=gnu++17 $^ -o $@ -L/usr/local/lib -lprotobuf -lz +gndate: gndate.o githash.o ext/fmt-6.1.2/src/format.o navmon.o + $(CXX) -std=gnu++17 $^ -o $@ -L/usr/local/lib + + check: testrunner ./testrunner diff --git a/gndate.cc b/gndate.cc new file mode 100644 index 0000000..d027981 --- /dev/null +++ b/gndate.cc @@ -0,0 +1,57 @@ +#include "navmon.hh" +#include +#include "CLI/CLI.hpp" +#include "version.hh" + +extern const char* g_gitHash; +using namespace std; + +int main(int argc, char** argv) +{ + string program("gndate"); + CLI::App app(program); + string date; + bool doGPSWN{false}, doGALWN{false}, doVERSION{false}, doUTC{false}; + app.add_flag("--version", doVERSION, "show program version and copyright"); + app.add_option("--date,-d", date, "yyyy-mm-dd hh:mm"); + app.add_flag("--utc,-u", doUTC, "Interpret --date,-d as UTC"); + app.add_flag("--gps-wn", doGPSWN, "Print GPS week number"); + app.add_flag("--gal-wn", doGALWN, "Print GPS week number"); + try { + app.parse(argc, argv); + } catch(const CLI::Error &e) { + return app.exit(e); + } + + if(doVERSION) { + showVersion(program.c_str(), g_gitHash); + exit(0); + } + + + time_t now; + if(date.empty()) + now = time(0); + else { + if(doUTC) + setenv("TZ", "UTC", 1); + now = parseTime(date); + } + + int wn, tow; + + if(doGPSWN) { + getGPSDateFromUTC(now, wn, tow); + cout<