📄 cml__utils_8h-source.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>Copley Motion Library: CML_Utils.h Source File</title><link href="doxygen.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.4.4 --><div class="qindex"><a class="qindex" href="main.html">Main Page</a> | <a class="qindex" href="hierarchy.html">Class Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical List</a> | <a class="qindex" href="annotated.html">Class List</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="functions.html">Class Members</a> | <a class="qindex" href="globals.html">File Members</a></div><div class="nav"><a class="el" href="dir_000001.html">inc</a></div><h1>CML_Utils.h</h1><a href="CML__Utils_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/************************************************************/</span><a name="l00002"></a>00002 <span class="comment">/* */</span><a name="l00003"></a>00003 <span class="comment">/* Copley Motion Libraries */</span><a name="l00004"></a>00004 <span class="comment">/* */</span><a name="l00005"></a>00005 <span class="comment">/* Author: Stephen Glow */</span><a name="l00006"></a>00006 <span class="comment">/* */</span><a name="l00007"></a>00007 <span class="comment">/* Copyright (c) 2002-2005 Copley Controls Corp. */</span><a name="l00008"></a>00008 <span class="comment">/* http://www.copleycontrols.com */</span><a name="l00009"></a>00009 <span class="comment">/* */</span><a name="l00010"></a>00010 <span class="comment">/************************************************************/</span><a name="l00011"></a>00011 <span class="comment"></span><a name="l00012"></a>00012 <span class="comment">/** \file</span><a name="l00013"></a>00013 <span class="comment">This file holds various handy utility types and functions.</span><a name="l00014"></a>00014 <span class="comment">*/</span><a name="l00015"></a>00015 <a name="l00016"></a>00016 <span class="preprocessor">#ifndef _DEF_INC_UTILS</span><a name="l00017"></a>00017 <span class="preprocessor"></span><span class="preprocessor">#define _DEF_INC_UTILS</span><a name="l00018"></a>00018 <span class="preprocessor"></span><a name="l00019"></a>00019 <span class="preprocessor">#include <limits.h></span><a name="l00020"></a>00020 <span class="preprocessor">#include "<a class="code" href="CML__Settings_8h.html">CML_Settings.h</a>"</span><a name="l00021"></a>00021 <a name="l00022"></a>00022 <a class="code" href="CML__Settings_8h.html#a11">CML_NAMESPACE_START</a>()<a name="l00023"></a>00023 <a name="l00024"></a>00024 <span class="comment">/* handy types */</span><a name="l00025"></a><a class="code" href="CML__Utils_8h.html#a1">00025</a> typedef <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <a class="code" href="CML__Utils_8h.html#a1">uchar</a>; <span class="comment">///< unsigned character</span><a name="l00026"></a><a class="code" href="CML__Utils_8h.html#a2">00026</a> <span class="comment"></span>typedef <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <a class="code" href="CML__Utils_8h.html#a2">byte</a>; <span class="comment">///< unsigned character</span><a name="l00027"></a><a class="code" href="CML__Utils_8h.html#a3">00027</a> <span class="comment"></span>typedef <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="CML__Utils_8h.html#a3">uint</a>; <span class="comment">///< unsigned integer type</span><a name="l00028"></a><a class="code" href="CML__Utils_8h.html#a4">00028</a> <span class="comment"></span>typedef <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> <a class="code" href="CML__Utils_8h.html#a4">ulong</a>; <span class="comment">///< unsigned long type</span><a name="l00029"></a><a class="code" href="CML__Utils_8h.html#a5">00029</a> <span class="comment"></span>typedef <span class="keywordtype">signed</span> <span class="keywordtype">char</span> <a class="code" href="CML__Utils_8h.html#a5">int8</a>; <span class="comment">///< 8-bit integer type</span><a name="l00030"></a><a class="code" href="CML__Utils_8h.html#a6">00030</a> <span class="comment"></span>typedef <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <a class="code" href="CML__Utils_8h.html#a6">uint8</a>; <span class="comment">///< 8-bit unsigned integer type</span><a name="l00031"></a>00031 <span class="comment"></span><span class="comment"></span><a name="l00032"></a>00032 <span class="comment">/** \typedef int16</span><a name="l00033"></a>00033 <span class="comment">Signed 16-bit integer type. </span><a name="l00034"></a>00034 <span class="comment">Note that the actual definition of this type will depend </span><a name="l00035"></a>00035 <span class="comment">on the compiler being used. The standard C language header</span><a name="l00036"></a>00036 <span class="comment">file limits.h will be used to determine how to create </span><a name="l00037"></a>00037 <span class="comment">the type definition. </span><a name="l00038"></a>00038 <span class="comment">*/</span><a name="l00039"></a>00039 #if SHRT_MAX == 32767<a name="l00040"></a><a class="code" href="CML__Utils_8h.html#a7">00040</a> typedef <span class="keywordtype">short</span> <a class="code" href="CML__Utils_8h.html#a7">int16</a>;<a name="l00041"></a>00041 #elif INT_MAX == 32767<a name="l00042"></a>00042 typedef <span class="keywordtype">int</span> int16;<a name="l00043"></a>00043 #else<a name="l00044"></a>00044 # error "Unable to find a suitable 16-bit <span class="keywordtype">int</span> type!"<a name="l00045"></a>00045 #endif<a name="l00046"></a>00046 <span class="comment"></span><a name="l00047"></a>00047 <span class="comment">/** \typedef uint16</span><a name="l00048"></a>00048 <span class="comment">Unsigned 16-bit integer type. </span><a name="l00049"></a>00049 <span class="comment">Note that the actual definition of this type will depend </span><a name="l00050"></a>00050 <span class="comment">on the compiler being used. The standard C language header</span><a name="l00051"></a>00051 <span class="comment">file limits.h will be used to determine how to create </span><a name="l00052"></a>00052 <span class="comment">the type definition. </span><a name="l00053"></a>00053 <span class="comment">*/</span><a name="l00054"></a>00054 #if USHRT_MAX == 65535<a name="l00055"></a><a class="code" href="CML__Utils_8h.html#a8">00055</a> typedef <span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> <a class="code" href="CML__Utils_8h.html#a8">uint16</a>; <span class="comment">///< 16-bit unsigned integer type</span><a name="l00056"></a>00056 <span class="comment"></span>#elif UINT_MAX == 65535<a name="l00057"></a>00057 typedef <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> uint16; <span class="comment">///< 16-bit unsigned integer type</span><a name="l00058"></a>00058 <span class="comment"></span>#else<a name="l00059"></a>00059 # error "Unable to find a suitable 16-bit <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> type!"<a name="l00060"></a>00060 #endif<a name="l00061"></a>00061 <span class="comment"></span><a name="l00062"></a>00062 <span class="comment">/** \typedef int32</span><a name="l00063"></a>00063 <span class="comment">Signed 32-bit integer type. </span><a name="l00064"></a>00064 <span class="comment">Note that the actual definition of this type will depend </span><a name="l00065"></a>00065 <span class="comment">on the compiler being used. The standard C language header</span><a name="l00066"></a>00066 <span class="comment">file limits.h will be used to determine how to create </span><a name="l00067"></a>00067 <span class="comment">the type definition. </span><a name="l00068"></a>00068 <span class="comment">*/</span><a name="l00069"></a>00069 #if INT_MAX == 2147483647<a name="l00070"></a><a class="code" href="CML__Utils_8h.html#a9">00070</a> typedef <span class="keywordtype">int</span> <a class="code" href="CML__Utils_8h.html#a9">int32</a>;<a name="l00071"></a>00071 #elif LONG_MAX == 2147483647L<a name="l00072"></a>00072 typedef <span class="keywordtype">long</span> int32;<a name="l00073"></a>00073 #else<a name="l00074"></a>00074 # error "Unable to find a suitable 32-bit <span class="keywordtype">int</span> type!"<a name="l00075"></a>00075 #endif<a name="l00076"></a>00076 <span class="comment"></span><a name="l00077"></a>00077 <span class="comment">/** \typedef uint32</span><a name="l00078"></a>00078 <span class="comment">Unsigned 32-bit integer type. </span><a name="l00079"></a>00079 <span class="comment">Note that the actual definition of this type will depend </span><a name="l00080"></a>00080 <span class="comment">on the compiler being used. The standard C language header</span><a name="l00081"></a>00081 <span class="comment">file limits.h will be used to determine how to create </span><a name="l00082"></a>00082 <span class="comment">the type definition. </span><a name="l00083"></a>00083 <span class="comment">*/</span><a name="l00084"></a>00084 #if UINT_MAX == 4294967295U<a name="l00085"></a><a class="code" href="CML__Utils_8h.html#a10">00085</a> typedef <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="CML__Utils_8h.html#a10">uint32</a>;<a name="l00086"></a>00086 #elif ULONG_MAX == 4294967295UL<a name="l00087"></a>00087 typedef <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> uint32;<a name="l00088"></a>00088 #else<a name="l00089"></a>00089 # error "Unable to find a suitable 32-bit <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> type!"<a name="l00090"></a>00090 #endif<a name="l00091"></a>00091 <a name="l00092"></a>00092 <span class="comment">/***************************************************************************/</span><span class="comment"></span><a name="l00093"></a>00093 <span class="comment">/** \typedef uunit</span><a name="l00094"></a>00094 <span class="comment">User programmable unit. If user units are enabled in the CML_Settings.h file,</span><a name="l00095"></a>00095 <span class="comment">then this type will resolve to double precision floating point. If not, then</span><a name="l00096"></a>00096 <span class="comment">this type will resolve to a 32-bit integer.</span><a name="l00097"></a>00097 <span class="comment"></span><a name="l00098"></a>00098 <span class="comment">User units are used for all position, velocity, acceleration, and jerk values</span><a name="l00099"></a>00099 <span class="comment">passed to/from an Amp object.</span><a name="l00100"></a>00100 <span class="comment">*/</span><a name="l00101"></a>00101 <span class="comment">/***************************************************************************/</span><a name="l00102"></a>00102 #ifdef <a class="code" href="CML__Settings_8h.html#a4">CML_ENABLE_USER_UNITS</a><a name="l00103"></a><a class="code" href="CML__Utils_8h.html#a11">00103</a> typedef <span class="keywordtype">double</span> <a class="code" href="CML__Utils_8h.html#a11">uunit</a>;<a name="l00104"></a>00104 #else<a name="l00105"></a>00105 typedef int32 uunit;<a name="l00106"></a>00106 #endif<a name="l00107"></a>00107 <a name="l00108"></a>00108 <span class="comment">/***************************************************************************/</span><span class="comment"></span><a name="l00109"></a>00109 <span class="comment">/** \def ByteCast</span><a name="l00110"></a>00110 <span class="comment">The ByteCast() macro is used to cast a value to a byte type (unsigned char).</span><a name="l00111"></a>00111 <span class="comment">The reason that a macro is used rather then a simple cast is that some </span><a name="l00112"></a>00112 <span class="comment">processors have characters that are more then 8 bits long. This is particularly</span><a name="l00113"></a>00113 <span class="comment">common with 16-bit or 32-bit microcontrollers and DSPs. On such systems the</span><a name="l00114"></a>00114 <span class="comment">ByteCast macro will strip off any upper bits and then cast the result to a byte.</span><a name="l00115"></a>00115 <span class="comment">On systems with 8-bit bytes the ByteCast macro simply casts the passed value to</span><a name="l00116"></a>00116 <span class="comment">a byte.</span><a name="l00117"></a>00117 <span class="comment"> */</span><a name="l00118"></a>00118 <span class="comment">/***************************************************************************/</span><a name="l00119"></a>00119 #if CHAR_BIT > 8<a name="l00120"></a>00120 #define <a class="code" href="CML__Utils_8h.html#a0">ByteCast</a>(x) ((byte)((x) & 0x00FF))<a name="l00121"></a>00121 #else<a name="l00122"></a><a class="code" href="CML__Utils_8h.html#a0">00122</a> #define <a class="code" href="CML__Utils_8h.html#a0">ByteCast</a>(x) ((byte)(x))<a name="l00123"></a>00123 #endif<a name="l00124"></a>00124 <a name="l00125"></a>00125 uint32 bytes_to_uint32( byte *b );<a name="l00126"></a>00126 uint16 bytes_to_uint16( byte *b );<a name="l00127"></a>00127 int32 bytes_to_int32( byte *b );<a name="l00128"></a>00128 int16 bytes_to_int16( byte *b );<a name="l00129"></a>00129 <a name="l00130"></a>00130 <a class="code" href="CML__Settings_8h.html#a12">CML_NAMESPACE_END</a>()<a name="l00131"></a>00131 <a name="l00132"></a>00132 #endif<a name="l00133"></a>00133 </pre></div><hr><address style="align: right;"><small>Copley Motion Library, Copyright (c) 2002-2003<a href="http://www.copleycontrols.com"><img src="CCC_logo.gif" alt="Copley Controls Corp." align="middle" border=0 ></a></small></address></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -