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 | |
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.
43 files changed, 719 insertions, 477 deletions
diff --git a/mbgcmptime/mbgcmptime.c b/mbgcmptime/mbgcmptime.c index 35b5c70..1822779 100644 --- a/mbgcmptime/mbgcmptime.c +++ b/mbgcmptime/mbgcmptime.c @@ -1,7 +1,7 @@ /************************************************************************** * - * $Id: mbgcmptime.c 1.11 2021/11/15 17:08:52 martin.burnicki REL_M $ + * $Id: mbgcmptime.c 1.12 2022/12/21 14:46:41 martin.burnicki REL_M $ * * Description: * Main file for mbgcmptime program which compares the time on 2 devices @@ -11,6 +11,8 @@ * * ----------------------------------------------------------------------- * $Log: mbgcmptime.c $ + * Revision 1.12 2022/12/21 14:46:41 martin.burnicki + * Removed obsolete (PCPS_DEV *) parameter from a function. * Revision 1.11 2021/11/15 17:08:52 martin.burnicki * Improved printing of usage information. * Revision 1.10 2021/11/08 18:01:08 martin.burnicki @@ -114,7 +116,7 @@ FILE *fopen_log( const char *mode ) static /*HDR*/ -int do_mbgcmptime( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev ) +int do_mbgcmptime( MBG_DEV_HANDLE dh ) { PCPS_HR_TIME_CYCLES prv_htc1 = { 0 }; PCPS_HR_TIME_CYCLES prv_htc2 = { 0 }; @@ -136,7 +138,7 @@ int do_mbgcmptime( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev ) if ( read_fast ) { - rc = chk_fast_tstamp_supp( dh, p_dev, dh_ref, &dev_info_ref, NULL ); // TODO err_msg_fnc ? + rc = chk_fast_tstamp_supp( dh, dh_ref, NULL ); // TODO err_msg_fnc ? if ( mbg_rc_is_error( rc ) ) { diff --git a/mbgctrl/mbgctrl.c b/mbgctrl/mbgctrl.c index e0a2858..96f9047 100644 --- a/mbgctrl/mbgctrl.c +++ b/mbgctrl/mbgctrl.c @@ -1,7 +1,7 @@ /************************************************************************** * - * $Id: mbgctrl.c 1.33 2021/11/15 17:08:54 martin.burnicki REL_M $ + * $Id: mbgctrl.c 1.34 2022/12/21 15:11:25 martin.burnicki REL_M $ * * Description: * Main file for mbgctrl program which sends commands and @@ -9,6 +9,9 @@ * * ----------------------------------------------------------------------- * $Log: mbgctrl.c $ + * Revision 1.34 2022/12/21 15:11:25 martin.burnicki + * Removed obsolete (PCPS_DEV *) parameter from some functions, + * and use feature check functions instead of macros. * Revision 1.33 2021/11/15 17:08:54 martin.burnicki * Improved printing of usage information. * Revision 1.32 2021/11/08 18:01:31 martin.burnicki @@ -519,7 +522,7 @@ void print_bit_mask_list( const char *info_1, const char *info_2, uint32_t supp_ static /*HDR*/ -void err_msg( const PCPS_DEV *p_dev, const char *msg ) +void err_msg( const char *msg ) { printf( "This device %s.\n", msg ); @@ -562,7 +565,7 @@ int set_gps_tzdl( MBG_DEV_HANDLE dh, const TZDL *tzdl, const char *info ) static /*HDR*/ -int set_timezone( MBG_DEV_HANDLE dh, const char *tz_name, const PCPS_DEV *p_dev ) +int set_timezone( MBG_DEV_HANDLE dh, const char *tz_name ) { const char *tz_info = NULL; TZDL *tz_tzdl = NULL; @@ -595,13 +598,13 @@ int set_timezone( MBG_DEV_HANDLE dh, const char *tz_name, const PCPS_DEV *p_dev if ( tz_info ) { - if ( _pcps_has_tzcode( p_dev ) ) + if ( mbg_rc_is_success( mbg_chk_dev_has_tzcode( dh ) ) ) rc = set_tz_code( dh, tz_code, tz_info ); else - if ( _pcps_has_tzdl( p_dev ) ) + if ( mbg_rc_is_success( mbg_chk_dev_has_tzdl( dh ) ) ) rc = set_gps_tzdl( dh, tz_tzdl, tz_info ); else - err_msg( p_dev, no_tz ); + err_msg( no_tz ); } return rc; @@ -703,7 +706,7 @@ fail: static /*HDR*/ -int show_lan_intf( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev, const char *info ) +int show_lan_intf( MBG_DEV_HANDLE dh, const char *info ) { IP4_SETTINGS ip4_settings; char ws[256]; @@ -713,6 +716,8 @@ int show_lan_intf( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev, const char *info ) if ( mbg_cond_err_msg( rc, "mbg_get_ip4_settings" ) ) return rc; + (void) info; // Avoid warning "not used". + printf( "On-board LAN interface settings:" ); if ( ip4_settings.flags & IP4_MSK_DHCP ) @@ -763,7 +768,7 @@ const char *intv_str( int i ) static /*HDR*/ -int show_ptp_cfg( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev, const char *info ) +int show_ptp_cfg( MBG_DEV_HANDLE dh, const char *info ) { ALL_PTP_CFG_INFO all_ptp_cfg_info; PTP_CFG_INFO *pi = &all_ptp_cfg_info.ptp_cfg_info; @@ -777,6 +782,9 @@ int show_ptp_cfg( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev, const char *info ) if ( mbg_cond_err_msg( rc, "mbg_get_all_ptp_cfg_info" ) ) return rc; + + (void) info; // Avoid warning "not used". + unicast_supported = ( pi->supp_flags & PTP_CFG_MSK_SUPPORT_PTP_UNICAST ) != 0; printf( "\nPTP configuration:\n"); @@ -1010,7 +1018,7 @@ int chk_int16_parm( const char *arg, const char *id, int16_t *p, int16_t range_m static /*HDR*/ -int set_ptp_cfg( MBG_DEV_HANDLE dh, const char *arg, const PCPS_DEV *p_dev ) +int set_ptp_cfg( MBG_DEV_HANDLE dh, const char *arg ) { ALL_PTP_CFG_INFO all_ptp_cfg_info = { { { 0 } } }; ALL_PTP_CFG_INFO prv_all_ptp_cfg_info; @@ -1350,7 +1358,7 @@ fail: static /*HDR*/ -int set_lan_intf( MBG_DEV_HANDLE dh, const char *arg, const PCPS_DEV *p_dev ) +int set_lan_intf( MBG_DEV_HANDLE dh, const char *arg ) { IP4_SETTINGS prv_ip4_settings; IP4_SETTINGS ip4_settings = { 0 }; @@ -1516,8 +1524,8 @@ invalid: static /*HDR*/ -int set_date_time( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev, - const char *sdate, const char *stime ) +int set_date_time( MBG_DEV_HANDLE dh, const char *sdate, const char *stime, + bool is_gps ) { PCPS_TIME_UNION u = { { 0 } }; TTM ttm = { 0 }; @@ -1576,7 +1584,7 @@ int set_date_time( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev, // different structures to set the on-board date and time, // so we have to distinguish. - if ( _pcps_is_gps( p_dev ) ) // Is a GPS card. + if ( is_gps ) // Is a GPS card. { ttm.channel = -1; @@ -1700,7 +1708,6 @@ static /*HDR*/ * * @param[in] dh Valid ::MBG_DEV_HANDLE handle to a Meinberg device. * @param[out] p_rpcfg Address of a ::RECEIVER_PORT_CFG structure to be set up. - * @param[in] p_dev Address of a ::PCPS_DEV structure associated with the device. * @param[in,out] p_ri Address of a ::RECEIVER_INFO associated with the device, * set up first, if required. * @@ -1708,7 +1715,7 @@ static /*HDR*/ * or one of the (negative) @ref MBG_ERROR_CODES on error. */ int check_get_receiver_port_cfg( MBG_DEV_HANDLE dh, RECEIVER_PORT_CFG *p_rpcfg, - const PCPS_DEV *p_dev, RECEIVER_INFO *p_ri ) + RECEIVER_INFO *p_ri ) { int rc = check_setup_receiver_info( dh, p_ri ); @@ -1721,7 +1728,7 @@ int check_get_receiver_port_cfg( MBG_DEV_HANDLE dh, RECEIVER_PORT_CFG *p_rpcfg, if ( ( p_ri->n_com_ports > 0 ) && ( p_rpcfg->pii[0].port_info.port_settings.parm.baud_rate == 0 ) ) { - rc = mbg_get_serial_settings( dh, p_dev, p_rpcfg, p_ri ); + rc = mbg_get_serial_settings( dh, p_rpcfg, p_ri ); mbg_cond_err_msg( rc, "mbg_get_serial_settings" ); } @@ -1755,7 +1762,7 @@ int snprint_port_cfg( char *s, int sz, unsigned int port_num, static /*HDR*/ -void show_serial_settings( MBG_DEV_HANDLE dh, const RECEIVER_PORT_CFG *p_rpcfg, +void show_serial_settings( const RECEIVER_PORT_CFG *p_rpcfg, const RECEIVER_INFO *p_ri ) { char ws[256]; @@ -1831,7 +1838,7 @@ void print_port_info_errors( const char *port_name, unsigned int port_num, static /*HDR*/ int save_serial_settings( MBG_DEV_HANDLE dh, unsigned int port_num, const char *parm_str, - const PCPS_DEV *p_dev, const RECEIVER_INFO *p_ri ) + const RECEIVER_INFO *p_ri ) { char ws[256]; RECEIVER_PORT_CFG rpcfg = { { { 0 } } }; @@ -1842,10 +1849,10 @@ int save_serial_settings( MBG_DEV_HANDLE dh, unsigned int port_num, const char * char *p_tail; int rc; int flags; - int i; + size_t i; // Load current settings and supported settings. - rc = mbg_get_serial_settings( dh, p_dev, &rpcfg, p_ri ); + rc = mbg_get_serial_settings( dh, &rpcfg, p_ri ); if ( mbg_cond_err_msg( rc, "mbg_get_serial_settings" ) ) return rc; @@ -1913,7 +1920,7 @@ done_parm_str: } // Save new parameters. - rc = mbg_save_serial_settings( dh, p_dev, &rpcfg, port_num ); + rc = mbg_save_serial_settings( dh, &rpcfg, port_num ); if ( mbg_cond_err_msg( rc, "mbg_save_serial_settings" ) ) return rc; @@ -1971,8 +1978,7 @@ int check_get_pout_cfg( MBG_DEV_HANDLE dh, ALL_POUT_INFO_IDX api, RECEIVER_INFO static /*HDR*/ -int help_pout_arg( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev, - const OPT_HANDLER_SPEC *p_opt, CTRL_FLAGS ctrl_flags ) +int help_pout_arg( MBG_DEV_HANDLE dh, const OPT_HANDLER_SPEC *p_opt, CTRL_FLAGS ctrl_flags ) { const INDENTS *p_ind = &usage_indents; const INDENTS *p_ind_detailed = &usage_indents_detailed; @@ -2329,7 +2335,7 @@ fail: static /*HDR*/ -int show_pout( MBG_DEV_HANDLE dh, const OPT_HANDLER_SPEC *p_opt, const PCPS_DEV *p_devx, const char *cmd_info ) +int show_pout( MBG_DEV_HANDLE dh, const OPT_HANDLER_SPEC *p_opt, const char *cmd_info ) { const INDENTS *p_ind = &show_indents; RECEIVER_INFO ri = { 0 }; @@ -2356,7 +2362,7 @@ int show_pout( MBG_DEV_HANDLE dh, const OPT_HANDLER_SPEC *p_opt, const PCPS_DEV // TODO Actually the code below only shows the current mode, // and whether the output signal is inverted, or not. // Full featured code should also display additional parameters - // depending the selected mode. + // depending on the selected mode. printf( "\n" ); print_indent( p_ind->indent_2 ); @@ -2429,7 +2435,7 @@ void printf_ef( uint16_t flag, const char *info ) static /*HDR*/ -int show_enable_flags( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev, const char *info ) +int show_enable_flags( MBG_DEV_HANDLE dh, const char *info ) { ENABLE_FLAGS ef; int rc; @@ -2444,7 +2450,7 @@ int show_enable_flags( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev, const char *inf printf( "," ); printf_ef( ef.pulses, ef_name_pulses ); - if ( _pcps_has_synth( p_dev ) ) + if ( mbg_rc_is_success( mbg_chk_dev_has_synth( dh ) ) ) { printf( "," ); printf_ef( ef.synth, ef_name_synth ); @@ -2489,7 +2495,7 @@ fail: static /*HDR*/ -int set_enable_flags( MBG_DEV_HANDLE dh, const char *arg, const PCPS_DEV *p_dev ) +int set_enable_flags( MBG_DEV_HANDLE dh, const char *arg ) { ENABLE_FLAGS ef; @@ -2655,7 +2661,7 @@ done: static /*HDR*/ -int show_time_scale( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev, const char *info ) +int show_time_scale( MBG_DEV_HANDLE dh, const char *info ) { MBG_TIME_SCALE_INFO tsci = { { 0 } }; int rc; @@ -2677,7 +2683,7 @@ int show_time_scale( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev, const char *info static /*HDR*/ -int set_time_scale( MBG_DEV_HANDLE dh, const char *arg, const PCPS_DEV *p_dev ) +int set_time_scale( MBG_DEV_HANDLE dh, const char *arg ) { MBG_TIME_SCALE_INFO tsci = { { 0 } }; int rc; @@ -2716,14 +2722,14 @@ int set_time_scale( MBG_DEV_HANDLE dh, const char *arg, const PCPS_DEV *p_dev ) static /*HDR*/ -void usage( MBG_DEV_HANDLE dh, PCPS_DEV *p_dev, RECEIVER_INFO *p_ri, +void usage( MBG_DEV_HANDLE dh, RECEIVER_INFO *p_ri, RECEIVER_PORT_CFG *p_rpcfg ) { int i; int n_time_scale; - if ( p_dev ) - check_get_receiver_port_cfg( dh, p_rpcfg, p_dev, p_ri ); + if ( dh != MBG_INVALID_DEV_HANDLE ) + check_get_receiver_port_cfg( dh, p_rpcfg, p_ri ); printf( "Usage: %s cmd [dev]\n" "\n" @@ -2744,7 +2750,8 @@ void usage( MBG_DEV_HANDLE dh, PCPS_DEV *p_dev, RECEIVER_INFO *p_ri, " TIMESCALE=<n> Set time scale of the device to scale with index <n>.\n" ); - n_time_scale = p_dev ? get_n_time_scale( dh, NULL ) : N_MBG_TIME_SCALE; + n_time_scale = ( dh != MBG_INVALID_DEV_HANDLE ) ? + get_n_time_scale( dh, NULL ) : N_MBG_TIME_SCALE; if ( n_time_scale ) { @@ -2792,7 +2799,7 @@ void usage( MBG_DEV_HANDLE dh, PCPS_DEV *p_dev, RECEIVER_INFO *p_ri, printf( "\n <t> is an optional time string format index" ); - if ( p_dev ) + if ( dh != MBG_INVALID_DEV_HANDLE ) { printf( ":" ); @@ -2806,7 +2813,7 @@ void usage( MBG_DEV_HANDLE dh, PCPS_DEV *p_dev, RECEIVER_INFO *p_ri, printf( "\n <m> is an optional time string mode index" ); - if ( p_dev ) + if ( dh != MBG_INVALID_DEV_HANDLE ) { printf( ":" ); @@ -2820,7 +2827,7 @@ void usage( MBG_DEV_HANDLE dh, PCPS_DEV *p_dev, RECEIVER_INFO *p_ri, printf( "\n" ); - help_pout_arg( dh, p_dev, &ohs_pout, 0 ); + help_pout_arg( dh, &ohs_pout, 0 ); printf( "\n" ); @@ -2897,9 +2904,9 @@ void usage( MBG_DEV_HANDLE dh, PCPS_DEV *p_dev, RECEIVER_INFO *p_ri, "\n" ); - if ( p_dev ) + if ( dh != MBG_INVALID_DEV_HANDLE ) { - if ( _pcps_has_event_time( p_dev ) ) + if ( mbg_rc_is_success( mbg_chk_dev_has_event_time( dh ) ) ) printf( " EVENT=<n> Set event time to system time + <n> seconds.\n" ); } @@ -2924,7 +2931,7 @@ const char *str_parm_p( const char *s, const char *keyword ) static /*HDR*/ -int check_cmd_line( int argc, char *argv[], MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev, +int check_cmd_line( int argc, char *argv[], MBG_DEV_HANDLE dh, RECEIVER_INFO *p_ri, RECEIVER_PORT_CFG *p_rpcfg ) { const char *sdate = NULL; @@ -2933,9 +2940,12 @@ int check_cmd_line( int argc, char *argv[], MBG_DEV_HANDLE dh, const PCPS_DEV *p int i; int rc = MBG_SUCCESS; int error_occurred = 0; - + bool is_gps = false; must_print_usage = false; + if ( dh != MBG_INVALID_DEV_HANDLE ) + is_gps = mbg_rc_is_success( mbg_chk_dev_is_gps( dh ) ); + for ( i = 1; i < argc; i++ ) { if ( mbg_rc_is_error( rc ) ) @@ -2956,12 +2966,12 @@ int check_cmd_line( int argc, char *argv[], MBG_DEV_HANDLE dh, const PCPS_DEV *p if ( strcmp( argv[i], "COLDBOOT" ) == 0 ) { - if ( p_dev ) + if ( dh != MBG_INVALID_DEV_HANDLE ) { - if ( _pcps_is_gps( p_dev ) ) + if ( is_gps ) rc = send_gps_cmd( dh, PC_GPS_CMD_INIT_SYS ); else - err_msg( p_dev, no_gps_cmd ); + err_msg( no_gps_cmd ); } continue; } @@ -2969,12 +2979,12 @@ int check_cmd_line( int argc, char *argv[], MBG_DEV_HANDLE dh, const PCPS_DEV *p if ( strcmp( argv[i], "BOOT" ) == 0 ) { - if ( p_dev ) + if ( dh != MBG_INVALID_DEV_HANDLE ) { - if ( _pcps_is_gps( p_dev ) ) + if ( is_gps ) rc = send_gps_cmd( dh, PC_GPS_CMD_BOOT ); else - err_msg( p_dev, no_gps_cmd ); + err_msg( no_gps_cmd ); } continue; } @@ -2984,8 +2994,8 @@ int check_cmd_line( int argc, char *argv[], MBG_DEV_HANDLE dh, const PCPS_DEV *p if ( cp ) { - if ( p_dev ) - rc = set_timezone( dh, cp, p_dev ); + if ( dh != MBG_INVALID_DEV_HANDLE ) + rc = set_timezone( dh, cp ); continue; } @@ -2995,12 +3005,12 @@ int check_cmd_line( int argc, char *argv[], MBG_DEV_HANDLE dh, const PCPS_DEV *p if ( cp ) { - if ( p_dev ) + if ( dh != MBG_INVALID_DEV_HANDLE ) { - if ( _pcps_is_gps( p_dev ) ) + if ( is_gps ) rc = set_gps_pos( dh, cp ); else - err_msg( p_dev, no_gps_cmd ); + err_msg( no_gps_cmd ); } continue; } @@ -3028,9 +3038,9 @@ int check_cmd_line( int argc, char *argv[], MBG_DEV_HANDLE dh, const PCPS_DEV *p if ( cp ) { - if ( p_dev ) + if ( dh != MBG_INVALID_DEV_HANDLE ) { - int rc = check_get_receiver_port_cfg( dh, p_rpcfg, p_dev, p_ri ); + int rc = check_get_receiver_port_cfg( dh, p_rpcfg, p_ri ); if ( mbg_rc_is_error( rc ) ) { @@ -3047,7 +3057,7 @@ int check_cmd_line( int argc, char *argv[], MBG_DEV_HANDLE dh, const PCPS_DEV *p continue; } - show_serial_settings( dh, p_rpcfg, p_ri ); + show_serial_settings( p_rpcfg, p_ri ); } else printf( "** This device does not provide a configurable COM port.\n" ); @@ -3061,12 +3071,12 @@ int check_cmd_line( int argc, char *argv[], MBG_DEV_HANDLE dh, const PCPS_DEV *p if ( cp ) { - if ( p_dev ) + if ( dh != MBG_INVALID_DEV_HANDLE ) { char *p_tail; ulong port_num; - rc = check_get_receiver_port_cfg( dh, p_rpcfg, p_dev, p_ri ); + rc = check_get_receiver_port_cfg( dh, p_rpcfg, p_ri ); if ( mbg_rc_is_error( rc ) ) { @@ -3100,7 +3110,7 @@ int check_cmd_line( int argc, char *argv[], MBG_DEV_HANDLE dh, const PCPS_DEV *p continue; } - rc = save_serial_settings( dh, (unsigned) port_num, ++cp, p_dev, p_ri ); + rc = save_serial_settings( dh, (unsigned) port_num, ++cp, p_ri ); } continue; } @@ -3110,7 +3120,7 @@ int check_cmd_line( int argc, char *argv[], MBG_DEV_HANDLE dh, const PCPS_DEV *p if ( cp ) { - if ( p_dev ) + if ( dh != MBG_INVALID_DEV_HANDLE ) { ulong n_pout; ulong pout_num; @@ -3129,7 +3139,7 @@ int check_cmd_line( int argc, char *argv[], MBG_DEV_HANDLE dh, const PCPS_DEV *p if ( p_tail == cp ) // No POUT number specified. { - show_pout( dh, &ohs_pout, p_dev, "Current programmable outputs settings" ); + show_pout( dh, &ohs_pout, "Current programmable outputs settings" ); continue; } @@ -3152,7 +3162,7 @@ int check_cmd_line( int argc, char *argv[], MBG_DEV_HANDLE dh, const PCPS_DEV *p rc = eval_pout( dh, ++cp, (unsigned) pout_num ); printf( "\n" ); - show_pout( dh, &ohs_pout, p_dev, "Current programmable outputs settings" ); + show_pout( dh, &ohs_pout, "Current programmable outputs settings" ); } continue; } @@ -3162,19 +3172,19 @@ int check_cmd_line( int argc, char *argv[], MBG_DEV_HANDLE dh, const PCPS_DEV *p if ( cp ) { - if ( p_dev ) + if ( dh != MBG_INVALID_DEV_HANDLE ) { char *info = "Current"; - if ( !_pcps_has_gps_data( p_dev ) ) + if ( mbg_rc_is_error( mbg_chk_dev_has_gps_data( dh ) ) ) { - err_msg( p_dev, no_enable_flags ); + err_msg( no_enable_flags ); continue; } if ( *cp == '=' ) { - rc = set_enable_flags( dh, ++cp, p_dev ); + rc = set_enable_flags( dh, ++cp ); if ( mbg_rc_is_error( rc ) ) { @@ -3186,7 +3196,7 @@ int check_cmd_line( int argc, char *argv[], MBG_DEV_HANDLE dh, const PCPS_DEV *p info = "New"; } - show_enable_flags( dh, p_dev, info ); + show_enable_flags( dh, info ); } continue; } @@ -3196,19 +3206,19 @@ int check_cmd_line( int argc, char *argv[], MBG_DEV_HANDLE dh, const PCPS_DEV *p if ( cp ) { - if ( p_dev ) + if ( dh != MBG_INVALID_DEV_HANDLE ) { char *info = "Current"; - if ( !_pcps_has_time_scale( p_dev ) ) + if ( mbg_rc_is_error( mbg_chk_dev_has_time_scale( dh ) ) ) { - err_msg( p_dev, no_time_scale ); + err_msg( no_time_scale ); continue; } if ( *cp == '=' ) { - rc = set_time_scale( dh, ++cp, p_dev ); + rc = set_time_scale( dh, ++cp ); if ( mbg_rc_is_error( rc ) ) { @@ -3219,7 +3229,7 @@ int check_cmd_line( int argc, char *argv[], MBG_DEV_HANDLE dh, const PCPS_DEV *p info = "New"; } - show_time_scale( dh, p_dev, info ); + show_time_scale( dh, info ); } continue; } @@ -3229,13 +3239,13 @@ int check_cmd_line( int argc, char *argv[], MBG_DEV_HANDLE dh, const PCPS_DEV *p if ( cp ) { - if ( p_dev ) + if ( dh != MBG_INVALID_DEV_HANDLE ) { char *info = "Current"; - if ( !_pcps_has_tzdl( p_dev ) ) + if ( mbg_rc_is_error( mbg_chk_dev_has_tzdl( dh ) ) ) { - err_msg( p_dev, no_tzdl ); + err_msg( no_tzdl ); continue; } @@ -3262,13 +3272,13 @@ int check_cmd_line( int argc, char *argv[], MBG_DEV_HANDLE dh, const PCPS_DEV *p if ( cp ) { - if ( p_dev ) + if ( dh != MBG_INVALID_DEV_HANDLE ) { char *info = "Current"; - if ( !_pcps_has_synth( p_dev ) ) + if ( mbg_rc_is_success( mbg_chk_dev_has_synth( dh ) ) ) { - err_msg( p_dev, no_synth ); + err_msg( no_synth ); continue; } @@ -3295,19 +3305,19 @@ int check_cmd_line( int argc, char *argv[], MBG_DEV_HANDLE dh, const PCPS_DEV *p if ( cp ) { - if ( p_dev ) + if ( dh != MBG_INVALID_DEV_HANDLE ) { char *info = "Current"; - if ( !_pcps_has_lan_intf( p_dev ) ) + if ( !mbg_rc_is_error( mbg_chk_dev_has_lan_intf( dh ) ) ) { - err_msg( p_dev, no_lan_intf ); + err_msg( no_lan_intf ); continue; } if ( *cp == '=' ) { - rc = set_lan_intf( dh, ++cp, p_dev ); + rc = set_lan_intf( dh, ++cp ); if ( mbg_rc_is_error( rc ) ) { @@ -3318,7 +3328,7 @@ int check_cmd_line( int argc, char *argv[], MBG_DEV_HANDLE dh, const PCPS_DEV *p info = "New"; } - show_lan_intf( dh, p_dev, info ); + show_lan_intf( dh, info ); } continue; } @@ -3328,19 +3338,19 @@ int check_cmd_line( int argc, char *argv[], MBG_DEV_HANDLE dh, const PCPS_DEV *p if ( cp ) { - if ( p_dev ) + if ( dh != MBG_INVALID_DEV_HANDLE ) { char *info = "Current"; - if ( !_pcps_has_ptp( p_dev ) ) + if ( mbg_rc_is_error( mbg_chk_dev_has_ptp( dh ) ) ) { - err_msg( p_dev, no_ptp ); + err_msg( no_ptp ); continue; } if ( *cp == '=' ) { - rc = set_ptp_cfg( dh, ++cp, p_dev ); + rc = set_ptp_cfg( dh, ++cp ); if ( mbg_rc_is_error( rc ) ) continue; @@ -3348,7 +3358,7 @@ int check_cmd_line( int argc, char *argv[], MBG_DEV_HANDLE dh, const PCPS_DEV *p info = "New"; } - show_ptp_cfg( dh, p_dev, info ); + show_ptp_cfg( dh, info ); } continue; } @@ -3357,13 +3367,13 @@ int check_cmd_line( int argc, char *argv[], MBG_DEV_HANDLE dh, const PCPS_DEV *p if ( cp ) { - if ( p_dev ) + if ( dh != MBG_INVALID_DEV_HANDLE ) { char *info = "Current"; - if ( !_pcps_has_cab_len( p_dev ) ) + if ( mbg_rc_is_error( mbg_chk_dev_has_cab_len( dh ) ) ) { - err_msg( p_dev, no_cab_len ); + err_msg( no_cab_len ); continue; } @@ -3390,9 +3400,9 @@ int check_cmd_line( int argc, char *argv[], MBG_DEV_HANDLE dh, const PCPS_DEV *p if ( cp ) { - if ( p_dev ) + if ( dh != MBG_INVALID_DEV_HANDLE ) { - if ( _pcps_has_event_time( p_dev ) ) + if ( mbg_rc_is_success( mbg_chk_dev_has_event_time( dh ) ) ) { if ( *cp == '=' ) rc = set_event_time( dh, ++cp ); @@ -3403,7 +3413,7 @@ int check_cmd_line( int argc, char *argv[], MBG_DEV_HANDLE dh, const PCPS_DEV *p printf( "*** Warning: invalid event time parameter\n" ); } else - err_msg( p_dev, no_event_time ); + err_msg( no_event_time ); } continue; } @@ -3421,10 +3431,10 @@ int check_cmd_line( int argc, char *argv[], MBG_DEV_HANDLE dh, const PCPS_DEV *p } - if ( p_dev ) + if ( dh != MBG_INVALID_DEV_HANDLE ) if ( sdate || stime ) { - rc = set_date_time( dh, p_dev, sdate, stime ); + rc = set_date_time( dh, sdate, stime, is_gps ); if ( mbg_rc_is_error( rc ) ) error_occurred = 1; @@ -3447,7 +3457,6 @@ int main( int argc, char *argv[] ) RECEIVER_PORT_CFG rpcfg = { { { 0 } } }; RECEIVER_INFO ri = { 0 }; PCPS_DEV dev = { { 0 } }; - PCPS_DEV *pdev = NULL; MBG_DEV_HANDLE dh = MBG_INVALID_DEV_HANDLE; MBG_DEV_FN tmp_dev_fn; int rc; @@ -3460,7 +3469,7 @@ int main( int argc, char *argv[] ) // Check the command line for a device name, but don't // pass a device handle, so commands are not evaluated. - check_cmd_line( argc, argv, dh, NULL, &ri, &rpcfg ); + check_cmd_line( argc, argv, dh, &ri, &rpcfg ); rc = mbg_open_device_by_param_chk( &dh, dev_name, 0, tmp_dev_fn.s, sizeof( tmp_dev_fn.s ) ); @@ -3476,9 +3485,7 @@ int main( int argc, char *argv[] ) goto fail; - pdev = &dev; - - rc = check_cmd_line( argc, argv, dh, pdev, &ri, &rpcfg ); + rc = check_cmd_line( argc, argv, dh, &ri, &rpcfg ); if ( rc < 0 ) goto fail; @@ -3494,7 +3501,7 @@ int main( int argc, char *argv[] ) show_usage: - usage( dh, pdev, &ri, &rpcfg ); + usage( dh, &ri, &rpcfg ); return MBG_EXIT_CODE_USAGE; fail: diff --git a/mbgfasttstamp/mbgfasttstamp.c b/mbgfasttstamp/mbgfasttstamp.c index 86552c4..a466071 100644 --- a/mbgfasttstamp/mbgfasttstamp.c +++ b/mbgfasttstamp/mbgfasttstamp.c @@ -1,7 +1,7 @@ /************************************************************************** * - * $Id: mbgfasttstamp.c 1.13 2021/11/15 17:08:52 martin.burnicki REL_M $ + * $Id: mbgfasttstamp.c 1.14 2022/12/21 15:13:13 martin.burnicki REL_M $ * * Description: * Main file for mbgfasttstamp program which demonstrates how to access @@ -9,6 +9,8 @@ * * ----------------------------------------------------------------------- * $Log: mbgfasttstamp.c $ + * Revision 1.14 2022/12/21 15:13:13 martin.burnicki + * Removed obsolete (PCPS_DEV *) parameter from a function. * Revision 1.13 2021/11/15 17:08:52 martin.burnicki * Improved printing of usage information. * Revision 1.12 2021/04/12 21:58:08 martin @@ -195,7 +197,7 @@ int show_fast_hr_timestamp_burst( MBG_DEV_HANDLE dh ) static /*HDR*/ -int do_mbgfasttstamp( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev ) +int do_mbgfasttstamp( MBG_DEV_HANDLE dh ) { int rc = mbg_chk_dev_has_fast_hr_timestamp( dh ); diff --git a/mbggpscap/mbggpscap.c b/mbggpscap/mbggpscap.c index be3e77b..5449943 100644 --- a/mbggpscap/mbggpscap.c +++ b/mbggpscap/mbggpscap.c @@ -1,7 +1,7 @@ /************************************************************************** * - * $Id: mbggpscap.c 1.20 2021/11/15 17:08:53 martin.burnicki REL_M $ + * $Id: mbggpscap.c 1.21 2022/12/21 15:16:24 martin.burnicki REL_M $ * * Description: * Main file for mbggpscap program which demonstrates how to access @@ -13,6 +13,10 @@ * * ----------------------------------------------------------------------- * $Log: mbggpscap.c $ + * Revision 1.21 2022/12/21 15:16:24 martin.burnicki + * Improved error handling, message output, and comments. + * Removed obsolete (PCPS_DEV *) parameter from some functions, + * and use feature check functions instead of macros. * Revision 1.20 2021/11/15 17:08:53 martin.burnicki * Improved printing of usage information. * Revision 1.19 2021/04/12 21:57:50 martin @@ -131,14 +135,16 @@ static /*HDR*/ * * @param[in] dh Valid ::MBG_DEV_HANDLE handle to a Meinberg device. * @param[out] p_uce Address of a ::PCPS_UCAP_ENTRIES variable to be filled. - * @param[in] info An optional string to be printed before the buffer information, may be @a NULL. + * @param[in] info_1 An optional string to be printed before the buffer information, may be @a NULL. + * @param[in] info_2 An optional string to be appended to the buffer information, may be @a NULL. * * @return ::MBG_SUCCESS on success, else one of the @ref MBG_ERROR_CODES. * * @see ::show_ucap_event * @see ::mbg_get_ucap_entries */ -int show_ucap_entries( MBG_DEV_HANDLE dh, PCPS_UCAP_ENTRIES *p_uce, const char *info ) +int show_ucap_entries( MBG_DEV_HANDLE dh, PCPS_UCAP_ENTRIES *p_uce, + const char *info_1, const char *info_2 ) { int rc = mbg_get_ucap_entries( dh, p_uce ); @@ -150,11 +156,15 @@ int show_ucap_entries( MBG_DEV_HANDLE dh, PCPS_UCAP_ENTRIES *p_uce, const char * if ( p_uce->max ) p_uce->max--; - if ( info ) - printf( "%s", info ); + if ( info_1 ) + printf( "%s", info_1 ); - printf( "%u of %u entries used\n", + printf( "%u of %u entries", p_uce->used, p_uce->max ); + + if ( info_2 ) + printf( "%s", info_2 ); + } return rc; @@ -341,19 +351,18 @@ static /*HDR*/ * So we check and print a warning if this may be the case. * * @param[in] dh Valid ::MBG_DEV_HANDLE handle to a Meinberg device. - * @param[in] p_dev Pointer do a device info structure for the device. * * @see ::mbg_get_ucap_event * @see ::mbg_get_gps_ucap */ -void check_serial_mode( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev ) +void check_serial_mode( MBG_DEV_HANDLE dh ) { RECEIVER_INFO ri; RECEIVER_PORT_CFG rpcfg; int i; int must_warn = 0; - int rc = mbg_setup_receiver_info( dh, p_dev, &ri ); + int rc = mbg_setup_receiver_info( dh, NULL, &ri ); if ( mbg_cond_err_msg( rc, "mbg_setup_receiver_info" ) ) return; @@ -362,7 +371,7 @@ void check_serial_mode( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev ) return; // so there's nothing to check. // Read the current serial port settings from the device. - rc = mbg_get_serial_settings( dh, p_dev, &rpcfg, &ri ); + rc = mbg_get_serial_settings( dh, &rpcfg, &ri ); if ( mbg_cond_err_msg( rc, "mbg_get_serial_settings" ) ) return; @@ -401,10 +410,35 @@ void check_serial_mode( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev ) static /*HDR*/ -int do_mbggpscap( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev ) +void check_clear_buffer( MBG_DEV_HANDLE dh, PCPS_UCAP_ENTRIES *p_ucap_entries ) { int rc; - int this_clear_buffer = clear_buffer; + + printf( "\nClearing the on-board FIFO buffer" ); + + rc = mbg_chk_dev_can_clr_ucap_buff( dh ); + + if ( mbg_rc_is_success( rc ) ) + { + printf( ".\n" ); + mbg_clr_ucap_buff( dh ); + } + else + printf( ": %s\n", mbg_strerror( rc ) ); + + if ( p_ucap_entries ) + show_ucap_entries( dh, p_ucap_entries, NULL, " remaining.\n" ); + +} // check_clear_buffer + + + +static /*HDR*/ +int do_mbggpscap( MBG_DEV_HANDLE dh ) +{ + int rc; + bool dev_has_ucap = mbg_rc_is_success( mbg_chk_dev_has_ucap( dh ) ); + bool dev_is_gps = mbg_rc_is_success( mbg_chk_dev_is_gps( dh ) ); must_check_intv = continuous && ( nom_cap_intv != 0 ); jitter_exceed_cnt = 0; @@ -412,15 +446,15 @@ int do_mbggpscap( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev ) buf_overrun_cnt = 0; has_been_called = 0; - if ( !_pcps_has_ucap( p_dev ) && !_pcps_is_gps( p_dev ) ) + if ( !( dev_has_ucap || dev_is_gps ) ) { printf( "This device type does not provide time capture inputs.\n" ); return 0; } - check_serial_mode( dh, p_dev ); + check_serial_mode( dh ); - printf( "Be sure the device has been properly configured to enable capture inputs.\n" ); + printf( "Be sure the device has been properly configured to enable capture inputs.\n\n" ); // There's an older API which has been introduced with the first GPS devices // and uses the TTM structure to return the capture events. However, that @@ -429,7 +463,7 @@ int do_mbggpscap( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev ) // The new API calls are supported by all newer devices that provide // user capture inputs, and also for older devices with a firmware update. - if ( !force_old_api && _pcps_has_ucap( p_dev ) ) // Check if the new API is supported. + if ( !force_old_api && dev_has_ucap ) // Use the new API. { PCPS_UCAP_ENTRIES ucap_entries; struct timespec prv_t = { 0 }; @@ -438,23 +472,20 @@ int do_mbggpscap( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev ) // The new API provides the following functions: // mbg_clr_ucap_buff() Clear the on-board FIFO buffer. - // mbg_get_ucap_entries() Het the max number of FIFO entries, and the current number of entries. + // mbg_get_ucap_entries() Get the max number of FIFO entries, and the current number of entries. // mbg_get_ucap_event() Read one entry from the FIFO. - show_ucap_entries( dh, &ucap_entries, "\nOn-board FIFO: " ); + show_ucap_entries( dh, &ucap_entries, "On-board FIFO: ", " used.\n" ); - if ( this_clear_buffer ) - { - printf( "Clearing on-board FIFO buffer\n" ); - mbg_clr_ucap_buff( dh ); - this_clear_buffer = 0; - } + if ( clear_buffer ) + check_clear_buffer( dh, &ucap_entries ); // If the program is not to run continuously, and no // capture events are available, we're done. if ( query_only || ( !continuous && ucap_entries.used == 0 ) ) return 0; + printf( "\n" ); clock_gettime( CLOCK_MONOTONIC, &prv_t ); @@ -517,7 +548,7 @@ int do_mbggpscap( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev ) if ( must_check_intv ) printf( " %" PRIu64 " jitter ovr., ", jitter_exceed_cnt ); - show_ucap_entries( dh, &ucap_entries, NULL ); + show_ucap_entries( dh, &ucap_entries, NULL, NULL ); prv_t = t; prv_events = events; @@ -531,6 +562,9 @@ int do_mbggpscap( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev ) } else // Use the old API. { + if ( clear_buffer ) + printf( "Clearing the buffer is not supported by the old API.\n" ); + printf( "Checking for capture events using the old API:\n" ); for (;;) diff --git a/mbghrtime/mbghrtime.c b/mbghrtime/mbghrtime.c index 1bbd190..ff49db3 100644 --- a/mbghrtime/mbghrtime.c +++ b/mbghrtime/mbghrtime.c @@ -1,7 +1,7 @@ /************************************************************************** * - * $Id: mbghrtime.c 1.19 2021/11/15 17:08:53 martin.burnicki REL_M $ + * $Id: mbghrtime.c 1.20 2022/12/21 15:17:28 martin.burnicki REL_M $ * * Description: * Main file for mbghrtime program which demonstrates how to access @@ -10,6 +10,8 @@ * * ----------------------------------------------------------------------- * $Log: mbghrtime.c $ + * Revision 1.20 2022/12/21 15:17:28 martin.burnicki + * Removed obsolete (PCPS_DEV *) parameter from a function. * Revision 1.19 2021/11/15 17:08:53 martin.burnicki * Improved printing of usage information. * Revision 1.18 2021/04/12 21:58:02 martin @@ -221,7 +223,7 @@ out: static /*HDR*/ -int do_mbghrtime( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev ) +int do_mbghrtime( MBG_DEV_HANDLE dh ) { int rc = mbg_chk_dev_has_hr_time( dh ); 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 ) { diff --git a/mbglib/common/cfg_hlp.c b/mbglib/common/cfg_hlp.c index 0a0f8bd..1b3d1ac 100644 --- a/mbglib/common/cfg_hlp.c +++ b/mbglib/common/cfg_hlp.c @@ -1,7 +1,7 @@ /************************************************************************** * - * $Id: cfg_hlp.c 1.5 2019/09/27 14:16:40 martin REL_M $ + * $Id: cfg_hlp.c 1.5.2.2 2022/12/19 15:48:24 martin.burnicki REL_M $ * * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany * @@ -10,7 +10,12 @@ * * ----------------------------------------------------------------------- * $Log: cfg_hlp.c $ - * Revision 1.5 2019/09/27 14:16:40 martin + * Revision 1.5.2.2 2022/12/19 15:48:24 martin.burnicki + * Removed obsolete _int_from_size_t() stuff. + * Revision 1.5.2.1 2022/12/15 16:02:41Z martin.burnicki + * Fix potential compiler warnings, and optionally exclude code + * from build using preprocessor symbol OMIT_PTPV2. + * Revision 1.5 2019/09/27 14:16:40Z martin * Merged changes from 1.3.1.33: * Support for next gen PTP config API added by thomas-b. * XMR improvements by philipp. @@ -830,7 +835,7 @@ int mbg_snprint_revision( char *s, size_t max_len, const char *prefix, const char *suffix, uint32_t rev ) { - size_t n = 0; + int n = 0; uint32_t major, minor, patch; if ( prefix ) @@ -844,7 +849,7 @@ int mbg_snprint_revision( char *s, size_t max_len, if ( suffix ) n += snprintf_safe( &s[n], max_len - n, "%s", suffix ); - return _int_from_size_t( n ); + return n; } // mbg_snprint_revision @@ -1608,6 +1613,8 @@ void free_all_ptp_v1_common_datasets( ALL_PTP_V1_COMMON_DATASETS *p ) +#if !OMIT_PTPV2 + /*HDR*/ /** * @brief Free an ::ALL_PTP_V2_COMMON_DATASETS structure allocated by ::mbgextio_get_all_ptp_v2_common_datasets @@ -1628,6 +1635,8 @@ void free_all_ptp_v2_common_datasets( ALL_PTP_V2_COMMON_DATASETS *p ) } // free_all_ptp_v2_common_datasets +#endif // !OMIT_PTPV2 + /*HDR*/ @@ -3395,9 +3404,9 @@ void cnvrt_long_to_bytes( uint8_t byte_array[], int num_bytes, uint64_t val ) /*HDR*/ -size_t nw_str_mac_addr_to_str( MBG_MAC_ADDR *mac_addr, char *buf, size_t buflen ) +int nw_str_mac_addr_to_str( MBG_MAC_ADDR *mac_addr, char *buf, size_t buflen ) { - size_t len = 0; + int len = 0; if ( !mac_addr || !buf ) return len; diff --git a/mbglib/common/cfg_hlp.h b/mbglib/common/cfg_hlp.h index 5b71d41..48a5109 100644 --- a/mbglib/common/cfg_hlp.h +++ b/mbglib/common/cfg_hlp.h @@ -1,7 +1,7 @@ /************************************************************************** * - * $Id: cfg_hlp.h 1.7 2019/09/27 14:24:45 martin REL_M $ + * $Id: cfg_hlp.h 1.7.3.1 2022/12/15 16:06:36 martin.burnicki REL_M $ * * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany * @@ -19,7 +19,10 @@ * * ----------------------------------------------------------------------- * $Log: cfg_hlp.h $ - * Revision 1.7 2019/09/27 14:24:45 martin + * Revision 1.7.3.1 2022/12/15 16:06:36 martin.burnicki + * Fix potential compiler warnings, and optionally exclude code + * from build using preprocessor symbol OMIT_PTPV2. + * Revision 1.7 2019/09/27 14:24:45Z martin * New structure definitions to support new API features. * Struct names were added by thomas-b to support forward declarations. * Some new inline functions. @@ -99,6 +102,11 @@ #endif // _PRELIMINARY_CODE +#if OMIT_PTPV2 + typedef int ALL_PTP_V2_COMMON_DATASETS; // Dummy declaration. +#endif + + #ifdef _CFG_HLP #define _ext #define _DO_INIT @@ -469,6 +477,8 @@ typedef struct +#if !OMIT_PTPV2 + /** * @brief All PTPv2 common datasets for a PTP device * @@ -493,6 +503,7 @@ typedef struct } ALL_PTP_V2_COMMON_DATASETS; +#endif // !OMIT_PTPV2 typedef struct mbg_sys_ref_src @@ -2050,7 +2061,7 @@ MBG_TLV_UID mbg_tlv_create_id( void ) */ void cnvrt_long_to_bytes( uint8_t byte_array[], int num_bytes, uint64_t val ) ; - size_t nw_str_mac_addr_to_str( MBG_MAC_ADDR *mac_addr, char *buf, size_t buflen ) ; + int nw_str_mac_addr_to_str( MBG_MAC_ADDR *mac_addr, char *buf, size_t buflen ) ; int nw_str_to_mac_addr( MBG_MAC_ADDR *mac_addr, const char *str ) ; int nw_ip6_addr_bytes_to_str( const uint8_t *addr, uint8_t protocol, char *str, size_t buflen ) ; int nw_str_to_ip6_addr_bytes( uint8_t *addr, const uint8_t protocol, char *str, size_t buflen ) ; diff --git a/mbglib/common/chk_time_info.c b/mbglib/common/chk_time_info.c index bb8cedc..fe16852 100644 --- a/mbglib/common/chk_time_info.c +++ b/mbglib/common/chk_time_info.c @@ -1,7 +1,7 @@ /************************************************************************** * - * $Id: chk_time_info.c 1.10 2021/04/29 14:20:17 martin REL_M $ + * $Id: chk_time_info.c 1.11 2022/12/21 14:41:52 martin.burnicki REL_M $ * * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany * @@ -10,6 +10,9 @@ * * ----------------------------------------------------------------------- * $Log: chk_time_info.c $ + * Revision 1.11 2022/12/21 14:41:52 martin.burnicki + * Removed obsolete _int_from_size_t() stuff. + * Preliminary changes to fix Windows build. * Revision 1.10 2021/04/29 14:20:17 martin * Variable pc_cycles_frequency was renamed to mbg_pc_cycles_frequency. * Revision 1.9 2021/04/12 22:16:34 martin @@ -45,7 +48,10 @@ #undef _CHK_TIME_INFO #include <str_util.h> -#include <toolutil.h> // Common utility functions. + +#if !defined( _IS_MBGADJTM ) + #include <toolutil.h> // FIXME TODO This should be supported. +#endif #include <stdio.h> @@ -101,8 +107,16 @@ void mbg_proc_chk_time_info( MBG_CHK_TIME_INFO *p_cti, CYCLES_FILTER_DATA *p_fil MBG_SYS_TIME_CYCLES *p_sys_tic = &p_cti->hrti.sys_time_cycles; // The system time cycles. // Convert both timestamps to floating point format. - p_cti->d_sys = (double) p_sys_tic->sys_time.secs + ( (double) p_sys_tic->sys_time.nano_secs / NSEC_PER_SEC ); - p_cti->d_ref = (double) p_ref_ts->sec + ( ( (double) p_ref_ts->frac ) / (double) MBG_FRAC32_UNITS_PER_SEC ); + // TODO We should use a function that implements this + // according to the target OS. + #if defined( MBG_TGT_WIN32 ) + #if !defined( _IS_MBGADJTM ) + #error This needs to be implemented! + #endif + #else + p_cti->d_sys = (double) p_sys_tic->sys_time.secs + ( (double) p_sys_tic->sys_time.nano_secs / NSEC_PER_SEC ); + p_cti->d_ref = (double) p_ref_ts->sec + ( ( (double) p_ref_ts->frac ) / (double) MBG_FRAC32_UNITS_PER_SEC ); + #endif // Compute the cycles deltas and limit. p_cti->ltcy_cyc = mbg_delta_pc_cycles( p_ref_cyc, &p_sys_tic->cyc_after ); @@ -113,9 +127,17 @@ void mbg_proc_chk_time_info( MBG_CHK_TIME_INFO *p_cti, CYCLES_FILTER_DATA *p_fil { // If the cycles frequency is known, also // compute the cycles deltas and limit as [s]. - p_cti->ltcy_sec = ( (double) p_cti->ltcy_cyc ) / (double) mbg_pc_cycles_frequency; - p_cti->exec_sec = ( (double) p_cti->exec_cyc ) / (double) mbg_pc_cycles_frequency; - p_cti->exec_sec_limit = ( (double) p_cti->exec_cyc_limit ) / (double) mbg_pc_cycles_frequency; + // TODO We should use a function that implements this + // according to the target OS. + #if defined( MBG_TGT_WIN32 ) + #if !defined( _IS_MBGADJTM ) + #error This needs to be implemented! + #endif + #else + p_cti->ltcy_sec = ( (double) p_cti->ltcy_cyc ) / (double) mbg_pc_cycles_frequency; + p_cti->exec_sec = ( (double) p_cti->exec_cyc ) / (double) mbg_pc_cycles_frequency; + p_cti->exec_sec_limit = ( (double) p_cti->exec_cyc_limit ) / (double) mbg_pc_cycles_frequency; + #endif } // The system timestamp and device timestamp have been read @@ -210,6 +232,8 @@ int mbg_chk_time_info( MBG_DEV_HANDLE dh, MBG_CHK_TIME_INFO *p_cti, CYCLES_FILTE +#if !defined( _IS_MBGADJTM ) // FIXME we should support this. + /*HDR*/ /** * @brief Print a device name into a string buffer. @@ -250,7 +274,7 @@ int snprint_chk_time_dev_name( char *s, size_t max_len, const char *dev_name ) int snprint_chk_time_info( char *s, size_t max_len, const MBG_CHK_TIME_INFO *p_cti, const PCPS_DEV *p_dev, int frac_digits, int print_raw ) { - size_t n = 0; + int n = 0; if ( p_dev ) n += snprint_chk_time_dev_name( &s[n], max_len - n, _pcps_type_name( p_dev ) ); @@ -281,7 +305,9 @@ int snprint_chk_time_info( char *s, size_t max_len, const MBG_CHK_TIME_INFO *p_c n += snprintf_safe( &s[n], max_len - n, ", raw: %+.*f", frac_digits, p_cti->d_ref - p_cti->d_sys ); - return _int_from_size_t( n ); + return n; } // snprint_chk_time_info +#endif // !defined( _IS_MBGADJTM ) + diff --git a/mbglib/common/cmp_time_util.c b/mbglib/common/cmp_time_util.c index 649c702..8ec203f 100644 --- a/mbglib/common/cmp_time_util.c +++ b/mbglib/common/cmp_time_util.c @@ -1,7 +1,7 @@ /************************************************************************** * - * $Id: cmp_time_util.c 1.9 2021/04/29 14:20:20 martin REL_M $ + * $Id: cmp_time_util.c 1.10 2022/12/21 14:48:23 martin.burnicki REL_M $ * * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany * @@ -10,6 +10,9 @@ * * ----------------------------------------------------------------------- * $Log: cmp_time_util.c $ + * Revision 1.10 2022/12/21 14:48:23 martin.burnicki + * Removed obsolete (PCPS_DEV *) parameters from a function. + * Removed some obsolete _int_from_size_t() stuff. * Revision 1.9 2021/04/29 14:20:20 martin * Variable pc_cycles_frequency was renamed to mbg_pc_cycles_frequency. * Revision 1.8 2021/03/22 10:09:38 martin @@ -52,25 +55,22 @@ * @brief Check if both devices support fast HR timestamps. * * @param[in] dh1 Handle of the first device. - * @param[in] p_dev_1 Device info of the first device. * @param[in] dh2 Handle of the second device. - * @param[in] p_dev_2 Device info of the second device. * @param[in] err_msg_fnc Pointer to a function to be called in case of error. * * @return ::MBG_SUCCESS on success, else one of the @ref MBG_ERROR_CODES. */ -int chk_fast_tstamp_supp( MBG_DEV_HANDLE dh1, const PCPS_DEV *p_dev_1, - MBG_DEV_HANDLE dh2, const PCPS_DEV *p_dev_2, +int chk_fast_tstamp_supp( MBG_DEV_HANDLE dh1, MBG_DEV_HANDLE dh2, MBG_ERR_MSG_FNC err_msg_fnc ) { int rc; const char n_supp_msg[] = "fast (memory mapped) time stamps"; - rc = chk_feat_supp( dh1, p_dev_1, mbg_chk_dev_has_fast_hr_timestamp, + rc = chk_feat_supp( dh1, mbg_chk_dev_has_fast_hr_timestamp, err_msg_fnc, n_supp_msg ); if ( mbg_rc_is_success( rc ) ) - rc = chk_feat_supp( dh2, p_dev_2, mbg_chk_dev_has_fast_hr_timestamp, + rc = chk_feat_supp( dh2, mbg_chk_dev_has_fast_hr_timestamp, err_msg_fnc, n_supp_msg ); return rc; @@ -302,7 +302,7 @@ int mbg_snprint_hr_tstamp_ext( char *s, int max_len, */ int mbg_snprint_hr_time_loc( char *s, size_t max_len, const PCPS_HR_TIME *p ) { - size_t n = mbg_snprint_hr_tstamp( s, max_len, &p->tstamp, p->utc_offs, 0 ); + int n = mbg_snprint_hr_tstamp( s, max_len, &p->tstamp, p->utc_offs, 0 ); n += snprintf_safe( &s[n], max_len - n, " UTC" ); @@ -316,7 +316,7 @@ int mbg_snprint_hr_time_loc( char *s, size_t max_len, const PCPS_HR_TIME *p ) ldt.quot, ldt.rem ); #endif - return _int_from_size_t( n ); + return n; } // mbg_snprint_hr_time_loc diff --git a/mbglib/common/cmp_time_util.h b/mbglib/common/cmp_time_util.h index 5b0a32e..31f5e2d 100644 --- a/mbglib/common/cmp_time_util.h +++ b/mbglib/common/cmp_time_util.h @@ -1,7 +1,7 @@ /************************************************************************** * - * $Id: cmp_time_util.h 1.5 2021/03/22 17:37:32 martin REL_M $ + * $Id: cmp_time_util.h 1.6 2022/12/21 14:49:56 martin.burnicki REL_M $ * * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany * @@ -10,6 +10,8 @@ * * ----------------------------------------------------------------------- * $Log: cmp_time_util.h $ + * Revision 1.6 2022/12/21 14:49:56 martin.burnicki + * Removed obsolete (PCPS_DEV *) parameters from a function. * Revision 1.5 2021/03/22 17:37:32 martin * Updated some comments. * Revision 1.4 2021/03/12 14:20:20 martin @@ -71,14 +73,12 @@ extern "C" { * @brief Check if both devices support fast HR timestamps. * * @param[in] dh1 Handle of the first device. - * @param[in] p_dev_1 Device info of the first device. * @param[in] dh2 Handle of the second device. - * @param[in] p_dev_2 Device info of the second device. * @param[in] err_msg_fnc Pointer to a function to be called in case of error. * * @return ::MBG_SUCCESS on success, else one of the @ref MBG_ERROR_CODES. */ - int chk_fast_tstamp_supp( MBG_DEV_HANDLE dh1, const PCPS_DEV *p_dev_1, MBG_DEV_HANDLE dh2, const PCPS_DEV *p_dev_2, MBG_ERR_MSG_FNC err_msg_fnc ) ; + int chk_fast_tstamp_supp( MBG_DEV_HANDLE dh1, MBG_DEV_HANDLE dh2, MBG_ERR_MSG_FNC err_msg_fnc ) ; /** * @brief Read timestamps and cycles from both devices. diff --git a/mbglib/common/ctrydttm.c b/mbglib/common/ctrydttm.c index d4e5221..a7eca19 100644 --- a/mbglib/common/ctrydttm.c +++ b/mbglib/common/ctrydttm.c @@ -1,7 +1,7 @@ /************************************************************************** * - * $Id: ctrydttm.c 1.10 2018/12/11 16:01:46 martin REL_M $ + * $Id: ctrydttm.c 1.11 2022/12/21 15:48:09 martin.burnicki REL_M $ * * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany * @@ -11,6 +11,9 @@ * * ----------------------------------------------------------------------- * $Log: ctrydttm.c $ + * Revision 1.11 2022/12/21 15:48:09 martin.burnicki + * Removed some obsolete _int_from_size_t() stuff. + * Quieted some potential compiler warnings. * Revision 1.10 2018/12/11 16:01:46 martin * Use standard int types for more compatibility. * Revision 1.9 2018/12/11 11:49:00Z martin @@ -96,11 +99,11 @@ int snprint_ctry_wday( char *s, size_t max_len, int wday, LANGUAGE language ) /*HDR*/ -int snprint_ctry_dt_short( char *s, size_t max_len, int mday, int month ) +int snprint_ctry_dt_short( char *s, size_t max_len, uint mday, uint month ) { - uchar tmp_1; - uchar tmp_2; - ushort n = 0; + uint tmp_1; + uint tmp_2; + int n; switch ( ctry.dt_fmt ) { @@ -130,7 +133,7 @@ int snprint_ctry_dt_short( char *s, size_t max_len, int mday, int month ) /*HDR*/ int snprint_ctry_dt( char *s, size_t max_len, int mday, int month, int year ) { - size_t n = 0; + int n = 0; if ( ctry.dt_fmt == DT_FMT_YYYYMMDD ) { @@ -146,7 +149,7 @@ int snprint_ctry_dt( char *s, size_t max_len, int mday, int month, int year ) n += snprint_04u( &s[n], max_len - n, year ); } - return _int_from_size_t( n ); + return n; } // snprint_ctry_dt @@ -155,11 +158,11 @@ int snprint_ctry_dt( char *s, size_t max_len, int mday, int month, int year ) /*HDR*/ int snprint_ctry_tm_short( char *s, size_t max_len, uchar hour, uchar minute ) { - size_t n = snprint_02u( s, max_len, hour ); + int n = snprint_02u( s, max_len, hour ); n += sn_cpy_char_safe( &s[n], max_len - n, ctry.tm_sep ); n += snprint_02u( &s[n], max_len - n, minute ); - return _int_from_size_t( n ); + return n; } // snprint_ctry_tm_short @@ -168,11 +171,11 @@ int snprint_ctry_tm_short( char *s, size_t max_len, uchar hour, uchar minute ) /*HDR*/ int snprint_ctry_tm( char *s, size_t max_len, uchar hour, uchar minute, uchar second ) { - size_t n = snprint_ctry_tm_short( s, max_len, hour, minute ); + int n = snprint_ctry_tm_short( s, max_len, hour, minute ); n += sn_cpy_char_safe( &s[n], max_len - n, ctry.tm_sep ); n += snprint_02u( &s[n], max_len - n, second ); - return _int_from_size_t( n ); + return n; } // snprint_ctry_tm @@ -182,11 +185,11 @@ int snprint_ctry_tm( char *s, size_t max_len, uchar hour, uchar minute, uchar se int snprint_ctry_tm_long( char *s, size_t max_len, uchar hour, uchar minute, uchar second, long frac, ushort frac_digits ) { - size_t n = snprint_ctry_tm( s, max_len, hour, minute, second ); + int n = snprint_ctry_tm( s, max_len, hour, minute, second ); n += sn_cpy_char_safe( &s[n], max_len - n, '.' ); n += snprintf_safe( &s[n], max_len - n, "%0*lu", frac_digits, frac ); - return _int_from_size_t( n ); + return n; } // snprint_ctry_tm_long diff --git a/mbglib/common/ctrydttm.h b/mbglib/common/ctrydttm.h index 2c1d46a..b671d34 100644 --- a/mbglib/common/ctrydttm.h +++ b/mbglib/common/ctrydttm.h @@ -1,7 +1,7 @@ /************************************************************************** * - * $Id: ctrydttm.h 1.7 2018/12/11 16:01:48 martin REL_M $ + * $Id: ctrydttm.h 1.8 2022/12/21 15:48:53 martin.burnicki REL_M $ * * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany * @@ -10,6 +10,8 @@ * * ----------------------------------------------------------------------- * $Log: ctrydttm.h $ + * Revision 1.8 2022/12/21 15:48:53 martin.burnicki + * Updated function prototypes. * Revision 1.7 2018/12/11 16:01:48 martin * Updated function prototypes. * Revision 1.6 2018/01/02 16:15:06Z martin @@ -62,7 +64,7 @@ extern "C" { int snprint_02u( char *s, size_t max_len, unsigned int uc ) ; int snprint_04u( char *s, size_t max_len, unsigned int us ) ; int snprint_ctry_wday( char *s, size_t max_len, int wday, LANGUAGE language ) ; - int snprint_ctry_dt_short( char *s, size_t max_len, int mday, int month ) ; + int snprint_ctry_dt_short( char *s, size_t max_len, uint mday, uint month ) ; int snprint_ctry_dt( char *s, size_t max_len, int mday, int month, int year ) ; int snprint_ctry_tm_short( char *s, size_t max_len, uchar hour, uchar minute ) ; int snprint_ctry_tm( char *s, size_t max_len, uchar hour, uchar minute, uchar second ) ; diff --git a/mbglib/common/deviohlp.c b/mbglib/common/deviohlp.c index 67f0885..0d2e3c8 100644 --- a/mbglib/common/deviohlp.c +++ b/mbglib/common/deviohlp.c @@ -1,7 +1,7 @@ /************************************************************************** * - * $Id: deviohlp.c 1.10 2022/06/30 09:09:59 martin.burnicki REL_M $ + * $Id: deviohlp.c 1.11 2022/08/24 16:25:29 martin.burnicki REL_M $ * * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany * @@ -18,6 +18,8 @@ * * ----------------------------------------------------------------------- * $Log: deviohlp.c $ + * Revision 1.11 2022/08/24 16:25:29 martin.burnicki + * Removed obsolete function parameters. * Revision 1.10 2022/06/30 09:09:59 martin.burnicki * Prepare for variants of some functions, and some style cleanup. * Revision 1.9 2021/03/22 17:57:27 martin @@ -85,7 +87,7 @@ /*HDR*/ -int chk_feat_supp( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev, MBG_CHK_SUPP_FNC *chk_supp_fnc, +int chk_feat_supp( MBG_DEV_HANDLE dh, MBG_CHK_SUPP_FNC *chk_supp_fnc, MBG_ERR_MSG_FNC *err_msg_fnc, const char *not_supp_msg ) { const char *cp = NULL; @@ -122,7 +124,7 @@ int chk_feat_supp( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev, MBG_CHK_SUPP_FNC *c fail: if ( err_msg_fnc && cp ) - err_msg_fnc( p_dev, cp ); + err_msg_fnc( cp ); out: return rc; @@ -235,7 +237,6 @@ out: * to write the modified serial port configuration back to the device. * * @param[in] dh Valid handle to a Meinberg device. - * @param[in] p_obs Obsolete pointer kept for compatibility, should be @a NULL. * @param[out] p_rpcfg Pointer to a ::RECEIVER_PORT_CFG structure to be filled up. * @param[in] p_ri Pointer to a valid ::RECEIVER_INFO structure. * @@ -246,7 +247,6 @@ out: * @see ::mbg_save_serial_settings */ int mbg_get_serial_settings( MBG_DEV_HANDLE dh, - const void *p_obs, RECEIVER_PORT_CFG *p_rpcfg, const RECEIVER_INFO *p_ri ) { @@ -344,7 +344,6 @@ out: * have to be passed to this function. * * @param[in] dh Valid handle to a Meinberg device. - * @param[in] p_obs Obsolete pointer kept for compatibility, should be @a NULL. * @param[in] p_rpcfg Pointer to a valid ::RECEIVER_PORT_CFG structure. * @param[in] port_num Index of the serial port to be saved. * @@ -354,8 +353,8 @@ out: * @see ::mbg_get_device_info * @see ::mbg_setup_receiver_info */ -int mbg_save_serial_settings( MBG_DEV_HANDLE dh, const void *p_obs, - RECEIVER_PORT_CFG *p_rpcfg, int port_num ) +int mbg_save_serial_settings( MBG_DEV_HANDLE dh, RECEIVER_PORT_CFG *p_rpcfg, + int port_num ) { int rc; @@ -1262,10 +1261,10 @@ success_out: -#if 0 && defined( DEBUG ) // ### TODO +#if 0 && defined( DEBUG ) // TODO /*HDR*/ -void test_gpio( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev, int verbose ) +void test_gpio( MBG_DEV_HANDLE dh, int verbose ) { int b; int rc; @@ -1280,7 +1279,7 @@ void test_gpio( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev, int verbose ) rc = mbg_dev_has_gpio( dh, &b ); - if ( rc != MBG_SUCCESS || !b ) + if ( mbg_rc_is_error( rc ) || !b ) { printf( "GPIO not supported, rc: %i, b: %i\n", rc, b ); return; @@ -1292,7 +1291,7 @@ void test_gpio( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev, int verbose ) rc = mbg_get_gpio_cfg_limits( dh, &gpio_cfg_limits ); - if ( rc != MBG_SUCCESS ) + if ( mbg_rc_is_error( rc ) ) { printf( "Failed to read GPIO limits, rc: %i\n", rc ); return; @@ -1302,7 +1301,7 @@ void test_gpio( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev, int verbose ) rc = mbg_get_gps_all_gpio_info( dh, all_gpio_info_idx, &gpio_cfg_limits ); - if ( rc != MBG_SUCCESS ) + if ( mbg_rc_is_error( rc ) ) printf( "Failed to read all GPIO info, rc: %i\n", rc ); if ( !( gpio_cfg_limits.flags & MBG_GPIO_CFG_LIMIT_FLAG_MASK_STATUS_SUPP ) ) @@ -1311,7 +1310,7 @@ void test_gpio( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev, int verbose ) { rc = mbg_get_gps_all_gpio_status( dh, all_gpio_status_idx, &gpio_cfg_limits ); - if ( rc != MBG_SUCCESS ) + if ( mbg_rc_is_error( rc ) ) printf( "Failed to read all GPIO status, rc: %i\n", rc ); } @@ -1394,7 +1393,7 @@ typedef struct /*HDR*/ -void test_xmr( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev, int verbose ) +void test_xmr( MBG_DEV_HANDLE dh, int verbose ) { static const char *multi_ref_names[N_MULTI_REF] = DEFAULT_MULTI_REF_NAMES; diff --git a/mbglib/common/deviohlp.h b/mbglib/common/deviohlp.h index 89afbd8..af3c1ae 100644 --- a/mbglib/common/deviohlp.h +++ b/mbglib/common/deviohlp.h @@ -1,7 +1,7 @@ /************************************************************************** * - * $Id: deviohlp.h 1.7 2022/06/30 09:10:39 martin.burnicki REL_M $ + * $Id: deviohlp.h 1.8 2022/08/24 16:25:41 martin.burnicki REL_M $ * * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany * @@ -10,6 +10,8 @@ * * ----------------------------------------------------------------------- * $Log: deviohlp.h $ + * Revision 1.8 2022/08/24 16:25:41 martin.burnicki + * Removed obsolete function parameters. * Revision 1.7 2022/06/30 09:10:39 martin.burnicki * Updated function prototypes due to some doxygen comment fixes. * Revision 1.6 2021/03/21 18:08:14 martin @@ -79,7 +81,7 @@ typedef struct -typedef int MBG_ERR_MSG_FNC( const PCPS_DEV *p_dev, const char *s ); +typedef int MBG_ERR_MSG_FNC( const char *s ); /** @@ -205,7 +207,7 @@ int _DEPRECATED_BY( "pcps_date_time_wday_is_valid" ) pcps_time_is_valid( const P /* This section was generated automatically */ /* by MAKEHDR, do not remove the comments. */ - int chk_feat_supp( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev, MBG_CHK_SUPP_FNC *chk_supp_fnc, MBG_ERR_MSG_FNC *err_msg_fnc, const char *not_supp_msg ) ; + int chk_feat_supp( MBG_DEV_HANDLE dh, MBG_CHK_SUPP_FNC *chk_supp_fnc, MBG_ERR_MSG_FNC *err_msg_fnc, const char *not_supp_msg ) ; /** * @brief Read or setup all GNSS status information. * @@ -247,7 +249,6 @@ int _DEPRECATED_BY( "pcps_date_time_wday_is_valid" ) pcps_time_is_valid( const P * to write the modified serial port configuration back to the device. * * @param[in] dh Valid handle to a Meinberg device. - * @param[in] p_obs Obsolete pointer kept for compatibility, should be @a NULL. * @param[out] p_rpcfg Pointer to a ::RECEIVER_PORT_CFG structure to be filled up. * @param[in] p_ri Pointer to a valid ::RECEIVER_INFO structure. * @@ -257,7 +258,7 @@ int _DEPRECATED_BY( "pcps_date_time_wday_is_valid" ) pcps_time_is_valid( const P * @see ::mbg_setup_receiver_info * @see ::mbg_save_serial_settings */ - int mbg_get_serial_settings( MBG_DEV_HANDLE dh, const void *p_obs, RECEIVER_PORT_CFG *p_rpcfg, const RECEIVER_INFO *p_ri ) ; + int mbg_get_serial_settings( MBG_DEV_HANDLE dh, RECEIVER_PORT_CFG *p_rpcfg, const RECEIVER_INFO *p_ri ) ; /** * @brief Write the configuration settings for a single serial port to a device. @@ -274,7 +275,6 @@ int _DEPRECATED_BY( "pcps_date_time_wday_is_valid" ) pcps_time_is_valid( const P * have to be passed to this function. * * @param[in] dh Valid handle to a Meinberg device. - * @param[in] p_obs Obsolete pointer kept for compatibility, should be @a NULL. * @param[in] p_rpcfg Pointer to a valid ::RECEIVER_PORT_CFG structure. * @param[in] port_num Index of the serial port to be saved. * @@ -284,7 +284,7 @@ int _DEPRECATED_BY( "pcps_date_time_wday_is_valid" ) pcps_time_is_valid( const P * @see ::mbg_get_device_info * @see ::mbg_setup_receiver_info */ - int mbg_save_serial_settings( MBG_DEV_HANDLE dh, const void *p_obs, RECEIVER_PORT_CFG *p_rpcfg, int port_num ) ; + int mbg_save_serial_settings( MBG_DEV_HANDLE dh, RECEIVER_PORT_CFG *p_rpcfg, int port_num ) ; /** * @brief Read all network configuration into an ::ALL_NET_CFG_INFO structure. @@ -469,8 +469,8 @@ int _DEPRECATED_BY( "pcps_date_time_wday_is_valid" ) pcps_time_is_valid( const P */ int mbg_get_all_ucap_info( MBG_DEV_HANDLE dh, ALL_UCAP_INFO **p ) ; - void test_gpio( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev, int verbose ) ; - void test_xmr( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev, int verbose ) ; + void test_gpio( MBG_DEV_HANDLE dh, int verbose ) ; + void test_xmr( MBG_DEV_HANDLE dh, int verbose ) ; void port_info_from_pcps_serial( PORT_INFO_IDX *p_pii, PCPS_SERIAL pcps_serial, uint32_t supp_baud_rates ) ; void pcps_serial_from_port_info( PCPS_SERIAL *p, const PORT_INFO_IDX *p_pii ) ; /** diff --git a/mbglib/common/gpsdefs.h b/mbglib/common/gpsdefs.h index 2d6fc5a..2b329ab 100644 --- a/mbglib/common/gpsdefs.h +++ b/mbglib/common/gpsdefs.h @@ -1,7 +1,7 @@ /************************************************************************** * - * $Id: gpsdefs.h 1.127 2019/09/27 13:10:17 martin REL_M $ + * $Id: gpsdefs.h 1.127.3.1 2022/12/15 16:02:41 martin.burnicki REL_M $ * * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany * @@ -13,7 +13,10 @@ * * ----------------------------------------------------------------------- * $Log: gpsdefs.h $ - * Revision 1.127 2019/09/27 13:10:17 martin + * Revision 1.127.3.1 2022/12/15 16:02:41 martin.burnicki + * Fix potential compiler warnings, and optionally exclude code + * from build using preprocessor symbol OMIT_PTPV2. + * Revision 1.127 2019/09/27 13:10:17Z martin * New model codes MSHPS100, BPE_STM, VSI180, * GNM181, RSCRDU_TTL, RSC2000, FCU200, REL1000_RC. * Replaced old model CSM100 by MSSB100. @@ -2271,16 +2274,16 @@ enum MBG_DEV_CPU_TYPES * * @see ::_setup_default_receiver_info_gps */ -#define _setup_default_receiver_info_dcf( _p, _pdev ) \ -do \ -{ \ - memset( (_p), 0, sizeof( *(_p) ) ); \ - \ - (_p)->ticks_per_sec = DEFAULT_GPS_TICKS_PER_SEC; \ - (_p)->n_ucaps = 0; \ - (_p)->n_com_ports = _pcps_has_serial( _pdev ) ? 1 : 0; \ - (_p)->n_str_type = ( (_p)->n_com_ports != 0 ) ? \ - DEFAULT_N_STR_TYPE_DCF : 0; \ +#define _setup_default_receiver_info_dcf( _p, _pdev ) \ +do \ +{ \ + memset( (_p), 0, sizeof( *(_p) ) ); \ + \ + (_p)->ticks_per_sec = (uint32_t) DEFAULT_GPS_TICKS_PER_SEC; \ + (_p)->n_ucaps = (uint8_t) 0; \ + (_p)->n_com_ports = (uint8_t) ( _pcps_has_serial( _pdev ) ? 1 : 0 ); \ + (_p)->n_str_type = (uint8_t) ( ( (_p)->n_com_ports != 0 ) ? \ + DEFAULT_N_STR_TYPE_DCF : 0 ); \ } while ( 0 ) @@ -15811,6 +15814,10 @@ typedef struct } +#define OMIT_PTPV2 1 + +#if !OMIT_PTPV2 + /** * @brief Flags structure for the PTPv2 default dataset * @@ -15867,6 +15874,9 @@ typedef struct _mbg_swab8( &(_p)->reserved_2 ); \ } +#endif // OMIT_PTPV2 + + /** * @brief Flags for the PTPv2 NG default dataset @@ -15972,6 +15982,9 @@ typedef struct mbg_ptp_v2_ng_current_dataset_s } + +#if !OMIT_PTPV2 + /** * @brief Flags structure for the PTPv2 parent dataset * @@ -15990,7 +16003,6 @@ typedef struct _nop_macro_fnc() - /** * @brief PTPv2 parent dataset * @@ -16031,6 +16043,8 @@ typedef struct _mbg_swab_ptp_clock_id( &(_p)->grandmaster_identity ); \ } +#endif // !OMIT_PTPV2 + /** @@ -16089,6 +16103,8 @@ typedef struct mbg_ptp_v2_ng_parent_dataset_s } +#if !OMIT_PTPV2 + /** * @brief Flags structure for the PTPv2 time properties dataset * @@ -16113,6 +16129,7 @@ typedef struct _nop_macro_fnc() + /** * @brief PTPv2 time properties dataset * @@ -16136,6 +16153,8 @@ typedef struct _mbg_swab8( &(_p)->time_source ); \ } +#endif // !OMIT_PTPV2 + enum MBG_PTP_V2_NG_TIME_PROPERTIES_DATASET_FLAGS { @@ -16181,6 +16200,8 @@ typedef struct mbg_ptp_v2_ng_time_properties_dataset_s } +#if !OMIT_PTPV2 + /** * @brief PTPv2 port dataset * @@ -16220,6 +16241,8 @@ typedef struct _mbg_swab8( &(_p)->log_min_pdelay_req_interval ); \ } +#endif // !OMIT_PTPV2 + typedef struct { @@ -16271,6 +16294,8 @@ typedef struct mbg_ptp_v2_ng_port_dataset_s } +#if !OMIT_PTPV2 + /** * @brief Index structure for PTPv2 port dataset * @@ -16292,6 +16317,9 @@ typedef struct _mbg_swab_ptp_v2_port_dataset( &(_p)->port_dataset ); \ } +#endif // !OMIT_PTPV2 + + /** * @brief Index structure for PTPv2 port dataset * diff --git a/mbglib/common/gpsutils.c b/mbglib/common/gpsutils.c index 6194907..83bff60 100644 --- a/mbglib/common/gpsutils.c +++ b/mbglib/common/gpsutils.c @@ -1,7 +1,7 @@ /************************************************************************** * - * $Id: gpsutils.c 1.12 2022/08/26 11:01:27 martin.burnicki REL_M $ + * $Id: gpsutils.c 1.13 2022/12/21 14:52:13 martin.burnicki REL_M $ * * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany * @@ -10,6 +10,8 @@ * * ----------------------------------------------------------------------- * $Log: gpsutils.c $ + * Revision 1.13 2022/12/21 14:52:13 martin.burnicki + * Quieted a potential compiler warning. * Revision 1.12 2022/08/26 11:01:27 martin.burnicki * Changed the return value of some snprint_... functions from size_t to int. * Also quieted some potential compiler warnings. @@ -407,7 +409,7 @@ int snprint_fixed_freq( char *s, size_t max_len, FIXED_FREQ_INFO *p_ff ) int range; uint unit; uint format; - size_t n = 0; + int n = 0; // Before re-calculating frequency, range is the base 10 exponent // to the frequency value which is represented in kHz. diff --git a/mbglib/common/lan_util.c b/mbglib/common/lan_util.c index 95f95a7..b6b3ebe 100644 --- a/mbglib/common/lan_util.c +++ b/mbglib/common/lan_util.c @@ -1,7 +1,7 @@ /************************************************************************** * - * $Id: lan_util.c 1.25 2022/12/13 15:25:16 martin.burnicki REL_M $ + * $Id: lan_util.c 1.26 2022/12/21 14:54:41 martin.burnicki REL_M $ * * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany * @@ -10,6 +10,8 @@ * * ----------------------------------------------------------------------- * $Log: lan_util.c $ + * Revision 1.26 2022/12/21 14:54:41 martin.burnicki + * Quieted another potential compiler warning. * Revision 1.25 2022/12/13 15:25:16 martin.burnicki * Fixed a potential compiler warning. * Revision 1.24 2022/08/26 13:55:28 martin.burnicki @@ -1581,7 +1583,7 @@ static /*HDR*/ void nl_log_bytes( const char *fnc, const char *info, const void *p, int n_bytes ) { char ws[80]; - size_t n = 0; + int n = 0; int i; for ( i = 0; i < n_bytes; i++ ) diff --git a/mbglib/common/mbg_syn1588_util.c b/mbglib/common/mbg_syn1588_util.c index 19cf41a..85a3cd8 100644 --- a/mbglib/common/mbg_syn1588_util.c +++ b/mbglib/common/mbg_syn1588_util.c @@ -1,7 +1,7 @@ /************************************************************************** * - * $Id: mbg_syn1588_util.c 1.2 2022/07/06 15:09:08 martin.burnicki REL_M $ + * $Id: mbg_syn1588_util.c 1.3 2022/12/21 15:21:56 martin.burnicki REL_M $ * * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany * @@ -9,6 +9,8 @@ * * ----------------------------------------------------------------------- * $Log: mbg_syn1588_util.c $ + * Revision 1.3 2022/12/21 15:21:56 martin.burnicki + * Quieted a potential compiler warning. * Revision 1.2 2022/07/06 15:09:08 martin.burnicki * Support SYN1588 insync range boundary code instead of the original enum. * Revision 1.1 2022/05/31 13:41:42 martin.burnicki @@ -93,6 +95,8 @@ int mbg_syn1588_snprint_insync_boundary_code( char *s, size_t max_len, int i; int n = 0; + (void) n; // Avoid warning "never used". + if ( check_max && ( code >= PTP_STATE_RANGE_MAX_CODE ) ) return snprintf_safe( s, max_len, "(out of bounds)" ); diff --git a/mbglib/common/mbg_syn1588_util.h b/mbglib/common/mbg_syn1588_util.h index 46bf824..96868e3 100644 --- a/mbglib/common/mbg_syn1588_util.h +++ b/mbglib/common/mbg_syn1588_util.h @@ -1,7 +1,7 @@ /************************************************************************** * - * $Id: mbg_syn1588_util.h 1.3 2022/07/19 16:05:17 martin.burnicki REL_M $ + * $Id: mbg_syn1588_util.h 1.4 2022/12/21 15:22:49 martin.burnicki REL_M $ * * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany * @@ -9,6 +9,8 @@ * * ----------------------------------------------------------------------- * $Log: mbg_syn1588_util.h $ + * Revision 1.4 2022/12/21 15:22:49 martin.burnicki + * Quieted some potential compiler warnings. * Revision 1.3 2022/07/19 16:05:17 martin.burnicki * Renamed some symbols to match a more common naming convention. * Fixed a spelling error in a debug message. @@ -529,13 +531,13 @@ int pcps_time_from_pcps_hr_time( PCPS_TIME *p, const PCPS_HR_TIME *p_ht, int64_t return rc; // Save the computed calendar date and time. - p->sec = tm.tm_sec; - p->min = tm.tm_min; - p->hour = tm.tm_hour; - p->mday = tm.tm_mday; - p->wday = _wday_sun06_to_mon17( tm.tm_wday ); - p->month = tm.tm_mon + 1; - p->year = tm.tm_year % 100; + p->sec = (uint8_t) tm.tm_sec; + p->min = (uint8_t) tm.tm_min; + p->hour = (uint8_t) tm.tm_hour; + p->mday = (uint8_t) tm.tm_mday; + p->wday = (uint8_t) _wday_sun06_to_mon17( tm.tm_wday ); + p->month = (uint8_t) ( tm.tm_mon + 1 ); + p->year = (uint8_t) ( tm.tm_year % 100 ); // Convert fractions of the second. p->sec100 = (uint8_t) ( nsec / ( NSEC_PER_SEC / 100 ) ); @@ -543,7 +545,7 @@ int pcps_time_from_pcps_hr_time( PCPS_TIME *p, const PCPS_HR_TIME *p_ht, int64_t // Convert the remaining fields. p->status = (PCPS_TIME_STATUS) p_ht->status; p->signal = p_ht->signal; - p->offs_utc = p_ht->utc_offs / SECS_PER_HOUR; + p->offs_utc = (int8_t) ( p_ht->utc_offs / SECS_PER_HOUR ); return MBG_SUCCESS; diff --git a/mbglib/common/mbg_xmr_util.c b/mbglib/common/mbg_xmr_util.c index db05ee7..e841bfe 100644 --- a/mbglib/common/mbg_xmr_util.c +++ b/mbglib/common/mbg_xmr_util.c @@ -1,7 +1,7 @@ /************************************************************************** * - * $Id: mbg_xmr_util.c 1.4 2022/10/07 16:41:55 martin.burnicki REL_M $ + * $Id: mbg_xmr_util.c 1.5 2022/12/21 15:23:45 martin.burnicki REL_M $ * * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany * @@ -9,6 +9,8 @@ * * ----------------------------------------------------------------------- * $Log: mbg_xmr_util.c $ + * Revision 1.5 2022/12/21 15:23:45 martin.burnicki + * Removed an obsolete function parameter. * Revision 1.4 2022/10/07 16:41:55 martin.burnicki * Increased string buffer for XMR status info. * Revision 1.3 2022/07/06 14:56:09 martin.burnicki @@ -98,11 +100,9 @@ int snprint_xmr_src_status( char *s, size_t max_len, unsigned xmr_status ) * @param[in] n_src Number of XMR ref. sources, from ::ALL_XMULTI_REF_INFO::instances. * @param[in] info An optional header string to print, may be @a NULL. * @param[in] indent_str An optional indentation string, may be @a NULL. - * @param[in] verbosity_level Level of verbosity of the printed output. */ void print_all_xmr_status( ALL_XMULTI_REF_STATUS *p_axrs, int n_src, - const char *info, const char *indent_str, - int verbosity_level ) + const char *info, const char *indent_str ) { size_t max_ref_name_len = 0; int i; diff --git a/mbglib/common/mbg_xmr_util.h b/mbglib/common/mbg_xmr_util.h index f35cc64..d4febf7 100644 --- a/mbglib/common/mbg_xmr_util.h +++ b/mbglib/common/mbg_xmr_util.h @@ -1,7 +1,7 @@ /************************************************************************** * - * $Id: mbg_xmr_util.h 1.2 2022/06/30 09:47:33 martin.burnicki REL_M $ + * $Id: mbg_xmr_util.h 1.3 2022/12/21 15:24:03 martin.burnicki REL_M $ * * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany * @@ -9,6 +9,8 @@ * * ----------------------------------------------------------------------- * $Log: mbg_xmr_util.h $ + * Revision 1.3 2022/12/21 15:24:03 martin.burnicki + * Removed an obsolete function parameter. * Revision 1.2 2022/06/30 09:47:33 martin.burnicki * Updated function prototypes. * Revision 1.1 2022/06/24 12:54:36 martin.burnicki @@ -53,9 +55,8 @@ extern "C" { * @param[in] n_src Number of XMR ref. sources, from ::ALL_XMULTI_REF_INFO::instances. * @param[in] info An optional header string to print, may be @a NULL. * @param[in] indent_str An optional indentation string, may be @a NULL. - * @param[in] verbosity_level Level of verbosity of the printed output. */ - void print_all_xmr_status( ALL_XMULTI_REF_STATUS *p_axrs, int n_src, const char *info, const char *indent_str, int verbosity_level ) ; + void print_all_xmr_status( ALL_XMULTI_REF_STATUS *p_axrs, int n_src, const char *info, const char *indent_str ) ; /* ----- function prototypes end ----- */ diff --git a/mbglib/common/mbg_xmr_util_devio.c b/mbglib/common/mbg_xmr_util_devio.c index baae16f..8d52d67 100644 --- a/mbglib/common/mbg_xmr_util_devio.c +++ b/mbglib/common/mbg_xmr_util_devio.c @@ -1,7 +1,7 @@ /************************************************************************** * - * $Id: mbg_xmr_util_devio.c 1.2 2022/06/30 09:47:10 martin.burnicki REL_M $ + * $Id: mbg_xmr_util_devio.c 1.3 2022/12/21 15:25:08 martin.burnicki REL_M $ * * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany * @@ -9,6 +9,9 @@ * * ----------------------------------------------------------------------- * $Log: mbg_xmr_util_devio.c $ + * Revision 1.3 2022/12/21 15:25:08 martin.burnicki + * Removed an obsolete function parameter. + * Quieted some potential compiler warnings. * Revision 1.2 2022/06/30 09:47:10 martin.burnicki * Support force-reading XMR info and status, which is useful for debugging * but can be dangerous if the device generally doesn't support XMR. @@ -51,7 +54,7 @@ int mbg_get_all_xmulti_ref_info_forced( MBG_DEV_HANDLE dh, ALL_XMULTI_REF_INFO **p ) { ALL_XMULTI_REF_INFO *xmr_info = *p; - size_t data_sz; + uint32_t data_sz; int rc; if ( xmr_info == NULL ) @@ -140,7 +143,7 @@ out: int mbg_get_all_xmulti_ref_status_forced( MBG_DEV_HANDLE dh, const ALL_XMULTI_REF_INFO *info, ALL_XMULTI_REF_STATUS **p ) { ALL_XMULTI_REF_STATUS *xmr_status = *p; - size_t data_sz; + uint32_t data_sz; int rc; if ( info == NULL ) @@ -212,7 +215,6 @@ out: * @param[in] dh Valid handle to a Meinberg device. * @param[in] info An optional header string to print, may be @a NULL. * @param[in] indent_str An optional indentation string, may be @a NULL. - * @param[in] verbosity_level Level of verbosity of the printed output. * @param[in] force If @a true, force-read XMR data even if the feature flag is not set. * * @return One of the @ref MBG_RETURN_CODES @@ -220,7 +222,7 @@ out: * @see ::print_all_xmr_status */ void show_all_xmr_status( MBG_DEV_HANDLE dh, const char *info, const char *indent_str, - int verbosity_level, bool force ) + bool force ) { ALL_XMULTI_REF_INFO *p_axri = NULL; ALL_XMULTI_REF_STATUS *p_axrs = NULL; @@ -245,7 +247,7 @@ void show_all_xmr_status( MBG_DEV_HANDLE dh, const char *info, const char *inden print_all_xmr_status( p_axrs, p_axri->instances.n_xmr_settings, - info, indent_str, verbosity_level ); + info, indent_str ); done: if ( p_axri ) diff --git a/mbglib/common/mbg_xmr_util_devio.h b/mbglib/common/mbg_xmr_util_devio.h index b9a1155..92688fa 100644 --- a/mbglib/common/mbg_xmr_util_devio.h +++ b/mbglib/common/mbg_xmr_util_devio.h @@ -1,7 +1,7 @@ /************************************************************************** * - * $Id: mbg_xmr_util_devio.h 1.2 2022/06/30 09:47:42 martin.burnicki REL_M $ + * $Id: mbg_xmr_util_devio.h 1.3 2022/12/21 15:26:03 martin.burnicki REL_M $ * * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany * @@ -9,6 +9,8 @@ * * ----------------------------------------------------------------------- * $Log: mbg_xmr_util_devio.h $ + * Revision 1.3 2022/12/21 15:26:03 martin.burnicki + * Removed an obsolete function parameter. * Revision 1.2 2022/06/30 09:47:42 martin.burnicki * Updated function prototypes. * Revision 1.1 2022/06/24 12:54:29 martin.burnicki @@ -102,14 +104,13 @@ extern "C" { * @param[in] dh Valid handle to a Meinberg device. * @param[in] info An optional header string to print, may be @a NULL. * @param[in] indent_str An optional indentation string, may be @a NULL. - * @param[in] verbosity_level Level of verbosity of the printed output. * @param[in] force If @a true, force-read XMR data even if the feature flag is not set. * * @return One of the @ref MBG_RETURN_CODES * * @see ::print_all_xmr_status */ - void show_all_xmr_status( MBG_DEV_HANDLE dh, const char *info, const char *indent_str, int verbosity_level, bool force ) ; + void show_all_xmr_status( MBG_DEV_HANDLE dh, const char *info, const char *indent_str, bool force ) ; /* ----- function prototypes end ----- */ diff --git a/mbglib/common/mbgdevio.c b/mbglib/common/mbgdevio.c index 617cc3b..34fa11c 100644 --- a/mbglib/common/mbgdevio.c +++ b/mbglib/common/mbgdevio.c @@ -1,7 +1,7 @@ /************************************************************************** * - * $Id: mbgdevio.c 1.57 2022/08/23 15:59:09 martin.burnicki REL_M $ + * $Id: mbgdevio.c 1.58 2022/12/21 14:55:38 martin.burnicki REL_M $ * * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany * @@ -10,6 +10,8 @@ * * ----------------------------------------------------------------------- * $Log: mbgdevio.c $ + * Revision 1.58 2022/12/21 14:55:38 martin.burnicki + * Quieted a potential compiler warning. * Revision 1.57 2022/08/23 15:59:09 martin.burnicki * Use feature check functions instead of macros. * Updated some doxygen comments. @@ -4459,7 +4461,7 @@ _MBG_API_ATTR MBG_DEV_HANDLE _MBG_API mbg_open_device_by_name( const char *srch_ PCPS_DEV dev_array[N_SUPP_DEV_BUS] = { { { 0 } } }; PCPS_CLOCK_NAME type_name; PCPS_SN_STR sernum; - size_t i = 0; + int i = 0; int dev_idx = -1; mbg_split_dev_name( srch_name, type_name, sizeof( type_name ), diff --git a/mbglib/common/mbgdevio.h b/mbglib/common/mbgdevio.h index dc5e472..d31130f 100644 --- a/mbglib/common/mbgdevio.h +++ b/mbglib/common/mbgdevio.h @@ -1,7 +1,7 @@ /************************************************************************** * - * $Id: mbgdevio.h 1.64 2022/08/23 16:20:24 martin.burnicki REL_M $ + * $Id: mbgdevio.h 1.65 2022/12/21 15:26:48 martin.burnicki REL_M $ * * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany * @@ -10,6 +10,8 @@ * * ----------------------------------------------------------------------- * $Log: mbgdevio.h $ + * Revision 1.65 2022/12/21 15:26:48 martin.burnicki + * Quieted a potential compiler warning. * Revision 1.64 2022/08/23 16:20:24 martin.burnicki * Updated function prototypes. * Revision 1.63 2022/06/02 08:20:23 martin.burnicki @@ -559,7 +561,7 @@ _ext _MBG_API_ATTR_VAR MBG_PC_CYCLES_FREQUENCY mbg_pc_cycles_frequency; #endif #if !defined( _mbg_cpu_isset ) - #define _mbg_cpu_isset( _i, _ps ) ( *(_ps) & ( 1UL << (_i) ) ) + #define _mbg_cpu_isset( _i, _ps ) ( *(_ps) & ( (MBG_CPU_SET) 1UL << (_i) ) ) #endif diff --git a/mbglib/common/mbggeo.h b/mbglib/common/mbggeo.h index 473083f..175e008 100644 --- a/mbglib/common/mbggeo.h +++ b/mbglib/common/mbggeo.h @@ -1,7 +1,7 @@ /************************************************************************** * - * $Id: mbggeo.h 1.16 2019/06/17 08:04:51 thomas-b REL_M $ + * $Id: mbggeo.h 1.17 2022/12/21 15:59:26 martin.burnicki REL_M $ * * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany * @@ -22,6 +22,8 @@ * * ----------------------------------------------------------------------- * $Log: mbggeo.h $ + * Revision 1.17 2022/12/21 15:59:26 martin.burnicki + * Updated some comments. * Revision 1.16 2019/06/17 08:04:51 thomas-b * Renamed structs according to Meinberg naming convention * Revision 1.15 2019/06/06 12:17:14 thomas-b @@ -76,7 +78,7 @@ /* Start of header body */ #if defined( _USE_PACK ) - #pragma pack( 1 ) // set byte alignment + #pragma pack( 1 ) // Set byte alignment. #define _USING_BYTE_ALIGNMENT #endif @@ -323,7 +325,7 @@ _ext double sqrt_mue; // sqrt( mue ) #if defined( _USING_BYTE_ALIGNMENT ) - #pragma pack() // set default alignment + #pragma pack() // Set default alignment. #undef _USING_BYTE_ALIGNMENT #endif diff --git a/mbglib/common/mbgtime.c b/mbglib/common/mbgtime.c index d246816..c48f9b5 100644 --- a/mbglib/common/mbgtime.c +++ b/mbglib/common/mbgtime.c @@ -1,7 +1,7 @@ /************************************************************************** * - * $Id: mbgtime.c 1.14 2019/11/27 11:02:57 martin REL_M $ + * $Id: mbgtime.c 1.15 2022/12/21 15:27:29 martin.burnicki REL_M $ * * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany * @@ -10,6 +10,8 @@ * * ----------------------------------------------------------------------- * $Log: mbgtime.c $ + * Revision 1.15 2022/12/21 15:27:29 martin.burnicki + * Quieted a potential compiler warning. * Revision 1.14 2019/11/27 11:02:57 martin * Renamed function n_days() to n_days_since_year_0() * to make clearer what the function returns, and provided @@ -514,7 +516,7 @@ int find_past_gps_wn_lsf_from_table( GPS_WNUM *p_wn, GPS_DNUM dn_t, int srch_all // If the caller has searched for day number 7, // we have to adjust the full week number // from the table accordingly. - *p_wn = ( dn_t == 7 ) ? ( p->wn - 1 ) : p->wn; + *p_wn = (GPS_WNUM) ( ( dn_t == 7 ) ? ( p->wn - 1 ) : p->wn ); // If the first search result is sufficient // for the application, we can stop searching. diff --git a/mbglib/common/mbgutil.c b/mbglib/common/mbgutil.c index bbf079d..bb2930f 100644 --- a/mbglib/common/mbgutil.c +++ b/mbglib/common/mbgutil.c @@ -1,7 +1,7 @@ /************************************************************************** * - * $Id: mbgutil.c 1.17 2022/08/23 17:30:49 martin.burnicki REL_M $ + * $Id: mbgutil.c 1.18 2022/12/21 14:58:15 martin.burnicki REL_M $ * * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany * @@ -9,6 +9,8 @@ * * ----------------------------------------------------------------------- * $Log: mbgutil.c $ + * Revision 1.18 2022/12/21 14:58:15 martin.burnicki + * Removed some obsolete _int_from_size_t() stuff. * Revision 1.17 2022/08/23 17:30:49 martin.burnicki * Quieted a compiler warning. * Revision 1.16 2021/11/08 20:01:37 martin.burnicki @@ -1015,7 +1017,7 @@ _MBG_API_ATTR int _MBG_API mbg_str_dev_name( char *s, int max_len, const char *s PCPS_SN_STR sernum = { 0 }; bool is_syn1588 = false; unsigned int i = 0; - size_t n = 0; + int n = 0; size_t l = strlen( short_name ); if ( l > 0 ) @@ -1093,7 +1095,7 @@ _MBG_API_ATTR int _MBG_API mbg_str_dev_name( char *s, int max_len, const char *s n += sn_cpy_str_safe( &s[n], max_len - n, ")" ); out: - return _int_from_size_t( n ); + return n; } // mbg_str_dev_name diff --git a/mbglib/common/myutil.h b/mbglib/common/myutil.h index 3b37358..c172215 100644 --- a/mbglib/common/myutil.h +++ b/mbglib/common/myutil.h @@ -1,7 +1,7 @@ /************************************************************************** * - * $Id: myutil.h 1.23 2019/08/09 12:04:12 martin REL_M $ + * $Id: myutil.h 1.24 2022/12/21 16:00:50 martin.burnicki REL_M $ * * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany * @@ -10,6 +10,8 @@ * * ----------------------------------------------------------------------- * $Log: myutil.h $ + * Revision 1.24 2022/12/21 16:00:50 martin.burnicki + * Updated some comments. * Revision 1.23 2019/08/09 12:04:12 martin * Added _inrange_s() macro and associated structures. * Updated some doxygen comments. @@ -86,7 +88,7 @@ /* Start of header body */ #if defined( _USE_PACK ) - #pragma pack( 1 ) // set byte alignment + #pragma pack( 1 ) // Set byte alignment. #define _USING_BYTE_ALIGNMENT #endif @@ -296,7 +298,7 @@ extern "C" { #if defined( _USING_BYTE_ALIGNMENT ) - #pragma pack() // set default alignment + #pragma pack() // Set default alignment. #undef _USING_BYTE_ALIGNMENT #endif diff --git a/mbglib/common/pcpslstr.c b/mbglib/common/pcpslstr.c index 552f305..f0d5861 100644 --- a/mbglib/common/pcpslstr.c +++ b/mbglib/common/pcpslstr.c @@ -1,7 +1,7 @@ /************************************************************************** * - * $Id: pcpslstr.c 1.30 2021/03/22 23:11:49 martin REL_M $ + * $Id: pcpslstr.c 1.31 2022/12/21 15:28:38 martin.burnicki REL_M $ * * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany * @@ -11,6 +11,9 @@ * * ----------------------------------------------------------------------- * $Log: pcpslstr.c $ + * Revision 1.31 2022/12/21 15:28:38 martin.burnicki + * Quieted some potential compiler warnings. + * Removed some obsolete _int_from_size_t() stuff. * Revision 1.30 2021/03/22 23:11:49 martin * Updated some comments. * Revision 1.29 2021/03/12 12:32:49 martin @@ -147,7 +150,7 @@ const char *inv_str( void ) static /*HDR*/ /** * @brief Determine a time zone name from the device status. - * + * * @param[in] pcps_status Status flags read from a device. * @param[in] utc_offs %UTC offset, [s]. * @param[in] flags A combination of ::PCPS_TZ_NAME_FLAGS contolling the output string format. @@ -259,7 +262,7 @@ const char *pcps_tz_name( const PCPS_TIME *t, ulong flags, int is_msf ) /*HDR*/ /** * @brief Determine a TZ name from a ::PCPS_HR_TIME structure with status and %UTC offset. - * + * * @param[in] hrt A ::PCPS_HR_TIME structure read from a device. * @param[in] flags A combination of ::PCPS_TZ_NAME_FLAGS contolling the output string format. * @param[in] is_msf A Flag used to indicate if the is an MSF receiver. @@ -381,6 +384,8 @@ char *pcps_date_time_str( char *s, size_t max_len, const PCPS_TIME *t, n += sn_cpy_str_safe( &s[n], max_len - n, tz_str ); } + + (void) n; // Avoid warning "never used". } return s; @@ -392,7 +397,7 @@ char *pcps_date_time_str( char *s, size_t max_len, const PCPS_TIME *t, /*HDR*/ int pcps_str_tm_gps_date_time( char *s, size_t max_len, const TM_GPS *t ) { - size_t n; + int n; int i; n = snprint_ctry_wday( s, max_len, t->wday, language ); @@ -407,7 +412,7 @@ int pcps_str_tm_gps_date_time( char *s, size_t max_len, const TM_GPS *t ) n += snprintf_safe( &s[n], max_len - n, "%02i:%02i:%02i.%07i", t->hour, t->min, t->sec, t->frac ); - return _int_from_size_t ( n ); + return n; } // pcps_str_tm_gps_date_time @@ -458,11 +463,11 @@ void pcps_setup_status_str( PCPS_STATUS_STR *pstr, int err_cond, * @brief Set up a set of device status strings. * * The strings depend on the status codes and the device type. - * + * * @param[in] status Extended status code, see ::PCPS_TIME_STATUS_X. * @param[in] status_is_read Flag indicating if the @p status has actually been read. * @param[in] is_gps Flag indicating if the status has been read from a GPS receiver. - * @param[out] pstrs Array of strings to be set up. + * @param[out] pstrs Array of strings to be set up. */ void pcps_status_strs( PCPS_TIME_STATUS_X status, int status_is_read, int is_gps, PCPS_STATUS_STRS *pstrs ) @@ -581,6 +586,8 @@ char *pcps_serial_str( char *s, size_t max_len, int i, const RECEIVER_PORT_CFG * n += snprintf_safe( &s[n], max_len - n, ", %s", _lstr( mode_name[p_ps->mode] ) ); } + (void) n; // Avoid warning "never used". + return s; } // pcps_serial_str diff --git a/mbglib/common/ptp_util.h b/mbglib/common/ptp_util.h index 4fac0dd..b01aee2 100644 --- a/mbglib/common/ptp_util.h +++ b/mbglib/common/ptp_util.h @@ -1,7 +1,7 @@ /************************************************************************** * - * $Id: ptp_util.h 1.7 2021/03/16 12:20:39 martin REL_M $ + * $Id: ptp_util.h 1.8 2022/12/21 16:03:43 martin.burnicki REL_M $ * * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany * @@ -10,6 +10,8 @@ * * ----------------------------------------------------------------------- * $Log: ptp_util.h $ + * Revision 1.8 2022/12/21 16:03:43 martin.burnicki + * Updated some comments. * Revision 1.7 2021/03/16 12:20:39 martin * Updated some comments. * Revision 1.6 2017/05/10 15:26:10 martin @@ -50,7 +52,7 @@ /* Start of header body */ #if defined( _USE_PACK ) - #pragma pack( 1 ) // set byte alignment + #pragma pack( 1 ) // Set byte alignment. #define _USING_BYTE_ALIGNMENT #endif @@ -60,7 +62,7 @@ extern "C" { /** - * @brief Derive a "supported PTP roles" bit mask from ::PTP_CFG_INFO::supp_flags + * @brief Derive a "supported PTP roles" bit mask from ::PTP_CFG_INFO::supp_flags. * * The relevant bits used with ::PTP_CFG_INFO::supp_flags have not been * defined sequentially, so we need to test them individually to put a @@ -76,9 +78,9 @@ extern "C" { * If ::PTP_CFG_SUPP_MCAST_SLAVE_FLAG is not set, the device * definitely supports the multicast slave role. * - * @param flags bit mask from ::PTP_CFG_INFO::supp_flags, see @ref PTP_CFG_FLAG_MASKS + * @param flags bit mask from ::PTP_CFG_INFO::supp_flags, see @ref PTP_CFG_FLAG_MASKS. * - * @return bit mask of supported PTP roles, see ::PTP_ROLE_MASKS + * @return bit mask of supported PTP roles, see ::PTP_ROLE_MASKS. */ static __mbg_inline uint32_t get_supp_ptp_role_mask( uint32_t flags ) @@ -178,7 +180,7 @@ uint32_t get_supp_ptp_role_mask( uint32_t flags ) #if defined( _USING_BYTE_ALIGNMENT ) - #pragma pack() // set default alignment + #pragma pack() // Set default alignment. #undef _USING_BYTE_ALIGNMENT #endif diff --git a/mbglib/common/str_util.c b/mbglib/common/str_util.c index eae3881..e83d291 100644 --- a/mbglib/common/str_util.c +++ b/mbglib/common/str_util.c @@ -1,7 +1,7 @@ /************************************************************************** * - * $Id: str_util.c 1.12 2022/08/26 15:01:49 martin.burnicki REL_M $ + * $Id: str_util.c 1.13 2022/12/21 15:31:56 martin.burnicki REL_M $ * * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany * @@ -10,6 +10,9 @@ * * ----------------------------------------------------------------------- * $Log: str_util.c $ + * Revision 1.13 2022/12/21 15:31:56 martin.burnicki + * Removed some obsolete _int_from_size_t() stuff. + * Fixed some other size_t/int mismatch. * Revision 1.12 2022/08/26 15:01:49 martin.burnicki * Updated a doxygen comment and fixed a typo in an older commit message. * Revision 1.11 2021/03/22 11:28:52 martin @@ -117,7 +120,7 @@ int vsnprintf( char *s, size_t max_len, const char *fmt, va_list args ) * can be larger (e.g. @a unsigned_long) than the @a int type returned * by mostly all functions of the @a printf family. So if a very large * buffer is specified, and a large number of characters (more than - * @a MAXINT) are written to that buffer, how can an @a int type + * @a INT_MAX) are written to that buffer, how can an @a int type * return the large number of characters written to the buffer? * We also try to workaround this here. * @@ -135,9 +138,9 @@ int vsnprintf( char *s, size_t max_len, const char *fmt, va_list args ) * @see ::sn_cpy_char_safe */ __attribute__( ( format( printf, 3, 0 ) ) ) -int vsnprintf_safe( char *s, size_t max_len, const char *fmt, va_list args ) +int vsnprintf_safe( char *s, ssize_t max_len, const char *fmt, va_list args ) { - size_t n; + int n; if ( !mbg_buffer_specs_valid( s, max_len ) ) return 0; // Nothing to do anyway. @@ -171,7 +174,7 @@ int vsnprintf_safe( char *s, size_t max_len, const char *fmt, va_list args ) * @see ::sn_cpy_char_safe */ __attribute__( ( format( printf, 3, 4 ) ) ) -int snprintf_safe( char *s, size_t max_len, const char *fmt, ... ) +int snprintf_safe( char *s, ssize_t max_len, const char *fmt, ... ) { va_list args; int len; @@ -209,9 +212,9 @@ static __mbg_inline /*HDR*/ * @see ::sn_cpy_str_safe * @see ::sn_cpy_char_safe */ -size_t do_str_copy_safe( char *dst, const char *src, size_t n ) +int do_str_copy_safe( char *dst, const char *src, ssize_t n ) { - size_t i = 0; + int i = 0; if ( n > 0 ) { @@ -222,7 +225,8 @@ size_t do_str_copy_safe( char *dst, const char *src, size_t n ) if ( *dst == 0 ) break; // Just copied the terminating 0, done. - if ( --n == 0 ) // No more space left in buffer. + if ( ( --n == 0 ) // No more space left in buffer. + || ( i == INT_MAX ) ) // Reached the limit we can handle. { *dst = 0; // Force terminating 0. break; @@ -295,9 +299,9 @@ char *strncpy_safe( char *dst, const char *src, size_t max_len ) */ int sn_cpy_str_safe( char *dst, size_t max_len, const char *src ) { - size_t n = do_str_copy_safe( dst, src, max_len ); + int n = do_str_copy_safe( dst, src, max_len ); - return _int_from_size_t( n ); + return n; } // sn_cpy_str_safe @@ -326,7 +330,7 @@ int sn_cpy_str_safe( char *dst, size_t max_len, const char *src ) */ int sn_cpy_char_safe( char *dst, size_t max_len, char c ) { - size_t n; + int n; char tmp_str[2]; tmp_str[0] = c; @@ -334,7 +338,7 @@ int sn_cpy_char_safe( char *dst, size_t max_len, char c ) n = do_str_copy_safe( dst, tmp_str, max_len ); - return _int_from_size_t( n ); + return n; } // sn_cpy_char_safe diff --git a/mbglib/common/str_util.h b/mbglib/common/str_util.h index efd9f39..e6f130d 100644 --- a/mbglib/common/str_util.h +++ b/mbglib/common/str_util.h @@ -1,7 +1,7 @@ /************************************************************************** * - * $Id: str_util.h 1.13 2022/08/26 15:02:13 martin.burnicki REL_M $ + * $Id: str_util.h 1.14 2022/12/21 15:02:26 martin.burnicki REL_M $ * * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany * @@ -10,6 +10,8 @@ * * ----------------------------------------------------------------------- * $Log: str_util.h $ + * Revision 1.14 2022/12/21 15:02:26 martin.burnicki + * Fixed some size_t/int mismatch. * Revision 1.13 2022/08/26 15:02:13 martin.burnicki * Updated a doxygen comment. * Revision 1.12 2021/03/22 11:27:45 martin @@ -61,6 +63,7 @@ #else #include <stdlib.h> #include <stdarg.h> + #include <limits.h> #endif @@ -103,9 +106,11 @@ static __mbg_inline /*HDR*/ * * @return @a true if the buffer address is not @a NULL and the size is > 0, else @a false. */ -bool mbg_buffer_specs_valid( char *s, size_t max_len ) +bool mbg_buffer_specs_valid( char *s, ssize_t max_len ) { - return s != NULL && max_len > 0; + return ( s != NULL ) + && ( max_len > 0 ) + && ( max_len < INT_MAX ); } // mbg_buffer_specs_valid @@ -138,7 +143,7 @@ static __mbg_inline /*HDR*/ * @see ::mbg_kdd_vsnprintf * @see ::mbg_buffer_specs_valid */ -int mbg_chk_snprint_results( size_t n, char *s, size_t max_len ) +int mbg_chk_snprint_results( int n, char *s, ssize_t max_len ) { if ( !mbg_buffer_specs_valid( s, max_len ) ) return 0; // Buffer parameters are not valid. @@ -153,7 +158,7 @@ int mbg_chk_snprint_results( size_t n, char *s, size_t max_len ) goto out; // Determine the real string length, but don't just call strlen() - // since that function may not be available in kernel mode. + // because that function may not be available in kernel mode. for ( n = 0; s[n]; n++ ); out: @@ -211,7 +216,7 @@ out: * can be larger (e.g. @a unsigned_long) than the @a int type returned * by mostly all functions of the @a printf family. So if a very large * buffer is specified, and a large number of characters (more than - * @a MAXINT) are written to that buffer, how can an @a int type + * @a INT_MAX) are written to that buffer, how can an @a int type * return the large number of characters written to the buffer? * We also try to workaround this here. * @@ -228,7 +233,7 @@ out: * @see ::sn_cpy_str_safe * @see ::sn_cpy_char_safe */ - __attribute__( ( format( printf, 3, 0 ) ) ) int vsnprintf_safe( char *s, size_t max_len, const char *fmt, va_list args ) ; + __attribute__( ( format( printf, 3, 0 ) ) ) int vsnprintf_safe( char *s, ssize_t max_len, const char *fmt, va_list args ) ; /** * @brief A portable, safe implementation of snprintf(). @@ -248,7 +253,7 @@ out: * @see ::sn_cpy_str_safe * @see ::sn_cpy_char_safe */ - __attribute__( ( format( printf, 3, 4 ) ) ) int snprintf_safe( char *s, size_t max_len, const char *fmt, ... ) ; + __attribute__( ( format( printf, 3, 4 ) ) ) int snprintf_safe( char *s, ssize_t max_len, const char *fmt, ... ) ; /** * @brief A portable, safe implementation of strncpy(). diff --git a/mbglib/common/timeutil.c b/mbglib/common/timeutil.c index 4bf34bd..e749d41 100644 --- a/mbglib/common/timeutil.c +++ b/mbglib/common/timeutil.c @@ -1,7 +1,7 @@ /************************************************************************** * - * $Id: timeutil.c 1.15 2021/03/22 11:52:30 martin REL_M $ + * $Id: timeutil.c 1.16 2022/12/21 15:32:49 martin.burnicki REL_M $ * * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany * @@ -10,6 +10,8 @@ * * ----------------------------------------------------------------------- * $Log: timeutil.c $ + * Revision 1.16 2022/12/21 15:32:49 martin.burnicki + * Removed some obsolete _int_from_size_t() stuff. * Revision 1.15 2021/03/22 11:52:30 martin * Updated some comments. * Revision 1.14 2021/03/12 12:32:18 martin @@ -66,7 +68,7 @@ /*HDR*/ int snprint_gmtime_error( char *s, size_t max_len, int mbg_errno, time_t t, const char *calling_fnc ) { - size_t n = snprintf_safe( s, max_len, "gmtime() call failed" ); + int n = snprintf_safe( s, max_len, "gmtime() call failed" ); if ( calling_fnc ) n += snprintf_safe( &s[n], max_len - n, " in %s", calling_fnc ); @@ -80,7 +82,7 @@ int snprint_gmtime_error( char *s, size_t max_len, int mbg_errno, time_t t, cons (uint64_t) t, mbg_strerror( mbg_errno ) ); #endif - return _int_from_size_t( n ); + return n; } // snprint_gmtime_error @@ -275,7 +277,7 @@ out: */ int snprint_utc_offs( char *s, size_t max_len, const char *info, long utc_offs ) { - size_t n = 0; + int n = 0; // utc_offs is in [s] char utc_offs_sign = (char) ( ( utc_offs < 0 ) ? '-' : '+' ); @@ -298,7 +300,7 @@ int snprint_utc_offs( char *s, size_t max_len, const char *info, long utc_offs ) n += sn_cpy_str_safe( &s[n], max_len - n, "h" ); - return _int_from_size_t( n ); + return n; } // snprint_utc_offs @@ -308,7 +310,7 @@ int snprint_utc_offs( char *s, size_t max_len, const char *info, long utc_offs ) int snprint_time_t_to_iso( time_t tstamp, int offs_hours, char *buf, size_t len ) { struct tm tm = { 0 }; - size_t n; + int n; int rc; if ( offs_hours ) @@ -325,7 +327,7 @@ int snprint_time_t_to_iso( time_t tstamp, int offs_hours, char *buf, size_t len tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec ); - return _int_from_size_t( n ); + return n; } // snprint_time_t_to_iso @@ -335,10 +337,10 @@ static __mbg_inline /*HDR*/ int __to_iso_frac( time_t tstamp, int offset, time_t frac, const char* fmt, char *buf, size_t max_len ) { - size_t n = snprint_time_t_to_iso( tstamp, offset, buf, max_len ); + int n = snprint_time_t_to_iso( tstamp, offset, buf, max_len ); n += snprintf_safe( &buf[n], max_len - n, fmt, frac ); - return _int_from_size_t( n ); + return n; } // __to_iso_frac diff --git a/mbglib/common/toolutil.c b/mbglib/common/toolutil.c index b08c79e..3ef13d7 100644 --- a/mbglib/common/toolutil.c +++ b/mbglib/common/toolutil.c @@ -1,13 +1,17 @@ /************************************************************************** * - * $Id: toolutil.c 1.25 2022/07/25 16:41:55 martin.burnicki REL_M $ + * $Id: toolutil.c 1.26 2022/12/21 15:34:41 martin.burnicki REL_M $ * * Common functions that can be used with Meinberg command line * utility programs. * * ----------------------------------------------------------------------- * $Log: toolutil.c $ + * Revision 1.26 2022/12/21 15:34:41 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.25 2022/07/25 16:41:55 martin.burnicki * Support getting full version string from git. * Revision 1.24 2022/04/01 15:00:12 martin.burnicki @@ -525,7 +529,9 @@ int mbg_get_show_dev_info( MBG_DEV_HANDLE dh, const char *dev_name, PCPS_DEV *p_ if ( chk_sw_rev_name( &ri.sw_rev, 0 ) ) printf( " \"%s\"", ri.sw_rev.name ); - if ( _pcps_has_asic_version( p_dev ) ) + rc = mbg_chk_dev_has_asic_version( dh ); + + if ( mbg_rc_is_success( rc ) ) { PCI_ASIC_VERSION av; int rc = mbg_get_asic_version( dh, &av ); @@ -595,7 +601,7 @@ int mbg_handle_device( MBG_DEV_HANDLE dh, const char *dev_name, if ( mbg_rc_is_success( rc ) ) if ( fnc ) - rc = fnc( dh, &dev ); + rc = fnc( dh ); mbg_close_device( &dh ); @@ -872,7 +878,7 @@ int mbg_handle_devices( int argc, char *argv[], int optind, if ( fnc ) { dh = MBG_INVALID_DEV_HANDLE; - rc = fnc( dh, NULL ); + rc = fnc( dh ); } else { @@ -941,7 +947,7 @@ out: */ int mbg_snprint_date_time( char *s, size_t max_len, const PCPS_TIME *p, int verbose ) { - size_t n = 0; + int n = 0; n += snprintf_safe( &s[n], max_len - n, "%04u-%02u-%02u %02u:%02u:%02u.%02u", mbg_exp_year( p->year, mbg_exp_year_limit ), p->month, p->mday, @@ -954,7 +960,7 @@ int mbg_snprint_date_time( char *s, size_t max_len, const PCPS_TIME *p, int verb if ( verbose > 1 ) n += snprintf_safe( &s[n], max_len - n, ", sig: %i", p->signal ); - return _int_from_size_t( n ); + return n; } // mbg_snprint_date_time @@ -979,7 +985,7 @@ int mbg_snprint_hr_tstamp( char *s, size_t max_len, const PCPS_TIME_STAMP *p, long l; time_t t; struct tm tm = { 0 }; - size_t n = 0; + int n = 0; int rc; if ( show_raw ) @@ -1005,7 +1011,7 @@ int mbg_snprint_hr_tstamp( char *s, size_t max_len, const PCPS_TIME_STAMP *p, else n += snprint_gmtime_error( &s[n], max_len - n, rc, t, __func__ ); - return _int_from_size_t( n ); + return n; } // mbg_snprint_hr_tstamp @@ -1030,7 +1036,7 @@ int mbg_snprint_hr_time( char *s, size_t max_len, const PCPS_HR_TIME *p, int sho { char ws[80]; PCPS_TIME_STAMP ts = p->tstamp; - size_t n; + int n; const char *time_scale_name; const char *cp; @@ -1060,7 +1066,7 @@ int mbg_snprint_hr_time( char *s, size_t max_len, const PCPS_HR_TIME *p, int sho n += snprintf_safe( &s[n], max_len - n, " %s%s", time_scale_name, cp ); - return _int_from_size_t( n ); + return n; } // mbg_snprint_hr_time diff --git a/mbglib/common/toolutil.h b/mbglib/common/toolutil.h index 10a782d..74c5997 100644 --- a/mbglib/common/toolutil.h +++ b/mbglib/common/toolutil.h @@ -1,7 +1,7 @@ /************************************************************************** * - * $Id: toolutil.h 1.19 2021/11/15 17:09:16 martin.burnicki REL_M $ + * $Id: toolutil.h 1.20 2022/12/21 15:39:02 martin.burnicki REL_M $ * * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany * @@ -9,6 +9,10 @@ * * ----------------------------------------------------------------------- * $Log: toolutil.h $ + * Revision 1.20 2022/12/21 15:39:02 martin.burnicki + * MBG_DEV_HANDLER_FNC no longer takes a (PCPS_DEV *) parameter, + * so functions of this type must call feature check functions instead of + * using feature check macros. * Revision 1.19 2021/11/15 17:09:16 martin.burnicki * Updated function prototypes. * Revision 1.18 2021/11/08 20:26:20 martin.burnicki @@ -175,7 +179,7 @@ _ext const char *pzf_corr_state_name[N_PZF_CORR_STATE] /** * @brief The type of functions to be called to handle a device in a specific way. */ -typedef int MBG_DEV_HANDLER_FNC( MBG_DEV_HANDLE, const PCPS_DEV *); +typedef int MBG_DEV_HANDLER_FNC( MBG_DEV_HANDLE ); diff --git a/mbglib/common/usbdefs.h b/mbglib/common/usbdefs.h index c2f4a82..e52da47 100644 --- a/mbglib/common/usbdefs.h +++ b/mbglib/common/usbdefs.h @@ -1,7 +1,7 @@ /************************************************************************** * - * $Id: usbdefs.h 1.62 2022/06/09 10:21:00 torben.mueller TRASH $ + * $Id: usbdefs.h 1.64 2022/12/19 14:30:27 paul.kretz REL_M $ * * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany * @@ -10,7 +10,11 @@ * * ----------------------------------------------------------------------- * $Log: usbdefs.h $ - * Revision 1.62 2022/06/09 10:21:00 torben.mueller + * Revision 1.64 2022/12/19 14:30:27 paul.kretz + * added definitons for REL1002 + * Revision 1.63 2022/11/08 13:57:06Z paul.kretz + * added definitons for N2X185 + * Revision 1.62 2022/06/09 10:21:00Z torben.mueller * added definitons for BPE8NNN * Revision 1.61 2022/05/23 11:22:10Z paul.kretz * added definitons for CPE182, FDM182 and FDM182M @@ -314,7 +318,8 @@ enum MBG_USB_CLASS_CODES #define USB_DEV_SPT_01 ( ( MBG_USB_CLASS_SPT << 8 ) | 0x01 ) -#define USB_DEV_REL_01 ( ( MBG_USB_CLASS_REL << 8 ) | 0x01 ) +#define USB_DEV_REL_01 ( ( MBG_USB_CLASS_REL << 8 ) | 0x01 ) // 3x relays, SAM3S controller +#define USB_DEV_REL1002 ( ( MBG_USB_CLASS_REL << 8 ) | 0x01 ) // 3x relays, STM32F0 controller /// LANTIME CPU quad FTDI serial interface chip #define USB_DEV_LAN_CPU_SERIAL ( ( MBG_USB_CLASS_SERIAL << 8 ) | 0x01 ) @@ -357,7 +362,8 @@ enum MBG_USB_CLASS_CODES #define USB_DEV_GNS182 ( ( MBG_USB_CLASS_GNS << 8 ) | 0x09 ) ///< FPGA 4CE15 #define USB_DEV_GNS182_UC ( ( MBG_USB_CLASS_GNS << 8 ) | 0x0A ) ///< FPGA 4CE15 -#define USB_DEV_N2X180 ( ( MBG_USB_CLASS_N2X << 8 ) | 0x01 ) +#define USB_DEV_N2X180 ( ( MBG_USB_CLASS_N2X << 8 ) | 0x01 ) ///< FPGA 4GX15 +#define USB_DEV_N2X185 ( ( MBG_USB_CLASS_N2X << 8 ) | 0x02 ) ///< FPGA LFE5U-25F-8BG381C #define USB_DEV_FCM180 ( ( MBG_USB_CLASS_FCM << 8 ) | 0x01 ) ///< Fake Clock Module @@ -448,6 +454,7 @@ enum MBG_USB_CLASS_CODES #define USB_DEV_NAME_SPT_01 "SPT_01" #define USB_DEV_NAME_REL_01 "REL_01" +#define USB_DEV_NAME_REL1002 "REL_1002" #define USB_DEV_NAME_LAN_CPU_SERIAL "LAN_CPU_SERIAL" @@ -489,6 +496,7 @@ enum MBG_USB_CLASS_CODES #define USB_DEV_NAME_GNS182_UC "GNS182_UC" #define USB_DEV_NAME_N2X180 "N2X180" +#define USB_DEV_NAME_N2X185 "N2X185" #define USB_DEV_NAME_FCM180 "FCM180" @@ -594,6 +602,8 @@ enum MBG_USB_CLASS_CODES { USB_DEV_FDM182, USB_DEV_NAME_FDM182 }, \ { USB_DEV_FDM182M, USB_DEV_NAME_FDM182M }, \ { USB_DEV_BPE8NNN, USB_DEV_NAME_BPE8NNN }, \ + { USB_DEV_N2X185, USB_DEV_NAME_N2X185 }, \ + { USB_DEV_REL1002, USB_DEV_NAME_REL1002 }, \ { 0, /* end of table */ NULL } \ } diff --git a/mbgsetsystime/mbgsetsystime.c b/mbgsetsystime/mbgsetsystime.c index 9efa1ba..9321a4a 100644 --- a/mbgsetsystime/mbgsetsystime.c +++ b/mbgsetsystime/mbgsetsystime.c @@ -1,7 +1,7 @@ /************************************************************************** * - * $Id: mbgsetsystime.c 1.18 2021/11/15 17:08:53 martin.burnicki REL_M $ + * $Id: mbgsetsystime.c 1.19 2022/12/21 15:39:49 martin.burnicki REL_M $ * * Description: * Main file for mbgsetsystime program which reads the current date @@ -14,6 +14,8 @@ * * ----------------------------------------------------------------------- * $Log: mbgsetsystime.c $ + * Revision 1.19 2022/12/21 15:39:49 martin.burnicki + * Removed obsolete (PCPS_DEV *) parameter from a function. * Revision 1.18 2021/11/15 17:08:53 martin.burnicki * Improved printing of usage information. * Revision 1.17 2021/04/12 21:57:46 martin @@ -292,7 +294,7 @@ int do_set_system_time_from_pcps_hr_time( MBG_DEV_HANDLE dh ) static /*HDR*/ -int do_mbgsetsystime( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev ) +int do_mbgsetsystime( MBG_DEV_HANDLE dh ) { static int system_time_has_been_set; diff --git a/mbgshowsignal/mbgshowsignal.c b/mbgshowsignal/mbgshowsignal.c index 6136799..8475f74 100644 --- a/mbgshowsignal/mbgshowsignal.c +++ b/mbgshowsignal/mbgshowsignal.c @@ -1,7 +1,7 @@ /************************************************************************** * - * $Id: mbgshowsignal.c 1.16 2021/11/15 17:08:55 martin.burnicki REL_M $ + * $Id: mbgshowsignal.c 1.17 2022/12/21 15:40:14 martin.burnicki REL_M $ * * Description: * Main file for mbgshowsignal program which demonstrates how to @@ -10,6 +10,8 @@ * * ----------------------------------------------------------------------- * $Log: mbgshowsignal.c $ + * Revision 1.17 2022/12/21 15:40:14 martin.burnicki + * Removed obsolete (PCPS_DEV *) parameter from a function. * Revision 1.16 2021/11/15 17:08:55 martin.burnicki * Improved printing of usage information. * Revision 1.15 2021/04/12 21:57:52 martin @@ -138,7 +140,7 @@ int show_modulation( MBG_DEV_HANDLE dh ) static /*HDR*/ -int do_mbgshowsignal( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev ) +int do_mbgshowsignal( MBG_DEV_HANDLE dh ) { int do_force_read = 0; int rc = mbg_chk_dev_has_mod( dh ); diff --git a/mbgstatus/mbgstatus.c b/mbgstatus/mbgstatus.c index 7e87717..b7ae7eb 100644 --- a/mbgstatus/mbgstatus.c +++ b/mbgstatus/mbgstatus.c @@ -1,7 +1,7 @@ /************************************************************************** * - * $Id: mbgstatus.c 1.38 2022/07/19 16:07:11 martin.burnicki REL_M $ + * $Id: mbgstatus.c 1.39 2022/12/21 15:46:41 martin.burnicki REL_M $ * * Description: * Main file for mbgstatus program which demonstrates how to @@ -10,6 +10,9 @@ * * ----------------------------------------------------------------------- * $Log: mbgstatus.c $ + * Revision 1.39 2022/12/21 15:46:41 martin.burnicki + * Removed obsolete (PCPS_DEV *) parameter from some functions, + * and use feature check functions instead of macros. * Revision 1.38 2022/07/19 16:07:11 martin.burnicki * Account for a changed function name. * Fixed a spelling error in a status message. @@ -176,64 +179,73 @@ CTRY ctry; typedef struct { - bool has_receiver_info; - bool has_gps_data; - bool has_generic_io; - bool has_asic_version; - bool has_asic_features; + bool is_syn1588; + + // bool has_receiver_info; + // bool has_gps_data; + // bool has_generic_io; + // bool has_asic_version; + // bool has_asic_features; bool has_xmr; - bool is_isa; - bool is_mca; - bool is_pci; - bool is_pci_express; + + // bool is_isa; + // bool is_mca; + // bool is_pci; + // bool is_pci_express; bool is_usb; + bool is_gps; bool is_gnss; + + bool is_lwr; bool is_dcf; bool has_pzf; bool is_msf; bool is_wwvb; bool is_jjy; - bool is_lwr; + bool is_tcr; - bool has_lan_intf; - bool has_ptp; - bool has_ptp_unicast; + // bool has_lan_intf; + // bool has_ptp; + // bool has_ptp_unicast; bool has_hr_time; bool has_fast_hr_timestamp; - bool has_time_scale; + // bool has_time_scale; bool has_event_time; - bool has_ucap; - bool can_clr_ucap_buff; - bool has_tzdl; - bool has_pcps_tzdl; - bool has_tzcode; - bool has_tz; - bool has_irig; + // bool has_ucap; + // bool can_clr_ucap_buff; + // bool has_tzdl; + // bool has_pcps_tzdl; + // bool has_tzcode; + // bool has_tz; + // bool has_irig; bool has_irig_rx; bool has_irig_tx; bool has_irig_ctrl_bits; bool has_raw_irig_data; bool has_irig_time; bool has_signal; - bool has_mod; + // bool has_mod; bool has_sync_time; bool has_rcvr_pos; bool has_bvar_stat; + bool has_stat_info; + bool has_stat_info_mode; + bool has_stat_info_svs; bool has_ttm_time; - bool has_serial; - bool has_serial_hs; - bool has_synth; - bool has_gpio; - bool has_cab_len; + // bool has_serial; + // bool has_serial_hs; + // bool has_synth; + // bool has_gpio; + // bool has_cab_len; bool has_ref_offs; - bool has_opt_flags; + // bool has_opt_flags; bool has_utc_parm; - bool has_corr_info; - bool has_tr_distance; - bool has_debug_status; - bool has_evt_log; - bool has_dac_ctrl; + // bool has_corr_info; + // bool has_tr_distance; + // bool has_debug_status; + // bool has_evt_log; + // bool has_dac_ctrl; PCPS_DEV dev_info; @@ -284,7 +296,6 @@ typedef struct MBG_RAW_IRIG_DATA raw_irig_data; bool raw_irig_data_avail; - bool is_syn1588; SYN1588_PTP_SYNC_STATUS syn1588_ptp_sync_status; bool syn1588_ptp_sync_status_avail; @@ -459,10 +470,7 @@ void print_position( const char *s, const POS *p, const char *tail ) static /*HDR*/ void show_signal( const DEVICE_STATUS *p_ds, int signal ) { - const PCPS_DEV *p_dev = &p_ds->dev_info; - int ref_type; - - ref_type = _pcps_ref_type( p_dev ); + int ref_type = _pcps_ref_type( &p_ds->dev_info ); if ( ref_type >= N_PCPS_REF ) ref_type = PCPS_REF_NONE; @@ -496,7 +504,7 @@ void show_signal( const DEVICE_STATUS *p_ds, int signal ) } } else - if ( _pcps_has_pzf( p_dev ) ) + if ( p_ds->has_pzf ) printf( "/PZF" ); printf( ")\n" ); @@ -510,12 +518,10 @@ void show_time_and_status( const DEVICE_STATUS *p_ds ) { static const char tail[] = "\n"; // TODO - const PCPS_DEV *p_dev = &p_ds->dev_info; - const char status_fmt[] = "Status info: %s%s\n"; const char status_err[] = "*** "; const char status_ok[] = ""; - const char *info_err = ( _pcps_is_gps( p_dev ) || _pcps_is_lwr( p_dev ) ) ? + const char *info_err = ( p_ds->is_gps || p_ds->is_lwr ) ? "ANTENNA FAULTY" : "NO INPUT SIGNAL"; const char info_ok[] = "Input signal available"; char ws[80]; @@ -569,7 +575,7 @@ void show_time_and_status( const DEVICE_STATUS *p_ds ) if ( signal > PCPS_SIG_MAX ) signal = PCPS_SIG_MAX; - if ( _pcps_has_signal( p_dev ) ) // TODO + if ( p_ds->has_signal ) show_signal( p_ds, signal ); if ( p_ds->corr_info_avail ) @@ -760,7 +766,6 @@ void print_bvar_stat( const BVAR_STAT *p ) static /*HDR*/ void show_ext_stat_info( const DEVICE_STATUS *p_ds ) { - const PCPS_DEV *p_dev = &p_ds->dev_info; const RECEIVER_INFO *p_ri = &p_ds->ri; char ws[80]; const char *cp; @@ -773,9 +778,9 @@ void show_ext_stat_info( const DEVICE_STATUS *p_ds ) printf( "EPLD name: \"%s\"\n", p_ri->epld_name ); } - if ( _pcps_has_stat_info( p_dev ) ) + if ( p_ds->has_stat_info ) { - if ( _pcps_has_stat_info_mode( p_dev ) ) + if ( p_ds->has_stat_info_mode ) { switch ( p_ds->agi.stat_info.mode ) { @@ -799,9 +804,9 @@ void show_ext_stat_info( const DEVICE_STATUS *p_ds ) int i; #if 0 && defined( DEBUG ) // FIXME TODO - int must_print_sv_list = _pcps_has_stat_info_svs( p_dev ) && verbose; + int must_print_sv_list = p_ds->has_stat_info_svs && verbose; #else - int must_print_sv_list = _pcps_is_gnss( p_dev ) && verbose; + int must_print_sv_list = p_ds->is_gnss && verbose; #endif int print_multi_lines = ( p_ds->agi.n_gnss_supp > 1 ) || must_print_sv_list; @@ -871,7 +876,7 @@ void show_ext_stat_info( const DEVICE_STATUS *p_ds ) { printf( "Osc type: %s", osc_name[( p_ri->osc_type < N_GPS_OSC ) ? p_ri->osc_type : GPS_OSC_UNKNOWN] ); - if ( _pcps_has_stat_info( p_dev ) ) + if ( p_ds->has_stat_info ) { printf( ", DAC cal: %+i, fine: %+i", (int) ( p_ds->agi.stat_info.dac_cal - OSC_DAC_BIAS ), @@ -1189,10 +1194,9 @@ out: static /*HDR*/ int collect_utc_info( MBG_DEV_HANDLE dh, DEVICE_STATUS *p_ds ) { - const PCPS_DEV *p_dev = &p_ds->dev_info; int rc; - if ( p_ds->has_utc_parm && ( _pcps_is_gps( p_dev ) || ( verbose > 0 ) ) ) + if ( p_ds->has_utc_parm && ( p_ds->is_gps || ( verbose > 0 ) ) ) { rc = mbg_get_utc_parm( dh, &p_ds->utc_info ); p_ds->utc_info_avail = !mbg_cond_err_msg( rc, "mbg_get_utc_parm" ); @@ -1261,7 +1265,7 @@ void show_raw_irig_data( const DEVICE_STATUS *p_ds ) if ( p_ds->raw_irig_data_avail ) { char ws[80]; - int i; + size_t i; printf( "Raw IRIG data:" ); @@ -1576,13 +1580,13 @@ void show_ptp_state( MBG_DEV_HANDLE dh ) static /*HDR*/ /*HDR*/ /** - * @brief Read the version code of the on-board PCI/PCIe interface ASIC. + * @brief Check whether it is safe to use IRQs with this device. * * The API call ::mbg_chk_dev_has_asic_version checks whether * this call is supported by a device. * - * @param[in] dh Valid ::MBG_DEV_HANDLE handle to a Meinberg device. - * @param[out] p_dev Pointer to a ::PCI_ASIC_VERSION type to be filled up. + * @param[in] dh Valid ::MBG_DEV_HANDLE handle to a Meinberg device. + * @param[in] p_dev Pointer to a device info structure read from the device. * * @return ::MBG_SUCCESS on success, else one of the @ref MBG_ERROR_CODES * @@ -1663,7 +1667,6 @@ int check_all_device_features( MBG_DEV_HANDLE dh, DEVICE_STATUS *p_ds, if ( mbg_cond_err_msg( rc, "mbg_setup_receiver_info" ) ) goto out; - // p_ds->has_receiver_info = mbg_rc_is_success( ( dh ) ); // p_ds->has_gps_data = mbg_rc_is_success( ( dh ) ); // p_ds->has_generic_io = mbg_rc_is_success( ( dh ) ); @@ -1674,23 +1677,30 @@ int check_all_device_features( MBG_DEV_HANDLE dh, DEVICE_STATUS *p_ds, // p_ds->is_mca = mbg_rc_is_success( ( dh ) ); // p_ds->is_pci = mbg_rc_is_success( ( dh ) ); // p_ds->is_pci_express = mbg_rc_is_success( ( dh ) ); - // p_ds->is_usb = mbg_rc_is_success( ( dh ) ); + p_ds->is_usb = mbg_rc_is_success( mbg_chk_dev_is_usb( dh ) ); + p_ds->is_gps = mbg_rc_is_success( mbg_chk_dev_is_gps( dh ) ); - // p_ds->is_gnss = mbg_rc_is_success( ( dh ) ); - // p_ds->is_dcf = mbg_rc_is_success( ( dh ) ); - // p_ds->has_pzf = mbg_rc_is_success( ( dh ) ); - // p_ds->is_msf = mbg_rc_is_success( ( dh ) ); - // p_ds->is_wwvb = mbg_rc_is_success( ( dh ) ); - // p_ds->is_jjy = mbg_rc_is_success( ( dh ) ); - // p_ds->is_lwr = mbg_rc_is_success( ( dh ) ); - // p_ds->is_tcr = mbg_rc_is_success( ( dh ) ); + if ( p_ds->is_gps ) + p_ds->is_gnss = mbg_rc_is_success( mbg_chk_dev_is_gnss( dh ) ); + + p_ds->is_lwr = mbg_rc_is_success( mbg_chk_dev_is_lwr( dh ) ); + if ( p_ds->is_lwr ) + { + p_ds->is_dcf = mbg_rc_is_success( mbg_chk_dev_is_dcf( dh ) ); + p_ds->has_pzf = mbg_rc_is_success( mbg_chk_dev_has_pzf( dh ) ); + p_ds->is_msf = mbg_rc_is_success( mbg_chk_dev_is_msf( dh ) ); + p_ds->is_wwvb = mbg_rc_is_success( mbg_chk_dev_is_wwvb( dh ) ); + p_ds->is_jjy = mbg_rc_is_success( mbg_chk_dev_is_jjy( dh ) ); + } + + p_ds->is_tcr = mbg_rc_is_success( mbg_chk_dev_is_tcr( dh ) ); // p_ds->has_lan_intf = mbg_rc_is_success( ( dh ) ); // p_ds->has_ptp = mbg_rc_is_success( ( dh ) ); // p_ds->has_ptp_unicast = mbg_rc_is_success( ( dh ) ); p_ds->has_hr_time = mbg_rc_is_success( mbg_chk_dev_has_hr_time( dh ) ); p_ds->has_fast_hr_timestamp = mbg_rc_is_success( mbg_chk_dev_has_fast_hr_timestamp( dh ) ); // p_ds->has_time_scale = mbg_rc_is_success( ( dh ) ); - // p_ds->has_event_time = mbg_rc_is_success( ( dh ) ); + p_ds->has_event_time = mbg_rc_is_success( mbg_chk_dev_has_event_time( dh ) ); // p_ds->has_ucap = mbg_rc_is_success( ( dh ) ); // p_ds->can_clr_ucap_buff = mbg_rc_is_success( ( dh ) ); // p_ds->has_tzdl = mbg_rc_is_success( ( dh ) ); @@ -1699,15 +1709,18 @@ int check_all_device_features( MBG_DEV_HANDLE dh, DEVICE_STATUS *p_ds, // p_ds->has_tz = mbg_rc_is_success( ( dh ) ); // p_ds->has_irig = mbg_rc_is_success( ( dh ) ); p_ds->has_irig_rx = mbg_rc_is_success( mbg_chk_dev_is_tcr( dh ) ); - // p_ds->has_irig_tx = mbg_rc_is_success( ( dh ) ); - // p_ds->has_irig_ctrl_bits = mbg_rc_is_success( ( dh ) ); - // p_ds->has_raw_irig_data = mbg_rc_is_success( ( dh ) ); + p_ds->has_irig_tx = mbg_rc_is_success( mbg_chk_dev_has_irig_tx( dh ) ); + p_ds->has_irig_ctrl_bits = mbg_rc_is_success( mbg_chk_dev_has_irig_ctrl_bits( dh ) ); + p_ds->has_raw_irig_data = mbg_rc_is_success( mbg_chk_dev_has_raw_irig_data( dh ) ); p_ds->has_irig_time = mbg_rc_is_success( mbg_chk_dev_has_irig_time( dh ) ); - // p_ds->has_signal = mbg_rc_is_success( ( dh ) ); + p_ds->has_signal = mbg_rc_is_success( mbg_chk_dev_has_signal( dh ) ); // p_ds->has_mod = mbg_rc_is_success( ( dh ) ); p_ds->has_sync_time = mbg_rc_is_success( mbg_chk_dev_has_sync_time( dh ) ); p_ds->has_rcvr_pos = mbg_rc_is_success( mbg_chk_dev_has_rcvr_pos( dh ) ); p_ds->has_bvar_stat = mbg_rc_is_success( mbg_chk_dev_has_bvar_stat( dh ) ); + p_ds->has_stat_info = p_ds->is_gps || p_ds->has_pzf; // TODO + p_ds->has_stat_info_mode = p_ds->is_gps; // TODO + p_ds->has_stat_info_svs = p_ds->is_gps; // TODO p_ds->has_ttm_time = mbg_rc_is_success( mbg_chk_dev_has_ttm_time( dh ) ); // p_ds->has_serial = mbg_rc_is_success( ( dh ) ); // p_ds->has_serial_hs = mbg_rc_is_success( ( dh ) ); @@ -1773,38 +1786,50 @@ void print_all_device_status( const DEVICE_STATUS *p_ds ) static /*HDR*/ -int do_mbgstatus( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev ) +int do_mbgstatus( MBG_DEV_HANDLE dh ) { + PCPS_DEV dev; DEVICE_STATUS device_status; DEVICE_STATUS *p_ds = &device_status; int ret_val = 0; + int rc; + + // First we collect some information without accessing + // the device hardware. // SYN1588 devices are somewhat different ... bool is_syn1588 = mbg_rc_is_success( mbg_chk_dev_is_syn1588_type( dh ) ); + rc = mbg_get_device_info( dh, &dev ); + + if ( mbg_cond_err_msg( rc, "mbg_get_device_info" ) ) + goto done; + if ( !is_syn1588 ) { - if ( mbg_rc_is_error( check_irq_safe( dh, p_dev ) ) ) + if ( mbg_rc_is_error( check_irq_safe( dh, &dev ) ) ) goto done; if ( verbose ) { show_dev_cpu_info( dh ); - printf( "Firmware ID: \"%s\"\n", _pcps_fw_id( p_dev ) ); + printf( "Firmware ID: \"%s\"\n", _pcps_fw_id( &dev ) ); } } if ( list_only ) goto done; - check_all_device_features( dh, p_ds, p_dev, is_syn1588 ); + + // Now we collect the majority of device information. + check_all_device_features( dh, p_ds, &dev, is_syn1588 ); for (;;) { collect_all_device_status( dh, p_ds ); print_all_device_status( p_ds ); - if ( verbose && _pcps_is_irig_rx( p_dev ) ) + if ( verbose && p_ds->is_tcr ) show_irig_debug_status( dh ); if ( mbg_rc_is_success( mbg_chk_dev_has_lan_intf( dh ) ) ) @@ -1819,7 +1844,7 @@ int do_mbgstatus( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev ) if ( p_ds->has_xmr || do_force_read ) show_all_xmr_status( dh, do_force_read ? "MRS status (disabled, forced access):" : "MRS status:", - " ", verbose - 4, do_force_read ); + " ", do_force_read ); } show_invt_reason(); diff --git a/mbgtcrcal/mbgtcrcal.c b/mbgtcrcal/mbgtcrcal.c index afddacd..3b321f6 100644 --- a/mbgtcrcal/mbgtcrcal.c +++ b/mbgtcrcal/mbgtcrcal.c @@ -1,7 +1,7 @@ /************************************************************************** * - * $Id: mbgtcrcal.c 1.18 2021/11/15 17:08:53 martin.burnicki REL_M $ + * $Id: mbgtcrcal.c 1.19 2022/12/21 15:07:32 martin.burnicki REL_M $ * * Description: * Main file for mbgtcrcal program which can be used to calibrate @@ -9,6 +9,9 @@ * * ----------------------------------------------------------------------- * $Log: mbgtcrcal.c $ + * Revision 1.19 2022/12/21 15:07:32 martin.burnicki + * Removed obsolete (PCPS_DEV *) parameter from some functions, + * and use feature check functions instead of macros. * Revision 1.18 2021/11/15 17:08:53 martin.burnicki * Improved printing of usage information. * Revision 1.17 2021/04/12 21:58:03 martin @@ -93,7 +96,7 @@ char *str_comp_data( char *s, int max_len, int comp_data ) static /*HDR*/ -void print_cal_recs( int num_rec, int curr_group_idx, CAL_REC_IRIG_RX_COMP cal_rec_comp[] ) +void print_cal_recs( int num_rec, CAL_REC_IRIG_RX_COMP cal_rec_comp[] ) { int idx; char ws[20]; @@ -122,7 +125,7 @@ void print_cal_recs( int num_rec, int curr_group_idx, CAL_REC_IRIG_RX_COMP cal_r static /*HDR*/ -int do_mbgtcrcal( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev ) +int do_mbgtcrcal( MBG_DEV_HANDLE dh ) { IRIG_INFO irig_rx_info; CAL_REC_IRIG_RX_COMP cal_rec_comp[N_IRIG_RX_COMP] = { { { 0 } } }; @@ -134,9 +137,10 @@ int do_mbgtcrcal( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev ) char ws[20]; int curr_group_idx; - // Check if this device provides an IRIG input. - if ( !_pcps_is_irig_rx( p_dev ) ) + rc = mbg_chk_dev_is_tcr( dh ); + + if ( mbg_rc_is_error( rc ) ) { printf( "This device does not provide an IRIG input.\n" ); goto done; @@ -172,7 +176,7 @@ int do_mbgtcrcal( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev ) // but we will not be able to assign and save new settings. - if ( !_pcps_has_generic_io( p_dev ) ) + if ( mbg_rc_is_error( mbg_chk_dev_has_generic_io( dh ) ) ) { printf( "This device does not support IRIG calibration\n" ); goto done; @@ -256,7 +260,7 @@ int do_mbgtcrcal( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev ) printf( "\nCurrent compensation settings:\n" ); - print_cal_recs( num_rec, curr_group_idx, cal_rec_comp ); + print_cal_recs( num_rec, cal_rec_comp ); printf( "\nCurrent IRIG code: %s --> group %i compensation effective\n", icode_rx_names[irig_rx_info.settings.icode], diff --git a/mbgxhrtime/mbgxhrtime.c b/mbgxhrtime/mbgxhrtime.c index 87b7ba6..30bebd9 100644 --- a/mbgxhrtime/mbgxhrtime.c +++ b/mbgxhrtime/mbgxhrtime.c @@ -1,7 +1,7 @@ /************************************************************************** * - * $Id: mbgxhrtime.c 1.11 2021/11/15 17:08:54 martin.burnicki REL_M $ + * $Id: mbgxhrtime.c 1.12 2022/12/21 15:43:02 martin.burnicki REL_M $ * * Description: * Main file for mbgxhrtime program which demonstrates how to retrieve @@ -41,6 +41,10 @@ * * ----------------------------------------------------------------------- * $Log: mbgxhrtime.c $ + * Revision 1.12 2022/12/21 15:43:02 martin.burnicki + * Removed obsolete (PCPS_DEV *) parameter from a function, + * and use feature check functions instead of macros. + * This feature is not supported with SYN1588 devices. * Revision 1.11 2021/11/15 17:08:54 martin.burnicki * Improved printing of usage information. * Revision 1.10 2021/04/12 21:57:48 martin @@ -175,7 +179,7 @@ void check_set_process_affinity_mask( MBG_PROCESS_ID pid, int cpu_num ) static /*HDR*/ -int do_mbgxhrtime( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev ) +int do_mbgxhrtime( MBG_DEV_HANDLE dh ) { MBG_PC_CYCLES_FREQUENCY freq_hz = 0; MBG_PC_CYCLES_FREQUENCY default_freq_hz = 0; @@ -183,7 +187,13 @@ int do_mbgxhrtime( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev ) MBG_POLL_THREAD_INFO poll_thread_info = { { { { 0 } } } }; int rc; - if ( !_pcps_has_hr_time( p_dev ) ) + if ( mbg_rc_is_success( mbg_chk_dev_is_syn1588_type( dh ) ) ) + { + printf( "This feature is not yet supported for SYN1588 devices.\n" ); + return 0; + } + + if ( mbg_rc_is_error( mbg_chk_dev_has_hr_time( dh ) ) ) { printf( "High resolution time not supported by this device.\n" ); return 0; |