utils.h
Go to the documentation of this file.
1 /*
2 * Unpublished Copyright (c) 2009-2019 AutonomouStuff, LLC, All Rights Reserved.
3 *
4 * This file is part of the ibeo_core ROS driver which is released under the MIT license.
5 * See file LICENSE included with this software or go to https://opensource.org/licenses/MIT for full license details.
6 */
7 
8 #ifndef IBEO_CORE_UTILS_H
9 #define IBEO_CORE_UTILS_H
10 
11 #include <cmath>
12 #include <cstddef>
13 #include <cstdint>
14 #include <ctime>
15 #include <vector>
16 
17 namespace AS
18 {
19 namespace Drivers
20 {
21 namespace Ibeo
22 {
23 const size_t MAGIC_WORD = 0xAFFEC0C2;
24 typedef uint64_t NTPTime;
25 
26 inline NTPTime unix_time_to_ntp(struct tm *tm, struct timeval *tv)
27 {
28  NTPTime ret_val;
29 
30  uint64_t ntp_sec = tm->tm_year * 31536000; // Add years since 1900 (in seconds)
31  ntp_sec += tm->tm_yday * 86400; // Add days since Jan 1st (in seconds)
32  ntp_sec += tm->tm_hour * 3600; // Add hours since midnight (in seconds)
33  ntp_sec += tm->tm_min * 60; // Add minutes after the hour (in seconds)
34  ntp_sec += tm->tm_sec; // Add seconds after the minute
35 
36  ret_val = (ntp_sec << 32);
37 
38  uint64_t ntp_frac = tv->tv_usec;
39 
40  ret_val |= ntp_frac;
41 
42  return ret_val;
43 }
44 
45 inline double ticks_to_angle(int16_t angle_ticks, uint16_t angle_ticks_per_rotation)
46 {
47  return (2.0 * M_PI * static_cast<double>(angle_ticks) / static_cast<double>(angle_ticks_per_rotation));
48 };
49 } // namespace Ibeo
50 } // namespace Drivers
51 } // namespace AS
52 
53 #endif // IBEO_CORE_UTILS_H
double ticks_to_angle(int16_t angle_ticks, uint16_t angle_ticks_per_rotation)
Definition: utils.h:45
const size_t MAGIC_WORD
Definition: utils.h:23
uint64_t NTPTime
Definition: utils.h:24
NTPTime unix_time_to_ntp(struct tm *tm, struct timeval *tv)
Definition: utils.h:26


ibeo_core
Author(s): Joshua Whitley , Daniel Stanek
autogenerated on Fri Jun 7 2019 21:53:43