rikbeuncode
Dependencies: mbed-rtos mbed Xbus
Fork of MTi-1_example by
Revision 11:8593ba137917, committed 2015-05-13
- Comitter:
- Alex Young
- Date:
- Wed May 13 17:43:40 2015 +0200
- Parent:
- 10:18a6661b7e59
- Child:
- 12:3426c966768a
- Commit message:
- Simple support for going to config/measurement
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- 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);
