summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Burnicki <martin.burnicki@meinberg.de>2022-08-25 16:36:45 +0200
committerMartin Burnicki <martin.burnicki@meinberg.de>2022-08-25 16:36:45 +0200
commitde28b56bc098c165648bd472105824ee8eeb1017 (patch)
treec028667f53d142110198d0d137669cc60caaacd9
parenta83fdff44a5eef739cda034fc24b5de0e9e2a61d (diff)
downloadmbgtools-lx-de28b56bc098c165648bd472105824ee8eeb1017.tar.gz
mbgtools-lx-de28b56bc098c165648bd472105824ee8eeb1017.zip
mbgsvcd doesn't enter holdover mode if device has no valid time
-rw-r--r--mbgsvcd/mbgsvcd.c83
1 files changed, 54 insertions, 29 deletions
diff --git a/mbgsvcd/mbgsvcd.c b/mbgsvcd/mbgsvcd.c
index bb176f3..90e2c43 100644
--- a/mbgsvcd/mbgsvcd.c
+++ b/mbgsvcd/mbgsvcd.c
@@ -1,7 +1,7 @@
/**************************************************************************
*
- * $Id: mbgsvcd.c 1.18 2022/08/24 14:12:23 martin.burnicki REL_M $
+ * $Id: mbgsvcd.c 1.19 2022/08/25 14:34:07 martin.burnicki REL_M $
*
* Main file for mbgsvcd which compares the system time to the
* time from a Meinberg device, and feeds these data pairs
@@ -9,6 +9,9 @@
*
* -----------------------------------------------------------------------
* $Log: mbgsvcd.c $
+ * Revision 1.19 2022/08/25 14:34:07 martin.burnicki
+ * Don't enter holdover mode if device has no valid time.
+ * Fixed usage msg with regard to trust time.
* Revision 1.18 2022/08/24 14:12:23 martin.burnicki
* Use feature check functions instead of macros.
* Revision 1.17 2021/12/01 19:06:54 martin.burnicki
@@ -130,14 +133,18 @@
#if defined( DEBUG )
- #define DEBUG_TRUSTTIME 1 // Can be 0 or > 0.
+ #define DEBUG_DEV_STATE 1 // Can be 0 or > 0.
#else
- #define DEBUG_TRUSTTIME 0 // Always 0.
+ #define DEBUG_DEV_STATE 0 // Always 0.
#endif
-#define DEFAULT_TRUST_DAYS 4 ///< 4 days default refclock trust time.
-#define DEFAULT_TRUST_TIME ( DEFAULT_TRUST_DAYS * SECS_PER_DAY ) ///< Trust time, in seconds.
+#if 0
+ #define DEFAULT_TRUST_DAYS 4 ///< 4 days default refclock trust time.
+ #define DEFAULT_TRUST_TIME_SECS ( DEFAULT_TRUST_DAYS * SECS_PER_DAY ) ///< Trust time, in seconds.
+#else
+ #define DEFAULT_TRUST_TIME_SECS 0
+#endif
static const char *pname = "mbgsvcd";
@@ -149,7 +156,8 @@ static bool glb_pretend_sync; ///< -p Pretend to SHM that the devic
static bool always_update_shm; ///< -U Update SHM unit even if LEAP_NOTINSYNC.
static bool print_raw; ///< -r Print raw time stamps.
static int sleep_intv = 1; ///< -s Sleep interval between time comparisons.
-static ulong glb_trust_time_seconds; ///< -t Global trust time [seconds].
+static ulong glb_trust_time_seconds ///< -t Global trust time [seconds].
+ = DEFAULT_TRUST_TIME_SECS;
static int n_units = MAX_SHM_REFCLOCKS; ///< -n Total number of usable SHM units, default: all.
static int n_unit0 = 0; ///< -o Index of first usable SHM unit, default: 0.
@@ -218,10 +226,12 @@ typedef uint DEV_STATE_FLAGS;
*/
enum DEV_STATE_FLAG_MASKS
{
- DEV_STATE_SET = 0x0001, ///< Hidden flag, indicating that state has been set.
- DEV_STATE_DATA_AVAIL = 0x0002, ///< Data could be read from the device.
- DEV_STATE_SYNCHRONIZED = 0x0004, ///< Device is synchronized.
- DEV_STATE_IN_HOLDOVER = 0x0008 ///< Device is not synchronized, but in holdover mode.
+ DEV_STATE_SET = 0x0001, ///< Hidden flag, indicating that state has been set.
+ DEV_STATE_DATA_AVAIL = 0x0002, ///< Data could be read from the device.
+ DEV_STATE_SYNCHRONIZED = 0x0004, ///< Device is synchronized.
+ DEV_STATE_IN_HOLDOVER = 0x0008, ///< Device is not synchronized, but in holdover mode.
+ DEV_STATE_INVALID_TIME = 0x0010, ///< Device reported "invalid time".
+ DEV_STATE_INVALID_TIME_REPORTED = 0x0020 ///< "Invalid time" has already been reported.
};
@@ -598,13 +608,12 @@ void dev_state_check_changes( DEV_STATE *p_ds )
{
DEV_STATE_FLAGS changed_state = p_ds->state ^ p_ds->prv_state;
-#if 0 //##++++++++++
- printf( "state %-9s: 0x%04X, changed: 0x%04X%s \n",
- _pcps_type_name( &p_ds->dev_info ),
- p_ds->state, changed_state,
- changed_state ? " *" : str_empty );
-#endif
-
+ #if DEBUG_DEV_STATE
+ printf( "state %-9s: 0x%04X, changed: 0x%04X%s \n",
+ _pcps_type_name( &p_ds->dev_info ),
+ p_ds->state, changed_state,
+ changed_state ? " *" : str_empty );
+ #endif
if ( changed_state & DEV_STATE_SET )
{
@@ -622,7 +631,10 @@ void dev_state_check_changes( DEV_STATE *p_ds )
if ( p_ds->state & DEV_STATE_SYNCHRONIZED )
mbg_log_dev( LOG_INFO, p_ds, "Is synchronized" );
else
- mbg_log_dev( LOG_WARNING, p_ds, "Is not synchronized" );
+ if ( p_ds->state & DEV_STATE_INVALID_TIME )
+ mbg_log_dev( LOG_WARNING, p_ds, "Has no valid time" );
+ else
+ mbg_log_dev( LOG_WARNING, p_ds, "Is not synchronized" );
goto done;
}
@@ -642,7 +654,10 @@ void dev_state_check_changes( DEV_STATE *p_ds )
if ( p_ds->state & DEV_STATE_SYNCHRONIZED )
mbg_log_dev( LOG_INFO, p_ds, "Data has become available, and device is synchronized" );
else
- mbg_log_dev( LOG_WARNING, p_ds, "Data has become available, but device is NOT synchronized" );
+ if ( p_ds->state & DEV_STATE_INVALID_TIME )
+ mbg_log_dev( LOG_WARNING, p_ds, "Data has become available, but device has no valid time" );
+ else
+ mbg_log_dev( LOG_WARNING, p_ds, "Data has become available, but device is NOT synchronized" );
goto done;
}
@@ -680,10 +695,20 @@ void dev_state_check_changes( DEV_STATE *p_ds )
goto done;
}
- // If a trust time has been specified, we start holdover mode.
+ // If a trust time has been specified, we possibly start holdover mode.
if ( p_ds->trust_time_seconds )
{
- mbg_log_dev( LOG_WARNING, p_ds, "Sync. lost: entering holdover for %lu second%s",
+ if ( p_ds->state & DEV_STATE_INVALID_TIME )
+ {
+ if ( p_ds->state & DEV_STATE_INVALID_TIME_REPORTED )
+ goto done;
+
+ mbg_log_dev( LOG_WARNING, p_ds, "Sync. lost, not entering holdover: device time is not valid" );
+ dev_state_update_state( p_ds, DEV_STATE_INVALID_TIME_REPORTED, true );
+ goto done;
+ }
+
+ mbg_log_dev( LOG_WARNING, p_ds, "Sync. lost, entering holdover for %lu second%s",
p_ds->trust_time_seconds, get_plural_str( p_ds->trust_time_seconds ) );
start_holdover( p_ds );
goto done;
@@ -697,9 +722,12 @@ void dev_state_check_changes( DEV_STATE *p_ds )
done:
if ( p_ds->state & DEV_STATE_IN_HOLDOVER )
if ( check_holdover_expired( p_ds ) )
- mbg_log_dev( LOG_WARNING, p_ds, "Sync. lost: holdover ends after trust time (%lu second%s) expired",
+ mbg_log_dev( LOG_WARNING, p_ds, "Sync. lost, holdover ends after trust time (%lu second%s) expired",
p_ds->trust_time_seconds, get_plural_str( p_ds->trust_time_seconds ) );
+ if ( changed_state & DEV_STATE_INVALID_TIME )
+ dev_state_update_state( p_ds, DEV_STATE_INVALID_TIME_REPORTED, false );
+
p_ds->prv_state = p_ds->state;
} // dev_state_check_changes
@@ -721,7 +749,10 @@ void eval_status( DEV_STATE *p_ds )
// Only if the device is accessible, we check
// if it is synchronized.
if ( p_ds->state & DEV_STATE_DATA_AVAIL )
+ {
dev_state_update_state( p_ds, DEV_STATE_SYNCHRONIZED, check_if_sync( p_status ) );
+ dev_state_update_state( p_ds, DEV_STATE_INVALID_TIME, ( *p_status & PCPS_INVT ) != 0 );
+ }
// Check for status changes.
dev_state_check_changes( p_ds );
@@ -1434,8 +1465,6 @@ static /*HDR*/
*/
void usage( void )
{
- char ws[256];
-
mbg_print_usage_intro( pname, false,
"This program periodically reads a reference time stamp and an associated\n"
"system time stamp from every mbgclock device, and feeds the time stamp pairs\n"
@@ -1452,11 +1481,7 @@ void usage( void )
mbg_print_opt_info( "-s num", "Sleep num seconds between calls" );
mbg_print_opt_info( "-p", "Pretend device is always synchronized" );
mbg_print_opt_info( "-U", "Even update SHM unit if NTP leap bits are 'not synchronized'" );
-
- snprintf_safe( ws, sizeof( ws ), "Set num seconds for refclock trust time, default %i days (%lu seconds)",
- DEFAULT_TRUST_DAYS, DEFAULT_TRUST_TIME );
- mbg_print_opt_info( "-t num", "%s", ws );
-
+ mbg_print_opt_info( "-t num", "Set refclock trust time to num seconds, default %lu", glb_trust_time_seconds );
mbg_print_opt_info( "-n num", "Number of SHM segments to use" );
mbg_print_opt_info( "-o num", "SHM segment number offset (default 0)" );