From 52ea59f446eebd6bd0c4452efd45d5f844cd1437 Mon Sep 17 00:00:00 2001 From: petermcs Date: Tue, 17 Jan 2012 07:46:53 +0000 Subject: [PATCH] Removed MS C specific gettimeofday function from mstpcap.c as there is one in the timer.c in the Win32 port. Changed the conditional compilation in the Win32 timer.cto allow gettimeofday compile with MS C --- bacnet-stack/demo/mstpcap/main.c | 72 -------------------------------- bacnet-stack/ports/win32/timer.c | 5 +-- 2 files changed, 2 insertions(+), 75 deletions(-) diff --git a/bacnet-stack/demo/mstpcap/main.c b/bacnet-stack/demo/mstpcap/main.c index abb16178..bba1baa1 100644 --- a/bacnet-stack/demo/mstpcap/main.c +++ b/bacnet-stack/demo/mstpcap/main.c @@ -507,78 +507,6 @@ static void write_global_header( } } -#if defined(_MSC_VER) - -/* - * Missing gettimeofday function for compiling with MS Visual Studio - * Visual C++ Express Edition. - * Courtesy of the Unix to Windows Porting Dictionary for HPC - * at http://suacommunity.com/dictionary/gettimeofday-entry.php - */ - -#if defined(_MSC_VER) || defined(_MSC_EXTENSIONS) - #define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64 -#else - #define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL -#endif - -struct timezone -{ - int tz_minuteswest; /* minutes W of Greenwich */ - int tz_dsttime; /* type of dst correction */ -}; - -// Definition of a gettimeofday function - -int gettimeofday(struct timeval *tv, struct timezone *tz) -{ -// Define a structure to receive the current Windows filetime - FILETIME ft; - -// Initialize the present time to 0 and the timezone to UTC - unsigned __int64 tmpres = 0; - static int tzflag = 0; - - if (NULL != tv) - { - GetSystemTimeAsFileTime(&ft); - -// The GetSystemTimeAsFileTime returns the number of 100 nanosecond -// intervals since Jan 1, 1601 in a structure. Copy the high bits to -// the 64 bit tmpres, shift it left by 32 then or in the low 32 bits. - tmpres |= ft.dwHighDateTime; - tmpres <<= 32; - tmpres |= ft.dwLowDateTime; - -// Convert to microseconds by dividing by 10 - tmpres /= 10; - -// The Unix epoch starts on Jan 1 1970. Need to subtract the difference -// in seconds from Jan 1 1601. - tmpres -= DELTA_EPOCH_IN_MICROSECS; - -// Finally change microseconds to seconds and place in the seconds value. -// The modulus picks up the microseconds. - tv->tv_sec = (long)(tmpres / 1000000UL); - tv->tv_usec = (long)(tmpres % 1000000UL); - } - - if (NULL != tz) - { - if (!tzflag) - { - _tzset(); - tzflag++; - } - -// Adjust for the timezone west of Greenwich - tz->tz_minuteswest = _timezone / 60; - tz->tz_dsttime = _daylight; - } - - return 0; -} -#endif static void write_received_packet( volatile struct mstp_port_struct_t *mstp_port) diff --git a/bacnet-stack/ports/win32/timer.c b/bacnet-stack/ports/win32/timer.c index 00e3fd1a..dfe762e0 100644 --- a/bacnet-stack/ports/win32/timer.c +++ b/bacnet-stack/ports/win32/timer.c @@ -49,12 +49,11 @@ static volatile uint32_t Millisecond_Counter[MAX_MILLISECOND_TIMERS]; /* Windows timer period - in milliseconds */ static uint32_t Timer_Period = 1; -#if defined(__BORLANDC__) +#if defined(_MSC_VER) || defined(__BORLANDC__) struct timezone { int tz_minuteswest; /* minutes W of Greenwich */ int tz_dsttime; /* type of dst correction */ }; -#endif /************************************************************************* * Description: simulate the gettimeofday Linux function @@ -64,7 +63,7 @@ struct timezone { * To get microseconds accuracy we need to use QueryPerformanceCounter or * timeGetTime for the elapsed time. *************************************************************************/ -#if !defined(_MSC_VER) + int gettimeofday( struct timeval *tp, void *tzp)