Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support getting of time on MacOSX/XCode versions that don't support `… #144

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions c/src/dynamixel_sdk/port_handler_mac.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@
#include <sys/time.h>
#include <sys/ioctl.h>

#ifdef __MACH__
#include <mach/clock.h>
#include <mach/mach.h>
#endif

#include "port_handler_mac.h"

#define LATENCY_TIMER 8 // msec (USB latency timer) [was changed from 4 due to the Ubuntu update 16.04.2]
Expand Down Expand Up @@ -207,7 +212,17 @@ uint8_t isPacketTimeoutMac(int port_num)
double getCurrentTimeMac()
{
struct timespec tv;
#ifdef __MACH__ // OS X does not have clock_gettime, use clock_get_time
clock_serv_t cclock;
mach_timespec_t mts;
host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
clock_get_time(cclock, &mts);
mach_port_deallocate(mach_task_self(), cclock);
tv.tv_sec = mts.tv_sec;
tv.tv_nsec = mts.tv_nsec;
#else
clock_gettime(CLOCK_REALTIME, &tv);
#endif
return ((double)tv.tv_sec*1000.0 + (double)tv.tv_nsec*0.001*0.001);
}

Expand Down