messageserializer.cpp
Go to the documentation of this file.
1 
2 // Copyright (c) 2003-2021 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 
34 // Copyright (c) 2003-2021 Xsens Technologies B.V. or subsidiaries worldwide.
35 // All rights reserved.
36 //
37 // Redistribution and use in source and binary forms, with or without modification,
38 // are permitted provided that the following conditions are met:
39 //
40 // 1. Redistributions of source code must retain the above copyright notice,
41 // this list of conditions, and the following disclaimer.
42 //
43 // 2. Redistributions in binary form must reproduce the above copyright notice,
44 // this list of conditions, and the following disclaimer in the documentation
45 // and/or other materials provided with the distribution.
46 //
47 // 3. Neither the names of the copyright holders nor the names of their contributors
48 // may be used to endorse or promote products derived from this software without
49 // specific prior written permission.
50 //
51 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
52 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
53 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
54 // THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 // SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
56 // OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR
58 // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
59 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.THE LAWS OF THE NETHERLANDS
60 // SHALL BE EXCLUSIVELY APPLICABLE AND ANY DISPUTES SHALL BE FINALLY SETTLED UNDER THE RULES
61 // OF ARBITRATION OF THE INTERNATIONAL CHAMBER OF COMMERCE IN THE HAGUE BY ONE OR MORE
62 // ARBITRATORS APPOINTED IN ACCORDANCE WITH SAID RULES.
63 //
64 
65 #include "messageserializer.h"
66 #include <xstypes/xsdeviceid.h>
71 #include <xstypes/xsdid.h>
72 
73 
81  : m_message(msg)
82  , m_index(offset)
83 {
84 
85 }
86 
90 {
91  try
92  {
93  finalize();
94  }
95  catch (...)
96  {
97  }
98 }
99 
105 {
106  return operator<<((uint16_t)id);
107 }
108 
114 {
115  return operator<<((uint8_t)id);
116 }
117 
123 {
124  return operator<<((uint8_t)((idl == XCFF_11Bit_Identifier) ? 0 : 1));
125 }
126 
132 {
133  operator<<(id.legacyDeviceId());
134  if (!id.isLegacyDeviceId())
135  operator<<((uint32_t)(id.toInt() >> 32));
136  return *this;
137 }
138 
144 {
145  m_message.setDataByte(value, m_index);
146  m_index += sizeof(value);
147  return *this;
148 }
149 
155 {
156  m_message.setDataShort(value, m_index);
157  m_index += sizeof(value);
158  return *this;
159 }
160 
166 {
167  m_message.setDataLong(value, m_index);
168  m_index += sizeof(value);
169  return *this;
170 }
171 
177 {
178  m_message.setDataLongLong(value, m_index);
179  m_index += sizeof(value);
180  return *this;
181 }
182 
188 {
189  if (config.size() == 0)
190  return (*this << (XsOutputConfiguration(XDI_None, 0)));
191 
192  for (auto& cfg : config)
193  *this << cfg;
194  return *this;
195 }
196 
202 {
203  return (*this << cfg.m_dataIdentifier << cfg.m_frequency);
204 }
205 
211 {
212  if (config.size() == 0)
213  return (*this << (XsCanOutputConfiguration(XCFF_11Bit_Identifier, XCDI_Invalid, 0, 0)));
214 
215  for (auto& cfg : config)
216  *this << cfg;
217  return *this;
218 }
219 
225 {
226  return (*this << cfg.m_dataIdentifier << cfg.m_frameFormat << cfg.m_id << cfg.m_frequency);
227 }
228 
229 
234 void MessageSerializer::append(const uint8_t* data, XsSize size)
235 {
236  m_message.setDataBuffer(data, size, m_index);
237  m_index += size;
238 }
239 
243 {
244  m_message.resizeData(m_index);
245 }
246 
247 
255  : m_message(msg)
256  , m_index(offset)
257 {
258 }
259 
263 {
264 }
265 
271 {
272  uint16_t v;
273  operator>>(v);
274  value = static_cast<XsDataIdentifier>(v);
275  return *this;
276 }
277 
283 {
284  uint8_t v;
285  operator>>(v);
286  value = static_cast<XsCanDataIdentifier>(v);
287  return *this;
288 }
289 
295 {
296  uint8_t v;
297  operator>>(v);
298  value = static_cast<XsCanFrameFormat>(v);
299  return *this;
300 }
301 
307 {
308  uint32_t v;
309  operator>>(v);
310  if (v & XS_DID64_BIT)
311  {
312  uint32_t u;
313  operator>>(u);
314  uint64_t w = (((uint64_t) u) << 32) | (uint64_t) v;
315  value = XsDeviceId(w);
316  }
317  else
318  value = XsDeviceId(v);
319  return *this;
320 }
321 
327 {
328  value = m_message.getDataByte(m_index);
329  m_index += sizeof(value);
330  return *this;
331 }
332 
338 {
339  value = (int8_t)m_message.getDataByte(m_index);
340  m_index += sizeof(value);
341  return *this;
342 }
343 
349 {
350  value = m_message.getDataShort(m_index);
351  m_index += sizeof(value);
352  return *this;
353 }
354 
360 {
361  value = m_message.getDataLong(m_index);
362  m_index += sizeof(value);
363  return *this;
364 }
365 
371 {
372  value = m_message.getDataLongLong(m_index);
373  m_index += sizeof(value);
374  return *this;
375 }
376 
382 {
383  config.clear();
384  while (!atEnd())
385  {
387  *this >> cfg;
388  config.push_back(cfg);
389  }
390  return *this;
391 }
392 
398 {
399  return (*this >> cfg.m_dataIdentifier >> cfg.m_frequency);
400 }
401 
407 {
408  config.clear();
409  while (!atEnd())
410  {
412  *this >> cfg;
413  config.push_back(cfg);
414  }
415  return *this;
416 }
417 
423 {
424  return (*this >> cfg.m_dataIdentifier >> cfg.m_frameFormat >> cfg.m_id >> cfg.m_frequency);
425 }
426 
431 {
432  assert(m_index <= m_message.getDataSize());
433  return m_index == m_message.getDataSize();
434 }
XsOutputConfiguration::m_frequency
uint16_t m_frequency
The frequency.
Definition: xsoutputconfiguration.h:99
XsOutputConfiguration
struct XsOutputConfiguration XsOutputConfiguration
Definition: xsoutputconfiguration.h:118
MessageDeserializer
A class that does the message deserialization.
Definition: messageserializer.h:149
msg
msg
XsOutputConfiguration::m_dataIdentifier
XsDataIdentifier m_dataIdentifier
The data identifier.
Definition: xsoutputconfiguration.h:98
MessageSerializer::MessageSerializer
MessageSerializer(XsMessage &message, XsSize offset=0)
Default constructor.
Definition: messageserializer.cpp:80
XsCanOutputConfiguration::m_frequency
uint16_t m_frequency
The frequency.
Definition: xscanoutputconfiguration.h:102
XDI_None
@ XDI_None
Empty datatype.
Definition: xsdataidentifier.h:86
MessageSerializer::append
void append(const uint8_t *data, XsSize size)
Appends the data to the message.
Definition: messageserializer.cpp:234
xsoutputconfiguration.h
XsCanOutputConfiguration
struct XsCanOutputConfiguration XsCanOutputConfiguration
Definition: xscanoutputconfiguration.h:137
XCFF_11Bit_Identifier
@ XCFF_11Bit_Identifier
Definition: xscanframeformat.h:80
xscanoutputconfigurationarray.h
MessageSerializer::m_message
XsMessage & m_message
Definition: messageserializer.h:145
MessageDeserializer::operator>>
MessageDeserializer & operator>>(XsDataIdentifier &value)
Input stream operator that takes a XsDataIdentifier from the stream.
Definition: messageserializer.cpp:270
data
data
MessageSerializer::m_index
XsSize m_index
Definition: messageserializer.h:146
MessageDeserializer::~MessageDeserializer
virtual ~MessageDeserializer()
Destructor.
Definition: messageserializer.cpp:262
XCDI_Invalid
@ XCDI_Invalid
Definition: xscandataidentifier.h:84
XsCanDataIdentifier
XsCanDataIdentifier
Defines the data identifiers for CAN messages.
Definition: xscandataidentifier.h:82
XsOutputConfigurationArray
A list of XsOutputConfiguration values.
XS_DID64_BIT
#define XS_DID64_BIT
Definition: xsdid.h:216
MessageDeserializer::m_index
XsSize m_index
Definition: messageserializer.h:214
MessageSerializer::finalize
void finalize()
Finalizes the message serialization.
Definition: messageserializer.cpp:242
XsDataIdentifier
XsDataIdentifier
Defines the data identifiers.
Definition: xsdataidentifier.h:84
uint32_t
unsigned int uint32_t
Definition: pstdint.h:485
MessageSerializer::~MessageSerializer
virtual ~MessageSerializer()
Destructor.
Definition: messageserializer.cpp:89
MessageDeserializer::MessageDeserializer
MessageDeserializer(const XsMessage &message, XsSize offset=0)
Default constructor.
Definition: messageserializer.cpp:254
MessageDeserializer::atEnd
bool atEnd() const
Checks if we are at the end of message.
Definition: messageserializer.cpp:430
xsdid.h
XsSize
size_t XsSize
XsSize must be unsigned number!
Definition: xstypedefs.h:74
XsDeviceId
struct XsDeviceId XsDeviceId
Definition: xsdeviceid.h:912
XsCanOutputConfiguration::m_dataIdentifier
XsCanDataIdentifier m_dataIdentifier
The data identifier.
Definition: xscanoutputconfiguration.h:100
xsdeviceid.h
XsMessage
Structure for storing a single message.
Definition: xsmessage.h:202
xsoutputconfigurationarray.h
XsDeviceId
Contains an Xsens device ID and provides operations for determining the type of device.
Definition: xsdeviceid.h:192
xscanoutputconfiguration.h
XsCanFrameFormat
XsCanFrameFormat
Defines the Frame format for CAN messages.
Definition: xscanframeformat.h:78
MessageSerializer
A class that does the message serialization.
Definition: messageserializer.h:79
XsCanOutputConfiguration::m_frameFormat
XsCanFrameFormat m_frameFormat
The frame format of the CAN message.
Definition: xscanoutputconfiguration.h:99
XsCanOutputConfiguration
Single data type CAN output configuration.
Definition: xscanoutputconfiguration.h:97
XsCanOutputConfiguration::m_id
uint32_t m_id
The 11 or 29 bit ID identifier.
Definition: xscanoutputconfiguration.h:101
XsCanOutputConfigurationArray
A list of XsCanOutputConfiguration values.
XsOutputConfiguration
Single data type output configuration.
Definition: xsoutputconfiguration.h:96
messageserializer.h
MessageDeserializer::m_message
const XsMessage & m_message
Definition: messageserializer.h:213
MessageSerializer::operator<<
MessageSerializer & operator<<(XsDataIdentifier value)
Output stream operator that adds a XsDataIdentifier to the stream.
Definition: messageserializer.cpp:104


xsens_mti_driver
Author(s):
autogenerated on Sun Sep 3 2023 02:43:20