Go to the documentation of this file.
84 #define XSMESSAGE_INITIALIZER { XSBYTEARRAY_INITIALIZER, 1, 0 }
144 #define XS_PREAMBLE 0xFA
145 #define XS_EXTLENCODE 0xFF
147 #define XS_LEN_MSGHEADER 4
148 #define XS_LEN_MSGEXTHEADER 6
149 #define XS_LEN_MSGHEADERCS 5
150 #define XS_LEN_MSGEXTHEADERCS 7
151 #define XS_LEN_CHECKSUM 1
152 #define XS_LEN_UNSIGSHORT 2
153 #define XS_LEN_UNSIGINT 4
154 #define XS_LEN_FLOAT 4
157 #define XS_MAXDATALEN (8192-XS_LEN_MSGEXTHEADERCS)
158 #define XS_MAXSHORTDATALEN 254
159 #define XS_MAXMSGLEN (XS_MAXDATALEN+XS_LEN_MSGEXTHEADERCS)
160 #define XS_MAXSHORTMSGLEN (XS_MAXSHORTDATALEN+XS_LEN_MSGHEADERCS)
161 #define XS_MAXGARBAGE (XS_MAXMSGLEN+1)
247 XsSize szm = source.size() / 2;
248 XsSize szmcc = szm + (computeChecksum ? 1 : 0);
250 auto tonibble = [](
char a) -> uint8_t
252 if (a >=
'0' && a <=
'9')
253 return (uint8_t)(a -
'0');
254 if (a >=
'a' && a <=
'f')
255 return (uint8_t)(10 + a -
'a');
256 if (a >=
'A' && a <=
'F')
257 return (uint8_t)(10 + a -
'A');
260 for (
XsSize i = 0; i < szm; ++i)
261 tmp[i] = tonibble(source[i * 2]) * (uint8_t)16 + tonibble(source[i * 2 + 1]);
283 inline void clear(
void)
292 inline bool empty(
void)
const
298 inline uint8_t getBusId(
void)
const
308 inline const uint8_t* getDataBuffer(
XsSize offset = 0)
const
315 inline uint8_t getDataByte(
XsSize offset = 0)
const
322 inline double getDataDouble(
XsSize offset = 0)
const
329 inline float getDataFloat(
XsSize offset = 0)
const
336 inline double getDataF1220(
XsSize offset = 0)
const
343 inline double getDataFP1632(
XsSize offset = 0)
const
357 inline uint64_t getDataLongLong(
XsSize offset = 0)
const
364 inline uint16_t getDataShort(
XsSize offset = 0)
const
371 inline XsSize getDataSize(
void)
const
400 inline const uint8_t* getMessageStart(
void)
const
407 inline XsSize getTotalMessageSize(
void)
const
414 inline bool isChecksumOk(
void)
const
426 inline bool loadFromString(
const uint8_t* src,
XsSize msgSize)
430 return isChecksumOk();
435 inline void recomputeChecksum(
void)
442 inline void resizeData(
XsSize newSize)
449 inline void setBusId(uint8_t busId)
456 inline void setBusId(
int busId)
463 inline void setDataBuffer(
const uint8_t* buffer,
XsSize size,
XsSize offset = 0)
470 inline void setDataByte(
const uint8_t value,
XsSize offset = 0)
477 inline void setDataDouble(
const double value,
XsSize offset = 0)
484 inline void setDataFloat(
const float value,
XsSize offset = 0)
491 inline void setDataF1220(
const double value,
XsSize offset = 0)
498 inline void setDataFP1632(
const double value,
XsSize offset = 0)
512 inline void setDataLongLong(
const uint64_t value,
XsSize offset = 0)
519 inline void setDataShort(
const uint16_t value,
XsSize offset = 0)
626 template <
typename T>
630 for (
int i = 0; i < numValues; ++i)
641 template <
typename T>
645 for (
int i = 0; i < numValues; ++i)
654 template <
typename T>
658 return numValues * (int)
sizeof(T);
663 inline void updateChecksumPtr()
689 inline void XsMessage::getData<double>(
double* data,
XsDataIdentifier id,
XsSize offset,
int numValues)
const
691 getDataFPValue(
id,
data, offset, (
XsSize)(ptrdiff_t)numValues);
703 inline void XsMessage::setData<double>(
double const* data,
XsDataIdentifier id,
XsSize offset,
int numValues)
705 setDataFPValue(
id, data, offset, (
XsSize)(ptrdiff_t)numValues);
721 #define swapEndian16(src) (uint16_t)(((uint16_t)(src) >> 8) | ((uint16_t)(src) << 8))
722 #define swapEndian32(src) (uint32_t)(((uint32_t)(src) >> 24) | (((uint32_t)(src) >> 8) & 0xFF00) | (((uint32_t)(src) << 8) & 0xFF0000) | ((uint32_t)(src) << 24))
723 #define swapEndian64(src) (uint64_t)(((src >> 56) & 0xFFULL) | ((src >> 40) & 0xFF00ULL) | ((src >> 24) & 0xFF0000ULL) | ((src >> 8) & 0xFF000000ULL) | ((src << 8) & 0xFF00000000ULL) | ((src << 24) & 0xFF0000000000ULL) | ((src << 40) & 0xFF000000000000ULL) | ((src << 56)))
#define XS_BID_MASTER
The bus identifier of the master device.
XSTYPES_DLL_API void XsMessage_deleteData(XsMessage *thisPtr, XsSize count, XsSize offset)
Remove count bytes of data from the message at offset.
XSTYPES_DLL_API void XsMessage_getDataFPValuesById(XsMessage const *thisPtr, XsDataIdentifier dataIdentifier, double *dest, XsSize offset, XsSize numValues)
Return current data values as double, conversion depends on outputSetting.
XSTYPES_DLL_API void XsMessage_getEndianCorrectData(XsMessage const *thisPtr, void *value, XsSize size, XsSize offset)
Get data of size size at offset, and put it byteswapped into value.
XSTYPES_DLL_API void XsMessage_setDataFPValuesById(XsMessage *thisPtr, XsDataIdentifier dataIdentifier, double const *data, XsSize offset, XsSize numValues)
Write a number of floating/fixed point values into to the data buffer, conversion depends on outputSe...
XSTYPES_DLL_API void XsMessage_assign(XsMessage *thisPtr, XsSize dataSize)
This function reinitializes the XsMessage object and reserves dataSize bytes for data.
XSTYPES_DLL_API void XsMessage_setBusId(XsMessage *thisPtr, uint8_t busId)
Set the bus id for this message to busId.
XSTYPES_DLL_API void XsMessage_swap(XsMessage *a, XsMessage *b)
Swap the contents of a and b.
struct XsMessage XsMessage
A list of uint8_t values.
XSTYPES_DLL_API double XsMessage_getDataFP1632(XsMessage const *thisPtr, XsSize offset)
Returns the F16.32 value at offset in the data of the message.
XSTYPES_DLL_API void XsArray_destruct(void *thisPtr)
XSTYPES_DLL_API void XsMessage_insertData(XsMessage *thisPtr, XsSize count, XsSize offset)
Create count bytes of empty space at offset in this message.
XSTYPES_DLL_API void XsMessage_constructSized(XsMessage *thisPtr, XsSize dataSize)
This function initializes the XsMessage object and reserves dataSize bytes for data.
@ XRV_NULLPTR
274: Tried to supply a NULL value where it is not allowed
XSTYPES_DLL_API void XsMessage_setEndianCorrectData(XsMessage *thisPtr, void const *value, XsSize size, XsSize offset)
Set value value of size size byteswapped at offset.
XSTYPES_DLL_API uint64_t XsMessage_getDataLongLong(XsMessage const *thisPtr, XsSize offset)
Returns the long value at offset in the data of the message.
XSTYPES_DLL_API void XsMessage_recomputeChecksum(XsMessage *thisPtr)
Update the checksum for the message.
#define XS_PACKED_STRUCT_START
XSTYPES_DLL_API void XsMessage_setDataFP1632(XsMessage *thisPtr, double value, XsSize offset)
Sets the F16.32 at offset in the message to value.
XSTYPES_DLL_API uint8_t XsMessage_computeChecksum(XsMessage const *thisPtr)
Computes the checksum for the message.
@ XRV_TIMEOUTNODATA
259: Operation aborted because of no data read
XSTYPES_DLL_API XsSize XsMessage_getTotalMessageSize(XsMessage const *thisPtr)
Return the length of the message buffer.
XSTYPES_DLL_API void XsMessage_setMessageId(XsMessage *thisPtr, XsXbusMessageId msgId)
Set the message id for this message to msgId.
XSTYPES_DLL_API void XsMessage_getDataRealValuesById(XsMessage const *thisPtr, XsDataIdentifier dataIdentifier, XsReal *dest, XsSize offset, XsSize numValues)
Return current data values as XsReal, conversion is done automatically based on data identifier.
XSTYPES_DLL_API void XsMessage_resizeData(XsMessage *thisPtr, XsSize newSize)
Resize the buffer of message to newSize bytes.
const XSTYPES_DLL_API uint8_t * XsMessage_getDataBuffer(XsMessage const *thisPtr, XsSize offset)
Returns a const pointer to the data buffer of the message.
@ XRV_OK
0: Operation was performed successfully
XSTYPES_DLL_API uint8_t XsMessage_getDataByte(XsMessage const *thisPtr, XsSize offset)
Returns the byte value at offset in the data of the message.
XSTYPES_DLL_API int XsMessage_isChecksumOk(XsMessage const *thisPtr)
Returns non-zero if the checksum inside the message is correct for the message, zero otherwise.
XSTYPES_DLL_API void XsMessage_toHexString(XsMessage const *thisPtr, XsSize maxBytes, XsString *resultValue)
Return a string containing the first maxBytes bytes of the message in hex format.
XSTYPES_DLL_API void XsMessage_setDataLongLong(XsMessage *thisPtr, uint64_t value, XsSize offset)
Sets the long at offset in the message to value.
XsResultValue
Xsens result values.
XSTYPES_DLL_API void XsMessage_setDataShort(XsMessage *thisPtr, uint16_t value, XsSize offset)
Sets the short at offset in the message to value.
bool operator==(const XsFilterProfile &lhs, const XsFilterProfile &rhs)
Returns true if lhs has the same type as rhs.
XsDataIdentifier
Defines the data identifiers.
#define XS_PACKED_STRUCT_END
XSTYPES_DLL_API void XsMessage_copyConstruct(XsMessage *thisPtr, XsMessage const *src)
Construct an XsMessage as a copy of XsMessage src.
XSTYPES_DLL_API void XsMessage_load(XsMessage *thisPtr, XsSize msgSize, unsigned char const *src)
This function initializes the XsMessage object and reserves msgSize bytes for data,...
XSTYPES_DLL_API 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.
XSTYPES_DLL_API XsSize XsMessage_dataSize(XsMessage const *thisPtr)
This function returns the datasize of the message in thisptr.
uint8_t *const m_checksum
Points to the checksum to speed up automatic checksum updates.
double XsReal
Defines the floating point type used by the Xsens libraries.
const XSTYPES_DLL_API XsMessageHeader * XsMessage_getConstHeader(XsMessage const *thisPtr)
XSTYPES_DLL_API void XsMessage_setDataLong(XsMessage *thisPtr, uint32_t value, XsSize offset)
Sets the long at offset in the message to value.
uint8_t XsMessage_getFPValueSize(XsDataIdentifier id)
Returns the byte size of id if the format is a floating point format.
XSTYPES_DLL_API void XsMessage_copy(XsMessage *copy, XsMessage const *src)
This function copies from thisPtr to copy.
size_t XsSize
XsSize must be unsigned number!
XSTYPES_DLL_API void XsMessage_setDataF1220(XsMessage *thisPtr, double value, XsSize offset)
Sets the F12.20 at offset in the message to value.
XsXbusMessageId
Xsens Xbus Message Identifiers.
XSTYPES_DLL_API int XsMessage_empty(XsMessage const *thisPtr)
Test if this message is empty.
XSTYPES_DLL_API void XsMessage_construct(XsMessage *thisPtr)
This function initializes the XsMessage object.
Structure for storing a single message.
XSTYPES_DLL_API double XsMessage_getDataF1220(XsMessage const *thisPtr, XsSize offset)
Returns the F12.20 value at offset in the data of the message.
XSTYPES_DLL_API void XsMessage_setDataDouble(XsMessage *thisPtr, double value, XsSize offset)
Sets the double at offset in the message to value.
XSTYPES_DLL_API void XsMessage_setDataByte(XsMessage *thisPtr, uint8_t value, XsSize offset)
Set the byte at offset in the message to value.
XSTYPES_DLL_API uint32_t XsMessage_getDataLong(XsMessage const *thisPtr, XsSize offset)
Returns the long value at offset in the data of the message.
XSTYPES_DLL_API void XsMessage_destruct(XsMessage *thisPtr)
This function clears the data in the message.
XSTYPES_DLL_API int XsMessage_compare(XsMessage const *a, XsMessage const *b)
Compare the contents of the messages a and b, returning non-0 if they are different.
const XSTYPES_DLL_API uint8_t * XsMessage_getMessageStart(XsMessage const *thisPtr)
This function returns a const pointer to the header of the message in thisptr.
XS_PACKED_STRUCT_START struct XsMessageHeader XS_PACKED_STRUCT
XSTYPES_DLL_API XsMessageHeader * XsMessage_getHeader(XsMessage *)
Returns a pointer to the message header for this message.
const XSTYPES_DLL_API uint8_t * XsMessage_constData(XsMessage const *thisPtr, XsSize offset)
This function returns a const pointer to the offset in the data of the message in thisptr.
XSTYPES_DLL_API float XsMessage_getDataFloat(XsMessage const *thisPtr, XsSize offset)
Returns the float value at offset in the data of the message.
XSTYPES_DLL_API double XsMessage_getDataDouble(XsMessage const *thisPtr, XsSize offset)
Returns the double at offset in the data of the message.
A 0-terminated managed string of characters.
XSTYPES_DLL_API void XsMessage_setDataRealValuesById(XsMessage *thisPtr, XsDataIdentifier dataIdentifier, XsReal const *data, XsSize offset, XsSize numValues)
Write a number of floating/fixed point values into to the data buffer, conversion depends on data ide...
XSTYPES_DLL_API void XsMessage_setDataFloat(XsMessage *thisPtr, float value, XsSize offset)
Sets the float at offset in the message to value.
XSTYPES_DLL_API uint16_t XsMessage_getDataShort(XsMessage const *thisPtr, XsSize offset)
Returns the short value at offset in the data of the message.