aboutsummaryrefslogtreecommitdiffstats
path: root/host
diff options
context:
space:
mode:
authorAndrej Rode <andrej.rode@ettus.com>2017-02-17 10:06:38 -0800
committerMartin Braun <martin.braun@ettus.com>2017-04-12 12:15:02 -0700
commit18cd5c46fc8463292629e8161f8e0ae905bdb60e (patch)
tree771e2acf5ce3019d148f51ef4d2656a76682673c /host
parente804bcf5ebe382d25fe0148794b0e3403105a853 (diff)
downloaduhd-18cd5c46fc8463292629e8161f8e0ae905bdb60e.tar.gz
uhd-18cd5c46fc8463292629e8161f8e0ae905bdb60e.tar.bz2
uhd-18cd5c46fc8463292629e8161f8e0ae905bdb60e.zip
usrp: remove gregorian and lexical casting in gps_ctrl
Diffstat (limited to 'host')
-rw-r--r--host/lib/usrp/gps_ctrl.cpp26
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) {