| 1 |
|
| 2 |
// Copyright (c) 2003-2019 Xsens Technologies B.V. or subsidiaries worldwide. |
| 3 |
// All rights reserved. |
| 4 |
// |
| 5 |
// Redistribution and use in source and binary forms, with or without modification, |
| 6 |
// are permitted provided that the following conditions are met: |
| 7 |
// |
| 8 |
// 1. Redistributions of source code must retain the above copyright notice, |
| 9 |
// this list of conditions, and the following disclaimer. |
| 10 |
// |
| 11 |
// 2. Redistributions in binary form must reproduce the above copyright notice, |
| 12 |
// this list of conditions, and the following disclaimer in the documentation |
| 13 |
// and/or other materials provided with the distribution. |
| 14 |
// |
| 15 |
// 3. Neither the names of the copyright holders nor the names of their contributors |
| 16 |
// may be used to endorse or promote products derived from this software without |
| 17 |
// specific prior written permission. |
| 18 |
// |
| 19 |
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY |
| 20 |
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 21 |
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL |
| 22 |
// THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 |
// SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT |
| 24 |
// OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 25 |
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR |
| 26 |
// TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 27 |
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.THE LAWS OF THE NETHERLANDS |
| 28 |
// SHALL BE EXCLUSIVELY APPLICABLE AND ANY DISPUTES SHALL BE FINALLY SETTLED UNDER THE RULES |
| 29 |
// OF ARBITRATION OF THE INTERNATIONAL CHAMBER OF COMMERCE IN THE HAGUE BY ONE OR MORE |
| 30 |
// ARBITRATORS APPOINTED IN ACCORDANCE WITH SAID RULES. |
| 31 |
// |
| 32 |
|
| 33 |
#ifndef XSTIMEINFO_H |
| 34 |
#define XSTIMEINFO_H |
| 35 |
|
| 36 |
#include "xstypesconfig.h" |
| 37 |
#include "pstdint.h" |
| 38 |
|
| 39 |
#ifdef __cplusplus |
| 40 |
extern "C" |
| 41 |
{ |
| 42 |
#endif |
| 43 |
#ifndef __cplusplus |
| 44 |
#define XSTIMEINFO_INITIALIZER { 0, 0 ,0, 0, 0, 0, 0, 0, 0} |
| 45 |
#endif |
| 46 |
struct XsTimeInfo; |
| 47 |
|
| 48 |
XSTYPES_DLL_API void XsTimeInfo_currentTime(struct XsTimeInfo * thisPtr); |
| 49 |
XSTYPES_DLL_API void XsTimeInfo_currentLocalTime(struct XsTimeInfo * thisPtr); |
| 50 |
XSTYPES_DLL_API void XsTimeInfo_makeUtc(struct XsTimeInfo * thisPtr); |
| 51 |
|
| 52 |
#ifdef __cplusplus |
| 53 |
} // extern "C" |
| 54 |
#endif |
| 55 |
|
| 56 |
/*! \brief A structure for storing Time values. */ |
| 57 |
struct XsTimeInfo { |
| 58 |
uint32_t m_nano; //!< \brief Nanosecond part of the time |
| 59 |
uint16_t m_year; //!< \brief The year (if date is valid) |
| 60 |
uint8_t m_month; //!< \brief The month (if date is valid) |
| 61 |
uint8_t m_day; //!< \brief The day of the month (if date is valid) |
| 62 |
uint8_t m_hour; //!< \brief The hour (if time is valid) |
| 63 |
uint8_t m_minute; //!< \brief The minute (if time is valid) |
| 64 |
uint8_t m_second; //!< \brief The second (if time is valid) |
| 65 |
uint8_t m_valid; //!< \brief Validity indicator \details When received: bit (0) - UTC Date is valid; bit (1) - UTC Time of Day is valid; bit (2) - UTC Time of Day has been fully resolved (i.e. no seconds uncertainty). |
| 66 |
int16_t m_utcOffset; //!< \brief Offset to UTC time in minutes. This value can be added to the stored time to get UTC time. |
| 67 |
|
| 68 |
#ifdef __cplusplus |
| 69 |
/*! \brief Sets all values to 0 */ |
| 70 |
void clear() |
| 71 |
{ |
| 72 |
memset(this, 0, sizeof(XsTimeInfo)); |
| 73 |
} |
| 74 |
|
| 75 |
/*! \copydoc XsTimeInfo_currentTime |
| 76 |
\return The current UTC Time |
| 77 |
*/ |
| 78 |
inline static XsTimeInfo currentTime() |
| 79 |
{ |
| 80 |
XsTimeInfo tmp; |
| 81 |
XsTimeInfo_currentTime(&tmp); |
| 82 |
return tmp; |
| 83 |
} |
| 84 |
|
| 85 |
/*! \copydoc XsTimeInfo_currentLocalTime |
| 86 |
\return The current local Time |
| 87 |
*/ |
| 88 |
inline static XsTimeInfo currentLocalTime() |
| 89 |
{ |
| 90 |
XsTimeInfo tmp; |
| 91 |
XsTimeInfo_currentLocalTime(&tmp); |
| 92 |
return tmp; |
| 93 |
} |
| 94 |
|
| 95 |
/*! \brief Returns true if all fields of this and \a other are exactly identical */ |
| 96 |
inline bool operator == (const XsTimeInfo& other) const |
| 97 |
{ |
| 98 |
return m_nano == other.m_nano && |
| 99 |
m_year == other.m_year && |
| 100 |
m_month == other.m_month && |
| 101 |
m_day == other.m_day && |
| 102 |
m_hour == other.m_hour && |
| 103 |
m_minute == other.m_minute && |
| 104 |
m_second == other.m_second && |
| 105 |
m_valid == other.m_valid && |
| 106 |
m_utcOffset == other.m_utcOffset; |
| 107 |
} |
| 108 |
|
| 109 |
/*! \brief Removes the local time information, making the object pure UTC */ |
| 110 |
void makeUtc() |
| 111 |
{ |
| 112 |
if (m_utcOffset) |
| 113 |
XsTimeInfo_makeUtc(this); |
| 114 |
} |
| 115 |
#endif |
| 116 |
}; |
| 117 |
typedef struct XsTimeInfo XsTimeInfo; |
| 118 |
|
| 119 |
#endif |