move functions around for gndate
parent
f1f0312b60
commit
b680654693
22
navcat.cc
22
navcat.cc
|
@ -26,28 +26,6 @@ using namespace std;
|
|||
|
||||
extern const char* g_gitHash;
|
||||
|
||||
time_t parseTime(std::string_view in)
|
||||
{
|
||||
time_t now=time(0);
|
||||
|
||||
vector<string> formats({"%Y-%m-%d %H:%M", "%Y%m%d %H%M", "%H:%M", "%H%M"});
|
||||
for(const auto& f : formats) {
|
||||
struct tm tm;
|
||||
memset(&tm, 0, sizeof(tm));
|
||||
|
||||
localtime_r(&now, &tm);
|
||||
tm.tm_isdst = -1;
|
||||
tm.tm_sec = 0;
|
||||
char* res = strptime(&in[0], f.c_str(), &tm);
|
||||
if(res && !*res) {
|
||||
cerr<<"Matched on "<<f<<endl;
|
||||
return mktime(&tm);
|
||||
}
|
||||
}
|
||||
|
||||
throw runtime_error("Can only parse %Y-%m-%d %H:%M");
|
||||
}
|
||||
|
||||
|
||||
vector<uint64_t> getSources(string_view dirname)
|
||||
{
|
||||
|
|
42
navmon.cc
42
navmon.cc
|
@ -9,7 +9,7 @@
|
|||
#include <signal.h>
|
||||
#include <sys/poll.h>
|
||||
#include <iostream>
|
||||
|
||||
#include <vector>
|
||||
using namespace std;
|
||||
|
||||
using Clock = std::chrono::steady_clock;
|
||||
|
@ -280,6 +280,20 @@ std::string makeSatPartialName(const SatID& satid)
|
|||
return fmt::sprintf("%c%02d", getGNSSChar(satid.gnss), satid.sv);
|
||||
}
|
||||
|
||||
void getGPSDateFromUTC(time_t t, int& wn, int& tow)
|
||||
{
|
||||
t -= 315964800;
|
||||
t += 18;
|
||||
wn = t/(7*86400);
|
||||
tow = t%(7*86400);
|
||||
}
|
||||
void getGalDateFromUTC(time_t t, int& wn, int& tow)
|
||||
{
|
||||
t -= 935280000;
|
||||
t += 18;
|
||||
wn = t/(7*86400);
|
||||
tow = t%(7*86400);
|
||||
}
|
||||
|
||||
int g_dtLS{18}, g_dtLSBeidou{4};
|
||||
uint64_t utcFromGST(int wn, int tow)
|
||||
|
@ -356,3 +370,29 @@ void unixDie(const std::string& reason)
|
|||
{
|
||||
throw std::runtime_error(reason+": "+strerror(errno));
|
||||
}
|
||||
|
||||
time_t parseTime(std::string_view in)
|
||||
{
|
||||
time_t now=time(0);
|
||||
|
||||
vector<string> formats({"%Y-%m-%d %H:%M", "%Y%m%d %H%M", "%H:%M", "%H%M"});
|
||||
for(const auto& f : formats) {
|
||||
struct tm tm;
|
||||
memset(&tm, 0, sizeof(tm));
|
||||
|
||||
localtime_r(&now, &tm);
|
||||
tm.tm_isdst = -1;
|
||||
tm.tm_sec = 0;
|
||||
char* res = strptime(&in[0], f.c_str(), &tm);
|
||||
if(res && !*res) {
|
||||
// cerr<<"Matched on "<<f<<endl;
|
||||
return mktime(&tm);
|
||||
}
|
||||
}
|
||||
|
||||
string err="Can only parse on";
|
||||
for(const auto& f : formats)
|
||||
err += " "+ f;
|
||||
throw runtime_error(err);
|
||||
}
|
||||
|
||||
|
|
|
@ -76,6 +76,11 @@ uint64_t utcFromGST(int wn, int tow);
|
|||
double utcFromGST(int wn, double tow);
|
||||
double utcFromGPS(int wn, double tow);
|
||||
|
||||
void getGPSDateFromUTC(time_t t, int& wn, int& tow);
|
||||
void getGalDateFromUTC(time_t t, int& wn, int& tow);
|
||||
|
||||
|
||||
std::string makeHexDump(const std::string& str);
|
||||
size_t writen2(int fd, const void *buf, size_t count);
|
||||
void unixDie(const std::string& reason);
|
||||
time_t parseTime(std::string_view in);
|
||||
|
|
Loading…
Reference in New Issue