2019-08-30 17:08:56 -06:00
|
|
|
#pragma once
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <unistd.h>
|
2019-09-09 12:49:31 -06:00
|
|
|
#include <time.h>
|
|
|
|
#include <string>
|
2019-10-01 07:03:30 -06:00
|
|
|
#include <tuple>
|
2019-10-12 06:57:44 -06:00
|
|
|
#include <mutex>
|
2019-09-09 12:49:31 -06:00
|
|
|
|
2020-02-11 08:54:41 -07:00
|
|
|
extern const char* g_gitHash;
|
|
|
|
|
|
|
|
|
2019-08-30 17:08:56 -06:00
|
|
|
struct EofException{};
|
2019-11-22 06:32:25 -07:00
|
|
|
struct TimeoutError{};
|
|
|
|
|
2019-08-30 17:08:56 -06:00
|
|
|
size_t readn2(int fd, void* buffer, size_t len);
|
2019-11-22 06:32:25 -07:00
|
|
|
size_t readn2Timeout(int fd, void* buffer, size_t len, double* timeout);
|
2019-10-15 06:51:39 -06:00
|
|
|
std::string humanTimeNow();
|
2019-09-09 12:49:31 -06:00
|
|
|
std::string humanTime(time_t t);
|
2020-02-04 13:25:20 -07:00
|
|
|
std::string humanTimeShort(time_t t);
|
2019-10-01 07:03:30 -06:00
|
|
|
std::string humanTime(time_t t, uint32_t nanoseconds);
|
|
|
|
struct SatID
|
|
|
|
{
|
|
|
|
uint32_t gnss{255}; // these could all be 'int16_t' but leads to howling numbers of warnings with protobuf
|
|
|
|
uint32_t sv{0};
|
|
|
|
uint32_t sigid{0};
|
|
|
|
bool operator<(const SatID& rhs) const
|
|
|
|
{
|
|
|
|
return std::tie(gnss, sv, sigid) < std::tie(rhs.gnss, rhs.sv, rhs.sigid);
|
|
|
|
}
|
|
|
|
};
|
2019-10-12 06:57:44 -06:00
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
class GetterSetter
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
void set(const T& t)
|
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> mut(d_lock);
|
|
|
|
d_t = t;
|
|
|
|
}
|
|
|
|
|
|
|
|
T get()
|
|
|
|
{
|
|
|
|
T ret;
|
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> mut(d_lock);
|
|
|
|
ret = d_t;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
T d_t;
|
|
|
|
std::mutex d_lock;
|
|
|
|
};
|
|
|
|
|
2020-01-18 08:48:22 -07:00
|
|
|
|
|
|
|
double truncPrec(double in, unsigned int digits);
|
2020-01-26 07:22:42 -07:00
|
|
|
std::string humanFt(uint8_t ft);
|
|
|
|
std::string humanSisa(uint8_t sisa);
|
|
|
|
std::string humanUra(uint8_t ura);
|
|
|
|
|
|
|
|
double numFt(uint8_t ft);
|
|
|
|
double numSisa(uint8_t sisa);
|
|
|
|
double numUra(uint8_t ura);
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-02-04 13:25:20 -07:00
|
|
|
char getGNSSChar(int id);
|
|
|
|
std::string makeSatIDName(const SatID& satid);
|
|
|
|
std::string makeSatPartialName(const SatID& satid);
|
|
|
|
|
2020-02-11 08:33:27 -07:00
|
|
|
std::string sbasName(int prn);
|
|
|
|
|
2020-02-04 13:25:20 -07:00
|
|
|
extern int g_dtLS, g_dtLSBeidou;
|
|
|
|
uint64_t utcFromGST(int wn, int tow);
|
|
|
|
double utcFromGST(int wn, double tow);
|
|
|
|
double utcFromGPS(int wn, double tow);
|
2020-02-05 05:54:26 -07:00
|
|
|
|
2020-07-16 06:13:57 -06:00
|
|
|
void getGPSDateFromUTC(time_t t, int& wn, int& tow);
|
|
|
|
void getGalDateFromUTC(time_t t, int& wn, int& tow);
|
|
|
|
|
|
|
|
|
2020-02-05 05:54:26 -07:00
|
|
|
std::string makeHexDump(const std::string& str);
|
2020-07-29 03:31:55 -06:00
|
|
|
std::string makeHexDump(const std::basic_string<uint8_t>& str);
|
2020-02-29 06:28:36 -07:00
|
|
|
size_t writen2(int fd, const void *buf, size_t count);
|
2020-04-26 04:24:45 -06:00
|
|
|
void unixDie(const std::string& reason);
|
2020-07-16 06:13:57 -06:00
|
|
|
time_t parseTime(std::string_view in);
|