mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-01-08 17:08:28 -04:00
AP_HAL: add support for get realtime on Darwin systems
This commit is contained in:
parent
3a8ed06267
commit
8903bc9eab
@ -2,6 +2,9 @@
|
||||
#include "Util.h"
|
||||
#include "utility/print_vprintf.h"
|
||||
#include <time.h>
|
||||
#if defined(__APPLE__) && defined(__MACH__)
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
/* Helper class implements AP_HAL::Print so we can use utility/vprintf */
|
||||
class BufferPrinter : public AP_HAL::Print {
|
||||
@ -50,9 +53,15 @@ int AP_HAL::Util::vsnprintf(char* str, size_t size, const char *format, va_list
|
||||
|
||||
uint64_t AP_HAL::Util::get_system_clock_ms() const
|
||||
{
|
||||
#if defined(__APPLE__) && defined(__MACH__)
|
||||
struct timeval ts;
|
||||
gettimeofday(&ts, NULL);
|
||||
return ((long long)((ts.tv_sec * 1000) + (ts.tv_usec / 1000)));
|
||||
#else
|
||||
struct timespec ts;
|
||||
clock_gettime(CLOCK_REALTIME, &ts);
|
||||
return ((long long)(ts.tv_sec * 1000 + ts.tv_nsec/1000000));
|
||||
#endif
|
||||
}
|
||||
|
||||
void AP_HAL::Util::get_system_clock_utc(int32_t &hour, int32_t &min, int32_t &sec, int32_t &ms) const
|
||||
|
Loading…
Reference in New Issue
Block a user