colab.hpp
Go to the documentation of this file.
00001 //
00002 // colab.hpp
00003 //
00004 // (c) 2011 SICK AG, Hamburg, Germany
00005 //
00006 
00007 #ifndef COLAB_HPP
00008 #define COLAB_HPP
00009 
00010 #include "sick_scan/tcp/BasicDatatypes.hpp"
00011 #include <memory.h>     // for memread<>
00012 
00013 //
00014 // Parser functions for a partly implementation of the CoLa-B
00015 // protocol, needed for communication with SICK sensors.
00016 //
00017 namespace colab
00018 {
00019 
00028 void addStringToBuffer(UINT8* buffer, UINT16& pos, const std::string& stringValue);
00029 
00030 
00035 void addStringToBuffer(BYTE* buffer, const std::string& stringValue);
00036 
00037 
00038 
00043 std::string getStringFromBuffer(UINT8* buffer, UINT16& pos, UINT16 length);
00044 
00045 
00046 
00051 std::string getStringFromBuffer(BYTE*& buffer, UINT16 length);
00052 
00053 
00054 
00058 std::string getCommandStringFromBuffer(UINT8* buffer);
00059 
00060 
00061 
00062 
00071 std::string getIdentifierFromBuffer(UINT8* buffer, UINT16& nextData, UINT16 bufferLength);
00072 
00073 
00074 
00078 void addFrameToBuffer(UINT8* sendBuffer, UINT8* cmdBuffer, UINT16* len);
00079 
00080 
00081 //  Returns the requested value. pos points then to the first byte of the next data field.
00082 double getDoubleFromBuffer(UINT8* buffer, UINT16& pos);
00083 
00084 //
00085 UINT16 decodeUINT16(BYTE* buffer);
00086 
00087 
00088 
00089 // -----------------------------------------------------------------------------------------------------------------
00090 //                                               TEMPLATE FUNCTIONS
00091 // -----------------------------------------------------------------------------------------------------------------
00092 
00093 
00094 // FIXME: use template functions from types.hpp instead !!! (memread/memwrite)
00095 
00103 template<typename T>
00104 void addIntegerToBuffer(UINT8* buffer, UINT16& pos, T intValue)
00105 {
00106         UINT16 width = sizeof(T);
00107 
00108         for (int i = 0; i < width; i++)
00109         {
00110                 buffer[pos+width-1-i] = (intValue >> (8 * i)) & 0xff; // BIG ENDIAN: width-1-i
00111         }
00112 
00113         pos += width;
00114 }
00115 
00116 
00117 
00123 template<typename T>
00124 T getIntegerFromBuffer(UINT8* buffer, UINT16& pos)
00125 {
00126         UINT16 width = sizeof(T);
00127 //              UINT8* buffer2 = buffer;
00128 //              T intValue = memread<T>(buffer2);
00129 
00130         T intValue = 0;
00131 
00132         for (int i = 0; i < width; i++)
00133         {
00134                 intValue += buffer[pos+width-1-i] << (8 * i);
00135         }
00136 
00137         pos += width;
00138         return intValue;
00139 }
00140 
00141 
00142 
00151 template<typename T>
00152 void addFloatToBuffer(UINT8* buffer, UINT16& pos, T floatValue)
00153 {
00154         UINT16 width = sizeof(T);
00155 
00156 
00157 
00158         pos += width;
00159 }
00160 
00161 
00162 } // END namespace colab
00163 #endif


sick_scan
Author(s): Michael Lehning , Jochen Sprickerhof , Martin Günther
autogenerated on Tue Jul 9 2019 05:05:34