amtec_conversion.c
Go to the documentation of this file.
00001 /*********************************************************************
00002  *
00003  * Software License Agreement (BSD License)
00004  *
00005  *  Copyright (c) 2008, Robert Bosch LLC.
00006  *  All rights reserved.
00007  *
00008  *  Redistribution and use in source and binary forms, with or without
00009  *  modification, are permitted provided that the following conditions
00010  *  are met:
00011  *
00012  *   * Redistributions of source code must retain the above copyright
00013  *     notice, this list of conditions and the following disclaimer.
00014  *   * Redistributions in binary form must reproduce the above
00015  *     copyright notice, this list of conditions and the following
00016  *     disclaimer in the documentation and/or other materials provided
00017  *     with the distribution.
00018  *   * Neither the name of the Robert Bosch nor the names of its
00019  *     contributors may be used to endorse or promote products derived
00020  *     from this software without specific prior written permission.
00021  *
00022  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00025  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00026  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00027  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00028  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00029  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00030  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00032  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00033  *  POSSIBILITY OF SUCH DAMAGE.
00034  *
00035  *********************************************************************/
00036 
00037 #include "amtec_conversion.h"
00038 
00039 int ParamBytes(int type)
00040 {
00041   switch(type) {
00042   case INT8:
00043     return(1);
00044     break;
00045   case UINT8:
00046     return(1);
00047     break;
00048   case INT16:
00049     return(2);
00050     break;
00051   case UINT16:
00052     return(2);
00053     break;
00054   case INT32:
00055     return(4);
00056     break;
00057   case UINT32:
00058     return(4);
00059     break;
00060   case FLOAT:
00061     return(4);
00062     break;
00063   }
00064   return(0);
00065 }
00066 
00067 /* CONVERSION BYTES -> NUM */
00068 
00069 char convertBytes2Int8(unsigned char *bytes)
00070 {
00071   char i;
00072   memcpy(&i, bytes, sizeof(char));
00073   return(i);
00074 }
00075 
00076 unsigned char convertBytes2UInt8(unsigned char *bytes)
00077 {
00078   unsigned char i;
00079   memcpy(&i, bytes, sizeof(unsigned char));
00080   return(i);
00081 }
00082 
00083 short convertBytes2Int16(unsigned char *bytes)
00084 {
00085   short i;
00086   memcpy(&i, bytes, sizeof(short));
00087   return(i);
00088 }
00089 
00090 unsigned short convertBytes2UInt16(unsigned char *bytes)
00091 {
00092   unsigned short i;
00093   memcpy(&i, bytes, sizeof(unsigned short));
00094   return(i);
00095 }
00096 
00097 int convertBytes2Int32(unsigned char *bytes)
00098 {
00099   int i;
00100   memcpy(&i, bytes, sizeof(int));
00101   return(i);
00102 }
00103 
00104 unsigned int convertBytes2UInt32(unsigned char *bytes)
00105 {
00106   unsigned int i;
00107   memcpy(&i, bytes, sizeof(unsigned int));
00108   return(i);
00109 }
00110 
00111 float convertBytes2Float(unsigned char *bytes)
00112 {
00113   float f;
00114   memcpy(&f, bytes, sizeof(float));
00115   return(f);
00116 }
00117 
00118 /* CONVERSION NUM -> BYTES */
00119 
00120 void convertInt8(char i, unsigned char *bytes)
00121 {
00122   memcpy(bytes, &i, sizeof(char));
00123 }
00124 
00125 void convertUInt8(unsigned char i, unsigned char *bytes)
00126 {
00127   memcpy(bytes, &i, sizeof(unsigned char));
00128 }
00129 
00130 void convertInt16(short i, unsigned char *bytes)
00131 {
00132   memcpy(bytes, &i, sizeof(short));
00133 }
00134 
00135 void convertUInt16(unsigned short i, unsigned char *bytes)
00136 {
00137   memcpy(bytes, &i, sizeof(unsigned short));
00138 }
00139 
00140 void convertInt32(int i, unsigned char *bytes)
00141 {
00142   memcpy(bytes, &i, sizeof(int));
00143 }
00144 
00145 void convertUInt32(unsigned int i, unsigned char *bytes)
00146 {
00147   memcpy(bytes, &i, sizeof(unsigned int));
00148 }
00149 
00150 void convertFloat(float f, unsigned char *bytes)
00151 {
00152   memcpy(bytes, &f, sizeof(float));
00153 }


amtec
Author(s): Charles DuHadway, Benjamin Pitzer (Maintained by Benjamin Pitzer)
autogenerated on Mon Oct 6 2014 10:10:36