diff options
author | Martin Burnicki <martin.burnicki@meinberg.de> | 2009-08-18 12:01:00 +0200 |
---|---|---|
committer | Martin Burnicki <martin.burnicki@meinberg.de> | 2009-08-18 12:01:00 +0200 |
commit | 11b97bd0d893a4d2ff7cb31971ca043f21e49ccf (patch) | |
tree | 4593a4b1ec979cd9ded1672e9e3d6738a961ed69 | |
parent | 825eead41f318b3f01b2e7771396e685ef01e98d (diff) | |
download | mbgsdk-win-11b97bd0d893a4d2ff7cb31971ca043f21e49ccf.tar.gz mbgsdk-win-11b97bd0d893a4d2ff7cb31971ca043f21e49ccf.zip |
Update some C demo files
-rw-r--r-- | c/demo/mbgdevio/mbgdevio_demo.c | 231 |
1 files changed, 211 insertions, 20 deletions
diff --git a/c/demo/mbgdevio/mbgdevio_demo.c b/c/demo/mbgdevio/mbgdevio_demo.c index 7efdae0..9997f71 100644 --- a/c/demo/mbgdevio/mbgdevio_demo.c +++ b/c/demo/mbgdevio/mbgdevio_demo.c @@ -1,13 +1,18 @@ /************************************************************************** * - * $Id: mbgdevio_demo.c 1.8 2009/03/23 15:12:54Z daniel REL_M $ - * $Name: MBGDEVIO_DEMO_101 $ + * $Id: mbgdevio_demo.c 1.10 2009/08/18 14:14:27Z daniel TRASH $ + * $Name: MBGDEVIO_DEMO_120 $ * * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany * * ----------------------------------------------------------------------- * $Log: mbgdevio_demo.c $ + * Revision 1.10 2009/08/18 14:14:27Z daniel + * Added calls to read the irig control bits, irig time, irig debug status, + * ptp infos and LAN interface info. + * Revision 1.9 2009/04/01 14:07:24Z martin + * Code cleanup. * 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 @@ -46,19 +51,14 @@ #include <mbgdevio.h> +#include <mbgtime.h> #include <mbgutil.h> #include <stdio.h> +#include <stdlib.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 @@ -103,12 +103,10 @@ void print_drvr_info( void ) exit( 1 ); } - printf( "Kernel driver: %s v%i.%02i, %i device%s\n\n", + printf( "Kernel driver: %s v%i.%02i\n\n", drvr_info.id_str, drvr_info.ver_num / 100, - drvr_info.ver_num % 100, - drvr_info.n_devs, - ( drvr_info.n_devs == 1 ) ? "" : "s" + drvr_info.ver_num % 100 ); } // print_drvr_info @@ -507,6 +505,166 @@ void print_utc_parameters( MBG_DEV_HANDLE dh, PCPS_DEV *pdev ) +static /*HDR*/ +void show_irig_ctrl_bits( MBG_DEV_HANDLE dh ) +{ + MBG_IRIG_CTRL_BITS irig_ctrl_bits; + + int rc = mbg_get_irig_ctrl_bits( dh, &irig_ctrl_bits ); + + if ( rc != MBG_SUCCESS ) + return; + + printf( "\nIRIG control bits: %08lX (hex, LSB first)\n", (ulong) irig_ctrl_bits ); + +} // show_irig_ctrl_bits + + + +static /*HDR*/ +void show_irig_debug_status( MBG_DEV_HANDLE dh ) +{ + static const char *status_str[N_MBG_DEBUG_BIT] = MBG_DEBUG_STATUS_STRS; + + MBG_DEBUG_STATUS st; + int i; + int rc = _mbg_generic_read_var( dh, PCPS_GET_DEBUG_STATUS, st ); + + if ( rc != MBG_SUCCESS ) + return; + + printf( "\nDebug status (hex): %08lX\n", (ulong) st ); + + for ( i = 0; i < N_MBG_DEBUG_BIT; i++ ) + if ( st & ( 1UL << i ) ) + printf( " %s\n", status_str[i] ); + +} // show_irig_debug_status + + +/*HDR*/ +int snprint_ip4_addr( char *s, size_t max_len, const IP4_ADDR *addr ) +{ + int n; + + n = mbg_snprintf( s, max_len, "%i.%i.%i.%i", + BYTE_OF( *addr, 3 ), + BYTE_OF( *addr, 2 ), + BYTE_OF( *addr, 1 ), + BYTE_OF( *addr, 0 ) + ); + + return n; + +} // snprint_ip4_addr + + + +static /*HDR*/ +void show_lan_intf_state( MBG_DEV_HANDLE dh ) +{ + IP4_SETTINGS ip4_settings; + LAN_IF_INFO lan_if_info; + char ws[100]; + + int rc = mbg_get_ip4_state( dh, &ip4_settings ); + + if ( rc != MBG_SUCCESS ) + return; + + rc = mbg_get_lan_if_info( dh, &lan_if_info ); + + if ( rc != MBG_SUCCESS ) + return; + + + printf( "\nOn-board LAN interface settings:\n" ); + + mbg_snprintf( ws, sizeof( ws ), "%02X-%02X-%02X-%02X-%02X-%02X", + lan_if_info.mac_addr[0], + lan_if_info.mac_addr[1], + lan_if_info.mac_addr[2], + lan_if_info.mac_addr[3], + lan_if_info.mac_addr[4], + lan_if_info.mac_addr[5] + ); + printf( " MAC Address: %s\n", ws ); + + snprint_ip4_addr( ws, sizeof( ws ), &ip4_settings.ip_addr ); + printf( " IP Address: %s%s\n", ws, ( ip4_settings.flags & IP4_MSK_DHCP ) ? + "(DHCP)" : "" ); + + snprint_ip4_addr( ws, sizeof( ws ), &ip4_settings.netmask ); + printf( " Net Mask: %s\n", ws ); + + snprint_ip4_addr( ws, sizeof( ws ), &ip4_settings.broad_addr ); + printf( " Broadcast Addr: %s\n", ws ); + + snprint_ip4_addr( ws, sizeof( ws ), &ip4_settings.gateway ); + printf( " Gateway: %s\n", ws ); + + printf( " Link detected: %s\n", ( ip4_settings.flags & IP4_MSK_LINK ) ? "YES" : "NO" ); + +} // show_lan_intf_state + + + +static /*HDR*/ +void print_ptp_status( MBG_DEV_HANDLE dh ) +{ + static const char *ptp_stat_str[N_PTP_PORT_STATE] = PTP_PORT_STATE_STRS; + char ws[100]; + const char *cp; + int ptp_state_available; + PTP_STATE ptp_state; + + int rc = mbg_get_ptp_state( dh, &ptp_state ); + + if ( rc != MBG_SUCCESS ) + { + printf(" Error getting PTP State!\n"); + return; + } + + printf( "\nPTP port status:\n" ); + + printf( " Port mode: %s\n", ( ptp_state.port_state < N_PTP_PORT_STATE ) ? + ptp_stat_str[ptp_state.port_state] : "(undefined)" ); + + ptp_state_available = ( ptp_state.port_state == PTP_PORT_STATE_SLAVE ); + + cp = ptp_state_available ? ws : "N/A"; + + mbg_snprintf( ws, sizeof( ws ), "%02X-%02X-%02X-%02X-%02X-%02X", + ptp_state.gm_identity.b[0], + ptp_state.gm_identity.b[1], + ptp_state.gm_identity.b[2], + ptp_state.gm_identity.b[5], + ptp_state.gm_identity.b[6], + ptp_state.gm_identity.b[7] + ); + printf( " Grandmaster MAC: %s\n", cp ); + + + mbg_snprintf( ws, sizeof( ws ), "%c%li.%09li s", + _nano_time_negative( &ptp_state.path_delay ) ? '-' : '+', + labs( (long) ptp_state.path_delay.secs ), + labs( (long) ptp_state.path_delay.nano_secs ) + ); + printf( " PTP path delay: %s\n", cp ); + + + mbg_snprintf( ws, sizeof( ws ), "%c%li.%09li s", + _nano_time_negative( &ptp_state.offset ) ? '-' : '+', + labs( (long) ptp_state.offset.secs ), + labs( (long) ptp_state.offset.nano_secs ) + ); + printf( " PTP time offset: %s\n\n", cp ); + + +} + + int main( int argc, char* argv[] ) { int i,j; @@ -583,6 +741,19 @@ int main( int argc, char* argv[] ) if ( _pcps_has_hr_time( &dev ) ) print_hr_time( dh ); + // Newer IRIG receiver cards support reading the original + // raw IRIG time stamp. + if ( _pcps_has_irig_time( &dev ) ) + { + PCPS_IRIG_TIME it; + + rc = mbg_get_irig_time( dh, &it ); + + if ( rc == MBG_SUCCESS ) + printf( "\nRaw IRIG time: yday %u, %02u:%02u:%02u\n", + it.yday, it.hour, it.min, it.sec ); + } + // Print some GPS clock specific info if ( _pcps_is_gps( &dev ) ) @@ -590,11 +761,25 @@ 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"); } + if ( _pcps_has_utc_parm( &dev ) ) + print_utc_parameters( dh, &dev ); + + if ( _pcps_is_irig_rx( &dev ) ) + show_irig_debug_status( dh ); + + if ( _pcps_has_irig_ctrl_bits( &dev ) ) + show_irig_ctrl_bits( dh ); + + if ( _pcps_has_lan_intf( &dev ) ) + show_lan_intf_state( dh ); + + if ( _pcps_is_ptp( &dev ) ) + print_ptp_status( dh ); + //*********** // Loop some seconds waiting for second to change @@ -616,20 +801,26 @@ int main( int argc, char* argv[] ) 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]; + uint32_t latency[MAX_MEM_MAPPED_CNT] = { 0 }; int rc; // Read some memory mapped time stamps // as fast as possible - for(j = 0; j < MAX_MEM_MAPPED_CNT; j++) + for ( j = 0; j < MAX_MEM_MAPPED_CNT; j++ ) + { rc = mbg_get_fast_hr_timestamp_comp( dh, &hrtime[j].tstamp, &latency[j] ); + + if ( rc != PCPS_SUCCESS ) + { + printf(" Error: mbg_get_fast_hr_timestamp_comp() returned 0x%X\n",rc ); + break; + } + } - if ( rc != PCPS_SUCCESS ) - printf(" Error: mbg_get_fast_hr_timestamp_comp() returned 0x%X\n",rc ); - else + if ( j == MAX_MEM_MAPPED_CNT ) { // Print time stamps - for(j = 0; j < MAX_MEM_MAPPED_CNT; j++) + for ( j = 0; j < MAX_MEM_MAPPED_CNT; j++ ) { char ws[200]; |