kjj

Dependencies:   mbed-rtos mbed Xbus

Fork of MTi-1_example by Xsens

Revision:
11:8593ba137917
Parent:
8:77cd45916596
Child:
14:155f9a55ec51
--- a/main.cpp	Wed May 13 17:42:38 2015 +0200
+++ b/main.cpp	Wed May 13 17:43:40 2015 +0200
@@ -1,6 +1,7 @@
 #include "mbed.h"
 #include "xbusparser.h"
 #include "mtdata2.h"
+#include "xbusmessage.h"
 
 static Serial pc(PA_2, PA_3);
 static Serial mt(PB_9, PB_8);
@@ -20,6 +21,39 @@
 	}
 }
 
+static void sendCommand(XsMessageId cmdId)
+{
+	uint8_t buf[8];
+	XbusMessage m = {cmdId};
+	size_t rawLength = XbusMessage_format(buf, &m);
+	for (size_t i = 0; i < rawLength; ++i)
+	{
+		mt.putc(buf[i]);
+	}
+}
+
+static void handlePcCommand(char cmd)
+{
+	switch (cmd)
+	{
+		case 'c':
+			sendCommand(XMID_GotoConfig);
+			break;
+
+		case 'm':
+			sendCommand(XMID_GotoMeasurement);
+			break;
+	}
+}
+
+static void pcHandler(void)
+{
+	while (pc.readable())
+	{
+		handlePcCommand(pc.getc());
+	}
+}
+
 static void mtDataHandler(uint8_t mid, uint16_t dataLength, uint8_t const* data)
 {
 	if (mid == MTDATA2_MESSAGE_ID)
@@ -53,6 +87,7 @@
 {
 	pc.baud(921600);
 	pc.format(8, Serial::None, 2);
+	pc.attach(pcHandler, Serial::RxIrq);
 
 	mt.baud(921600);
 	mt.format(8, Serial::None, 2);