Program Listing for File colab.hpp
↰ Return to documentation for file (include/sick_scan/tcp/colab.hpp
)
#include "sick_scan/sick_scan_base.h" /* Base definitions included in all header files, added by add_sick_scan_base_header.py. Do not edit this line. */
//
// colab.hpp
//
// (c) 2011 SICK AG, Hamburg, Germany
//
#ifndef COLAB_HPP
#define COLAB_HPP
#include "sick_scan/tcp/BasicDatatypes.hpp"
#include <memory.h> // for memread<>
//
// Parser functions for a partly implementation of the CoLa-B
// protocol, needed for communication with SICK sensors.
//
namespace colab
{
void addStringToBuffer(UINT8* buffer, UINT16& pos, const std::string& stringValue);
void addStringToBuffer(BYTE* buffer, const std::string& stringValue);
std::string getStringFromBuffer(UINT8* buffer, UINT16& pos, UINT16 length);
std::string getStringFromBuffer(BYTE*& buffer, UINT16 length);
std::string getCommandStringFromBuffer(UINT8* buffer);
std::string getIdentifierFromBuffer(UINT8* buffer, UINT16& nextData, UINT16 bufferLength);
void addFrameToBuffer(UINT8* sendBuffer, UINT8* cmdBuffer, UINT16* len);
// Returns the requested value. pos points then to the first byte of the next data field.
double getDoubleFromBuffer(UINT8* buffer, UINT16& pos);
//
UINT16 decodeUINT16(BYTE* buffer);
// -----------------------------------------------------------------------------------------------------------------
// TEMPLATE FUNCTIONS
// -----------------------------------------------------------------------------------------------------------------
// FIXME: use template functions from types.hpp instead !!! (memread/memwrite)
template<typename T>
void addIntegerToBuffer(UINT8* buffer, UINT16& pos, T intValue)
{
UINT16 width = sizeof(T);
for (int i = 0; i < width; i++)
{
buffer[pos+width-1-i] = (intValue >> (8 * i)) & 0xff; // BIG ENDIAN: width-1-i
}
pos += width;
}
template<typename T>
T getIntegerFromBuffer(UINT8* buffer, UINT16& pos)
{
UINT16 width = sizeof(T);
// UINT8* buffer2 = buffer;
// T intValue = memread<T>(buffer2);
T intValue = 0;
for (int i = 0; i < width; i++)
{
intValue += buffer[pos+width-1-i] << (8 * i);
}
pos += width;
return intValue;
}
template<typename T>
void addFloatToBuffer(UINT8* buffer, UINT16& pos, T floatValue)
{
UINT16 width = sizeof(T);
pos += width;
}
} // END namespace colab
#endif