diff options
author | Martin Burnicki <martin.burnicki@meinberg.de> | 2022-12-21 17:05:52 +0100 |
---|---|---|
committer | Martin Burnicki <martin.burnicki@meinberg.de> | 2022-12-21 17:05:52 +0100 |
commit | 633ba68d16d71f68a3282458d4608fcafea1bc12 (patch) | |
tree | 645ae5b5d6ecec4d3988bcb8c0ede8d035adad89 /mbgirigcfg | |
parent | e87224fb8e7bbb6059ae2d895421357dc29ac32b (diff) | |
download | mbgtools-lx-633ba68d16d71f68a3282458d4608fcafea1bc12.tar.gz mbgtools-lx-633ba68d16d71f68a3282458d4608fcafea1bc12.zip |
Update many files to clean up things
Remove obsolete (PCPS_DEV *) parameter from some functions, and
use feature check functions instead of macros.
Change the return value of some snprint_... functions from size_t
to int, and remove obsolete _int_from_size_t() stuff.
Quiet some potential compiler warnings.
Diffstat (limited to 'mbgirigcfg')
-rw-r--r-- | mbgirigcfg/mbgirigcfg.c | 142 |
1 files changed, 75 insertions, 67 deletions
diff --git a/mbgirigcfg/mbgirigcfg.c b/mbgirigcfg/mbgirigcfg.c index 52618ff..b1136ae 100644 --- a/mbgirigcfg/mbgirigcfg.c +++ b/mbgirigcfg/mbgirigcfg.c @@ -1,7 +1,7 @@ /************************************************************************** * - * $Id: mbgirigcfg.c 1.17 2021/04/12 21:57:44 martin REL_M $ + * $Id: mbgirigcfg.c 1.18 2022/12/21 15:20:27 martin.burnicki REL_M $ * * Description: * Main file for the mbgirigcfg program which can be used to configure @@ -10,6 +10,10 @@ * * ----------------------------------------------------------------------- * $Log: mbgirigcfg.c $ + * Revision 1.18 2022/12/21 15:20:27 martin.burnicki + * Removed obsolete (PCPS_DEV *) parameter from some functions, + * and use feature check functions instead of macros. + * Removed some obsolete _int_from_size_t() stuff. * Revision 1.17 2021/04/12 21:57:44 martin * Updated printing of usage information. * Revision 1.16 2021/03/21 18:03:09 martin @@ -104,14 +108,14 @@ static IRIG_INFO irig_tx_info; static MBG_REF_OFFS ref_offs; static MBG_OPT_INFO opt_info; -static int cfg_err_rx; -static int cfg_err_tx; -static int changed_cfg_rx; -static int changed_cfg_tx; -static int warned_no_rx; -static int warned_no_tx; +static bool cfg_err_rx; +static bool cfg_err_tx; +static bool changed_cfg_rx; +static bool changed_cfg_tx; +static bool warned_no_rx; +static bool warned_no_tx; -static int must_print_help_info; +static bool must_print_help_info; static const char *icode_rx_names[N_ICODE_RX] = DEFAULT_ICODE_RX_NAMES; static const char *icode_rx_descr[N_ICODE_RX] = DEFAULT_ICODE_RX_DESCRIPTIONS_ENG; @@ -129,7 +133,7 @@ int snprint_hours_mins( char *s, size_t max_len, long num_minutes ) { ldiv_t ldt = ldiv( labs( num_minutes ), MINS_PER_HOUR ); - size_t n = mbg_snprintf( s, max_len, "%c%li", + int n = mbg_snprintf( s, max_len, "%c%li", ( num_minutes < 0 ) ? '-' : '+', ldt.quot ); if ( ldt.rem ) @@ -137,7 +141,7 @@ int snprint_hours_mins( char *s, size_t max_len, long num_minutes ) n += mbg_snprintf( &s[n], max_len - n, "h" ); - return _int_from_size_t( n ); + return n; } // snprint_hours_mins @@ -221,20 +225,20 @@ void set_new_icode_rx( char *s ) { fprintf( stderr, "** IRIG RX code index %i is out of range (0..%i).\n", idx, N_ICODE_RX - 1 ); - cfg_err_rx = 1; + cfg_err_rx = true; return; } if ( _is_supported( idx, irig_rx_info.supp_codes ) ) { irig_rx_info.settings.icode = idx; - changed_cfg_rx = 1; + changed_cfg_rx = true; } else { fprintf( stderr, "** IRIG RX code \"%s\" not supported by this device.\n", icode_rx_names[idx] ); - cfg_err_rx = 1; + cfg_err_rx = true; } } // set_new_icode_rx @@ -284,13 +288,13 @@ void set_new_ref_offs( char *s ) } ref_offs = (MBG_REF_OFFS) new_ref_offs; - changed_cfg_rx = 1; + changed_cfg_rx = true; return; invalid: - cfg_err_rx = 1; + cfg_err_rx = true; } // set_new_ref_offs @@ -300,7 +304,7 @@ static /*HDR*/ void set_ref_offs_not_cfgd( void ) { ref_offs = MBG_REF_OFFS_NOT_CFGD; - changed_cfg_rx = 1; + changed_cfg_rx = true; } // set_ref_offs_not_cfgd @@ -326,9 +330,9 @@ void set_new_str_utc( char *s ) this_cfg_err = 1; if ( this_cfg_err ) - cfg_err_rx = 1; + cfg_err_rx = true; else - changed_cfg_rx = 1; + changed_cfg_rx = true; } // set_new_str_utc @@ -343,20 +347,20 @@ void set_new_icode_tx( char *s ) { fprintf( stderr, "** IRIG TX code index %i is out of range (0..%i).\n", idx, N_ICODE_TX - 1 ); - cfg_err_tx = 1; + cfg_err_tx = true; return; } if ( _is_supported( idx, irig_tx_info.supp_codes ) ) { irig_tx_info.settings.icode = idx; - changed_cfg_tx = 1; + changed_cfg_tx = true; } else { fprintf( stderr, "** IRIG TX code \"%s\" not supported by this device.\n", icode_tx_names[idx] ); - cfg_err_tx = 1; + cfg_err_tx = true; } } // set_new_icode_tx @@ -377,16 +381,16 @@ void set_new_irig_tx_local( char *s ) this_cfg_err = 1; if ( this_cfg_err ) - cfg_err_tx = 1; + cfg_err_tx = true; else - changed_cfg_tx = 1; + changed_cfg_tx = true; } // set_new_irig_tx_local static /*HDR*/ -void set_new_tfom_flag( char *s, IRIG_SETTINGS *p, int *changed_flag, int *err_flag ) +void set_new_tfom_flag( char *s, IRIG_SETTINGS *p, bool *changed_flag, bool *err_flag ) { if ( !(_idx_bit( p->icode ) & MSK_ICODE_TX_HAS_TFOM ) ) return; // not supported @@ -399,23 +403,23 @@ void set_new_tfom_flag( char *s, IRIG_SETTINGS *p, int *changed_flag, int *err_f p->flags &= ~IFLAGS_DISABLE_TFOM; else { - *err_flag = 1; + *err_flag = true; return; } - *changed_flag = 1; + *changed_flag = true; } // set_new_tfom_flag static /*HDR*/ -int chk_dev_rx( const PCPS_DEV *p_dev ) +bool chk_dev_rx( bool dev_opened, bool dev_is_rx ) { - if ( p_dev ) + if ( dev_opened ) { - if ( _pcps_is_irig_rx( p_dev ) ) - return 1; + if ( dev_is_rx ) + return true; if ( !warned_no_rx ) { @@ -423,22 +427,22 @@ int chk_dev_rx( const PCPS_DEV *p_dev ) warned_no_rx = 1; } - cfg_err_rx = 1; + cfg_err_rx = true; } - return 0; + return false; } // chk_dev_rx static /*HDR*/ -int chk_dev_tx( const PCPS_DEV *p_dev ) +bool chk_dev_tx( bool dev_opened, bool dev_has_tx ) { - if ( p_dev ) + if ( dev_opened ) { - if ( _pcps_has_irig_tx( p_dev ) ) - return 1; + if ( dev_has_tx ) + return true; if ( !warned_no_tx ) { @@ -446,18 +450,19 @@ int chk_dev_tx( const PCPS_DEV *p_dev ) warned_no_tx = 1; } - cfg_err_tx = 1; + cfg_err_tx = true; } - return 0; + return false; } // chk_dev_tx static /*HDR*/ -void check_cmd_line( int argc, char *argv[], const PCPS_DEV *p_dev ) +void check_cmd_line( int argc, char *argv[], MBG_DEV_HANDLE dh, bool dev_is_tcr, bool dev_has_tx ) { + bool dev_opened = dh != MBG_INVALID_DEV_HANDLE; int c; // Force checking all parameters because this function @@ -477,27 +482,27 @@ void check_cmd_line( int argc, char *argv[], const PCPS_DEV *p_dev ) // IRIG receiver options. case 'r': // IRIG RX code frame. - if ( chk_dev_rx( p_dev ) ) + if ( chk_dev_rx( dev_opened, dev_is_tcr ) ) set_new_icode_rx( optarg ); break; case 'o': // Incoming time offset from UTC. - if ( chk_dev_rx( p_dev ) ) + if ( chk_dev_rx( dev_opened, dev_is_tcr ) ) set_new_ref_offs( optarg ); break; case 'u': // Option flag: serial output is always UTC. - if ( chk_dev_rx( p_dev ) ) + if ( chk_dev_rx( dev_opened, dev_is_tcr ) ) set_new_str_utc( optarg ); break; case 'i': // Option flag: ignore incoming TFOM flag, alway sync. - if ( chk_dev_rx( p_dev ) ) + if ( chk_dev_rx( dev_opened, dev_is_tcr ) ) set_new_tfom_flag( optarg, &irig_rx_info.settings, &changed_cfg_rx, &cfg_err_rx ); break; case 'X': // Set UTC ref_offs to "not configured". - if ( chk_dev_rx( p_dev ) ) + if ( chk_dev_rx( dev_opened, dev_is_tcr ) ) set_ref_offs_not_cfgd(); break; @@ -505,17 +510,17 @@ void check_cmd_line( int argc, char *argv[], const PCPS_DEV *p_dev ) // IRIG output options. case 't': // IRIG TX code frame. - if ( chk_dev_tx( p_dev ) ) + if ( chk_dev_tx( dev_opened, dev_has_tx ) ) set_new_icode_tx( optarg ); break; case 'l': // Option flag: transmit local time, not UTC. - if ( chk_dev_tx( p_dev ) ) + if ( chk_dev_tx( dev_opened, dev_has_tx ) ) set_new_irig_tx_local( optarg ); break; case 's': // Option flag: always send TFOM as "sync". - if ( chk_dev_tx( p_dev ) ) + if ( chk_dev_tx( dev_opened, dev_has_tx ) ) set_new_tfom_flag( optarg, &irig_tx_info.settings, &changed_cfg_tx, &cfg_err_tx ); break; @@ -636,35 +641,38 @@ void usage( void ) static /*HDR*/ -int do_mbgirigcfg( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev ) +int do_mbgirigcfg( MBG_DEV_HANDLE dh ) { int rc = MBG_SUCCESS; - cfg_err_rx = 0; - cfg_err_tx = 0; - changed_cfg_rx = 0; - changed_cfg_tx = 0; - warned_no_rx = 0; - warned_no_tx = 0; + bool dev_opened = dh != MBG_INVALID_DEV_HANDLE; + bool dev_is_tcr = mbg_rc_is_success( mbg_chk_dev_is_tcr( dh ) ); + bool dev_has_irig_tx = mbg_rc_is_success( mbg_chk_dev_has_irig_tx( dh ) ); + cfg_err_rx = false; + cfg_err_tx = false; + changed_cfg_rx = false; + changed_cfg_tx = false; + warned_no_rx = false; + warned_no_tx = false; - if ( !_pcps_has_irig( p_dev ) ) + if ( !( dev_is_tcr || dev_has_irig_tx ) ) { fprintf( stderr, "** This device does not provide an IRIG input or output.\n" ); rc = MBG_ERR_NOT_SUPP_BY_DEV; - must_print_help_info = 1; + must_print_help_info = true; goto done; } - if ( _pcps_is_irig_rx( p_dev ) ) + if ( dev_is_tcr ) { - rc = mbg_get_all_irig_rx_info( dh, p_dev, &irig_rx_info, + rc = mbg_get_all_irig_rx_info( dh, NULL, &irig_rx_info, &ref_offs, &opt_info ); if ( mbg_cond_err_msg( rc, "read IRIG input configuration" ) ) goto done; } - if ( _pcps_has_irig_tx( p_dev ) ) + if ( dev_has_irig_tx ) { rc = mbg_get_irig_tx_info( dh, &irig_tx_info ); @@ -672,36 +680,36 @@ int do_mbgirigcfg( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev ) goto done; } - check_cmd_line( glb_argc, glb_argv, p_dev ); + check_cmd_line( glb_argc, glb_argv, dh, dev_is_tcr, dev_has_irig_tx ); if ( cfg_err_rx || cfg_err_tx ) { printf( "** Invalid configuration options specified.\n" ); - must_print_help_info = 1; + must_print_help_info = true; rc = MBG_ERR_CFG; goto done; } if ( changed_cfg_rx ) { - if ( chk_dev_rx( p_dev ) ) + if ( chk_dev_rx( dev_opened, dev_is_tcr ) ) { print_cfg_rx( info_new, msg_rx ); - rc = mbg_save_all_irig_rx_settings( dh, p_dev, &irig_rx_info.settings, + rc = mbg_save_all_irig_rx_settings( dh, NULL, &irig_rx_info.settings, &ref_offs, &opt_info.settings ); if ( mbg_cond_err_msg( rc, "write IRIG input configuration" ) ) goto done; } } else // RX cfg not changed. - if ( _pcps_is_irig_rx( p_dev ) ) + if ( dev_is_tcr ) print_cfg_rx( info_curr, msg_rx ); if ( changed_cfg_tx ) { - if ( chk_dev_tx( p_dev ) ) + if ( chk_dev_tx( dev_opened, dev_is_tcr ) ) { print_cfg_tx( info_new, msg_tx ); @@ -712,7 +720,7 @@ int do_mbgirigcfg( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev ) } } else - if ( _pcps_has_irig_tx( p_dev ) ) + if ( dev_has_irig_tx ) print_cfg_tx( info_curr, msg_tx ); done: @@ -733,7 +741,7 @@ int main( int argc, char *argv[] ) snprint_hours_mins( str_ref_offs_min, sizeof( str_ref_offs_min ), -MBG_REF_OFFS_MAX ); snprint_hours_mins( str_ref_offs_max, sizeof( str_ref_offs_max ), MBG_REF_OFFS_MAX ); - check_cmd_line( argc, argv, NULL ); + check_cmd_line( argc, argv, MBG_INVALID_DEV_HANDLE, false, false ); if ( must_print_usage ) { |