FRDM-KL25Zand Xsens MTi-3
Dependencies: mbed mbed-rtos Xbus
main.cpp@4:98f063b2e6da, 2015-05-13 (annotated)
- Committer:
- Alex Young
- Date:
- Wed May 13 12:02:31 2015 +0200
- Revision:
- 4:98f063b2e6da
- Parent:
- 2:b3e402dc11ca
- Child:
- 5:abc52dd88be2
Use Xbus parser to handle data from MT.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Alex Young |
4:98f063b2e6da | 1 | #include "mbed.h" |
Alex Young |
4:98f063b2e6da | 2 | #include "xbusparser.h" |
Alex Young |
4:98f063b2e6da | 3 | |
Alex Young |
4:98f063b2e6da | 4 | static Serial pc(PA_2, PA_3); |
Alex Young |
4:98f063b2e6da | 5 | static Serial mt(PB_9, PB_8); |
Alex Young |
4:98f063b2e6da | 6 | static XbusParser* xbusParser; |
Alex Young |
4:98f063b2e6da | 7 | static uint8_t rxBuffer[256]; |
Alex Young |
4:98f063b2e6da | 8 | |
Alex Young |
4:98f063b2e6da | 9 | static void* allocateBuffer(size_t bufSize) |
Alex Young |
4:98f063b2e6da | 10 | { |
Alex Young |
4:98f063b2e6da | 11 | return bufSize < sizeof(rxBuffer) ? rxBuffer : NULL; |
Alex Young |
4:98f063b2e6da | 12 | } |
Alex Young |
4:98f063b2e6da | 13 | |
Alex Young |
4:98f063b2e6da | 14 | static void mtLowLevelHandler(void) |
Alex Young |
4:98f063b2e6da | 15 | { |
Alex Young |
4:98f063b2e6da | 16 | while (mt.readable()) |
Alex Young |
4:98f063b2e6da | 17 | { |
Alex Young |
4:98f063b2e6da | 18 | XbusParser_parseByte(xbusParser, mt.getc()); |
Alex Young |
4:98f063b2e6da | 19 | } |
Alex Young |
4:98f063b2e6da | 20 | } |
Alex Young |
4:98f063b2e6da | 21 | |
Alex Young |
4:98f063b2e6da | 22 | static void mtDataHandler(uint8_t mid, uint16_t dataLength, uint8_t const* data) |
Alex Young |
4:98f063b2e6da | 23 | { |
Alex Young |
4:98f063b2e6da | 24 | pc.printf("Received Xbus message. MID=%X, length=%d\n", mid, dataLength); |
Alex Young |
4:98f063b2e6da | 25 | } |
Alex Young |
4:98f063b2e6da | 26 | |
Alex Young |
4:98f063b2e6da | 27 | |
Alex Young |
4:98f063b2e6da | 28 | static void configureSerialPorts(void) |
Alex Young |
4:98f063b2e6da | 29 | { |
Alex Young |
4:98f063b2e6da | 30 | pc.baud(921600); |
Alex Young |
4:98f063b2e6da | 31 | pc.format(8, Serial::None, 2); |
Alex Young |
4:98f063b2e6da | 32 | |
Alex Young |
4:98f063b2e6da | 33 | mt.baud(921600); |
Alex Young |
4:98f063b2e6da | 34 | mt.format(8, Serial::None, 2); |
Alex Young |
4:98f063b2e6da | 35 | mt.attach(mtLowLevelHandler, Serial::RxIrq); |
Alex Young |
4:98f063b2e6da | 36 | } |
Alex Young |
4:98f063b2e6da | 37 | |
Alex Young |
2:b3e402dc11ca | 38 | int main(void) |
Alex Young |
2:b3e402dc11ca | 39 | { |
Alex Young |
4:98f063b2e6da | 40 | XbusParserCallback xbusCallback = {}; |
Alex Young |
4:98f063b2e6da | 41 | xbusCallback.allocateBuffer = allocateBuffer; |
Alex Young |
4:98f063b2e6da | 42 | xbusCallback.handleMessage = mtDataHandler; |
Alex Young |
4:98f063b2e6da | 43 | |
Alex Young |
4:98f063b2e6da | 44 | xbusParser = XbusParser_create(&xbusCallback); |
Alex Young |
4:98f063b2e6da | 45 | configureSerialPorts(); |
Alex Young |
4:98f063b2e6da | 46 | } |