summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Burnicki <martin.burnicki@meinberg.de>2009-03-26 12:01:00 +0100
committerMartin Burnicki <martin.burnicki@meinberg.de>2009-03-26 12:01:00 +0100
commitd72132e71d5b5130f50631244d130cd409eb3db9 (patch)
treeca56d9aecb629988080d727f9ed7867d460588b7
parentb80090737e4148916dcf7c05c8bad4aaaa2748f4 (diff)
downloadmbgsdk-win-d72132e71d5b5130f50631244d130cd409eb3db9.tar.gz
mbgsdk-win-d72132e71d5b5130f50631244d130cd409eb3db9.zip
Update some C demo project files
-rw-r--r--c/demo/mbgdevio/mbgdevio_demo.c135
-rw-r--r--c/demo/mbgdevio/vc6/hrtime.dsp20
-rw-r--r--c/demo/mbgdevio/vc6/mbgdevio_demo.dsp8
-rw-r--r--c/demo/mbgsvcio/vc6/mbgdmpst.dsw12
4 files changed, 137 insertions, 38 deletions
diff --git a/c/demo/mbgdevio/mbgdevio_demo.c b/c/demo/mbgdevio/mbgdevio_demo.c
index 0df7655..7efdae0 100644
--- a/c/demo/mbgdevio/mbgdevio_demo.c
+++ b/c/demo/mbgdevio/mbgdevio_demo.c
@@ -1,13 +1,15 @@
/**************************************************************************
*
- * $Id: mbgdevio_demo.c 1.7 2009/01/23 08:31:28Z daniel REL_M $
- * $Name: MBGDEVIO_DEMO_100 $
+ * $Id: mbgdevio_demo.c 1.8 2009/03/23 15:12:54Z daniel REL_M $
+ * $Name: MBGDEVIO_DEMO_101 $
*
* Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany
*
* -----------------------------------------------------------------------
* $Log: mbgdevio_demo.c $
+ * Revision 1.8 2009/03/23 15:12:54Z daniel
+ * Include UTC parameters and time scales.
* Revision 1.7 2009/01/23 08:31:28Z daniel
* Revision 1.6 2009/01/20 11:13:26Z daniel
* Added comments.
@@ -28,8 +30,8 @@
Example program to access Meinberg computer peripherals
using the mbgdevio (Meinberg Device I/O) DLL.<br>
The program checks first whether a certain feature like high
- resolution time, Memory Mapped I/O or user capture is
- supported by the device.
+ resolution time, Memory Mapped I/O, different time scales or
+ user capture is supported by the device.
Build environment settings:
@@ -49,9 +51,22 @@
#include <stdio.h>
+// The Unix time_t epoche is usually 1970-01-01 00:00 whereas
+// the GPS epoche is 1980-01-06 00:00, so the difference is 10 years,
+// plus 2 days due to leap years (1972 and 1976), plus the difference
+// of the day-of-month (6 - 1).
+#define GPS_SEC_BIAS 315964800UL // ( ( ( 10UL * 365UL ) + 2 + 5 ) * SECS_PER_DAY )
+
+#define SECS_PER_DAY 86400L
+#define SECS_PER_WEEK 604800L
+
+/** Number of memory mapped time reads */
+#define MAX_MEM_MAPPED_CNT 20
+
static int n_sec_change = 0;
-#define MAX_MEM_MAPPED_CNT 20 /** Number of memory mapped time reads */
+const char *time_scale_str[N_MBG_TIME_SCALE] = MBG_TIME_SCALE_STRS;
+
static /*HDR*/
@@ -169,9 +184,18 @@ void print_date_time_status( MBG_DEV_HANDLE dh )
static /*HDR*/
char *sprint_hr_time( char *s, const PCPS_HR_TIME *t )
{
- sprintf( s, "%08lX.%08lX UTC%+ldsec, st: %04X",
+ const char *cp = "UTC";
+
+ if ( t->status & PCPS_SCALE_TAI )
+ cp = "TAI";
+ else
+ if ( t->status & PCPS_SCALE_GPS )
+ cp = "GPS";
+
+ sprintf( s, "%08lX.%08lX %s%+ldsec, st: %04X",
t->tstamp.sec,
t->tstamp.frac,
+ cp,
t->utc_offs,
t->status
);
@@ -204,12 +228,19 @@ void print_hr_time( MBG_DEV_HANDLE dh )
if ( PCPS_SUCCESS == mbg_get_hr_time_comp( dh, &hr_t, &latency ) )
{
char ws[200];
+ const char *cp = "UTC";
+
+ if ( hr_t.status & PCPS_SCALE_TAI )
+ cp = "TAI";
+ else
+ if ( hr_t.status & PCPS_SCALE_GPS )
+ cp = "GPS";
- printf( " HR time (raw): %s, latency: %i hns\n", sprint_hr_time( ws, &hr_t ), latency );
+ printf( " HR time (RAW): %s, latency: %i hns\n", sprint_hr_time( ws, &hr_t ), latency );
// Format function taken from mbgutil.h
mbg_str_pcps_hr_tstamp_utc( ws, sizeof( ws ), &hr_t );
- printf( " HR time (utc): %s, latency=%i hns\n", ws, latency );
+ printf( " HR time (%s): %s, latency=%i hns\n", cp, ws, latency );
}
else
err_msg( "Failed to read High Resolution Time" );
@@ -242,8 +273,8 @@ void print_sec_changes( MBG_DEV_HANDLE dh )
if ( rc == PCPS_SUCCESS )
{
- print_date_time( &t, " New sec: " );
print_hr_time( dh );
+ print_date_time( &t, " New sec: " );
}
else
err_msg( "Failed to get time at second change." );
@@ -432,6 +463,50 @@ void check_user_captures( MBG_DEV_HANDLE dh, PCPS_DEV *pdev )
+static /*HDR*/
+void print_utc_parameters( MBG_DEV_HANDLE dh, PCPS_DEV *pdev )
+{
+
+ if ( _pcps_has_utc_parm( pdev ) )
+ {
+ UTC utc;
+
+ if ( mbg_get_utc_parm( dh, &utc ) == PCPS_SUCCESS )
+ {
+ printf(" UTC parameters:\n");
+
+ if ( !utc.valid )
+ printf(" UTC parameters not valid!\n");
+ else
+ {
+ if ( utc.delta_tls != utc.delta_tlsf )
+ {
+
+ // a leap second is currently being announced
+
+ time_t t_ls = (time_t) utc.WNlsf * SECS_PER_WEEK
+ + (time_t) utc.DNt * SECS_PER_DAY
+ + GPS_SEC_BIAS - 1;
+
+ struct tm *tm = gmtime( &t_ls );
+
+ printf( " UTC offset transition from %is to %is due to leap second\n"
+ " %s at UTC midnight at the end of %04i-%02i-%02i.\n",
+ utc.delta_tls, utc.delta_tlsf,
+ ( utc.delta_tls < utc.delta_tlsf ) ? "insertion" : "deletion",
+ tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday
+ );
+
+ }
+ else
+ printf( " UTC offset parameter: %is, no leap second announced.\n", utc.delta_tls );
+ }
+ }
+ }
+} // print_utc_parameters
+
+
+
int main( int argc, char* argv[] )
{
int i,j;
@@ -484,9 +559,21 @@ int main( int argc, char* argv[] )
continue;
}
-
print_dev_info( dh, &dev );
+ if ( _pcps_has_time_scale (&dev ) )
+ {
+ MBG_TIME_SCALE_INFO tsi;
+ int rc;
+
+ rc = mbg_get_time_scale_info( dh, &tsi );
+
+ if ( rc == PCPS_SUCCESS )
+ printf( " Current time scale: \"%s\"\n", time_scale_str[tsi.settings.scale] );
+ else
+ printf( " Error: mbg_get_time_scale_info() returned 0x%X.\n", rc);
+ }
+
// Read the current date, time, and status.
print_date_time_status( dh );
@@ -503,6 +590,9 @@ int main( int argc, char* argv[] )
print_receiver_position( dh );
print_sv_info( dh );
check_user_captures( dh, &dev );
+ print_utc_parameters( dh, &dev );
+
+ printf("\n");
}
@@ -510,7 +600,7 @@ int main( int argc, char* argv[] )
// Loop some seconds waiting for second to change
// Uncomment the line below if required:
- // print_sec_changes( dh );
+ //print_sec_changes( dh );
//***********
@@ -523,24 +613,29 @@ int main( int argc, char* argv[] )
rc = mbg_get_asic_features( dh, &asic_features );
- if ( rc == PCPS_SUCCESS && asic_features >= PCI_ASIC_HAS_MM_IO )
+ if ( rc == PCPS_SUCCESS && ( asic_features & PCI_ASIC_HAS_MM_IO ) )
{
PCPS_HR_TIME hrtime[MAX_MEM_MAPPED_CNT] = { 0 };
uint32_t latency[MAX_MEM_MAPPED_CNT];
+ int rc;
// Read some memory mapped time stamps
// as fast as possible
for(j = 0; j < MAX_MEM_MAPPED_CNT; j++)
- mbg_get_fast_hr_timestamp_comp( dh, &hrtime[j].tstamp, &latency[j] );
-
+ rc = mbg_get_fast_hr_timestamp_comp( dh, &hrtime[j].tstamp, &latency[j] );
- // Print time stamps
- for(j = 0; j < MAX_MEM_MAPPED_CNT; j++)
+ if ( rc != PCPS_SUCCESS )
+ printf(" Error: mbg_get_fast_hr_timestamp_comp() returned 0x%X\n",rc );
+ else
{
- char ws[200];
-
- mbg_str_pcps_hr_tstamp_utc( ws, sizeof( ws ), &hrtime[j] );
- printf( " HR timestamp (MEM): %s latency=%u hns\n", ws, latency[j] );
+ // Print time stamps
+ for(j = 0; j < MAX_MEM_MAPPED_CNT; j++)
+ {
+ char ws[200];
+
+ mbg_str_pcps_hr_tstamp_utc( ws, sizeof( ws ), &hrtime[j] );
+ printf( " HR timestamp (MEM): %s latency=%u hns\n", ws, latency[j] );
+ }
}
}
}
diff --git a/c/demo/mbgdevio/vc6/hrtime.dsp b/c/demo/mbgdevio/vc6/hrtime.dsp
index 00b900a..9a36f23 100644
--- a/c/demo/mbgdevio/vc6/hrtime.dsp
+++ b/c/demo/mbgdevio/vc6/hrtime.dsp
@@ -48,8 +48,8 @@ BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# 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 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 gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib 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 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 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 gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib 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
!ELSEIF "$(CFG)" == "hrtime - Win32 Debug"
@@ -63,16 +63,16 @@ LINK32=link.exe
# PROP Output_Dir "hrtime___Win32_Debug"
# PROP Intermediate_Dir "hrtime___Win32_Debug"
# PROP Target_Dir ""
-# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
-# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "..\..\..\mbglib\include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "..\..\..\mbglib\include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD BASE RSC /l 0x407 /d "_DEBUG"
# ADD RSC /l 0x407 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# 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 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 gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib 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 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 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 gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib 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
!ENDIF
@@ -105,6 +105,10 @@ 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
@@ -113,6 +117,10 @@ SOURCE=..\..\..\mbglib\include\mbgutil.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
diff --git a/c/demo/mbgdevio/vc6/mbgdevio_demo.dsp b/c/demo/mbgdevio/vc6/mbgdevio_demo.dsp
index bc893a7..082e424 100644
--- a/c/demo/mbgdevio/vc6/mbgdevio_demo.dsp
+++ b/c/demo/mbgdevio/vc6/mbgdevio_demo.dsp
@@ -109,6 +109,10 @@ 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
@@ -117,6 +121,10 @@ SOURCE=..\..\..\mbglib\include\mbgutil.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
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>