Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed-rtos mbed Xbus
Fork of MTi-1_example by
main.cpp
- Committer:
- Alex Young
- Date:
- 2015-05-19
- Revision:
- 17:680f28e00d17
- Parent:
- 16:4bdcdac223d8
- Child:
- 20:38560fa3d2eb
File content as of revision 17:680f28e00d17:
#include "mbed.h"
#include "xbusparser.h"
#include "xbusmessage.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 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(struct XbusMessage const* message)
{
if (message->mid == XMID_MtData2)
{
pc.printf("MTData2:");
uint16_t counter;
if (XbusMessage_getDataItem(&counter, XDI_PacketCounter, message))
{
pc.printf(" Packet counter: %5d", counter);
}
float ori[4];
if (XbusMessage_getDataItem(ori, XDI_Quaternion, message))
{
pc.printf(" Orientation: (% .3f, % .3f, % .3f, % .3f)", ori[0], ori[1],
ori[2], ori[3]);
}
uint32_t status;
if (XbusMessage_getDataItem(&status, XDI_StatusWord, message))
{
pc.printf(" Status:%X", status);
}
pc.printf("\n");
}
else
{
pc.printf("Received Xbus message. MID=%X, length=%d\n", message->mid, message->length);
}
}
static void configureSerialPorts(void)
{
pc.baud(921600);
pc.format(8, Serial::None, 2);
pc.attach(pcHandler, Serial::RxIrq);
mt.baud(921600);
mt.format(8, Serial::None, 2);
mt.attach(mtLowLevelHandler, Serial::RxIrq);
}
int main(void)
{
XbusParserCallback xbusCallback = {};
xbusCallback.allocateBuffer = allocateBuffer;
xbusCallback.handleMessage = mtDataHandler;
xbusParser = XbusParser_create(&xbusCallback);
configureSerialPorts();
for (;;)
{
sleep();
}
}

Xsens MTi 1-series