summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Burnicki <martin.burnicki@meinberg.de>2019-10-25 12:02:00 +0200
committerMartin Burnicki <martin.burnicki@meinberg.de>2019-10-25 12:02:00 +0200
commit5b504536b9568f8691e2dc6bf8af728324048488 (patch)
treee568bda578f1008a7df3f64e43e23768f0bc0ab7
parentf1a002e5f618d977c09ebe72e630a0f22f21c337 (diff)
downloadmbgsdk-win-5b504536b9568f8691e2dc6bf8af728324048488.tar.gz
mbgsdk-win-5b504536b9568f8691e2dc6bf8af728324048488.zip
Update mbgsvcio example program (mbgdmpst)
New option -o to specify an output file. By default use a new function to retrieve the device status. Optionally (-L) use the legacy function. In verbose mode (-v), print an additional line indicating which function was used. Print usage information with option -? or -h.
-rw-r--r--c/demo/mbgsvcio/mbgdmpst.c195
-rw-r--r--c/demo/mbgsvcio/vc6/mbgdmpst.dsp92
-rw-r--r--c/demo/mbgsvcio/vc6/mbgdmpst.dsw12
-rw-r--r--c/demo/mbgsvcio/vs2005/mbgdmpst.vcproj62
4 files changed, 283 insertions, 78 deletions
diff --git a/c/demo/mbgsvcio/mbgdmpst.c b/c/demo/mbgsvcio/mbgdmpst.c
index 9056dd5..dad313c 100644
--- a/c/demo/mbgsvcio/mbgdmpst.c
+++ b/c/demo/mbgsvcio/mbgdmpst.c
@@ -1,20 +1,47 @@
-// mbgdmpst.cpp : Defines the entry point for the application.
-//
+
+/**************************************************************************
+ *
+ * $Id: mbgdmpst.c 1.2 2019/10/25 12:30:58Z martin TRASH $
+ *
+ * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany
+ *
+ * Meinberg Time Adjustment status dumper example program.
+ *
+ * -----------------------------------------------------------------------
+ * $Log: mbgdmpst.c $
+ * Revision 1.2 2019/10/25 12:30:58Z martin
+ * New option -o to specify an output file.
+ * By default use a new function to retrieve the device status.
+ * Optionally (-L) use the legacy function.
+ * In verbose mode (-v), print an additional line indicating
+ * which function was used.
+ * Print usage information with option -? or -h.
+ *
+ **************************************************************************/
#include <mbgsvcio.h>
#include <pcpsdefs.h>
+#include <mbgerror.h>
-#include <stdio.h>
+#include <wingetopt.h>
+#include <stdio.h>
static const char *prog_info = "Meinberg Time Adjustment Status Dumper";
-static const char *prog_version = "v1.1";
+static const char *prog_version = "v2.0";
+
+// Command line options.
+static const char *out_fn; // -o <file> Specify name of output file.
+static int verbose; // -v Verbose output; additional line(s) in [info] section.
+static bool legacy; // -L Use legacy function to retrieve device status.
+static bool must_print_usage; // -? -h Print usage information.
+
#define SECTION_INFO "[Info]"
#define SECTION_OUTPUT "[Output]"
-
+
#define KEY_SVC_ACTIVE "SvcTimeAdjustmentActive"
#define KEY_SVC_REF_ACCESSIBLE "SvcRefTimeAccessible"
@@ -31,6 +58,16 @@ static const char *prog_version = "v1.1";
static /*HDR*/
+void print_error( int rc, const char *info )
+{
+ fprintf( stderr, "** %s failed: %s (rc = %i)\n",
+ info, mbg_strerror( rc ), rc );
+
+} // print_error
+
+
+
+static /*HDR*/
void dump_status_item( FILE *fp, const char *name, int val, int cond )
{
fprintf( fp, "%s=", name );
@@ -75,7 +112,7 @@ void dump_status( FILE *fp, int st, int cond )
const ST_INFO *p = &st_info[i];
int val = ( st & p->mask ) != 0;
dump_status_item( fp, p->key_name, val, cond );
- }
+ }
} // dump_status
@@ -87,58 +124,142 @@ void mbg_dump_time_adjustment_status( FILE *fp )
static const char *key_svc_active = KEY_SVC_ACTIVE;
static const char *key_ref_accessible = KEY_SVC_REF_ACCESSIBLE;
- int svc_active;
- int ref_accessible;
- int ref_time_status;
+ bool svc_active = false;
+ bool ref_accessible = false;
+ PCPS_TIME_STATUS_X ref_time_status;
+ int rc;
+
+ // Print info section.
+ fprintf( fp, "%s\n", SECTION_INFO );
+ fprintf( fp, "About=%s %s\n", prog_info, prog_version );
+
+ if ( verbose )
+ fprintf( fp, "Hint=Using %s function to get device status\n",
+ legacy ? "legacy" : "new" );
+
+ fprintf( fp, "\n" );
- fprintf( fp,
- "%s\n"
- "About=%s %s\n"
- "\n",
- SECTION_INFO,
- prog_info,
- prog_version
- );
+ // Print output section.
fprintf( fp, "%s\n", SECTION_OUTPUT );
- svc_active = mbg_time_adjustment_active();
- dump_status_item( fp, key_svc_active, svc_active, 1 );
+ rc = mbg_time_adjustment_active();
+
+ if ( mbg_rc_is_error( rc ) )
+ print_error( rc, "mbg_time_adjustment_active" );
+
+ dump_status_item( fp, key_svc_active, rc, 1 );
+ svc_active = rc > 0;
+
+ rc = mbg_ref_time_accessible();
+
+ if ( mbg_rc_is_error( rc ) && svc_active )
+ print_error( rc, "mbg_ref_time_accessible" );
- svc_active = svc_active > 0;
+ dump_status_item( fp, key_ref_accessible, rc, svc_active );
+ ref_accessible = rc > 0;
- ref_accessible = svc_active && mbg_ref_time_accessible();
- dump_status_item( fp, key_ref_accessible, ref_accessible, svc_active );
- ref_accessible = ref_accessible > 0;
+ if ( legacy )
+ ref_time_status = mbg_get_ref_time_status();
+ else
+ {
+ rc = mbg_get_ref_time_status_ex( &ref_time_status );
+
+ if ( mbg_rc_is_error( rc ) && ref_accessible )
+ print_error( rc, "mbg_get_ref_time_status_ex" );
+ }
- ref_time_status = mbg_get_ref_time_status();
dump_status( fp, ref_time_status, ref_accessible );
- fprintf( fp, "\n" );
+ fprintf( fp, "\n" );
} // mbg_dump_time_adjustment_status
-
-int main(int argc, char* argv[])
+static /*HDR*/
+void usage( void )
{
-#if 1
- if ( argc > 1 )
+ printf( "\n" );
+ printf( "%s %s\n", prog_info, prog_version );
+ printf( "\n" );
+ printf( "Dump the status of the Meinberg time adjustment service\n" );
+ printf( "in .inf file format.\n" );
+ printf( "\n" );
+ printf( "The device status (e.g. sync status) is only available if\n" );
+ printf( "the device is accessible by the time adjustment service.\n" );
+ printf( "\n" );
+ printf( "Whether the device is accessible or not can only be determined\n" );
+ printf( "it the time adjustment service is active.\n" );
+ printf( "\n" );
+ printf( "So, if the time adjustment service is not active, no more\n" );
+ printf( "information is available.\n" );
+ printf( "\n" );
+ printf( "\n" );
+ printf( "Usage: %s [[opt] [opt] ...]\n", prog_info );
+ printf( "\n" );
+ printf( "where \"opt\" is one of the following options:\n" );
+ printf( " -? or -h Print this usage information.\n" );
+ printf( " -o <file> Specify name of output file.\n" );
+ printf( " -v Verbose output; additional line(s) in [info] section.\n" );
+ printf( " -L Use legacy function to retrieve device status.\n" );
+ printf( "\n" );
+
+} // usage
+
+
+
+int main( int argc, char* argv[] )
+{
+ FILE *fp = stdout;
+ int c;
+
+ // Check command line parameters.
+ while ( ( c = getopt( argc, argv, "o:vLh?" ) ) != -1 )
{
- FILE *fp = fopen( argv[1], "wt" );
+ switch ( c )
+ {
+ case 'o':
+ out_fn = optarg;
+ break;
+
+ case 'v':
+ verbose++;
+ break;
+
+ case 'L':
+ legacy = true;
+ break;
+
+ case 'h':
+ case '?':
+ default:
+ must_print_usage = true;
+ }
+ }
- if ( fp )
- {
- mbg_dump_time_adjustment_status( fp );
+ if ( must_print_usage )
+ {
+ usage();
+ return MBG_EXIT_CODE_USAGE;
+ }
+
+
+ if ( out_fn )
+ fp = fopen( out_fn, "wt" );
+
+ if ( fp )
+ {
+ if ( out_fn )
+ printf( "\nOutput goes to file \"%s\".\n", out_fn );
+
+ mbg_dump_time_adjustment_status( fp );
+
+ if ( out_fn )
fclose( fp );
- }
}
-#endif
return 0;
}
-
-
diff --git a/c/demo/mbgsvcio/vc6/mbgdmpst.dsp b/c/demo/mbgsvcio/vc6/mbgdmpst.dsp
index 773477c..12068f2 100644
--- a/c/demo/mbgsvcio/vc6/mbgdmpst.dsp
+++ b/c/demo/mbgsvcio/vc6/mbgdmpst.dsp
@@ -54,7 +54,7 @@ BSC32=bscmake.exe
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 kernel32.lib user32.lib ws2_32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# SUBTRACT LINK32 /pdb:none
!ELSEIF "$(CFG)" == "mbgdmpst - Win32 Debug"
@@ -82,7 +82,7 @@ BSC32=bscmake.exe
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib ws2_32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# SUBTRACT LINK32 /pdb:none
!ENDIF
@@ -98,28 +98,116 @@ LINK32=link.exe
SOURCE=..\mbgdmpst.c
# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\mbglib\common\mbgerror.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\mbglib\win32\wingetopt.c
+# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter ""
# Begin Source File
+SOURCE=..\..\..\mbglib\include\cfg_hlp.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\mbglib\include\gpsdefs.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\..\..\..\..\..\WINDDK\2600\inc\w2k\guiddef.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\mbglib\include\mbg_arch.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\mbglib\include\mbg_cof.h
+# End Source File
+# Begin Source File
+
SOURCE=..\..\..\mbglib\include\mbg_tgt.h
# End Source File
# Begin Source File
+SOURCE=..\..\..\mbglib\include\mbgdevio.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\mbglib\include\mbgerror.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\mbglib\include\mbggeo.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\mbglib\include\mbgioctl.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\mbglib\include\mbgklist.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\mbglib\include\mbgmutex.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\mbglib\include\mbgpccyc.h
+# End Source File
+# Begin Source File
+
SOURCE=..\..\..\mbglib\include\mbgsvcio.h
# End Source File
# Begin Source File
+SOURCE=..\..\..\mbglib\include\mbgsystm.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\mbglib\include\mbgtime.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\mbglib\include\pci_asic.h
+# End Source File
+# Begin Source File
+
SOURCE=..\..\..\mbglib\include\pcpsdefs.h
# End Source File
# Begin Source File
+SOURCE=..\..\..\mbglib\include\pcpsdev.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\mbglib\include\pcpsiobf.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\mbglib\include\timeutil.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\mbglib\include\usbdefs.h
+# End Source File
+# Begin Source File
+
SOURCE=..\..\..\mbglib\include\use_pack.h
# End Source File
# Begin Source File
+SOURCE=..\..\..\mbglib\include\wingetopt.h
+# End Source File
+# Begin Source File
+
SOURCE=..\..\..\mbglib\include\words.h
# End Source File
# End Group
diff --git a/c/demo/mbgsvcio/vc6/mbgdmpst.dsw b/c/demo/mbgsvcio/vc6/mbgdmpst.dsw
index 71839c5..5c76f67 100644
--- a/c/demo/mbgsvcio/vc6/mbgdmpst.dsw
+++ b/c/demo/mbgsvcio/vc6/mbgdmpst.dsw
@@ -15,18 +15,6 @@ Package=<4>
###############################################################################
-Project: "mbgsvctm"=.\mbgsvctm\mbgsvctm.dsp - Package Owner=<4>
-
-Package=<5>
-{{{
-}}}
-
-Package=<4>
-{{{
-}}}
-
-###############################################################################
-
Global:
Package=<5>
diff --git a/c/demo/mbgsvcio/vs2005/mbgdmpst.vcproj b/c/demo/mbgsvcio/vs2005/mbgdmpst.vcproj
index 68b76fd..96ffe96 100644
--- a/c/demo/mbgsvcio/vs2005/mbgdmpst.vcproj
+++ b/c/demo/mbgsvcio/vs2005/mbgdmpst.vcproj
@@ -64,7 +64,7 @@
/>
<Tool
Name="VCLinkerTool"
- AdditionalDependencies="mbgsvcio.lib"
+ AdditionalDependencies="mbgsvcio.lib ws2_32.lib"
LinkIncremental="2"
AdditionalLibraryDirectories="..\..\..\mbglib\lib\msc"
GenerateDebugInformation="true"
@@ -97,12 +97,11 @@
/>
</Configuration>
<Configuration
- Name="Release|Win32"
- OutputDirectory="$(SolutionDir)$(ConfigurationName)"
- IntermediateDirectory="$(ConfigurationName)"
+ Name="Debug|x64"
+ OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)"
+ IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
- WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
@@ -118,12 +117,16 @@
/>
<Tool
Name="VCMIDLTool"
+ TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
+ Optimization="0"
AdditionalIncludeDirectories="..\..\..\mbglib\include"
- PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
- RuntimeLibrary="2"
+ PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
+ MinimalRebuild="true"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="3"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
@@ -140,14 +143,12 @@
/>
<Tool
Name="VCLinkerTool"
- AdditionalDependencies="mbgsvcio.lib"
- LinkIncremental="1"
- AdditionalLibraryDirectories="..\..\..\mbglib\lib\msc"
+ AdditionalDependencies="mbgsvcio.lib ws2_32.lib"
+ LinkIncremental="2"
+ AdditionalLibraryDirectories="..\..\..\mbglib\lib64\msc"
GenerateDebugInformation="true"
SubSystem="1"
- OptimizeReferences="2"
- EnableCOMDATFolding="2"
- TargetMachine="1"
+ TargetMachine="17"
/>
<Tool
Name="VCALinkTool"
@@ -175,11 +176,12 @@
/>
</Configuration>
<Configuration
- Name="Debug|x64"
- OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)"
- IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
+ Name="Release|Win32"
+ OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
+ WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
@@ -195,16 +197,12 @@
/>
<Tool
Name="VCMIDLTool"
- TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
- Optimization="0"
AdditionalIncludeDirectories="..\..\..\mbglib\include"
- PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
- MinimalRebuild="true"
- BasicRuntimeChecks="3"
- RuntimeLibrary="3"
+ PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
+ RuntimeLibrary="2"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
@@ -221,12 +219,14 @@
/>
<Tool
Name="VCLinkerTool"
- AdditionalDependencies="mbgsvcio.lib"
- LinkIncremental="2"
- AdditionalLibraryDirectories="..\..\..\mbglib\lib64\msc"
+ AdditionalDependencies="mbgsvcio.lib ws2_32.lib"
+ LinkIncremental="1"
+ AdditionalLibraryDirectories="..\..\..\mbglib\lib\msc"
GenerateDebugInformation="true"
SubSystem="1"
- TargetMachine="17"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
@@ -298,7 +298,7 @@
/>
<Tool
Name="VCLinkerTool"
- AdditionalDependencies="mbgsvcio.lib"
+ AdditionalDependencies="mbgsvcio.lib ws2_32.lib"
LinkIncremental="1"
AdditionalLibraryDirectories="..\..\..\mbglib\lib64\msc"
GenerateDebugInformation="true"
@@ -345,6 +345,14 @@
RelativePath="..\mbgdmpst.c"
>
</File>
+ <File
+ RelativePath="..\..\..\mbglib\common\mbgerror.c"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\mbglib\win32\wingetopt.c"
+ >
+ </File>
</Filter>
<Filter
Name="Header Files"