Basic implementation of Xbus message parsing and generation for embedded processors. The code has no dependencies and should also work for other MCU architectures than ARM provided a C99 compiler is available.

Dependents:   MTi-1_example_LPC1768 MTi-1_rikbeun MTi-1_example MTi-1_example ... more

Important Information

This library is deprecated and no longer maintained. There are new embedded examples available in the MT SDK folder of the MT Software Suite. For more information please visit: https://xsenstechnologies.force.com/knowledgebase/s/article/Introduction-to-the-MT-SDK-programming-examples-for-MTi-devices

For an example of using the Xbus library to communicate with an MTi-1 series device using a full-duplex UART see:

Import programMTi-1_example

Example of using Xbus library to communicate with an MTi-1 series device using a full-duplex UART connection.

Files at this revision

API Documentation at this revision

Comitter:
tjerkhofmeijer
Date:
Fri Oct 02 16:22:33 2015 +0200
Parent:
0:eb25b1785ee4
Commit message:
Xbus library is updated to support MTi 1-series' I2C and SPI interfaces

Changed in this revision

xbusdef.h Show annotated file Show diff for this revision Revisions of this file
xbusmessage.c Show annotated file Show diff for this revision Revisions of this file
xbusmessage.h Show annotated file Show diff for this revision Revisions of this file
diff -r eb25b1785ee4 -r c24f69a2eff4 xbusdef.h
--- a/xbusdef.h	Tue Jun 16 07:54:23 2015 +0000
+++ b/xbusdef.h	Fri Oct 02 16:22:33 2015 +0200
@@ -1,30 +1,36 @@
-/*!
- * \file
- * \copyright Copyright (C) Xsens Technologies B.V., 2015.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy
- * of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations
- * under the License.
- */
-
-#ifndef __XBUSDEF_H
-#define __XBUSDEF_H
-
-/*! \brief Xbus message preamble byte. */
-#define XBUS_PREAMBLE (0xFA)
-/*! \brief Xbus message bus ID for master devices. */
-#define XBUS_MASTERDEVICE (0xFF)
-/*! \brief Xbus length byte for messages without payload. */
-#define XBUS_NO_PAYLOAD (0x00)
-/*! \brief Xbus length byte for message with an extended payload. */
-#define XBUS_EXTENDED_LENGTH (0xFF)
-
-#endif // __XBUSDEF_H
+/*!
+ * \file
+ * \copyright Copyright (C) Xsens Technologies B.V., 2015.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy
+ * of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef __XBUSDEF_H
+#define __XBUSDEF_H
+
+/*! \brief Xbus message preamble byte. */
+#define XBUS_PREAMBLE (0xFA)
+/*! \brief Xbus message bus ID for master devices. */
+#define XBUS_MASTERDEVICE (0xFF)
+/*! \brief Xbus length byte for messages without payload. */
+#define XBUS_NO_PAYLOAD (0x00)
+/*! \brief Xbus length byte for message with an extended payload. */
+#define XBUS_EXTENDED_LENGTH (0xFF)
+
+/*! \brief Opcode to write to control pipe in I2C/SPI mode */
+#define XBUS_CONTROL_PIPE (0x03)
+#define XBUS_PIPE_STATUS (0x04)
+#define XBUS_NOTIFICATION_PIPE (0x05)
+#define XBUS_MEASUREMENT_PIPE (0x06)
+
+#endif // __XBUSDEF_H
diff -r eb25b1785ee4 -r c24f69a2eff4 xbusmessage.c
--- a/xbusmessage.c	Tue Jun 16 07:54:23 2015 +0000
+++ b/xbusmessage.c	Fri Oct 02 16:22:33 2015 +0200
@@ -73,14 +73,36 @@
  * \brief Format a message into the raw Xbus format ready for transmission to
  * a motion tracker.
  */
-size_t XbusMessage_format(uint8_t* raw, struct XbusMessage const* message)
+size_t XbusMessage_format(uint8_t* raw, struct XbusMessage const* message, enum XbusLowLevelFormat format)
 {
 	uint8_t* dptr = raw;
-	*dptr++ = XBUS_PREAMBLE;
+	switch (format)
+	{
+		case XLLF_I2c:
+			{
+				*dptr++ = XBUS_CONTROL_PIPE;
+			}
+			break;
 
-	*dptr = XBUS_MASTERDEVICE;
-	uint8_t checksum = 0;
-	checksum -= *dptr++;
+		case XLLF_Spi:
+			{
+				*dptr++ = XBUS_CONTROL_PIPE;
+				// Fill bytes required to allow MT to process data
+				*dptr++ = 0;
+				*dptr++ = 0;
+				*dptr++ = 0;
+			}
+			break;
+
+		case XLLF_Uart:
+			{
+				*dptr++ = XBUS_PREAMBLE;
+				*dptr++ = XBUS_MASTERDEVICE;
+			}
+			break;
+	}
+
+	uint8_t checksum = (uint8_t)(-XBUS_MASTERDEVICE);
 
 	*dptr = message->mid;
 	checksum -= *dptr++;
diff -r eb25b1785ee4 -r c24f69a2eff4 xbusmessage.h
--- a/xbusmessage.h	Tue Jun 16 07:54:23 2015 +0000
+++ b/xbusmessage.h	Fri Oct 02 16:22:33 2015 +0200
@@ -1,104 +1,117 @@
-/*!
- * \file
- * \copyright Copyright (C) Xsens Technologies B.V., 2015.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy
- * of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations
- * under the License.
- */
-
-#ifndef __XBUSMESSAGE_H
-#define __XBUSMESSAGE_H
-
-#include <stddef.h>
-#include <stdint.h>
-#include <stdbool.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*! \brief Xbus message IDs. */
-enum XsMessageId
-{
-	XMID_Wakeup             = 0x3E,
-	XMID_WakeupAck          = 0x3F,
-	XMID_ReqDid             = 0x00,
-	XMID_DeviceId           = 0x01,
-	XMID_GotoConfig         = 0x30,
-	XMID_GotoConfigAck      = 0x31,
-	XMID_GotoMeasurement    = 0x10,
-	XMID_GotoMeasurementAck = 0x11,
-	XMID_MtData2            = 0x36,
-	XMID_ReqOutputConfig    = 0xC0,
-	XMID_SetOutputConfig    = 0xC0,
-	XMID_OutputConfig       = 0xC1,
-	XMID_Reset              = 0x40,
-	XMID_ResetAck           = 0x41,
-	XMID_Error              = 0x42,
-};
-
-/*! \brief Xbus data message type IDs. */
-enum XsDataIdentifier
-{
-	XDI_PacketCounter  = 0x1020,
-	XDI_SampleTimeFine = 0x1060,
-	XDI_Quaternion     = 0x2010,
-	XDI_DeltaV         = 0x4010,
-	XDI_Acceleration   = 0x4020,
-	XDI_RateOfTurn     = 0x8020,
-	XDI_DeltaQ         = 0x8030,
-	XDI_MagneticField  = 0xC020,
-	XDI_StatusWord     = 0xE020,
-};
-
-/*!
- * \brief An Xbus message structure with optional payload.
- */
-struct XbusMessage
-{
-	/*! \brief The message ID of the message. */
-	enum XsMessageId mid;
-	/*!
-	 * \brief The length of the payload.
-	 *
-	 * \note The meaning of the length is message dependent. For example,
-	 * for XMID_OutputConfig messages it is the number of OutputConfiguration
-	 * elements in the configuration array.
-	 */
-	uint16_t length;
-	/*! \brief Pointer to the payload data. */
-	void* data;
-};
-
-/*!
- * \brief Output configuration structure.
- */
-struct OutputConfiguration
-{
-	/*! \brief Data type of the output. */
-	enum XsDataIdentifier dtype;
-	/*!
-	 * \brief The output frequency in Hz, or 65535 if the value should be
-	 * included in every data message.
-	 */
-	uint16_t freq;
-};
-
-size_t XbusMessage_format(uint8_t* raw, struct XbusMessage const* message);
-bool XbusMessage_getDataItem(void* item, enum XsDataIdentifier id, struct XbusMessage const* message);
-char const* XbusMessage_dataDescription(enum XsDataIdentifier id);
-
-#ifdef __cplusplus
-}
-#endif // extern "C"
-
-#endif // __XBUSMESSAGE_H
+/*!
+ * \file
+ * \copyright Copyright (C) Xsens Technologies B.V., 2015.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy
+ * of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef __XBUSMESSAGE_H
+#define __XBUSMESSAGE_H
+
+#include <stddef.h>
+#include <stdint.h>
+#include <stdbool.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*! \brief Xbus message IDs. */
+enum XsMessageId
+{
+	XMID_Wakeup             = 0x3E,
+	XMID_WakeupAck          = 0x3F,
+	XMID_ReqDid             = 0x00,
+	XMID_DeviceId           = 0x01,
+	XMID_GotoConfig         = 0x30,
+	XMID_GotoConfigAck      = 0x31,
+	XMID_GotoMeasurement    = 0x10,
+	XMID_GotoMeasurementAck = 0x11,
+	XMID_MtData2            = 0x36,
+	XMID_ReqOutputConfig    = 0xC0,
+	XMID_SetOutputConfig    = 0xC0,
+	XMID_OutputConfig       = 0xC1,
+	XMID_Reset              = 0x40,
+	XMID_ResetAck           = 0x41,
+	XMID_Error              = 0x42,
+};
+
+/*! \brief Xbus data message type IDs. */
+enum XsDataIdentifier
+{
+	XDI_PacketCounter  = 0x1020,
+	XDI_SampleTimeFine = 0x1060,
+	XDI_Quaternion     = 0x2010,
+	XDI_DeltaV         = 0x4010,
+	XDI_Acceleration   = 0x4020,
+	XDI_RateOfTurn     = 0x8020,
+	XDI_DeltaQ         = 0x8030,
+	XDI_MagneticField  = 0xC020,
+	XDI_StatusWord     = 0xE020,
+};
+
+/*!
+ * \brief Low level format to use when formating Xbus messages for transmission.
+ */
+enum XbusLowLevelFormat
+{
+	/*! \brief Format for use with I2C interface. */
+	XLLF_I2c,
+	/*! \brief Format for use with SPI interface. */
+	XLLF_Spi,
+	/*! \brief Format for use with UART interface. */
+	XLLF_Uart
+};
+
+/*!
+ * \brief An Xbus message structure with optional payload.
+ */
+struct XbusMessage
+{
+	/*! \brief The message ID of the message. */
+	enum XsMessageId mid;
+	/*!
+	 * \brief The length of the payload.
+	 *
+	 * \note The meaning of the length is message dependent. For example,
+	 * for XMID_OutputConfig messages it is the number of OutputConfiguration
+	 * elements in the configuration array.
+	 */
+	uint16_t length;
+	/*! \brief Pointer to the payload data. */
+	void* data;
+};
+
+/*!
+ * \brief Output configuration structure.
+ */
+struct OutputConfiguration
+{
+	/*! \brief Data type of the output. */
+	enum XsDataIdentifier dtype;
+	/*!
+	 * \brief The output frequency in Hz, or 65535 if the value should be
+	 * included in every data message.
+	 */
+	uint16_t freq;
+};
+
+size_t XbusMessage_format(uint8_t* raw, struct XbusMessage const* message, enum XbusLowLevelFormat format);
+bool XbusMessage_getDataItem(void* item, enum XsDataIdentifier id, struct XbusMessage const* message);
+char const* XbusMessage_dataDescription(enum XsDataIdentifier id);
+
+#ifdef __cplusplus
+}
+#endif // extern "C"
+
+#endif // __XBUSMESSAGE_H