diff --git a/src/algorithms/PVT/adapters/rtklib_pvt.cc b/src/algorithms/PVT/adapters/rtklib_pvt.cc index 7a6ae02ce..ca19c2006 100644 --- a/src/algorithms/PVT/adapters/rtklib_pvt.cc +++ b/src/algorithms/PVT/adapters/rtklib_pvt.cc @@ -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_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 pvt_ = rtklib_make_pvt_gs(in_streams_, pvt_output_parameters, rtk); DLOG(INFO) << "pvt(" << pvt_->unique_id() << ")"; diff --git a/src/algorithms/PVT/gnuradio_blocks/rtklib_pvt_gs.cc b/src/algorithms/PVT/gnuradio_blocks/rtklib_pvt_gs.cc index da71df27f..b60f863c8 100644 --- a/src/algorithms/PVT/gnuradio_blocks/rtklib_pvt_gs.cc +++ b/src/algorithms/PVT/gnuradio_blocks/rtklib_pvt_gs.cc @@ -76,7 +76,10 @@ #include // for sort, unique #include // for exception #include // for ofstream +#include // for put_time, setprecision #include // for operator<< +#include // for locale +#include // for ostringstream #include // for length_error #include // for IPC_CREAT #include // for msgctl @@ -364,6 +367,18 @@ rtklib_pvt_gs::rtklib_pvt_gs(uint32_t nchannels, d_pvt_solver = std::make_shared(static_cast(nchannels), dump_ls_pvt_filename, d_dump, d_dump_mat, rtk); d_pvt_solver->set_averaging_depth(1); start = std::chrono::system_clock::now(); + + // Display time in local time zone + time_t when = std::time(nullptr); + auto const tm = *std::localtime(&when); + std::ostringstream os; + os << std::put_time(&tm, "%z"); + d_utc_diff = os.str(); + // d_utc_diff is in ISO 8601 format: "+HHMM" or "-HHMM" + int h = std::stoi(d_utc_diff.substr(0, 3), nullptr, 10); + int m = std::stoi(d_utc_diff[0] + d_utc_diff.substr(3), nullptr, 10); + d_utc_diff_time = boost::posix_time::hours(h) + boost::posix_time::minutes(m); + d_show_local_time_zone = conf_.show_local_time_zone; } @@ -1464,8 +1479,16 @@ int rtklib_pvt_gs::work(int noutput_items, gr_vector_const_void_star& input_item if (first_fix == true) { - std::cout << "First position fix at " << boost::posix_time::to_simple_string(d_pvt_solver->get_position_UTC_time()) - << " UTC is Lat = " << d_pvt_solver->get_latitude() << " [deg], Long = " << d_pvt_solver->get_longitude() + if (d_show_local_time_zone) + { + 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 << " (UTC " + d_utc_diff.substr(0, 3) + ":" + d_utc_diff.substr(3, 2) + ")"; + } + 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; ttff_msgbuf ttff; ttff.mtype = 1; @@ -3287,18 +3310,31 @@ int rtklib_pvt_gs::work(int noutput_items, gr_vector_const_void_star& input_item // DEBUG MESSAGE: Display position in console output 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 = " (UTC " + d_utc_diff.substr(0, 3) + ":" + d_utc_diff.substr(3, 2) + ")"; + } + else + { + time_solution = d_pvt_solver->get_position_UTC_time(); + UTC_solution_str = " UTC"; + } std::streamsize ss = std::cout.precision(); // save current precision 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"); 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); DLOG(INFO) << "RX clock offset: " << d_pvt_solver->get_time_offset_s() << "[s]"; diff --git a/src/algorithms/PVT/gnuradio_blocks/rtklib_pvt_gs.h b/src/algorithms/PVT/gnuradio_blocks/rtklib_pvt_gs.h index 4e3df2672..e892f7ee3 100644 --- a/src/algorithms/PVT/gnuradio_blocks/rtklib_pvt_gs.h +++ b/src/algorithms/PVT/gnuradio_blocks/rtklib_pvt_gs.h @@ -162,6 +162,10 @@ private: std::unique_ptr udp_sink_ptr; std::vector split_string(const std::string& s, char delim) const; + bool d_show_local_time_zone; + std::string d_utc_diff; + boost::posix_time::time_duration d_utc_diff_time; + public: ~rtklib_pvt_gs(); //!< Default destructor diff --git a/src/algorithms/PVT/libs/pvt_conf.cc b/src/algorithms/PVT/libs/pvt_conf.cc index 6a1e1023c..bd74b4900 100644 --- a/src/algorithms/PVT/libs/pvt_conf.cc +++ b/src/algorithms/PVT/libs/pvt_conf.cc @@ -70,4 +70,6 @@ Pvt_Conf::Pvt_Conf() monitor_enabled = false; udp_port = 0; + + show_local_time_zone = false; } diff --git a/src/algorithms/PVT/libs/pvt_conf.h b/src/algorithms/PVT/libs/pvt_conf.h index 484961cb2..f22eb8fe2 100644 --- a/src/algorithms/PVT/libs/pvt_conf.h +++ b/src/algorithms/PVT/libs/pvt_conf.h @@ -83,6 +83,8 @@ public: std::string udp_addresses; int udp_port; + bool show_local_time_zone; + Pvt_Conf(); };