xsdeviceconfiguration.c
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 "xsdeviceconfiguration.h"
66 #include <xstypes/xsmessage.h>
67 #include <xstypes/xsdeviceid.h>
68 #include "xsdef.h"
69 #include <stdlib.h>
70 #include <memory.h>
71 
72 #define INC_ALLOC ((void) 0)
73 #define INC_FREE ((void) 0)
74 
83 {
84  memset(thisPtr, 0, sizeof(XsDeviceConfiguration));
85 }
86 
97 {
98  if (numberOfDevices > thisPtr->m_numberOfDevices || numberOfDevices == 0)
99  {
101  if (numberOfDevices)
102  {
103  // init to size
104  *((XsMtDeviceConfiguration**) &thisPtr->m_deviceInfo) = (XsMtDeviceConfiguration*) malloc(numberOfDevices * sizeof(XsMtDeviceConfiguration));
105  INC_ALLOC;
106  }
107  }
108  assert(numberOfDevices != 0 || thisPtr->m_deviceInfo == 0);
109 
110  *((uint16_t*) &thisPtr->m_numberOfDevices) = (uint16_t) numberOfDevices;
111 
112  if (src)
113  {
114  memcpy(&thisPtr->m_masterInfo, &src->m_masterInfo, sizeof(XsMasterDeviceConfiguration));
115  if (numberOfDevices)
116  memcpy(thisPtr->m_deviceInfo, src->m_deviceInfo, numberOfDevices * sizeof(XsMtDeviceConfiguration));
117  }
118 }
119 
123 {
124  if (thisPtr->m_deviceInfo)
125  {
126  // clear contents
127  free(thisPtr->m_deviceInfo);
128  INC_FREE;
129  }
130  // init to 0
131  *((XsMtDeviceConfiguration**) &thisPtr->m_deviceInfo) = 0;
132  *((uint16_t*) &thisPtr->m_numberOfDevices) = 0;
133 }
134 
138 {
139  if (copy == src)
140  return;
142 }
143 
149 {
150  return thisPtr->m_numberOfDevices == 0;
151 }
152 
159 {
160  uint16_t i, nDevs;
161 
162  assert(XsMessage_getConstHeader(msg)->m_messageId == XMID_Configuration);
163 
164  nDevs = XsMessage_getDataShort(msg, 96);
165  if (nDevs != thisPtr->m_numberOfDevices)
166  XsDeviceConfiguration_assign(thisPtr, nDevs, 0);
167 
169  {
170  XsDeviceId deviceId = { thisPtr->m_masterInfo.m_masterDeviceId, XSDEVICEID_PRODUCT_CODE_INIT, 0, 0, 0};
171  if (XsDeviceId_isLegacyDeviceId(&deviceId))
172  {
175  memset(thisPtr->m_masterInfo.m_productCode, 0, XS_LEN_PRODUCTCODE * sizeof(thisPtr->m_masterInfo.m_productCode[0]));
176  }
177  else
178  {
179  thisPtr->m_masterInfo.m_masterDeviceId |= ((uint64_t)XsMessage_getDataLong(msg, 4) << 32);
180  memcpy(thisPtr->m_masterInfo.m_productCode, XsMessage_getDataBuffer(msg, 32), 20);
181  }
182  }
183  memcpy(thisPtr->m_masterInfo.m_reserved1, XsMessage_getDataBuffer(msg, 8), 8);
184  memcpy(thisPtr->m_masterInfo.m_date, XsMessage_getDataBuffer(msg, 16), 8);
185  memcpy(thisPtr->m_masterInfo.m_time, XsMessage_getDataBuffer(msg, 24), 8);
186  memcpy(thisPtr->m_masterInfo.m_reserved2, XsMessage_getDataBuffer(msg, 52), 44);
187 
188  for (i = 0; i < nDevs; ++i)
189  {
190  thisPtr->m_deviceInfo[i].m_deviceId = XsMessage_getDataLong(msg, 98 + i * 20);
191  XsDeviceId deviceId = {thisPtr->m_deviceInfo[i].m_deviceId, XSDEVICEID_PRODUCT_CODE_INIT, 0, 0, 0};
192  if (XsDeviceId_isLegacyDeviceId(&deviceId))
193  {
194  thisPtr->m_deviceInfo[i].m_deviceId = (uint32_t)XsMessage_getDataLong(msg, 98 + i * 20);
195  memcpy(thisPtr->m_deviceInfo[i].m_reserved, XsMessage_getDataBuffer(msg, 102 + i * 20), 8);
196  }
197  else
198  {
199  thisPtr->m_deviceInfo[i].m_deviceId = XsMessage_getDataLong(msg, 98 + i * 20);
200  thisPtr->m_deviceInfo[i].m_deviceId |= ((uint64_t)XsMessage_getDataLong(msg, 102 + i * 20) << 32);
201  memcpy(thisPtr->m_deviceInfo[i].m_reserved, XsMessage_getDataBuffer(msg, 106 + i * 20), 4);
202  }
203  thisPtr->m_deviceInfo[i].m_filterProfile = XsMessage_getDataShort(msg, 110 + i * 20);
204  thisPtr->m_deviceInfo[i].m_fwRevMajor = XsMessage_getDataByte(msg, 112 + i * 20);
205  thisPtr->m_deviceInfo[i].m_fwRevMinor = XsMessage_getDataByte(msg, 113 + i * 20);
206  thisPtr->m_deviceInfo[i].m_fwRevRevision = XsMessage_getDataByte(msg, 114 + i * 20);
207  thisPtr->m_deviceInfo[i].m_filterType = (char)XsMessage_getDataByte(msg, 115 + i * 20);
208  thisPtr->m_deviceInfo[i].m_filterMajor = XsMessage_getDataByte(msg, 116 + i * 20);
209  thisPtr->m_deviceInfo[i].m_filterMinor = XsMessage_getDataByte(msg, 117 + i * 20);
210  }
211 }
212 
219 {
220  uint16_t i;
221  XsMessageHeader* msgHeader;
222 
223  XsMessage_constructSized(msg, 98 + thisPtr->m_numberOfDevices * 20);
224  msgHeader = XsMessage_getHeader(msg);
225  msgHeader->m_messageId = XMID_Configuration;
226  msgHeader->m_busId = XS_BID_MASTER;
227 
228  {
230  if (XsDeviceId_isLegacyDeviceId(&deviceId))
231  {
235  }
236  else
237  {
238  XsMessage_setDataLong(msg, (uint32_t)thisPtr->m_masterInfo.m_masterDeviceId & 0x00000000FFFFFFFF, 0);
239  XsMessage_setDataLong(msg, (uint32_t)((thisPtr->m_masterInfo.m_masterDeviceId & 0xFFFFFFFF00000000) >> 32), 4);
240  }
241  }
242 
249 
250  for (i = 0; i < thisPtr->m_numberOfDevices; ++i)
251  {
252  XsDeviceId deviceId = {thisPtr->m_deviceInfo[i].m_deviceId, XSDEVICEID_PRODUCT_CODE_INIT, 0, 0, 0};
253  if (XsDeviceId_isLegacyDeviceId(&deviceId))
254  {
255  XsMessage_setDataLong(msg, (uint32_t)thisPtr->m_deviceInfo[i].m_deviceId, 98 + i * 20);
256  XsMessage_setDataBuffer(msg, thisPtr->m_masterInfo.m_reserved1, 8, 102 + i * 20);
257  }
258  else
259  {
260  XsMessage_setDataLong(msg, (uint32_t)thisPtr->m_deviceInfo[i].m_deviceId & 0x00000000FFFFFFFF, 98 + i * 20);
261  XsMessage_setDataLong(msg, (uint32_t)((thisPtr->m_deviceInfo[i].m_deviceId & 0xFFFFFFFF00000000) >> 32), 102 + i * 20);
262  XsMessage_setDataBuffer(msg, thisPtr->m_masterInfo.m_reserved1, 4, 106 + i * 20);
263  }
264  XsMessage_setDataShort(msg, thisPtr->m_deviceInfo[i].m_filterProfile, 110 + i * 20);
265  XsMessage_setDataByte(msg, thisPtr->m_deviceInfo[i].m_fwRevMajor, 112 + i * 20);
266  XsMessage_setDataByte(msg, thisPtr->m_deviceInfo[i].m_fwRevMinor, 113 + i * 20);
267  XsMessage_setDataByte(msg, thisPtr->m_deviceInfo[i].m_fwRevRevision, 114 + i * 20);
268  XsMessage_setDataByte(msg, (uint8_t) thisPtr->m_deviceInfo[i].m_filterType, 115 + i * 20);
269  XsMessage_setDataByte(msg, thisPtr->m_deviceInfo[i].m_filterMajor, 116 + i * 20);
270  XsMessage_setDataByte(msg, thisPtr->m_deviceInfo[i].m_filterMinor, 117 + i * 20);
271  }
273 }
274 
284 {
285  uint16_t i;
286  for (i = 0; i < thisPtr->m_numberOfDevices; ++i)
287  {
288  if (thisPtr->m_deviceInfo[i].m_deviceId == deviceId->m_deviceId)
289  return i + 1;
290  }
291  return 0;
292 }
XS_BID_MASTER
#define XS_BID_MASTER
The bus identifier of the master device.
Definition: xsbusid.h:73
XSDEVICEID_PRODUCT_CODE_INIT
#define XSDEVICEID_PRODUCT_CODE_INIT
Definition: xsdeviceid.h:78
XsMtDeviceConfiguration::m_filterType
char m_filterType
The filter type.
Definition: xsdeviceconfiguration.h:110
XsMtDeviceConfiguration::m_fwRevRevision
uint8_t m_fwRevRevision
The revision version of the firmware.
Definition: xsdeviceconfiguration.h:109
XsDeviceConfiguration::XsDeviceConfiguration_assign
void XsDeviceConfiguration_assign(XsDeviceConfiguration *thisPtr, XsSize numberOfDevices, const XsDeviceConfiguration *src)
Reinitializes the XsDeviceConfiguration with space for numberOfDevices devices and copies them from s...
Definition: xsdeviceconfiguration.c:96
XsMtDeviceConfiguration::m_filterProfile
uint16_t m_filterProfile
The currently chosen filter profile.
Definition: xsdeviceconfiguration.h:106
msg
msg
XsMessageHeader
A message header.
Definition: xsmessage.h:169
XsMessageHeader::m_busId
uint8_t m_busId
The bus ID.
Definition: xsmessage.h:172
XsDeviceId_isLegacyDeviceId
int XsDeviceId_isLegacyDeviceId(const struct XsDeviceId *thisPtr)
Test if the device ID represents a legacy device identification.
Definition: xsdeviceid.c:90
XsDeviceConfiguration::XsDeviceConfiguration_destruct
void XsDeviceConfiguration_destruct(XsDeviceConfiguration *thisPtr)
Clears and frees data in the XsDeviceConfiguration.
Definition: xsdeviceconfiguration.c:122
XsMessage_constructSized
void XsMessage_constructSized(XsMessage *thisPtr, XsSize dataSize)
This function initializes the XsMessage object and reserves dataSize bytes for data.
Definition: xsmessage.c:311
XsDeviceConfiguration
Structure containing a full device configuration as returned by the ReqConfig message.
Definition: xsdeviceconfiguration.h:143
XsMtDeviceConfiguration::m_deviceId
uint64_t m_deviceId
This device ID.
Definition: xsdeviceconfiguration.h:104
XsDeviceConfiguration::XsDeviceConfiguration_empty
int XsDeviceConfiguration_empty(const XsDeviceConfiguration *thisPtr)
Returns true if the XsDeviceConfiguration is empty.
Definition: xsdeviceconfiguration.c:148
XsDeviceConfiguration::XsDeviceConfiguration_writeToMessage
void XsDeviceConfiguration_writeToMessage(const XsDeviceConfiguration *thisPtr, XsMessage *msg)
Creates a message msg that represents the XsDeviceConfiguration.
Definition: xsdeviceconfiguration.c:218
XsMessage_recomputeChecksum
void XsMessage_recomputeChecksum(XsMessage *thisPtr)
Update the checksum for the message.
Definition: xsmessage.c:988
XS_LEN_PRODUCTCODE
#define XS_LEN_PRODUCTCODE
Definition: xsdef.h:107
XsMtDeviceConfiguration::m_reserved
uint8_t m_reserved[8]
Reserved space.
Definition: xsdeviceconfiguration.h:105
XsMasterDeviceConfiguration::m_reserved1
uint8_t m_reserved1[8]
Reserved space.
Definition: xsdeviceconfiguration.h:123
XsMessage_getDataBuffer
const uint8_t * XsMessage_getDataBuffer(XsMessage const *thisPtr, XsSize offset)
Returns a const pointer to the data buffer of the message.
Definition: xsmessage.c:595
XsDeviceConfiguration::XsDeviceConfiguration_copy
void XsDeviceConfiguration_copy(XsDeviceConfiguration *copy, XsDeviceConfiguration const *src)
Copy the XsDeviceConfiguration to copy.
Definition: xsdeviceconfiguration.c:137
XsMessage_getDataByte
uint8_t XsMessage_getDataByte(XsMessage const *thisPtr, XsSize offset)
Returns the byte value at offset in the data of the message.
Definition: xsmessage.c:481
XsDeviceConfiguration::XsDeviceConfiguration_construct
void XsDeviceConfiguration_construct(XsDeviceConfiguration *thisPtr)
Initializes the XsDeviceConfiguration object.
Definition: xsdeviceconfiguration.c:82
XsMasterDeviceConfiguration
Device information for the main device in an XsDeviceConfiguration.
Definition: xsdeviceconfiguration.h:118
INC_FREE
#define INC_FREE
Definition: xsdeviceconfiguration.c:73
XsMessage_setDataShort
void XsMessage_setDataShort(XsMessage *thisPtr, uint16_t value, XsSize offset)
Sets the short at offset in the message to value.
Definition: xsmessage.c:615
XsMtDeviceConfiguration::m_filterMinor
uint8_t m_filterMinor
The filter minor version.
Definition: xsdeviceconfiguration.h:112
uint32_t
unsigned int uint32_t
Definition: pstdint.h:485
XsMessage_setDataBuffer
void XsMessage_setDataBuffer(XsMessage *thisPtr, const uint8_t *buffer, XsSize size, XsSize offset)
Puts size number of bytes from buffer into the message at offset.
Definition: xsmessage.c:731
xsdef.h
Macros and types for use in the Xsens communication protocol and Xsens Device API classes.
XsMasterDeviceConfiguration::m_time
uint8_t m_time[8]
The time.
Definition: xsdeviceconfiguration.h:125
XsMessage_getConstHeader
const XsMessageHeader * XsMessage_getConstHeader(XsMessage const *thisPtr)
Definition: xsmessage.c:1012
XsMtDeviceConfiguration::m_filterMajor
uint8_t m_filterMajor
The filter major version.
Definition: xsdeviceconfiguration.h:111
XsMessage_setDataLong
void XsMessage_setDataLong(XsMessage *thisPtr, uint32_t value, XsSize offset)
Sets the long at offset in the message to value.
Definition: xsmessage.c:625
XsMasterDeviceConfiguration::m_masterDeviceId
uint64_t m_masterDeviceId
The master device ID.
Definition: xsdeviceconfiguration.h:120
XsSize
size_t XsSize
XsSize must be unsigned number!
Definition: xstypedefs.h:74
xsdeviceid.h
XsMessage
Structure for storing a single message.
Definition: xsmessage.h:202
XsMtDeviceConfiguration::m_fwRevMajor
uint8_t m_fwRevMajor
The major version of the firmware.
Definition: xsdeviceconfiguration.h:107
XMID_Configuration
@ XMID_Configuration
Definition: xsxbusmessageid.h:97
XsDeviceConfiguration::m_masterInfo
XsMasterDeviceConfiguration m_masterInfo
The master info.
Definition: xsdeviceconfiguration.h:350
XsDeviceId
Contains an Xsens device ID and provides operations for determining the type of device.
Definition: xsdeviceid.h:192
XsDeviceConfiguration::m_deviceInfo
XsMtDeviceConfiguration *const m_deviceInfo
The list of device infos.
Definition: xsdeviceconfiguration.h:352
XsMessage_setDataByte
void XsMessage_setDataByte(XsMessage *thisPtr, uint8_t value, XsSize offset)
Set the byte at offset in the message to value.
Definition: xsmessage.c:605
XsMessage_getDataLong
uint32_t XsMessage_getDataLong(XsMessage const *thisPtr, XsSize offset)
Returns the long value at offset in the data of the message.
Definition: xsmessage.c:505
xsmessage.h
INC_ALLOC
#define INC_ALLOC
Definition: xsdeviceconfiguration.c:72
XsMtDeviceConfiguration
Device information for MT devices in an XsDeviceConfiguration.
Definition: xsdeviceconfiguration.h:102
XsDeviceConfiguration::XsDeviceConfiguration_findDevice
XsSize XsDeviceConfiguration_findDevice(const XsDeviceConfiguration *thisPtr, const XsDeviceId *deviceId)
Returns a (naive) bus ID if deviceId is available in this configuration, 0 otherwise.
Definition: xsdeviceconfiguration.c:283
XsMasterDeviceConfiguration::m_reserved2
uint8_t m_reserved2[44]
Reserved space.
Definition: xsdeviceconfiguration.h:127
XsMasterDeviceConfiguration::m_outputSkipFactor
uint16_t m_outputSkipFactor
The output skip factor.
Definition: xsdeviceconfiguration.h:122
XsDeviceId::m_deviceId
uint64_t m_deviceId
The serialnumber of a device.
Definition: xsdeviceid.h:905
XsMasterDeviceConfiguration::m_date
uint8_t m_date[8]
The date.
Definition: xsdeviceconfiguration.h:124
XsMessage_getHeader
XsMessageHeader * XsMessage_getHeader(XsMessage *thisPtr)
Returns a pointer to the message header for this message.
Definition: xsmessage.c:1006
XsDeviceConfiguration::m_numberOfDevices
const uint16_t m_numberOfDevices
The currently allocated number of devices.
Definition: xsdeviceconfiguration.h:351
XsMtDeviceConfiguration::m_fwRevMinor
uint8_t m_fwRevMinor
The minor version of the firmware.
Definition: xsdeviceconfiguration.h:108
XsMessageHeader::m_messageId
uint8_t m_messageId
The message ID.
Definition: xsmessage.h:173
xsdeviceconfiguration.h
XsDeviceConfiguration::XsDeviceConfiguration_readFromMessage
void XsDeviceConfiguration_readFromMessage(XsDeviceConfiguration *thisPtr, const XsMessage *msg)
Sets up a XsDeviceConfiguration based upon msg.
Definition: xsdeviceconfiguration.c:158
XsMasterDeviceConfiguration::m_productCode
uint8_t m_productCode[20]
The master product code.
Definition: xsdeviceconfiguration.h:126
XsMasterDeviceConfiguration::m_samplingPeriod
uint16_t m_samplingPeriod
The sampling period.
Definition: xsdeviceconfiguration.h:121
XsMessage_getDataShort
uint16_t XsMessage_getDataShort(XsMessage const *thisPtr, XsSize offset)
Returns the short value at offset in the data of the message.
Definition: xsmessage.c:492


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