rikbeuncode

Dependencies:   mbed-rtos mbed Xbus

Fork of MTi-1_example by Xsens

Files at this revision

API Documentation at this revision

Comitter:
Alex Young
Date:
Thu May 21 14:36:52 2015 +0200
Parent:
39:9014c5236864
Child:
41:504b6821a96f
Commit message:
Add utility module for processing device ids

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
xbus/xsdeviceid.c Show annotated file Show diff for this revision Revisions of this file
xbus/xsdeviceid.h Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Thu May 21 13:10:39 2015 +0200
+++ b/main.cpp	Thu May 21 14:36:52 2015 +0200
@@ -17,6 +17,7 @@
 #include "rtos.h"
 #include "xbusparser.h"
 #include "xbusmessage.h"
+#include "xsdeviceid.h"
 
 #define MEMORY_POOL_SIZE (4)
 #define RESPONSE_QUEUE_SIZE (1)
@@ -247,10 +248,17 @@
 
 	if (deviceId)
 	{
-		uint8_t deviceType = (deviceId >> 24) & 0x0F;
-		pc.printf("Found MTi-%d\n", deviceType);
+		pc.printf("Found device with ID: %08X.\n", deviceId);
+		if (!XsDeviceId_isMtMk4_X(deviceId))
+		{
+			pc.printf("Device is not an MTi-1 series.\n");
+			return false;
+		}
 
-		if (deviceType == 1)
+		DeviceFunction function = XsDeviceId_getFunction(deviceId);
+		pc.printf("Device is an MTi-%d: %s.\n", function, XsDeviceId_functionDescription(function));
+
+		if (function == DF_IMU)
 		{
 			OutputConfiguration conf[] = {
 				{XDI_PacketCounter, 65535},
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/xbus/xsdeviceid.c	Thu May 21 14:36:52 2015 +0200
@@ -0,0 +1,46 @@
+/*!
+ * \file
+ * \copyright
+ * Copyright (C) Xsens Technologies B.V., 2015.  All rights reserved.
+ *
+ * This source code is intended for use only by Xsens Technologies BV and
+ * those that have explicit written permission to use it from
+ * Xsens Technologies BV.
+ *
+ * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
+ * KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
+ * PARTICULAR PURPOSE.
+ */
+
+#include "xsdeviceid.h"
+
+/*!
+ * \brief Return true if device ID corresponds to a MTi-1 series device.
+ */
+bool XsDeviceId_isMtMk4_X(uint32_t deviceId)
+{
+	uint8_t deviceSeries = (deviceId >> 20) & 0xF;
+	return ((deviceSeries == 0x8) || (deviceSeries == 0xC));
+}
+
+/*!
+ * \brief Get a string describing the function of the MTi device.
+ */
+char const* XsDeviceId_functionDescription(enum DeviceFunction function)
+{
+	switch (function)
+	{
+		case DF_IMU:
+			return "Inertial Measurement Unit";
+
+		case DF_VRU:
+			return "Vertical Reference Unit";
+
+		case DF_AHRS:
+			return "Attitude Heading Reference System";
+	}
+
+	return "Unknown device function";
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/xbus/xsdeviceid.h	Thu May 21 14:36:52 2015 +0200
@@ -0,0 +1,52 @@
+/*!
+ * \file
+ * \copyright
+ * Copyright (C) Xsens Technologies B.V., 2015.  All rights reserved.
+ *
+ * This source code is intended for use only by Xsens Technologies BV and
+ * those that have explicit written permission to use it from
+ * Xsens Technologies BV.
+ *
+ * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
+ * KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
+ * PARTICULAR PURPOSE.
+ */
+
+#ifndef __XSDEVICEID_H
+#define __XSDEVICEID_H
+
+#include <stdint.h>
+#include <stdbool.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+bool XsDeviceId_isMtMk4_X(uint32_t deviceId);
+
+enum DeviceFunction
+{
+	/*! \brief Inertial Measurement Unit. */
+	DF_IMU  = 1,
+	/*! \brief Vertical Reference Unit. */
+	DF_VRU  = 2,
+	/*! \brief Attitude Heading Reference System. */
+	DF_AHRS = 3
+};
+
+/*!
+ * \brief Get the function of the MTi device.
+ */
+static inline enum DeviceFunction XsDeviceId_getFunction(uint32_t deviceId)
+{
+	return (enum DeviceFunction)((deviceId >> 24) & 0xF);
+}
+
+char const* XsDeviceId_functionDescription(enum DeviceFunction function);
+
+#ifdef __cplusplus
+}
+#endif // extern "C"
+
+#endif // __XSDEVICEID_H