From 21d54ff7296ff33c11b9f7b788417a11e702f0d0 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Wed, 31 Jan 2018 04:39:16 +0100 Subject: Add TAI bulletin expiry to RC and to munin --- src/ClockTAI.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) (limited to 'src/ClockTAI.cpp') diff --git a/src/ClockTAI.cpp b/src/ClockTAI.cpp index 8c01127..c481841 100644 --- a/src/ClockTAI.cpp +++ b/src/ClockTAI.cpp @@ -76,6 +76,12 @@ static const char* tai_tz_url = static const char* tai_ietf_cache_file = "/tmp/odr-dabmux-leap-seconds.cache"; +ClockTAI::ClockTAI() : + RemoteControllable("clocktai") +{ + RC_ADD_PARAMETER(expiry, "Number of seconds until TAI Bulletin expires"); +} + int ClockTAI::get_valid_offset() { int offset = 0; @@ -152,6 +158,8 @@ int ClockTAI::get_offset() using namespace std::chrono; auto time_now = system_clock::now(); + std::unique_lock lock(m_data_mutex); + if (not m_offset_valid) { #ifdef TEST m_offset = 37; // Valid in early 2017 @@ -352,6 +360,11 @@ void ClockTAI::update_cache(const char* cache_filename) } bool ClockTAI::bulletin_is_valid() +{ + return bulletin_expiry_delay() > 0; +} + +int64_t ClockTAI::bulletin_expiry_delay() const { // The bulletin contains one line that specifies an expiration date // in NTP time. If that point in time is in the future, we consider @@ -380,10 +393,12 @@ bool ClockTAI::bulletin_is_valid() const int64_t expiry_unix = std::atol(expiry_data_str.c_str()) - ntp_unix_offset; - return expiry_unix > now; + if (expiry_unix > now) { + return expiry_unix - now; + } } } - return false; + return -1; } void ClockTAI::download_tai_utc_bulletin(const char* url) @@ -418,6 +433,36 @@ void ClockTAI::download_tai_utc_bulletin(const char* url) #endif // HAVE_CURL } +void ClockTAI::set_parameter(const string& parameter, const string& value) +{ + if (parameter == "expiry") { + throw ParameterError("Parameter '" + parameter + + "' is not read-only in controllable " + get_rc_name()); + } + else { + throw ParameterError("Parameter '" + parameter + + "' is not exported by controllable " + get_rc_name()); + } +} + +const string ClockTAI::get_parameter(const string& parameter) const +{ + if (parameter == "expiry") { + std::unique_lock lock(m_data_mutex); + int64_t expiry = bulletin_expiry_delay(); + if (expiry > 0) { + return to_string(expiry); + } + else { + return "Bulletin expired or invalid!"; + } + } + else { + throw ParameterError("Parameter '" + parameter + + "' is not exported by controllable " + get_rc_name()); + } +} + #if 0 // Example testing code void debug_tai_clk() -- cgit v1.2.3