rikbeuncode

Dependencies:   mbed-rtos mbed Xbus

Fork of MTi-1_example by Xsens

Revision:
4:98f063b2e6da
Parent:
2:b3e402dc11ca
Child:
5:abc52dd88be2
--- a/main.cpp	Wed May 13 12:00:28 2015 +0200
+++ b/main.cpp	Wed May 13 12:02:31 2015 +0200
@@ -1,3 +1,46 @@
+#include "mbed.h"
+#include "xbusparser.h"
+
+static Serial pc(PA_2, PA_3);
+static Serial mt(PB_9, PB_8);
+static XbusParser* xbusParser;
+static uint8_t rxBuffer[256];
+
+static void* allocateBuffer(size_t bufSize)
+{
+	return bufSize < sizeof(rxBuffer) ? rxBuffer : NULL;
+}
+
+static void mtLowLevelHandler(void)
+{
+	while (mt.readable())
+	{
+		XbusParser_parseByte(xbusParser, mt.getc());
+	}
+}
+
+static void mtDataHandler(uint8_t mid, uint16_t dataLength, uint8_t const* data)
+{
+	pc.printf("Received Xbus message. MID=%X, length=%d\n", mid, dataLength);
+}
+
+
+static void configureSerialPorts(void)
+{
+	pc.baud(921600);
+	pc.format(8, Serial::None, 2);
+
+	mt.baud(921600);
+	mt.format(8, Serial::None, 2);
+	mt.attach(mtLowLevelHandler, Serial::RxIrq);
+}
+
 int main(void)
 {
-}
\ No newline at end of file
+	XbusParserCallback xbusCallback = {};
+	xbusCallback.allocateBuffer = allocateBuffer;
+	xbusCallback.handleMessage = mtDataHandler;
+
+	xbusParser = XbusParser_create(&xbusCallback);
+	configureSerialPorts();
+}