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

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.

Revision:
1:c24f69a2eff4
Parent:
0:eb25b1785ee4
--- 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++;