83 #if defined( MBG_TGT_WIN32 ) 95 #if defined( MBG_TGT_WIN32 ) && defined( _MSC_VER ) 98 #define isatty _isatty 99 #define fileno _fileno 115 uint64_t ts = pcps_time_stamp_to_uint64( p_ts );
116 uint64_t prv_ts = pcps_time_stamp_to_uint64( p_prv_ts );
161 int first_year,
int last_year )
165 if ( last_year == 0 )
172 n +=
snprintf_safe( &s[n], max_len - n,
" copyright Meinberg " );
174 if ( first_year != last_year )
175 n +=
snprintf_safe( &s[n], max_len - n,
"%04i-", first_year );
199 if ( !isatty( fileno( stdout ) ) )
200 setvbuf( stdout, NULL, _IONBF, 0 );
204 printf(
"\n%s\n\n", ws );
219 printf(
"Usage: %s [[opt] [opt] ...] [[dev] [dev] ...]\n\n", pname );
222 printf(
"%s\n\n", info );
238 if ( opt_name == NULL )
241 if ( opt_info == NULL )
244 printf(
" %8s %s\n", opt_name, opt_info );
259 puts(
"where \"opt\" is one of the options:" );
274 puts(
"where \"dev\" can be:" );
276 #if MBG_TGT_HAS_DEV_FN_BASE 277 printf(
" a device file name, e.g. \"%s\" or \"%s\"\n",
280 printf(
" a device type name, with or with S/N appended, e.g. \"%s\" or \"%s\"\n",
283 printf(
" a device index, e.g. \"0\", \"1\",\"2\", ...\n" );
325 printf(
"%s:\n", dev_name );
374 printf(
" at port 0x%03lX", port );
379 printf(
"/0x%03lX", port );
384 printf(
", irq %i", irq_num );
387 printf(
"\n** Warning: %s v" PCPS_FW_STR_FMT " has a 20 ms timing bug. Please upgrade the firmware!",
422 rc = fnc( dh, &dev );
444 static int num_devices;
445 static bool has_searched_devices;
447 if ( !has_searched_devices )
450 has_searched_devices =
true;
480 char *dev_name_buffer,
size_t dev_name_buffer_size )
486 if ( dev_name_buffer == NULL || dev_name_buffer_size == 0 )
489 dev_name_buffer[0] = 0;
497 #if MBG_TGT_HAS_DEV_FN_BASE 501 snprintf_safe( dev_name_buffer, dev_name_buffer_size,
"%s", dev_param_str );
503 goto has_tried_to_open;
510 l = strtol( dev_param_str, &endptr, 0 );
514 if ( endptr == &dev_param_str[strlen( dev_param_str )] )
516 long l_max = (long) ( ( (
unsigned int) -1 ) >> 1 );
528 goto open_dev_with_idx;
534 snprintf_safe( dev_name_buffer, dev_name_buffer_size,
"%s", dev_param_str );
536 goto has_tried_to_open;
548 if ( devices_found == 0 )
551 if ( dev_idx >= devices_found )
597 char *dev_name_buffer,
size_t dev_name_buffer_size )
600 dev_name_buffer, dev_name_buffer_size );
605 n =
snprintf_safe( msg,
sizeof( msg ),
"** Failed to open device" );
607 if ( dev_name_buffer[0] )
608 n +=
snprintf_safe( &msg[n],
sizeof( msg ) - n,
" %s", dev_name_buffer );
611 n +=
snprintf_safe( &msg[n],
sizeof( msg ) - n,
" %s", dev_param_str );
613 n +=
snprintf_safe( &msg[n],
sizeof( msg ) - n,
" %i", dev_idx );
616 fprintf( stderr,
"%s\n\n", msg );
660 int devices_specified = argc - optind;
661 int devices_found = 0;
662 const char *dev_param_str = NULL;
666 if ( devices_specified )
670 for ( i = optind; i < argc; i++ )
672 dev_param_str = argv[i];
675 tmp_dev_fn,
sizeof( tmp_dev_fn ) );
678 rc =
mbg_handle_device( dh, ( devices_specified > 1 ) ? tmp_dev_fn : NULL, fnc );
700 rc = fnc( dh, NULL );
713 if ( devices_found == 0 )
717 if ( !( chk_dev_flags & CHK_DEV_WITHOUT_DEV ) )
719 printf(
"No device found.\n" );
734 for ( i = 0; i < devices_found; i++ )
770 n +=
snprintf_safe( &s[n], max_len - n,
"%04u-%02u-%02u %02u:%02u:%02u.%02u",
775 n +=
snprintf_safe( &s[n], max_len - n,
" (UTC%+ih), st: %02Xh",
800 long utc_offs,
int show_raw )
804 struct tm tm = { 0 };
809 n +=
snprintf_safe( &s[n], max_len - n,
"raw: 0x%08lX.%08lX, ",
814 l = (long) p->
sec + utc_offs;
825 tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
826 tm.tm_hour, tm.tm_min, tm.tm_sec,
856 const char *time_scale_name;
874 time_scale_name =
"UTC";
878 time_scale_name =
"TAI";
881 time_scale_name =
"GPS";
883 n +=
snprintf_safe( &s[n], max_len - n,
" %s%s", time_scale_name, cp );
913 int no_latency,
int show_raw )
918 printf(
"HR time %s", ws );
924 printf(
", latency: %.1f us", ( (
double) hns_latency ) / 10 );
957 int no_latency,
int show_raw,
int verbose )
962 printf(
"HR time %s", ws );
968 printf(
", latency: %.1f us", ( (
double) hns_latency ) / 10 );
974 printf(
", sig: %i", p_ht->
signal );
1011 printf(
"%s, PZF correlation: %u%%", cp, ci.
val );
1013 if ( show_corr_step )
1015 printf(
" Shift: %c", ci.
corr_dir );
char corr_dir
space, '<', or '>', just for information
#define PCPS_HRT_FRAC_SCALE
Scale to be used to print PCPS_TIME_STAMP::frac values.
_MBG_API_ATTR int _MBG_API mbg_find_devices(void)
Get the number of devices installed on the computer.
uint8_t year
year of the century, 0..99
#define _pcps_fw_rev_num_minor(_v)
#define _pcps_fw_rev_num_major(_v)
#define MBG_MICRO_VERSION_CODE
uint8_t mday
day of month, 0..31
uint8_t sec100
hundredths of seconds, 0..99, 10 ms resolution
#define _pcps_asic_version_major(_v)
Extract the major part of an ASIC version number.
#define MBG_ERR_NO_DEV
No such device, or attempted an inappropriate function.
char name[(16+1)]
Optional string identifying a customized firmware version, should be empty in standard versions...
#define MBG_ERR_INV_PARM
Invalid parameter.
static MBG_OPT_INFO opt_info
bool mbg_cond_err_msg(int rc, const char *what)
Check if a value is an error code and print an associated error message.
PCPS_SECONDS sec
seconds since 1970, usually UTC scale
#define _int_from_size_t(_n)
#define MBG_ERR_GENERIC
Generic error.
#define mbg_rc_is_success(_rc)
#define MBG_ERR_RANGE
input parameter was out of range
#define PCPS_ASIC_STR_FMT
_MBG_API_ATTR int _MBG_API mbg_dev_fn_from_dev_idx(char *s, int max_len, int dev_idx)
Create a device file name associated with an index number.
_MBG_API_ATTR MBG_DEV_HANDLE _MBG_API mbg_open_device_by_name(const MBG_DEV_NAME srch_name, int selection_mode)
Return a handle to a device with a particular device name.
uint8_t val
correlation value, or check count if status ==:: PZF_CORR_CHECK
uint8_t status
status codes, see PZF_CORR_STATES
#define MBG_CURRENT_COPYRIGHT_YEAR
#define PCPS_HRT_FRAC_SCALE_FMT
Format specifier used to print PCPS_TIME_STAMP::frac values.
static const char * pname
#define _pcps_irq_num(_d)
#define MBG_MINOR_VERSION_CODE
int32_t utc_offs
UTC offs [sec] (loc_time = tstamp + utc_offs)
static __mbg_inline time_t cvt_to_time_t(mbg_time_t t)
PCPS_TIME_STATUS_X status
status bits, see PCPS_TIME_STATUS_FLAGS
use the next available device of the same type
_MBG_API_ATTR int _MBG_API mbg_get_device_info(MBG_DEV_HANDLE dh, PCPS_DEV *p)
Read detailed device information.
_MBG_API_ATTR MBG_DEV_HANDLE _MBG_API mbg_open_device(int dev_idx)
Open a device by index number.
PCPS_FRAC_32 frac
binary fractions of second, see PCPS_FRAC_32
#define _pcps_has_asic_version(_d)
PCPS_TIME_STAMP tstamp
High resolution time stamp (UTC)
#define _pcps_short_port_base(_d, _n)
_MBG_API_ATTR int _MBG_API mbg_get_gps_gnss_mode_info(MBG_DEV_HANDLE dh, MBG_GNSS_MODE_INFO *p_mi)
Read the current GNSS mode info including current settings.
int8_t offs_utc
[hours], 0 if not _pcps_has_utc_offs
int snprint_gmtime_error(char *s, size_t max_len, int mbg_errno, time_t t, const char *calling_fnc)
#define MBG_FRAC32_UNITS_PER_SEC
Constant used to convert e.g. PCPS_TIME_STAMP::frac values.
#define MBG_SUCCESS
Error codes used with Meinberg devices and drivers.
_MBG_API_ATTR void _MBG_API mbg_close_device(MBG_DEV_HANDLE *dev_handle)
Close a device handle and set the handle value to MBG_INVALID_DEV_HANDLE.
_MBG_API_ATTR int _MBG_API mbg_setup_receiver_info(MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev, RECEIVER_INFO *p)
Set up a RECEIVER_INFO structure for a device.
static __mbg_inline int mbg_gmtime(struct tm *p_tm, const time_t *p_time)
static __mbg_inline int pcps_exp_year(int year, int year_lim)
Expand a 2-digit year number to a 4-digit year number.
PZF correlation status info.
#define _pcps_fw_rev_num(_d)
static __mbg_inline uint32_t bin_frac_32_to_dec_frac(uint32_t bin, uint32_t scale)
Convert a 32 bit binary fraction to a scaled decimal.
High resolution time including status and local time offset.
const char mbg_dev_fn_base[]
#define MBG_INVALID_DEV_HANDLE
int snprint_utc_offs(char *s, size_t max_len, const char *info, long utc_offs)
Print a UTC offset into a string.
uint32_t PCI_ASIC_VERSION
A data type to hold the PCI ASIC version code.
PCPS_SIG_VAL signal
signal strength, see PCPS_SIG_VAL_DEFS
PCPS_SIG_VAL signal
signal strength, see PCPS_SIG_VAL_DEFS, or capture input channel number
Local calendar date and time, plus sync status.
A high resolution time stamp.
#define _pcps_type_name(_d)
int snprintf_safe(char *s, size_t max_len, const char *fmt,...)
A portable, safe implementation of snprintf()
#define _pcps_asic_version_minor(_v)
Extract the minor part of an ASIC version number.
_MBG_API_ATTR int _MBG_API mbg_get_asic_version(MBG_DEV_HANDLE dh, PCI_ASIC_VERSION *p)
Read the version code of the on-board PCI/PCIe interface ASIC.
#define mbg_rc_is_error(_rc)
uint8_t min
minutes, 0..59
#define _convert_asic_version_number(_n)
Version number conversion macro.
const char * mbg_strerror(int mbg_errno)
Return an error string associated with the MBG_ERROR_CODES.
unsigned __int64 uint64_t
SW_REV sw_rev
software revision and ID
_MBG_API_ATTR MBG_DEV_HANDLE _MBG_API mbg_open_device_by_dev_fn(const char *dev_fn)
Open a device specified by a device file name.
A structure used to identify a device type and supported features.
char MBG_DEV_FN[260]
A string that can take a device file name.
#define MBG_MAJOR_VERSION_CODE
int mbg_get_last_error(const char *info)
Get and translate last error after non-socket function call.
int chk_sw_rev_name(SW_REV *p, int verbose)
Check if a software revision name should be displayed.
uint8_t month
month, 1..12
_MBG_API_ATTR int _MBG_API mbg_get_corr_info(MBG_DEV_HANDLE dh, CORR_INFO *p)
Read PZF correlation info from a device.
PCPS_TIME_STATUS status
status bits, see PCPS_TIME_STATUS_FLAGS_COMMON
uint8_t sec
seconds, 0..59, or 60 if leap second
#define _pcps_fw_has_20ms_bug(_d)