diff options
-rw-r--r-- | host/lib/usrp/gps_ctrl.cpp | 26 |
1 files changed, 14 insertions, 12 deletions
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 <boost/algorithm/string.hpp> #include <boost/assign/list_of.hpp> #include <stdint.h> -#include <boost/date_time/posix_time/posix_time.hpp> #include <boost/thread/thread.hpp> #include <boost/tokenizer.hpp> #include <boost/format.hpp> #include <boost/regex.hpp> #include <boost/thread/mutex.hpp> +#include <ctime> +#include <string> #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<int>(datestr.substr(4, 2)) + 2000), - greg_month(boost::lexical_cast<int>(datestr.substr(2, 2))), - greg_day(boost::lexical_cast<int>(datestr.substr(0, 2))) - ), - hours( boost::lexical_cast<int>(timestr.substr(0, 2))) - + minutes(boost::lexical_cast<int>(timestr.substr(2, 2))) - + seconds(boost::lexical_cast<int>(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) { |