Basic implementation of Xbus message parsing and generation for embedded processors. The code has no dependencies and should also work for other MCU architectures than ARM provided a C99 compiler is available.

Dependents:   MTi-1_example_LPC1768 MTi-1_rikbeun MTi-1_example MTi-1_example ... more

Important Information

This library is deprecated and no longer maintained. There are new embedded examples available in the MT SDK folder of the MT Software Suite. For more information please visit: https://xsenstechnologies.force.com/knowledgebase/s/article/Introduction-to-the-MT-SDK-programming-examples-for-MTi-devices

For an example of using the Xbus library to communicate with an MTi-1 series device using a full-duplex UART see:

Import programMTi-1_example

Example of using Xbus library to communicate with an MTi-1 series device using a full-duplex UART connection.

Committer:
alexandery
Date:
Tue Jun 16 07:54:23 2015 +0000
Revision:
0:eb25b1785ee4
Child:
1:c24f69a2eff4
Make Xbus code into a library;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
alexandery 0:eb25b1785ee4 1 /*!
alexandery 0:eb25b1785ee4 2 * \file
alexandery 0:eb25b1785ee4 3 * \copyright Copyright (C) Xsens Technologies B.V., 2015.
alexandery 0:eb25b1785ee4 4 *
alexandery 0:eb25b1785ee4 5 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
alexandery 0:eb25b1785ee4 6 * use this file except in compliance with the License. You may obtain a copy
alexandery 0:eb25b1785ee4 7 * of the License at
alexandery 0:eb25b1785ee4 8 *
alexandery 0:eb25b1785ee4 9 * http://www.apache.org/licenses/LICENSE-2.0
alexandery 0:eb25b1785ee4 10 *
alexandery 0:eb25b1785ee4 11 * Unless required by applicable law or agreed to in writing, software
alexandery 0:eb25b1785ee4 12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
alexandery 0:eb25b1785ee4 13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
alexandery 0:eb25b1785ee4 14 * License for the specific language governing permissions and limitations
alexandery 0:eb25b1785ee4 15 * under the License.
alexandery 0:eb25b1785ee4 16 */
alexandery 0:eb25b1785ee4 17
alexandery 0:eb25b1785ee4 18 #ifndef __XBUSMESSAGE_H
alexandery 0:eb25b1785ee4 19 #define __XBUSMESSAGE_H
alexandery 0:eb25b1785ee4 20
alexandery 0:eb25b1785ee4 21 #include <stddef.h>
alexandery 0:eb25b1785ee4 22 #include <stdint.h>
alexandery 0:eb25b1785ee4 23 #include <stdbool.h>
alexandery 0:eb25b1785ee4 24
alexandery 0:eb25b1785ee4 25 #ifdef __cplusplus
alexandery 0:eb25b1785ee4 26 extern "C" {
alexandery 0:eb25b1785ee4 27 #endif
alexandery 0:eb25b1785ee4 28
alexandery 0:eb25b1785ee4 29 /*! \brief Xbus message IDs. */
alexandery 0:eb25b1785ee4 30 enum XsMessageId
alexandery 0:eb25b1785ee4 31 {
alexandery 0:eb25b1785ee4 32 XMID_Wakeup = 0x3E,
alexandery 0:eb25b1785ee4 33 XMID_WakeupAck = 0x3F,
alexandery 0:eb25b1785ee4 34 XMID_ReqDid = 0x00,
alexandery 0:eb25b1785ee4 35 XMID_DeviceId = 0x01,
alexandery 0:eb25b1785ee4 36 XMID_GotoConfig = 0x30,
alexandery 0:eb25b1785ee4 37 XMID_GotoConfigAck = 0x31,
alexandery 0:eb25b1785ee4 38 XMID_GotoMeasurement = 0x10,
alexandery 0:eb25b1785ee4 39 XMID_GotoMeasurementAck = 0x11,
alexandery 0:eb25b1785ee4 40 XMID_MtData2 = 0x36,
alexandery 0:eb25b1785ee4 41 XMID_ReqOutputConfig = 0xC0,
alexandery 0:eb25b1785ee4 42 XMID_SetOutputConfig = 0xC0,
alexandery 0:eb25b1785ee4 43 XMID_OutputConfig = 0xC1,
alexandery 0:eb25b1785ee4 44 XMID_Reset = 0x40,
alexandery 0:eb25b1785ee4 45 XMID_ResetAck = 0x41,
alexandery 0:eb25b1785ee4 46 XMID_Error = 0x42,
alexandery 0:eb25b1785ee4 47 };
alexandery 0:eb25b1785ee4 48
alexandery 0:eb25b1785ee4 49 /*! \brief Xbus data message type IDs. */
alexandery 0:eb25b1785ee4 50 enum XsDataIdentifier
alexandery 0:eb25b1785ee4 51 {
alexandery 0:eb25b1785ee4 52 XDI_PacketCounter = 0x1020,
alexandery 0:eb25b1785ee4 53 XDI_SampleTimeFine = 0x1060,
alexandery 0:eb25b1785ee4 54 XDI_Quaternion = 0x2010,
alexandery 0:eb25b1785ee4 55 XDI_DeltaV = 0x4010,
alexandery 0:eb25b1785ee4 56 XDI_Acceleration = 0x4020,
alexandery 0:eb25b1785ee4 57 XDI_RateOfTurn = 0x8020,
alexandery 0:eb25b1785ee4 58 XDI_DeltaQ = 0x8030,
alexandery 0:eb25b1785ee4 59 XDI_MagneticField = 0xC020,
alexandery 0:eb25b1785ee4 60 XDI_StatusWord = 0xE020,
alexandery 0:eb25b1785ee4 61 };
alexandery 0:eb25b1785ee4 62
alexandery 0:eb25b1785ee4 63 /*!
alexandery 0:eb25b1785ee4 64 * \brief An Xbus message structure with optional payload.
alexandery 0:eb25b1785ee4 65 */
alexandery 0:eb25b1785ee4 66 struct XbusMessage
alexandery 0:eb25b1785ee4 67 {
alexandery 0:eb25b1785ee4 68 /*! \brief The message ID of the message. */
alexandery 0:eb25b1785ee4 69 enum XsMessageId mid;
alexandery 0:eb25b1785ee4 70 /*!
alexandery 0:eb25b1785ee4 71 * \brief The length of the payload.
alexandery 0:eb25b1785ee4 72 *
alexandery 0:eb25b1785ee4 73 * \note The meaning of the length is message dependent. For example,
alexandery 0:eb25b1785ee4 74 * for XMID_OutputConfig messages it is the number of OutputConfiguration
alexandery 0:eb25b1785ee4 75 * elements in the configuration array.
alexandery 0:eb25b1785ee4 76 */
alexandery 0:eb25b1785ee4 77 uint16_t length;
alexandery 0:eb25b1785ee4 78 /*! \brief Pointer to the payload data. */
alexandery 0:eb25b1785ee4 79 void* data;
alexandery 0:eb25b1785ee4 80 };
alexandery 0:eb25b1785ee4 81
alexandery 0:eb25b1785ee4 82 /*!
alexandery 0:eb25b1785ee4 83 * \brief Output configuration structure.
alexandery 0:eb25b1785ee4 84 */
alexandery 0:eb25b1785ee4 85 struct OutputConfiguration
alexandery 0:eb25b1785ee4 86 {
alexandery 0:eb25b1785ee4 87 /*! \brief Data type of the output. */
alexandery 0:eb25b1785ee4 88 enum XsDataIdentifier dtype;
alexandery 0:eb25b1785ee4 89 /*!
alexandery 0:eb25b1785ee4 90 * \brief The output frequency in Hz, or 65535 if the value should be
alexandery 0:eb25b1785ee4 91 * included in every data message.
alexandery 0:eb25b1785ee4 92 */
alexandery 0:eb25b1785ee4 93 uint16_t freq;
alexandery 0:eb25b1785ee4 94 };
alexandery 0:eb25b1785ee4 95
alexandery 0:eb25b1785ee4 96 size_t XbusMessage_format(uint8_t* raw, struct XbusMessage const* message);
alexandery 0:eb25b1785ee4 97 bool XbusMessage_getDataItem(void* item, enum XsDataIdentifier id, struct XbusMessage const* message);
alexandery 0:eb25b1785ee4 98 char const* XbusMessage_dataDescription(enum XsDataIdentifier id);
alexandery 0:eb25b1785ee4 99
alexandery 0:eb25b1785ee4 100 #ifdef __cplusplus
alexandery 0:eb25b1785ee4 101 }
alexandery 0:eb25b1785ee4 102 #endif // extern "C"
alexandery 0:eb25b1785ee4 103
alexandery 0:eb25b1785ee4 104 #endif // __XBUSMESSAGE_H