ReadWriteHelper.cpp
Go to the documentation of this file.
00001 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
00002 
00003 // -- BEGIN LICENSE BLOCK ----------------------------------------------
00004 
00024 // -- END LICENSE BLOCK ------------------------------------------------
00025 
00026 //----------------------------------------------------------------------
00033 //----------------------------------------------------------------------
00034 
00035 #include <sick_safetyscanners/data_processing/ReadWriteHelper.h>
00036 
00037 namespace sick {
00038 namespace data_processing {
00039 
00040 ReadWriteHelper::ReadWriteHelper() {}
00041 
00042 //*************
00043 // UINT 8
00044 
00045 uint8_t ReadWriteHelper::readuint8_t(const uint8_t*& buf, const uint16_t offset) const
00046 {
00047   uint8_t value = buf[offset];
00048   return value;
00049 }
00050 
00051 uint8_t ReadWriteHelper::readuint8_tLittleEndian(const uint8_t*& buf, const uint16_t offset) const
00052 {
00053   return readuint8_t(buf, offset);
00054 }
00055 
00056 uint8_t ReadWriteHelper::readuint8_tBigEndian(const uint8_t*& buf, const uint16_t offset) const
00057 {
00058   return readuint8_t(buf, offset);
00059 }
00060 
00061 void ReadWriteHelper::writeuint8_t(uint8_t*& buf, const uint8_t v, const uint16_t offset) const
00062 {
00063   buf[offset] = v;
00064 }
00065 
00066 void ReadWriteHelper::writeuint8_tBigEndian(uint8_t*& buf,
00067                                             const uint8_t v,
00068                                             const uint16_t offset) const
00069 {
00070   writeuint8_t(buf, v, offset);
00071 }
00072 
00073 void ReadWriteHelper::writeuint8_tLittleEndian(uint8_t*& buf,
00074                                                const uint8_t v,
00075                                                const uint16_t offset) const
00076 {
00077   writeuint8_t(buf, v, offset);
00078 }
00079 
00080 
00081 //*******
00082 // int8_t
00083 
00084 int8_t ReadWriteHelper::readint8_t(const uint8_t*& buffer, const uint16_t offset) const
00085 {
00086   return readuint8_t(buffer, offset);
00087 }
00088 
00089 
00090 int8_t ReadWriteHelper::readint8_tLittleEndian(const uint8_t*& buf, const uint16_t offset) const
00091 {
00092   return readint8_t(buf, offset);
00093 }
00094 
00095 int8_t ReadWriteHelper::readint8_tBigEndian(const uint8_t*& buf, const uint16_t offset) const
00096 {
00097   return readint8_t(buf, offset);
00098 }
00099 
00100 void ReadWriteHelper::writeint8_t(uint8_t*& buf, const uint8_t v, const uint16_t offset) const
00101 {
00102   writeuint8_t(buf, v, offset);
00103 }
00104 
00105 void ReadWriteHelper::writeint8_tBigEndian(uint8_t*& buf,
00106                                            const uint8_t v,
00107                                            const uint16_t offset) const
00108 {
00109   writeint8_t(buf, v, offset);
00110 }
00111 
00112 void ReadWriteHelper::writeint8_tLittleEndian(uint8_t*& buf,
00113                                               const uint8_t v,
00114                                               const uint16_t offset) const
00115 {
00116   writeint8_t(buf, v, offset);
00117 }
00118 
00119 //*******
00120 //  uint16_t
00121 
00122 uint16_t ReadWriteHelper::readuint16_tLittleEndian(const uint8_t*& buf, const uint16_t offset) const
00123 {
00124   return (buf[offset + 1] << 8) + buf[offset];
00125 }
00126 
00127 uint16_t ReadWriteHelper::readuint16_tBigEndian(const uint8_t*& buf, const uint16_t offset) const
00128 {
00129   return (buf[offset] << 8) + buf[offset + 1];
00130 }
00131 
00132 void ReadWriteHelper::writeuint16_tBigEndian(uint8_t*& buf,
00133                                              const uint16_t v,
00134                                              const uint16_t offset) const
00135 {
00136   buf[offset]     = (v & 0xff00) >> 8;
00137   buf[offset + 1] = v & 0xff;
00138 }
00139 
00140 void ReadWriteHelper::writeuint16_tLittleEndian(uint8_t*& buf,
00141                                                 const uint16_t v,
00142                                                 const uint16_t offset) const
00143 {
00144   buf[offset + 1] = (v & 0xff00) >> 8;
00145   buf[offset]     = v & 0xff;
00146 }
00147 
00148 //*******
00149 // int16_t
00150 
00151 int16_t ReadWriteHelper::readint16_tLittleEndian(const uint8_t*& buf, const uint16_t offset) const
00152 {
00153   return readuint16_tLittleEndian(buf, offset);
00154 }
00155 
00156 int16_t ReadWriteHelper::readint16_tBigEndian(const uint8_t*& buf, const uint16_t offset) const
00157 {
00158   return readuint16_tBigEndian(buf, offset);
00159 }
00160 
00161 
00162 //*******
00163 // uint32_t
00164 
00165 
00166 uint32_t ReadWriteHelper::readuint32_tLittleEndian(const uint8_t*& buf, const uint16_t offset) const
00167 {
00168   return (buf[offset + 3] << 24) + (buf[offset + 2] << 16) + (buf[offset + 1] << 8) + buf[offset];
00169 }
00170 
00171 uint32_t ReadWriteHelper::readuint32_tBigEndian(const uint8_t*& buf, const uint16_t offset) const
00172 {
00173   return (buf[offset] << 24) + (buf[offset + 1] << 16) + (buf[offset + 2] << 8) + buf[offset + 3];
00174 }
00175 
00176 void ReadWriteHelper::writeuint32_tLittleEndian(uint8_t*& buf,
00177                                                 const uint32_t v,
00178                                                 const uint16_t offset) const
00179 {
00180   buf[offset + 3] = (v & 0xff000000) >> 24;
00181   buf[offset + 2] = (v & 0xff0000) >> 16;
00182   buf[offset + 1] = (v & 0xff00) >> 8;
00183   buf[offset]     = v & 0xff;
00184 }
00185 
00186 void ReadWriteHelper::writeuint32_tBigEndian(uint8_t*& buf,
00187                                              const uint32_t v,
00188                                              const uint16_t offset) const
00189 {
00190   buf[offset]     = (v & 0xff000000) >> 24;
00191   buf[offset + 1] = (v & 0xff0000) >> 16;
00192   buf[offset + 2] = (v & 0xff00) >> 8;
00193   buf[offset + 3] = v & 0xff;
00194 }
00195 
00196 
00197 //*******
00198 // int32_t
00199 
00200 int32_t ReadWriteHelper::readint32_tLittleEndian(const uint8_t*& buf, const uint16_t offset) const
00201 {
00202   return readuint32_tLittleEndian(buf, offset);
00203 }
00204 
00205 int32_t ReadWriteHelper::readint32_tBigEndian(const uint8_t*& buf, const uint16_t offset) const
00206 {
00207   return readuint32_tBigEndian(buf, offset);
00208 }
00209 
00210 
00211 } // namespace data_processing
00212 } // namespace sick


sick_safetyscanners
Author(s): Lennart Puck
autogenerated on Tue May 7 2019 03:27:36