| 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 XSSYNCSETTINGS_H |
| 34 |
#define XSSYNCSETTINGS_H |
| 35 |
|
| 36 |
#include <string.h> |
| 37 |
|
| 38 |
#include "pstdint.h" |
| 39 |
#include "xstypesconfig.h" |
| 40 |
#include "xssyncline.h" |
| 41 |
#include "xssyncfunction.h" |
| 42 |
#include "xssyncpolarity.h" |
| 43 |
|
| 44 |
struct XsSyncSetting; |
| 45 |
|
| 46 |
#ifdef __cplusplus |
| 47 |
extern "C" { |
| 48 |
#endif |
| 49 |
#ifndef __cplusplus |
| 50 |
#define XSSYNCSETTINGS_INITIALIZER { XSL_Invalid, XSF_Invalid, XSP_None, 1, 0, 0, 0, 0, 0, 0 } |
| 51 |
#endif |
| 52 |
|
| 53 |
XSTYPES_DLL_API int XsSyncSetting_isInput(const struct XsSyncSetting* thisPtr); |
| 54 |
XSTYPES_DLL_API int XsSyncSetting_isOutput(const struct XsSyncSetting* thisPtr); |
| 55 |
XSTYPES_DLL_API void XsSyncSetting_swap(struct XsSyncSetting* a, struct XsSyncSetting* b); |
| 56 |
XSTYPES_DLL_API int XsSyncSetting_compare(const struct XsSyncSetting* a, const struct XsSyncSetting* b); |
| 57 |
|
| 58 |
#ifdef __cplusplus |
| 59 |
} // extern "C" |
| 60 |
#endif |
| 61 |
|
| 62 |
/*! \brief A structure for storing all xsens sync settings */ |
| 63 |
struct XsSyncSetting { |
| 64 |
XsSyncLine m_line; /*!< The sync lines enabled. \see XsSyncLine. */ |
| 65 |
XsSyncFunction m_function; /*!< The action to be performed, when an input sync line changes \see XsSyncFunction. */ |
| 66 |
XsSyncPolarity m_polarity; /*!< The edge on which the action is performed, \see XsSyncPolarity. */ |
| 67 |
uint32_t m_pulseWidth; /*!< The time to keep the line polarity before toggling back, in microseconds. */ |
| 68 |
int32_t m_offset; /*!< The time between reception of a line change and the execution of the sync action, in microseconds. */ |
| 69 |
uint16_t m_skipFirst; /*!< The number of frames to skip before executing the action. */ |
| 70 |
uint16_t m_skipFactor; /*!< The number of frames to skip between 2 actions. */ |
| 71 |
uint16_t m_clockPeriod; /*!< The frequency of the external clock in milliseconds, only valid when function is XSF_ClockBiasEstimation. */ |
| 72 |
uint8_t m_triggerOnce; /*!< Whether the action is repeated for each frame. */ |
| 73 |
uint8_t m_padding; /*!< Padding to get at a 4 byte boundary so memcpy/memcmp works with sizeof(XsSyncSetting) */ |
| 74 |
#ifdef __cplusplus |
| 75 |
//! \brief Default constructor, initializes to the given (default) settings |
| 76 |
explicit XsSyncSetting(XsSyncLine line = XSL_Invalid |
| 77 |
, XsSyncFunction function = XSF_Invalid |
| 78 |
, XsSyncPolarity polarity = XSP_RisingEdge |
| 79 |
, uint32_t pulseWidth = 1000 |
| 80 |
, int32_t offset = 0 |
| 81 |
, uint16_t skipFirst = 0 |
| 82 |
, uint16_t skipFactor = 0 |
| 83 |
, uint16_t clockPeriod = 0 |
| 84 |
, uint8_t triggerOnce = 0) |
| 85 |
: m_line(line) |
| 86 |
, m_function(function) |
| 87 |
, m_polarity(polarity) |
| 88 |
, m_pulseWidth(pulseWidth) |
| 89 |
, m_offset(offset) |
| 90 |
, m_skipFirst(skipFirst) |
| 91 |
, m_skipFactor(skipFactor) |
| 92 |
, m_clockPeriod(clockPeriod) |
| 93 |
, m_triggerOnce(triggerOnce) |
| 94 |
, m_padding(0) |
| 95 |
{ |
| 96 |
} |
| 97 |
|
| 98 |
//! \brief Construct a XsSyncSetting as a copy of \a other. |
| 99 |
XsSyncSetting(const XsSyncSetting& other) |
| 100 |
{ |
| 101 |
memcpy(this, &other, sizeof(XsSyncSetting)); |
| 102 |
} |
| 103 |
|
| 104 |
//! \brief Copy values of \a other into this. |
| 105 |
const XsSyncSetting& operator =(const XsSyncSetting& other) |
| 106 |
{ |
| 107 |
if (this != &other) |
| 108 |
memcpy(this, &other, sizeof(XsSyncSetting)); |
| 109 |
return *this; |
| 110 |
} |
| 111 |
|
| 112 |
//! \brief \copybrief XsSyncSetting_isInput |
| 113 |
inline bool isInput() const |
| 114 |
{ |
| 115 |
return 0 != XsSyncSetting_isInput(this); |
| 116 |
} |
| 117 |
|
| 118 |
//! \brief \copybrief XsSyncSetting_isOutput |
| 119 |
inline bool isOutput() const |
| 120 |
{ |
| 121 |
return 0 != XsSyncSetting_isOutput(this); |
| 122 |
} |
| 123 |
|
| 124 |
/*! \brief Swap the contents with \a other |
| 125 |
*/ |
| 126 |
inline void swap(XsSyncSetting& other) |
| 127 |
{ |
| 128 |
XsSyncSetting_swap(this, &other); |
| 129 |
} |
| 130 |
|
| 131 |
/*! \brief Return true if \a other is identical to this |
| 132 |
*/ |
| 133 |
inline bool operator == (const XsSyncSetting& other) const |
| 134 |
{ |
| 135 |
return (this == &other) || XsSyncSetting_compare(this, &other) == 0; |
| 136 |
} |
| 137 |
|
| 138 |
/*! \brief Return true if \a other is not identical to this |
| 139 |
*/ |
| 140 |
inline bool operator != (const XsSyncSetting& other) const |
| 141 |
{ |
| 142 |
return (this != &other) && XsSyncSetting_compare(this, &other) != 0; |
| 143 |
} |
| 144 |
|
| 145 |
/*! \brief Return true if \a other is less than this |
| 146 |
*/ |
| 147 |
inline bool operator < (const XsSyncSetting& other) const |
| 148 |
{ |
| 149 |
return (this != &other) && XsSyncSetting_compare(this, &other) < 0; |
| 150 |
} |
| 151 |
#endif |
| 152 |
}; |
| 153 |
|
| 154 |
typedef struct XsSyncSetting XsSyncSetting; |
| 155 |
|
| 156 |
#endif |