Debian Codegraph @

3rdparty/xspublic/xstypes/xssyncsetting.c

raw
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 #include "xssyncsetting.h"
34 #include <string.h>
35
36 /*! \addtogroup cinterface C Interface
37 @{
38 */
39
40 /*! \brief Returns whether the selected line is configured as an input line
41 */
42 int XsSyncSetting_isInput(const XsSyncSetting* thisPtr)
43 {
44 switch (thisPtr->m_line)
45 {
46 case XSL_In1:
47 case XSL_In2:
48 case XSL_Bi1In:
49 case XSL_ClockIn:
50 case XSL_CtsIn:
51 return 1;
52
53 default:
54 return 0;
55 }
56 }
57
58 /*! \brief Returns whether the selected line is configured as an output line
59 */
60 int XsSyncSetting_isOutput(const XsSyncSetting* thisPtr)
61 {
62 switch (thisPtr->m_line)
63 {
64 case XSL_Out1:
65 case XSL_Out2:
66 case XSL_Bi1Out:
67 case XSL_RtsOut:
68 return 1;
69
70 default:
71 return 0;
72 }
73 }
74
75 /*! \brief Swap the contents of \a a with \a b
76 */
77 void XsSyncSetting_swap(XsSyncSetting* a, XsSyncSetting* b)
78 {
79 XsSyncSetting tmp;
80 memcpy(&tmp, a, sizeof(XsSyncSetting));
81 memcpy(a, b, sizeof(XsSyncSetting));
82 memcpy(b, &tmp, sizeof(XsSyncSetting));
83 }
84
85 /*! \brief Compares \a a with \a b
86 \returns 0 if \a a equals \a b, negative value if \a a < \a b, positive value if \a a > \a b
87 \param[in] a Sync setting a
88 \param[in] b Sync setting b
89 */
90 int XsSyncSetting_compare(const struct XsSyncSetting* a, const struct XsSyncSetting* b)
91 {
92 assert(a && b);
93
94 if (a->m_line < b->m_line) return -1;
95 if (b->m_line < a->m_line) return 1;
96 if (a->m_function < b->m_function) return -1;
97 if (b->m_function < a->m_function) return 1;
98 if (a->m_polarity < b->m_polarity) return -1;
99 if (b->m_polarity < a->m_polarity) return 1;
100 if (XsSyncSetting_isOutput(a))
101 {
102 // only relevant for output triggers, ignored for inputs since inputs always trigger on an edge
103 if (a->m_pulseWidth < b->m_pulseWidth) return -1;
104 if (b->m_pulseWidth < a->m_pulseWidth) return 1;
105 }
106 if (a->m_offset < b->m_offset) return -1;
107 if (b->m_offset < a->m_offset) return 1;
108 if (a->m_skipFirst < b->m_skipFirst) return -1;
109 if (b->m_skipFirst < a->m_skipFirst) return 1;
110 if (a->m_skipFactor < b->m_skipFactor) return -1;
111 if (b->m_skipFactor < a->m_skipFactor) return 1;
112 if (a->m_function == XSF_ClockBiasEstimation)
113 {
114 if (a->m_clockPeriod < b->m_clockPeriod) return -1;
115 if (b->m_clockPeriod < a->m_clockPeriod) return 1;
116 }
117 if (a->m_triggerOnce < b->m_triggerOnce) return -1;
118 if (b->m_triggerOnce < a->m_triggerOnce) return 1;
119
120 return 0;
121 }
122
123 /*! @} */