David Khosravi / Mbed 2 deprecated MTi-1_example_LPC1768

Dependencies:   mbed-rtos mbed Xbus

Fork of MTi-1_example by Xsens

Committer:
Alex Young
Date:
Wed May 20 16:46:14 2015 +0200
Revision:
27:eebe5fc884e3
Parent:
18:2073072bad51
Child:
45:67203918bec9
Add functions for writing stdints to xbus message

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Alex Young 18:2073072bad51 1 /*!
Alex Young 18:2073072bad51 2 * \file
Alex Young 18:2073072bad51 3 * \copyright
Alex Young 18:2073072bad51 4 * Copyright (C) Xsens Technologies B.V., 2015. All rights reserved.
Alex Young 18:2073072bad51 5 *
Alex Young 18:2073072bad51 6 * This source code is intended for use only by Xsens Technologies BV and
Alex Young 18:2073072bad51 7 * those that have explicit written permission to use it from
Alex Young 18:2073072bad51 8 * Xsens Technologies BV.
Alex Young 18:2073072bad51 9 *
Alex Young 18:2073072bad51 10 * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
Alex Young 18:2073072bad51 11 * KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
Alex Young 18:2073072bad51 12 * IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
Alex Young 18:2073072bad51 13 * PARTICULAR PURPOSE.
Alex Young 18:2073072bad51 14 */
Alex Young 18:2073072bad51 15
Alex Young 18:2073072bad51 16 #include "xbusutility.h"
Alex Young 18:2073072bad51 17
Alex Young 18:2073072bad51 18 uint8_t const* XbusUtility_readU8(uint8_t* out, uint8_t const* in)
Alex Young 18:2073072bad51 19 {
Alex Young 18:2073072bad51 20 *out = *in;
Alex Young 18:2073072bad51 21 return ++in;
Alex Young 18:2073072bad51 22 }
Alex Young 18:2073072bad51 23
Alex Young 18:2073072bad51 24 uint8_t const* XbusUtility_readU16(uint16_t* out, uint8_t const* in)
Alex Young 18:2073072bad51 25 {
Alex Young 18:2073072bad51 26 *out = (in[0] << 8) | in[1];
Alex Young 18:2073072bad51 27 return in + sizeof(uint16_t);
Alex Young 18:2073072bad51 28 }
Alex Young 18:2073072bad51 29
Alex Young 18:2073072bad51 30 uint8_t const* XbusUtility_readU32(uint32_t* out, uint8_t const* in)
Alex Young 18:2073072bad51 31 {
Alex Young 18:2073072bad51 32 *out = (in[0] << 24) | (in[1] << 16) | (in[2] << 8) | in[3];
Alex Young 18:2073072bad51 33 return in + sizeof(uint32_t);
Alex Young 18:2073072bad51 34 }
Alex Young 27:eebe5fc884e3 35
Alex Young 27:eebe5fc884e3 36 uint8_t* XbusUtility_writeU8(uint8_t* out, uint8_t in)
Alex Young 27:eebe5fc884e3 37 {
Alex Young 27:eebe5fc884e3 38 *out++ = in;
Alex Young 27:eebe5fc884e3 39 return out;
Alex Young 27:eebe5fc884e3 40 }
Alex Young 27:eebe5fc884e3 41
Alex Young 27:eebe5fc884e3 42 uint8_t* XbusUtility_writeU16(uint8_t* out, uint16_t in)
Alex Young 27:eebe5fc884e3 43 {
Alex Young 27:eebe5fc884e3 44 *out++ = (in >> 8) & 0xFF;
Alex Young 27:eebe5fc884e3 45 *out++ = in & 0xFF;
Alex Young 27:eebe5fc884e3 46 return out;
Alex Young 27:eebe5fc884e3 47 }
Alex Young 27:eebe5fc884e3 48
Alex Young 27:eebe5fc884e3 49 uint8_t* XbusUtility_writeU32(uint8_t* out, uint32_t in)
Alex Young 27:eebe5fc884e3 50 {
Alex Young 27:eebe5fc884e3 51
Alex Young 27:eebe5fc884e3 52 *out++ = (in >> 24) & 0xFF;
Alex Young 27:eebe5fc884e3 53 *out++ = (in >> 16) & 0xFF;
Alex Young 27:eebe5fc884e3 54 *out++ = (in >> 8) & 0xFF;
Alex Young 27:eebe5fc884e3 55 *out++ = in & 0xFF;
Alex Young 27:eebe5fc884e3 56 return out;
Alex Young 27:eebe5fc884e3 57 }