00001 /*! 00002 * \file SickLMSUtility.hh 00003 * \brief Defines simple utility functions for working with the 00004 * Sick LMS 2xx laser range finder units. 00005 * 00006 * Code by Jason C. Derenick and Thomas H. Miller. 00007 * Contact derenick(at)lehigh(dot)edu 00008 * 00009 * The Sick LIDAR Matlab/C++ Toolbox 00010 * Copyright (c) 2008, Jason C. Derenick and Thomas H. Miller 00011 * All rights reserved. 00012 * 00013 * This software is released under a BSD Open-Source License. 00014 * See http://sicktoolbox.sourceforge.net 00015 */ 00016 00017 /* Auto-generated header */ 00018 #include "SickConfig.hh" 00019 00020 /** 00021 * \def REVERSE_BYTE_ORDER_16 00022 * \brief Reverses the byte order of the given 16 bit unsigned integer 00023 */ 00024 #define REVERSE_BYTE_ORDER_16( y ) ( ( ( y & 0x00FF ) << 8 ) | ( ( y & 0xFF00 ) >> 8 ) ) 00025 00026 /** 00027 * \def REVERSE_BYTE_ORDER_32 00028 * \brief Reverses the byte order of the given 32 bit unsigned integer 00029 */ 00030 #define REVERSE_BYTE_ORDER_32( y ) ( ( ( y & 0x000000FF ) << 24 ) | ( ( y & 0x0000FF00 ) << 8 ) | ( ( y & 0x00FF0000 ) >> 8 ) | ( ( y & 0xFF000000 ) >> 24 ) ) 00031 00032 /* Associate the namespace */ 00033 namespace SickToolbox { 00034 00035 #ifndef WORDS_BIGENDIAN 00036 00037 /* NOTE: The following functions are necessary since the Sick LD doesn't adopt the 00038 * convention of converting from network byte order. 00039 */ 00040 00041 /** 00042 * \brief Converts host byte order (little-endian) to Sick LMS byte order (little-endian) 00043 * \param value The 2-byte value to convert to little-endian 00044 * \return Value in Sick LMS byte order (little-endian) 00045 */ 00046 inline uint16_t host_to_sick_lms_byte_order( uint16_t value ) { 00047 return value; 00048 } 00049 00050 /** 00051 * \brief Converts host byte order (little-endian) to Sick LMS byte order (little-endian) 00052 * \param value The 4-byte value to convert to little-endian 00053 * \return Value in Sick LMS byte order (little-endian) 00054 */ 00055 inline uint32_t host_to_sick_lms_byte_order( uint32_t value ) { 00056 return value; 00057 } 00058 00059 /** 00060 * \brief Converts Sick LMS byte order (little-endian) to host byte order (little-endian) 00061 * \param value The 2-byte value to convert to little-endian 00062 * \return Value in host byte order (little-endian) 00063 */ 00064 inline uint16_t sick_lms_to_host_byte_order( uint16_t value ) { 00065 return value; 00066 } 00067 00068 /** 00069 * \brief Converts Sick LMS byte order (little-endian) to host byte order (little-endian) 00070 * \param value The 4-byte value to convert to little-endian 00071 * \return Value in host byte order (little-endian) 00072 */ 00073 inline uint32_t sick_lms_to_host_byte_order( uint32_t value ) { 00074 return value; 00075 } 00076 00077 #else // The host has a big-endian architecture 00078 00079 /** 00080 * \brief Converts host byte order (big-endian) to Sick LMS byte order (little-endian) 00081 * \param value The 2-byte value to convert to little-endian 00082 * \return Value in Sick LMS byte order (little-endian) 00083 */ 00084 inline uint16_t host_to_sick_lms_byte_order( uint16_t value ) { 00085 return REVERSE_BYTE_ORDER_16(value); 00086 } 00087 00088 /** 00089 * \brief Converts host byte order (big-endian) to Sick LMS byte order (little-endian) 00090 * \param value The 4-byte value to convertto little-endian 00091 * \return Value in Sick LMS byte order (little-endian) 00092 */ 00093 inline uint32_t host_to_sick_lms_byte_order( uint32_t value ) { 00094 return REVERSE_BYTE_ORDER_32(value); 00095 } 00096 00097 /** 00098 * \brief Converts Sick LMS byte order (little-endian) to host byte order (big-endian) 00099 * \param value The 2-byte value to convert to big-endian 00100 * \return Value in host byte order (big-endian) 00101 */ 00102 inline uint16_t sick_lms_to_host_byte_order( uint16_t value ) { 00103 return REVERSE_BYTE_ORDER_16(value); 00104 } 00105 00106 /** 00107 * \brief Converts Sick LMS byte order (little-endian) to host byte order (big-endian) 00108 * \param value The 4-byte value to convert to big-endian 00109 * \return Value in host byte order (big-endian) 00110 */ 00111 inline uint32_t sick_lms_to_host_byte_order( uint32_t value ) { 00112 return REVERSE_BYTE_ORDER_32(value); 00113 } 00114 00115 #endif /* _LITTLE_ENDIAN_HOST */ 00116 00117 /* 00118 * NOTE: Other utility functions can be defined here 00119 */ 00120 00121 } //namespace SickToolbox