event timestamps

Post questions, comments and feedback to our 3Dconnexion Mac Development Team.

Moderator: Moderators

Post Reply
cleepa
Posts: 2
Joined: Thu Jan 28, 2010 6:13 pm

event timestamps

Post by cleepa » Thu Jan 28, 2010 6:30 pm

Hi,

I'm trying to add some timing code to my application to debug a threading issue. For this I want to generate timestamps using the same method as the driver uses to generate ConnexionDeviceState.time. In the API documentation, it states the value comes from get_clock_uptime. This function does not exist. In the API header, it states it comes from clock_get_uptime, which is a kernel method, and presumably not accesible from userspace. I have seen a moderator in the forums suggest using mach_absolute_time. However, it was unclear if this value should be converted to nanoseconds when comparing with ConnextionDeviceState.time.

So, what is the correct method of doing this?

Thanks.

davecotter
Posts: 20
Joined: Tue Mar 11, 2008 10:36 pm

Post by davecotter » Thu Apr 12, 2012 11:14 am

The function "UpTime()" is the one you want. and yes, convert to nanoseconds for ease of comparison.

in the following code, i then convert to milliseconds cuz the clocks really aren't that accurate anyway, and i do not need such precision.

Code: Select all

#define			kNanoSecondsPerSecond	1000000000
#define			kMilliSecondsPerSecond	1000
#define			kNanoSecondsPerMilli	(kNanoSecondsPerSecond / kMilliSecondsPerSecond)

static bool	IsMostRecentMessage(UInt64& messageT)
{
	UInt64			dur_message_nanoT(UnsignedWideToUInt64(
		AbsoluteDeltaToNanoseconds(UpTime(), UInt64ToUnsignedWide(messageT))));
	UInt64			dur_message_milliT(dur_message_nanoT / kNanoSecondsPerMilli);
	UInt64			dur_tick_milliT(kMilliSecondsPerSecond / 60);
	bool			recentB = dur_message_milliT <= dur_tick_milliT;
	
	return recentB;
}

davecotter
Posts: 20
Joined: Tue Mar 11, 2008 10:36 pm

Post by davecotter » Thu Apr 12, 2012 11:15 am

fyi that function answers the question: "did this event happen within the last 1/60th of a second?"

davecotter
Posts: 20
Joined: Tue Mar 11, 2008 10:36 pm

Re: event timestamps

Post by davecotter » Sat Sep 21, 2013 12:25 pm

yes, "messageT" in the above code is "ConnexionDeviceState.time"

Post Reply