mbgtools-lx  4.2.8
toolutil.h
Go to the documentation of this file.
1 
2 /**************************************************************************
3  *
4  * $Id: toolutil.h 1.8 2019/03/13 09:44:57 martin REL_M $
5  *
6  * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany
7  *
8  * Description:
9  * Definitions and prototypes for toolutil.c.
10  *
11  * -----------------------------------------------------------------------
12  * $Log: toolutil.h $
13  * Revision 1.8 2019/03/13 09:44:57 martin
14  * Moved predefined program exit codes to mbgerror.h.
15  * Revision 1.7 2018/12/14 13:14:52 martin
16  * Updated function prototypes.
17  * Revision 1.6 2018/11/15 12:21:10 martin
18  * Updated function prototypes.
19  * Revision 1.5 2018/06/25 13:47:45 martin
20  * Updated function prototypes.
21  * Revision 1.4 2017/07/05 07:38:06 martin
22  * Support Windows target.
23  * Defined function type MBG_DEV_HANDLER_FNC.
24  * Defined some OS-specific strings e.g. for example
25  * file and device names used in help messages.
26  * Check for MBG_TGT_POSIX instead of MBG_TGT_UNIX.
27  * Doxygen comments.
28  * Updated function prototypes.
29  * Revision 1.3 2012/10/15 09:36:22 martin
30  * Use common way to handle version information.
31  * Added string table with PZF state names.
32  * Updated function prototypes.
33  * Revision 1.2 2009/06/19 12:11:35 martin
34  * Updated function prototypes.
35  * Revision 1.1 2008/12/17 10:45:14 martin
36  * Initial revision.
37  * Revision 1.1 2008/12/15 08:35:08 martin
38  * Initial revision.
39  *
40  **************************************************************************/
41 
42 #ifndef _TOOLUTIL_H
43 #define _TOOLUTIL_H
44 
45 
46 /* Other headers to be included */
47 
48 #include <mbgdevio.h>
49 #include <mbgversion.h>
50 
51 #if defined( MBG_TGT_POSIX )
52 
53  #include <unistd.h>
54 
55 #elif defined( MBG_TGT_WIN32 )
56 
57  #include <io.h>
58  #include <fcntl.h>
59  #include <sys/types.h>
60  #include <sys/stat.h>
61  #include <wingetopt.h>
62 
63  #define open _open
64  #define snprintf _snprintf
65  #define sleep( _x ) Sleep( (_x) * 1000 )
66  #define usleep( _x ) Sleep( (_x) / 1000 )
67 
68 #endif
69 
70 
71 
72 #ifdef _TOOLUTIL
73  #define _ext
74  #define _DO_INIT
75 #else
76  #define _ext extern
77 #endif
78 
79 
80 /* Start of header body */
81 
82 #ifdef __cplusplus
83 extern "C" {
84 #endif
85 
86 
88 {
91 };
92 
93 
94 
95 #if MBG_TGT_HAS_DEV_FN
96  #define EXAMPLE_DEV_FN_1 MBGCLOCK_DEV_FN_BASE "0"
97  #define EXAMPLE_DEV_FN_1_TCR EXAMPLE_DEV_FN_1
98  #define EXAMPLE_DEV_FN_2 MBGCLOCK_DEV_FN_BASE "3"
99 #endif
100 
101 #define EXAMPLE_DEV_NAME_1 "gps180pex"
102 #define EXAMPLE_DEV_NAME_1_TCR "tcr167pci"
103 #define EXAMPLE_DEV_NAME_2 "tcr170pex_027911002000"
104 
105 
106 #if defined( MBG_TGT_POSIX )
107  #define ROOT_PRIVILEGES_STR "with root privileges"
108 #else
109  #define ROOT_PRIVILEGES_STR "as administrator"
110 #endif
111 
112 
113 #if !defined( MBG_EXP_YEAR_LIMIT )
114  #define MBG_EXP_YEAR_LIMIT 1980
115 #endif
116 
117 
119 #ifdef _DO_INIT
121 #endif
122 ;
123 
125 
126 _ext const char str_empty[]
127 #ifdef _DO_INIT
128  = ""
129 #endif
130 ;
131 
132 
134 #ifdef _DO_INIT
136 #endif
137 ;
138 
139 
140 
145 
146 
147 
148 /* ----- function prototypes begin ----- */
149 
150 /* This section was generated automatically */
151 /* by MAKEHDR, do not remove the comments. */
152 
161  int mbg_program_version_str( char *s, size_t max_len ) ;
162 
174  int mbg_program_info_str( char *s, size_t max_len, const char *pname, int first_year, int last_year ) ;
175 
183  void mbg_print_program_info( const char *pname, int first_year, int last_year ) ;
184 
191  void mbg_print_usage_intro( const char *pname, const char *info ) ;
192 
199  void mbg_print_opt_info( const char *opt_name, const char *opt_info ) ;
200 
207  void mbg_print_help_options( void ) ;
208 
212  void mbg_print_device_options( void ) ;
213 
220  void mbg_print_default_usage( const char *pname, const char *prog_info ) ;
221 
231  int mbg_get_show_dev_info( MBG_DEV_HANDLE dh, const char *dev_name, PCPS_DEV *p_dev ) ;
232 
242  int mbg_handle_device( MBG_DEV_HANDLE dh, const char *dev_name, MBG_DEV_HANDLER_FNC *fnc ) ;
243 
251  int chk_get_num_devices( void ) ;
252 
272  int mbg_open_device_by_param( MBG_DEV_HANDLE *p_dh, const char *dev_param_str, int dev_idx, char *dev_name_buffer, size_t dev_name_buffer_size ) ;
273 
296  int mbg_open_device_by_param_chk( MBG_DEV_HANDLE *p_dh, const char *dev_param_str, int dev_idx, char *dev_name_buffer, size_t dev_name_buffer_size ) ;
297 
327  int mbg_handle_devices( int argc, char *argv[], int optind, MBG_DEV_HANDLER_FNC *fnc, int chk_dev_flags ) ;
328 
341  int mbg_snprint_date_time( char *s, size_t max_len, const PCPS_TIME *p, int verbose ) ;
342 
354  int mbg_snprint_hr_tstamp( char *s, size_t max_len, const PCPS_TIME_STAMP *p, long utc_offs, int show_raw ) ;
355 
369  int mbg_snprint_hr_time( char *s, size_t max_len, const PCPS_HR_TIME *p, int show_raw ) ;
370 
391  void mbg_print_hr_timestamp( PCPS_TIME_STAMP *p_ts, int32_t hns_latency, PCPS_TIME_STAMP *p_prv_ts, int no_latency, int show_raw ) ;
392 
416  void mbg_print_hr_time( PCPS_HR_TIME *p_ht, int32_t hns_latency, PCPS_TIME_STAMP *p_prv_ts, int no_latency, int show_raw, int verbose ) ;
417 
426  int mbg_show_pzf_corr_info( MBG_DEV_HANDLE dh, int show_corr_step ) ;
427 
437 
438 
439 /* ----- function prototypes end ----- */
440 
441 
442 #ifdef __cplusplus
443 }
444 #endif
445 
446 
447 /* End of header body */
448 
449 #undef _ext
450 #undef _DO_INIT
451 
452 #endif /* _TOOLUTIL_H */
453 
const char str_empty[]
int must_print_usage
int mbg_open_device_by_param(MBG_DEV_HANDLE *p_dh, const char *dev_param_str, int dev_idx, char *dev_name_buffer, size_t dev_name_buffer_size)
Try to open a device using a parameter string or device index.
Definition: toolutil.c:479
static char * dev_name
Definition: mbgctrl.c:131
int chk_get_num_devices(void)
Get the number of devices actually present.
Definition: toolutil.c:442
static int verbose
Definition: mbghrtime.c:80
void mbg_print_hr_time(PCPS_HR_TIME *p_ht, int32_t hns_latency, PCPS_TIME_STAMP *p_prv_ts, int no_latency, int show_raw, int verbose)
Print date and time from a PCPS_HR_TIME structure.
Definition: toolutil.c:956
void mbg_print_hr_timestamp(PCPS_TIME_STAMP *p_ts, int32_t hns_latency, PCPS_TIME_STAMP *p_prv_ts, int no_latency, int show_raw)
Print date and time from a PCPS_TIME_STAMP structure.
Definition: toolutil.c:912
static MBG_OPT_INFO opt_info
Definition: mbgirigcfg.c:99
void mbg_print_help_options(void)
Print info on common program help arguments.
Definition: toolutil.c:257
int mbg_handle_device(MBG_DEV_HANDLE dh, const char *dev_name, MBG_DEV_HANDLER_FNC *fnc)
Print device info and take some action on a specific device.
Definition: toolutil.c:412
unsigned short uint16_t
Definition: words.h:213
#define MBG_EXP_YEAR_LIMIT
Definition: toolutil.h:114
void mbg_print_device_options(void)
Print common info on how to specify devices on the command line.
Definition: toolutil.c:270
void mbg_print_opt_info(const char *opt_name, const char *opt_info)
Print info on a single program option / argument.
Definition: toolutil.c:236
int mbg_snprint_date_time(char *s, size_t max_len, const PCPS_TIME *p, int verbose)
Print date and time from a PCPS_TIME structure to a string.
Definition: toolutil.c:766
call callback for all devices
Definition: toolutil.h:89
static const char * pname
Definition: mbgcmptime.c:55
int mbg_program_version_str(char *s, size_t max_len)
Print the program version to a string buffer.
Definition: toolutil.c:135
int mbg_program_info_str(char *s, size_t max_len, const char *pname, int first_year, int last_year)
Print some program info to a string buffer.
Definition: toolutil.c:160
int mbg_open_device_by_param_chk(MBG_DEV_HANDLE *p_dh, const char *dev_param_str, int dev_idx, char *dev_name_buffer, size_t dev_name_buffer_size)
Try to open a device and print a message in case of error.
Definition: toolutil.c:596
uint16_t mbg_exp_year_limit
int mbg_snprint_hr_time(char *s, size_t max_len, const PCPS_HR_TIME *p, int show_raw)
Print date and time from a PCPS_HR_TIME structure to a string.
Definition: toolutil.c:851
int mbg_get_gps_gnss_mode_info_chk(MBG_DEV_HANDLE dh, MBG_GNSS_MODE_INFO *p)
Retrieve a MBG_GNSS_MODE_INFO structure from a device.
Definition: toolutil.c:1032
int MBG_DEV_HANDLER_FNC(MBG_DEV_HANDLE, const PCPS_DEV *)
The type of functions to called to handle a device in a specific way.
Definition: toolutil.h:144
void mbg_print_program_info(const char *pname, int first_year, int last_year)
Print program info to console.
Definition: toolutil.c:193
void mbg_print_default_usage(const char *pname, const char *prog_info)
Print program info and default usage information.
Definition: toolutil.c:296
int mbg_show_pzf_corr_info(MBG_DEV_HANDLE dh, int show_corr_step)
Retrieve and print PZF correlation info for a device which supports this.
Definition: toolutil.c:991
call callback once if no device found
Definition: toolutil.h:90
#define _ext
Definition: toolutil.h:76
High resolution time including status and local time offset.
Definition: pcpsdefs.h:1085
void mbg_print_usage_intro(const char *pname, const char *info)
Print usage intro to console.
Definition: toolutil.c:217
const char * pzf_corr_state_name[N_PZF_CORR_STATE]
Local calendar date and time, plus sync status.
Definition: pcpsdefs.h:1128
A high resolution time stamp.
Definition: pcpsdefs.h:972
int mbg_get_show_dev_info(MBG_DEV_HANDLE dh, const char *dev_name, PCPS_DEV *p_dev)
Retrieve and print some common device info.
Definition: toolutil.c:317
int mbg_handle_devices(int argc, char *argv[], int optind, MBG_DEV_HANDLER_FNC *fnc, int chk_dev_flags)
Main action handler that can be called by utility programs.
Definition: toolutil.c:655
CHK_DEV_FLAGS
Definition: toolutil.h:87
Device info structure.
Definition: pcpsdev.h:1043
int mbg_snprint_hr_tstamp(char *s, size_t max_len, const PCPS_TIME_STAMP *p, long utc_offs, int show_raw)
Print date and time from a PCPS_TIME_STAMP structure to a string.
Definition: toolutil.c:799
#define PZF_CORR_STATE_NAMES_ENG
Definition: pcpsdefs.h:1596