aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2017-06-16 09:09:05 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2017-06-16 09:09:05 +0200
commite9ba40d3cbcfe608f542e867e39828f922d62ccb (patch)
treebed3df2c52d627b13d45709cfc903a6057abb98f
parentbe8f9ea7ce46f3edfa1fef302af37594acf5af3f (diff)
downloaddabmux-e9ba40d3cbcfe608f542e867e39828f922d62ccb.tar.gz
dabmux-e9ba40d3cbcfe608f542e867e39828f922d62ccb.tar.bz2
dabmux-e9ba40d3cbcfe608f542e867e39828f922d62ccb.zip
Remove USNO bulletin from ClockTAI
Their format does not include an expiration time, making caching more difficult
-rw-r--r--src/ClockTAI.cpp134
-rw-r--r--src/ClockTAI.h7
2 files changed, 4 insertions, 137 deletions
diff --git a/src/ClockTAI.cpp b/src/ClockTAI.cpp
index 6d05370..7d2bd81 100644
--- a/src/ClockTAI.cpp
+++ b/src/ClockTAI.cpp
@@ -25,9 +25,8 @@
along with ODR-DabMux. If not, see <http://www.gnu.org/licenses/>.
*/
-/* This file downloads the TAI-UTC bulletins from the USNO servers and/or
- * from IETF and parses them so that correct time can be communicated in EDI
- * timestamps.
+/* This file downloads the TAI-UTC bulletins from the from IETF and parses them
+ * so that correct time can be communicated in EDI timestamps.
*
* This file contains self-test code that can be executed by running
* g++ -g -Wall -DTEST -DHAVE_CURL -std=c++11 -lcurl -lboost_regex -pthread \
@@ -66,16 +65,6 @@ static const char* tai_ietf_url =
// and in the tz distribution
static const char* tai_tz_url =
"https://raw.githubusercontent.com/eggert/tz/master/leap-seconds.list";
-// leap-seconds.list has a different format from the USNO one
-
-static const char* tai_usno_url1 =
- "http://maia.usno.navy.mil/ser7/tai-utc.dat";
-static const char* tai_usno_url2 =
- "http://toshi.nofs.navy.mil/ser7/tai-utc.dat";
-/* Last two lines from USNO bulletin, example:
- 2015 JUL 1 =JD 2457204.5 TAI-UTC= 36.0 S + (MJD - 41317.) X 0.0 S
- 2017 JAN 1 =JD 2457754.5 TAI-UTC= 37.0 S + (MJD - 41317.) X 0.0
- */
int ClockTAI::download_offset_task()
{
@@ -112,34 +101,6 @@ int ClockTAI::download_offset_task()
}
}
- if (not offset_valid) {
- try {
- download_tai_utc_bulletin(tai_usno_url1);
- offset = parse_usno_bulletin();
- offset_valid = true;
- }
- catch (std::runtime_error& e)
- {
- etiLog.level(warn) <<
- "TAI-UTC offset from USNO server #1 could not be retrieved: " <<
- e.what();
- }
- }
-
- if (not offset_valid) {
- try {
- download_tai_utc_bulletin(tai_usno_url2);
- offset = parse_usno_bulletin();
- offset_valid = true;
- }
- catch (std::runtime_error& e)
- {
- etiLog.level(warn) <<
- "TAI-UTC offset from USNO server #2 could not be retrieved: " <<
- e.what();
- }
- }
-
if (offset_valid) {
// With the current evolution of the offset, we're probably going
// to reach 500 long after DAB gets replaced by another standard.
@@ -311,97 +272,6 @@ int ClockTAI::parse_ietf_bulletin()
return tai_utc_offset;
}
-int ClockTAI::parse_usno_bulletin()
-{
- boost::regex regex_bulletin(
- "([0-9]{4}) ([A-Z]{3}) +([0-9]+) =JD +[0-9.]+ +TAI-UTC= *([0-9.]+)");
- /* regex groups:
- * Year Month Day Julian date Offset
- */
-
- const std::array<std::string, 12> months{"JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"};
-
- /* I'm not certain about the format they would use if the day is a
- * two-digit number. Will they keep two spaces after the month? The regex
- * should be resilient enough in that case.
- */
-
- time_t now = time(nullptr);
- struct tm *utc_time_now = gmtime(&now);
-
- const int year = utc_time_now->tm_year + 1900;
- const int month = utc_time_now->tm_mon; // January is 0
- if (month < 0 or month > 11) {
- throw std::runtime_error("Invalid value for month");
- }
- const int day = utc_time_now->tm_mday;
-
-
- int tai_utc_offset = 0;
- bool tai_utc_offset_valid = false;
-
- /* We cannot just take the last line, because it might
- * be in the future, announcing an upcoming leap second.
- *
- * So we need to look at the current date, and compare it
- * with the date of the leap second.
- */
- for (std::string line; std::getline(m_bulletin, line); ) {
-
- boost::smatch bulletin_entry;
-
- bool is_match = boost::regex_search(line, bulletin_entry, regex_bulletin);
- if (is_match) {
-
- if (bulletin_entry.size() != 5) {
- throw std::runtime_error(
- "Incorrect number of matched USNO TAI bulletin entries");
- }
- const std::string bulletin_year(bulletin_entry[1]);
- const std::string bulletin_month_name(bulletin_entry[2]);
- const std::string bulletin_day(bulletin_entry[3]);
- const std::string bulletin_offset(bulletin_entry[4]);
-
- const auto match = std::find(months.begin(), months.end(), bulletin_month_name);
- if (match == months.end()) {
- std::stringstream s;
- s << "Month " << bulletin_month_name << " not in array!";
- std::runtime_error(s.str());
- }
-
- if ( (std::atoi(bulletin_year.c_str()) < year) or
-
- (std::atoi(bulletin_year.c_str()) == year and
- std::distance(months.begin(), match) < month) or
-
- (std::atoi(bulletin_year.c_str()) == year and
- std::distance(months.begin(), match) == month and
- std::atoi(bulletin_day.c_str()) < day) ) {
- tai_utc_offset = std::atoi(bulletin_offset.c_str());
- tai_utc_offset_valid = true;
- }
-#if TEST
- else {
- std::cerr << "Ignoring offset " << bulletin_offset << " at date "
- << bulletin_year << " " << bulletin_month_name << " " <<
- bulletin_day << " in the future" << std::endl;
- }
-#endif
- }
-#if TEST
- else {
- std::cerr << "No match for line " << line << std::endl;
- }
-#endif
- }
-
- if (not tai_utc_offset_valid) {
- throw std::runtime_error("No data in TAI bulletin");
- }
-
- return tai_utc_offset;
-}
-
size_t ClockTAI::fill_bulletin(char *ptr, size_t size, size_t nmemb)
{
size_t len = size * nmemb;
diff --git a/src/ClockTAI.h b/src/ClockTAI.h
index 6ab9ab6..ab70384 100644
--- a/src/ClockTAI.h
+++ b/src/ClockTAI.h
@@ -44,10 +44,10 @@
// We can keep this code, maybe for future use
#define SUPPORT_SETTING_CLOCK_TAI 0
-/* Loads, parses and represents TAI-UTC offset information from the USNO bulletin */
+/* Loads, parses and represents TAI-UTC offset information from the IETF bulletin */
class ClockTAI {
public:
- // Fetch the bulletin from the USNO website and return the current
+ // Fetch the bulletin from the IETF website and return the current
// TAI-UTC offset.
// Throws runtime_error on failure.
int get_offset(void);
@@ -77,9 +77,6 @@ class ClockTAI {
// read TAI offset from m_bulletin in IETF format
int parse_ietf_bulletin(void);
- // read TAI offset from m_bulletin in USNO format
- int parse_usno_bulletin(void);
-
// callback that receives data from cURL
size_t fill_bulletin(char *ptr, size_t size, size_t nmemb);