Debian Codegraph @

3rdparty/xspublic/xstypes/xsstatusflag.h

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 #ifndef XSSTATUSFLAG_H
34 #define XSSTATUSFLAG_H
35
36 #include "pstdint.h"
37
38 /*! \addtogroup enums Global enumerations
39 @{
40 */
41 /*! \brief Status flags
42 \details These flags define the function of specific bits in the status returned by
43 XsDataPacket::status()
44 \sa XsDataPacket::status()
45 */
46
47 enum XsStatusFlag
48 {
49 XSF_SelfTestOk = 0x01 //!< Is set when the self test result was ok
50 ,XSF_OrientationValid = 0x02 //!< Is set when the computed orientation is valid. The orientation may be invalid during startup or when the sensor data is clipping during violent (for the device) motion
51 ,XSF_GpsValid = 0x04 //!< Is set when the device has a GPS receiver and the receiver says that there is a GPS position fix.
52
53 ,XSF_NoRotationMask = 0x18 //!< If all of these flags are set, the No Rotation algorithm is running
54 ,XSF_NoRotationAborted = 0x10 //!< If only this flag is set (out of the XSF_NoRotationMask) then the No Rotation algorithm was aborted
55 ,XSF_NoRotationSamplesRejected = 0x08 //!< If only this flag is set (out of the XSF_NoRotationMask) then the No Rotation algorithm is running but has rejected samples
56 ,XSF_NoRotationRunningNormally = 0x18 //!< If all these flags are set (out of the XSF_NoRotationMask) then the No Rotation algorithm is running normally
57
58 ,XSF_RepresentativeMotion = 0x20 //!< Indicates if the In-Run Compass Calibration is doing the representative motion analysis
59
60 ,XSF_ExternalClockSynced = 0x40 //!< Indicates whether the internal clock is synced with an external clock (Either GNSS or custom provided clock sync)
61
62 ,XSF_ClipAccX = 0x00000100
63 ,XSF_ClipAccY = 0x00000200
64 ,XSF_ClipAccZ = 0x00000400
65 ,XSF_ClipGyrX = 0x00000800
66 ,XSF_ClipGyrY = 0x00001000
67 ,XSF_ClipGyrZ = 0x00002000
68 ,XSF_ClipMagX = 0x00004000
69 ,XSF_ClipMagY = 0x00008000
70 ,XSF_ClipMagZ = 0x00010000
71
72 ,XSF_Retransmitted = 0x00040000 //!< When set Indicates the sample was received as a retransmission
73 ,XSF_ClippingDetected = 0x00080000 //!< When set Indicates clipping has occurred
74 ,XSF_Interpolated = 0x00100000 //!< When set Indicates the sample is an interpolation between other samples
75 ,XSF_SyncIn = 0x00200000 //!< When set indicates a sync-in event has been triggered
76 ,XSF_SyncOut = 0x00400000 //!< When set Indicates a sync-out event has been generated
77
78
79 ,XSF_FilterMode = 0x03800000 //!< Mask for the 3 bit filter mode field
80 ,XSF_HaveGnssTimePulse = 0x04000000 //!< Indicates that the 1PPS GNSS time pulse is present
81 };
82
83 /*! \brief Status flag bit offsets
84 \details Sometimes (rarely) it is necessary to know the bit offset instead of the bit mask (ie when
85 shifting to only keep a subset of flags) for the status flags. This enumeration provides these
86 offsets.
87 \sa XsStatusFlag
88 */
89 enum XsStatusFlagOffset {
90 XSFO_OffsetSelfTestOk = 0
91 ,XSFO_OffsetOrientationValid = 1
92 ,XSFO_OffsetGpsValid = 2
93 ,XSFO_OffsetNoRotation = 3
94
95 ,XSFO_OffsetClipAccX = 8
96 ,XSFO_OffsetClipAccY = 9
97 ,XSFO_OffsetClipAccZ = 10
98 ,XSFO_OffsetClipGyrX = 11
99 ,XSFO_OffsetClipGyrY = 12
100 ,XSFO_OffsetClipGyrZ = 13
101 ,XSFO_OffsetClipMagX = 14
102 ,XSFO_OffsetClipMagY = 15
103 ,XSFO_OffsetClipMagZ = 16
104
105 ,XSFO_Retransmitted = 19
106 ,XSFO_Interpolated = 20
107 ,XSFO_SyncIn = 21
108 ,XSFO_SyncOut = 22
109
110 ,XSFO_FilterMode = 23 // bits 23 -> 23 + XSFO_FilterModeNrOfBits - 1
111 ,XSFO_FilterModeNrOfBits = 3 // note: bit 26 is reserved for future use
112 };
113
114 /*! @} */
115 typedef enum XsStatusFlag XsStatusFlag;
116 typedef enum XsStatusFlagOffset XsStatusFlagOffset;
117
118 //! Return if any acc channel clipped
119 inline static bool anyAccClipped(int status)
120 {
121 return 0 != (status & (XSF_ClipAccX | XSF_ClipAccY | XSF_ClipAccZ));
122 }
123
124 //! Return if any gyr channel clipped
125 inline static bool anyGyrClipped(int status)
126 {
127 return 0 != (status & (XSF_ClipGyrX | XSF_ClipGyrY | XSF_ClipGyrZ));
128 }
129
130 //! Return if any mag channel clipped
131 inline static bool anyMagClipped(int status)
132 {
133 return 0 != (status & (XSF_ClipMagX | XSF_ClipMagY | XSF_ClipMagZ));
134 }
135
136
137 //! \brief Status object.
138 class XsStatus
139 {
140 public:
141 /*! \brief Status object constructor
142 \param s XsStatus object to copy from
143 */
144 inline XsStatus(const XsStatus& s) : m_status(s.m_status)
145 {
146 }
147
148 /*! \brief Status object constructor
149 \param status status flags to set in the object
150 */
151 inline XsStatus(int status) : m_status((uint32_t)status)
152 {
153 }
154
155 //! \brief Status object constructor, clears all flags
156 inline XsStatus() : m_status(0)
157 {
158 }
159
160 //! \brief Return statusflag of status object
161 inline XsStatusFlag get() const
162 {
163 return (XsStatusFlag) m_status;
164 }
165
166 /*! \brief Set statusflag of status object
167 \param a The Status object to copy from
168 */
169 inline void set(XsStatus const& a)
170 {
171 m_status = a.m_status;
172 }
173
174 /*! \brief Set statusflag of status object
175 \param a The full status flags to set
176 */
177 inline void set(uint32_t a)
178 {
179 m_status = a;
180 }
181
182 /*! \brief Set statusflag of status object
183 \param a The full status flags to set
184 */
185 inline void set(int a)
186 {
187 m_status = (uint32_t)(a & 0x1FFFF);
188 }
189
190 /*! \brief Assignment operator
191 \param a The Status object to copy from
192 \return A reference to this object
193 */
194 inline XsStatus const& operator = (XsStatus const& a)
195 {
196 m_status = a.m_status; return *this;
197 }
198
199 /*! \brief Assignment operator
200 \param a The full status flags to set
201 \return A reference to this object
202 */
203 inline XsStatus const& operator = (int a)
204 {
205 m_status = (uint32_t)(a & 0x1FFFF);
206 return *this;
207 }
208
209 /*! \brief Binary OR operator
210 \param a The status flags to set, leaving already set flags as they were
211 \return A reference to this object
212 */
213 inline XsStatus const& operator |= (XsStatus const& a)
214 {
215 m_status |= a.m_status;
216 return *this;
217 }
218
219 /*! \brief Binary OR operator
220 \param a The status flags to set, leaving already set flags as they were
221 \return A reference to this object
222 */
223 inline XsStatus const& operator |= (int a)
224 {
225 m_status |= (uint32_t)(a & 0x1FFFF);
226 return *this;
227 }
228
229 /*! \brief Binary AND operator
230 \param a The mask of flags to keep, clearing other flags
231 \return A reference to this object
232 */
233 inline XsStatus const& operator &= (XsStatus const& a)
234 {
235 m_status &= a.m_status;
236 return *this;
237 }
238
239 /*! \brief Binary AND operator
240 \param a The mask of flags to keep, clearing other flags
241 \return A reference to this object
242 */
243 inline XsStatus const& operator &= (int a)
244 {
245 m_status &= (uint32_t)(a & 0x1FFFF);
246 return *this;
247 }
248
249 //! Return if any acc channel clipped
250 inline bool anyAccClipped() const
251 {
252 return ::anyAccClipped((int)m_status);
253 }
254
255 //! Return if any gyr channel clipped
256 inline bool anyGyrClipped() const
257 {
258 return ::anyGyrClipped((int)m_status);
259 }
260
261 //! Return if any mag channel clipped
262 inline bool anyMagClipped() const
263 {
264 return ::anyMagClipped((int)m_status);
265 }
266
267 //! Clear status object
268 inline void clear()
269 {
270 m_status = 0;
271 }
272
273 protected:
274 uint32_t m_status; //!< Statusflag
275 };
276
277 #endif