2020-07-16 06:05:39 -06:00
|
|
|
#include "navmon.hh"
|
|
|
|
#include <iostream>
|
|
|
|
#include "CLI/CLI.hpp"
|
|
|
|
#include "version.hh"
|
|
|
|
|
|
|
|
extern const char* g_gitHash;
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
int main(int argc, char** argv)
|
2020-09-27 08:04:57 -06:00
|
|
|
try
|
2020-07-16 06:05:39 -06:00
|
|
|
{
|
|
|
|
string program("gndate");
|
|
|
|
CLI::App app(program);
|
|
|
|
string date;
|
2020-09-27 08:04:57 -06:00
|
|
|
int galwn{-1};
|
|
|
|
bool doProgOutput{false};
|
2020-07-16 06:05:39 -06:00
|
|
|
bool doGPSWN{false}, doGALWN{false}, doVERSION{false}, doUTC{false};
|
|
|
|
app.add_flag("--version", doVERSION, "show program version and copyright");
|
2020-09-27 08:04:57 -06:00
|
|
|
app.add_option("--date,-d", date, "yyyy-mm-dd hh:mm[:ss] hh:mm yyyymmdd hhmm");
|
|
|
|
app.add_option("--date-gal-wn", galwn, "Give data for this Galileo week number");
|
2020-07-16 06:05:39 -06:00
|
|
|
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");
|
2020-09-27 08:04:57 -06:00
|
|
|
app.add_flag("--prog-output", doProgOutput, "Modulate some date formats for use as parameters to programs");
|
2020-07-16 06:05:39 -06:00
|
|
|
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;
|
|
|
|
|
2020-09-27 08:04:57 -06:00
|
|
|
if(galwn >= 0) {
|
|
|
|
time_t week=utcFromGST(galwn, 0);
|
|
|
|
if(doProgOutput)
|
|
|
|
cout<<influxTime(week) << endl;
|
|
|
|
else
|
|
|
|
cout<<humanTime(week)<< " - " << humanTime(week+7*86400) << endl;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-07-16 06:05:39 -06:00
|
|
|
if(doGPSWN) {
|
|
|
|
getGPSDateFromUTC(now, wn, tow);
|
|
|
|
cout<<wn<<endl;
|
|
|
|
}
|
|
|
|
else if(doGALWN) {
|
|
|
|
getGalDateFromUTC(now, wn, tow);
|
|
|
|
cout<<wn<<endl;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
getGPSDateFromUTC(now, wn, tow);
|
|
|
|
cout<<"GPS Week Number (non-wrapped): "<< wn << ", tow " << tow << endl;
|
|
|
|
getGalDateFromUTC(now, wn, tow);
|
|
|
|
cout<<"Galileo Week Number: "<< wn << ", tow " << tow << endl;
|
|
|
|
}
|
|
|
|
}
|
2020-09-27 08:04:57 -06:00
|
|
|
catch(exception& e) {
|
|
|
|
cerr<<"Error: "<<e.what()<<endl;
|
|
|
|
}
|