From 18cd5c46fc8463292629e8161f8e0ae905bdb60e Mon Sep 17 00:00:00 2001 From: Andrej Rode Date: Fri, 17 Feb 2017 10:06:38 -0800 Subject: usrp: remove gregorian and lexical casting in gps_ctrl --- host/lib/usrp/gps_ctrl.cpp | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'host') diff --git a/host/lib/usrp/gps_ctrl.cpp b/host/lib/usrp/gps_ctrl.cpp index cc3e1b8e3..c1cdadd23 100644 --- a/host/lib/usrp/gps_ctrl.cpp +++ b/host/lib/usrp/gps_ctrl.cpp @@ -23,17 +23,17 @@ #include #include #include -#include #include #include #include #include #include +#include +#include #include "boost/tuple/tuple.hpp" using namespace uhd; -using namespace boost::gregorian; using namespace boost::posix_time; using namespace boost::algorithm; using namespace boost::this_thread; @@ -348,16 +348,18 @@ private: throw uhd::value_error(str(boost::format("Invalid response \"%s\"") % reply)); } - //just trust me on this one - gps_time = ptime( date( - greg_year(boost::lexical_cast(datestr.substr(4, 2)) + 2000), - greg_month(boost::lexical_cast(datestr.substr(2, 2))), - greg_day(boost::lexical_cast(datestr.substr(0, 2))) - ), - hours( boost::lexical_cast(timestr.substr(0, 2))) - + minutes(boost::lexical_cast(timestr.substr(2, 2))) - + seconds(boost::lexical_cast(timestr.substr(4, 2))) - ); + time_t raw_time = std::time(nullptr); + struct tm *raw_date = std::gmtime(&raw_time); // Initialize tm struct + raw_date->tm_year = std::stoi(datestr.substr(4, 2)) + 2000 - 1900; // years since 1900 + raw_date->tm_mon = std::stoi(datestr.substr(2, 2)) - 1; // months since january (0-11) + raw_date->tm_mday = std::stoi(datestr.substr(0, 2)); // dom (1-31) + raw_date->tm_hour = std::stoi(timestr.substr(0, 2)); + raw_date->tm_min = std::stoi(timestr.substr(2, 2)); + raw_date->tm_sec = std::stoi(timestr.substr(4,2)); + std::time_t gps_date = mktime(raw_date) - timezone; // mktime creates time_t in localtime + + gps_time = boost::posix_time::from_time_t(gps_date); + return gps_time; } catch(std::exception &e) { -- cgit v1.2.3