mirror of
https://github.com/gnss-sdr/gnss-sdr
synced 2024-12-14 20:20:35 +00:00
Merge branch 'time-zone' into next
Add new parameter show_local_time_zone to diplay time in the terminal in the local time zone instead of UTC. The difference with UTC is also displayed.
This commit is contained in:
commit
af85778b96
@ -714,6 +714,9 @@ Rtklib_Pvt::Rtklib_Pvt(ConfigurationInterface* configuration,
|
|||||||
pvt_output_parameters.udp_addresses = configuration->property(role + ".monitor_client_addresses", std::string("127.0.0.1"));
|
pvt_output_parameters.udp_addresses = configuration->property(role + ".monitor_client_addresses", std::string("127.0.0.1"));
|
||||||
pvt_output_parameters.udp_port = configuration->property(role + ".monitor_udp_port", 1234);
|
pvt_output_parameters.udp_port = configuration->property(role + ".monitor_udp_port", 1234);
|
||||||
|
|
||||||
|
// Show time in local zone
|
||||||
|
pvt_output_parameters.show_local_time_zone = configuration->property(role + ".show_local_time_zone", false);
|
||||||
|
|
||||||
// make PVT object
|
// make PVT object
|
||||||
pvt_ = rtklib_make_pvt_gs(in_streams_, pvt_output_parameters, rtk);
|
pvt_ = rtklib_make_pvt_gs(in_streams_, pvt_output_parameters, rtk);
|
||||||
DLOG(INFO) << "pvt(" << pvt_->unique_id() << ")";
|
DLOG(INFO) << "pvt(" << pvt_->unique_id() << ")";
|
||||||
|
@ -76,7 +76,10 @@
|
|||||||
#include <algorithm> // for sort, unique
|
#include <algorithm> // for sort, unique
|
||||||
#include <exception> // for exception
|
#include <exception> // for exception
|
||||||
#include <fstream> // for ofstream
|
#include <fstream> // for ofstream
|
||||||
|
#include <iomanip> // for put_time, setprecision
|
||||||
#include <iostream> // for operator<<
|
#include <iostream> // for operator<<
|
||||||
|
#include <locale> // for locale
|
||||||
|
#include <sstream> // for ostringstream
|
||||||
#include <stdexcept> // for length_error
|
#include <stdexcept> // for length_error
|
||||||
#include <sys/ipc.h> // for IPC_CREAT
|
#include <sys/ipc.h> // for IPC_CREAT
|
||||||
#include <sys/msg.h> // for msgctl
|
#include <sys/msg.h> // for msgctl
|
||||||
@ -361,6 +364,39 @@ rtklib_pvt_gs::rtklib_pvt_gs(uint32_t nchannels,
|
|||||||
throw std::exception();
|
throw std::exception();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Display time in local time zone
|
||||||
|
d_show_local_time_zone = conf_.show_local_time_zone;
|
||||||
|
time_t when = std::time(nullptr);
|
||||||
|
auto const tm = *std::localtime(&when);
|
||||||
|
std::ostringstream os;
|
||||||
|
os << std::put_time(&tm, "%z");
|
||||||
|
std::string utc_diff_str = os.str(); // in ISO 8601 format: "+HHMM" or "-HHMM"
|
||||||
|
if (utc_diff_str.empty())
|
||||||
|
{
|
||||||
|
utc_diff_str = "+0000";
|
||||||
|
}
|
||||||
|
int h = std::stoi(utc_diff_str.substr(0, 3), nullptr, 10);
|
||||||
|
int m = std::stoi(utc_diff_str[0] + utc_diff_str.substr(3), nullptr, 10);
|
||||||
|
d_utc_diff_time = boost::posix_time::hours(h) + boost::posix_time::minutes(m);
|
||||||
|
std::ostringstream os2;
|
||||||
|
os2 << std::put_time(&tm, "%Z");
|
||||||
|
std::string time_zone_abrv = os2.str();
|
||||||
|
if (time_zone_abrv.empty())
|
||||||
|
{
|
||||||
|
if (utc_diff_str == "+0000")
|
||||||
|
{
|
||||||
|
d_local_time_str = " UTC";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
d_local_time_str = " (UTC " + utc_diff_str.substr(0, 3) + ":" + utc_diff_str.substr(3, 2) + ")";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
d_local_time_str = std::string(" ") + time_zone_abrv + " (UTC " + utc_diff_str.substr(0, 3) + ":" + utc_diff_str.substr(3, 2) + ")";
|
||||||
|
}
|
||||||
|
|
||||||
d_pvt_solver = std::make_shared<Rtklib_Solver>(static_cast<int32_t>(nchannels), dump_ls_pvt_filename, d_dump, d_dump_mat, rtk);
|
d_pvt_solver = std::make_shared<Rtklib_Solver>(static_cast<int32_t>(nchannels), dump_ls_pvt_filename, d_dump, d_dump_mat, rtk);
|
||||||
d_pvt_solver->set_averaging_depth(1);
|
d_pvt_solver->set_averaging_depth(1);
|
||||||
start = std::chrono::system_clock::now();
|
start = std::chrono::system_clock::now();
|
||||||
@ -1464,8 +1500,16 @@ int rtklib_pvt_gs::work(int noutput_items, gr_vector_const_void_star& input_item
|
|||||||
|
|
||||||
if (first_fix == true)
|
if (first_fix == true)
|
||||||
{
|
{
|
||||||
std::cout << "First position fix at " << boost::posix_time::to_simple_string(d_pvt_solver->get_position_UTC_time())
|
if (d_show_local_time_zone)
|
||||||
<< " UTC is Lat = " << d_pvt_solver->get_latitude() << " [deg], Long = " << d_pvt_solver->get_longitude()
|
{
|
||||||
|
boost::posix_time::ptime time_first_solution = d_pvt_solver->get_position_UTC_time() + d_utc_diff_time;
|
||||||
|
std::cout << "First position fix at " << time_first_solution << d_local_time_str;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cout << "First position fix at " << d_pvt_solver->get_position_UTC_time() << " UTC";
|
||||||
|
}
|
||||||
|
std::cout << " is Lat = " << d_pvt_solver->get_latitude() << " [deg], Long = " << d_pvt_solver->get_longitude()
|
||||||
<< " [deg], Height= " << d_pvt_solver->get_height() << " [m]" << std::endl;
|
<< " [deg], Height= " << d_pvt_solver->get_height() << " [m]" << std::endl;
|
||||||
ttff_msgbuf ttff;
|
ttff_msgbuf ttff;
|
||||||
ttff.mtype = 1;
|
ttff.mtype = 1;
|
||||||
@ -3287,18 +3331,31 @@ int rtklib_pvt_gs::work(int noutput_items, gr_vector_const_void_star& input_item
|
|||||||
// DEBUG MESSAGE: Display position in console output
|
// DEBUG MESSAGE: Display position in console output
|
||||||
if (d_pvt_solver->is_valid_position() and flag_display_pvt)
|
if (d_pvt_solver->is_valid_position() and flag_display_pvt)
|
||||||
{
|
{
|
||||||
|
boost::posix_time::ptime time_solution;
|
||||||
|
std::string UTC_solution_str;
|
||||||
|
if (d_show_local_time_zone)
|
||||||
|
{
|
||||||
|
time_solution = d_pvt_solver->get_position_UTC_time() + d_utc_diff_time;
|
||||||
|
UTC_solution_str = d_local_time_str;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
time_solution = d_pvt_solver->get_position_UTC_time();
|
||||||
|
UTC_solution_str = " UTC";
|
||||||
|
}
|
||||||
std::streamsize ss = std::cout.precision(); // save current precision
|
std::streamsize ss = std::cout.precision(); // save current precision
|
||||||
std::cout.setf(std::ios::fixed, std::ios::floatfield);
|
std::cout.setf(std::ios::fixed, std::ios::floatfield);
|
||||||
auto facet = new boost::posix_time::time_facet("%Y-%b-%d %H:%M:%S.%f %z");
|
auto facet = new boost::posix_time::time_facet("%Y-%b-%d %H:%M:%S.%f %z");
|
||||||
std::cout.imbue(std::locale(std::cout.getloc(), facet));
|
std::cout.imbue(std::locale(std::cout.getloc(), facet));
|
||||||
|
std::cout
|
||||||
|
<< TEXT_BOLD_GREEN
|
||||||
|
<< "Position at " << time_solution << UTC_solution_str
|
||||||
|
<< " using " << d_pvt_solver->get_num_valid_observations()
|
||||||
|
<< std::fixed << std::setprecision(9)
|
||||||
|
<< " observations is Lat = " << d_pvt_solver->get_latitude() << " [deg], Long = " << d_pvt_solver->get_longitude()
|
||||||
|
<< std::fixed << std::setprecision(3)
|
||||||
|
<< " [deg], Height = " << d_pvt_solver->get_height() << " [m]" << TEXT_RESET << std::endl;
|
||||||
|
|
||||||
std::cout << TEXT_BOLD_GREEN
|
|
||||||
<< "Position at " << d_pvt_solver->get_position_UTC_time()
|
|
||||||
<< " UTC using " << d_pvt_solver->get_num_valid_observations()
|
|
||||||
<< std::fixed << std::setprecision(9)
|
|
||||||
<< " observations is Lat = " << d_pvt_solver->get_latitude() << " [deg], Long = " << d_pvt_solver->get_longitude()
|
|
||||||
<< std::fixed << std::setprecision(3)
|
|
||||||
<< " [deg], Height = " << d_pvt_solver->get_height() << " [m]" << TEXT_RESET << std::endl;
|
|
||||||
std::cout << std::setprecision(ss);
|
std::cout << std::setprecision(ss);
|
||||||
DLOG(INFO) << "RX clock offset: " << d_pvt_solver->get_time_offset_s() << "[s]";
|
DLOG(INFO) << "RX clock offset: " << d_pvt_solver->get_time_offset_s() << "[s]";
|
||||||
|
|
||||||
|
@ -162,6 +162,10 @@ private:
|
|||||||
std::unique_ptr<Monitor_Pvt_Udp_Sink> udp_sink_ptr;
|
std::unique_ptr<Monitor_Pvt_Udp_Sink> udp_sink_ptr;
|
||||||
std::vector<std::string> split_string(const std::string& s, char delim) const;
|
std::vector<std::string> split_string(const std::string& s, char delim) const;
|
||||||
|
|
||||||
|
bool d_show_local_time_zone;
|
||||||
|
std::string d_local_time_str;
|
||||||
|
boost::posix_time::time_duration d_utc_diff_time;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
~rtklib_pvt_gs(); //!< Default destructor
|
~rtklib_pvt_gs(); //!< Default destructor
|
||||||
|
|
||||||
|
@ -70,4 +70,6 @@ Pvt_Conf::Pvt_Conf()
|
|||||||
|
|
||||||
monitor_enabled = false;
|
monitor_enabled = false;
|
||||||
udp_port = 0;
|
udp_port = 0;
|
||||||
|
|
||||||
|
show_local_time_zone = false;
|
||||||
}
|
}
|
||||||
|
@ -83,6 +83,8 @@ public:
|
|||||||
std::string udp_addresses;
|
std::string udp_addresses;
|
||||||
int udp_port;
|
int udp_port;
|
||||||
|
|
||||||
|
bool show_local_time_zone;
|
||||||
|
|
||||||
Pvt_Conf();
|
Pvt_Conf();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user