colab.hpp
Go to the documentation of this file.
1 //
2 // colab.hpp
3 //
4 // (c) 2011 SICK AG, Hamburg, Germany
5 //
6 
7 #ifndef COLAB_HPP
8 #define COLAB_HPP
9 
11 #include <memory.h> // for memread<>
12 
13 //
14 // Parser functions for a partly implementation of the CoLa-B
15 // protocol, needed for communication with SICK sensors.
16 //
17 namespace colab
18 {
19 
28 void addStringToBuffer(UINT8* buffer, UINT16& pos, const std::string& stringValue);
29 
30 
35 void addStringToBuffer(BYTE* buffer, const std::string& stringValue);
36 
37 
38 
43 std::string getStringFromBuffer(UINT8* buffer, UINT16& pos, UINT16 length);
44 
45 
46 
51 std::string getStringFromBuffer(BYTE*& buffer, UINT16 length);
52 
53 
54 
58 std::string getCommandStringFromBuffer(UINT8* buffer);
59 
60 
61 
62 
71 std::string getIdentifierFromBuffer(UINT8* buffer, UINT16& nextData, UINT16 bufferLength);
72 
73 
74 
78 void addFrameToBuffer(UINT8* sendBuffer, UINT8* cmdBuffer, UINT16* len);
79 
80 
81 // Returns the requested value. pos points then to the first byte of the next data field.
82 double getDoubleFromBuffer(UINT8* buffer, UINT16& pos);
83 
84 //
85 UINT16 decodeUINT16(BYTE* buffer);
86 
87 
88 
89 // -----------------------------------------------------------------------------------------------------------------
90 // TEMPLATE FUNCTIONS
91 // -----------------------------------------------------------------------------------------------------------------
92 
93 
94 // FIXME: use template functions from types.hpp instead !!! (memread/memwrite)
95 
103 template<typename T>
104 void addIntegerToBuffer(UINT8* buffer, UINT16& pos, T intValue)
105 {
106  UINT16 width = sizeof(T);
107 
108  for (int i = 0; i < width; i++)
109  {
110  buffer[pos+width-1-i] = (intValue >> (8 * i)) & 0xff; // BIG ENDIAN: width-1-i
111  }
112 
113  pos += width;
114 }
115 
116 
117 
123 template<typename T>
125 {
126  UINT16 width = sizeof(T);
127 // UINT8* buffer2 = buffer;
128 // T intValue = memread<T>(buffer2);
129 
130  T intValue = 0;
131 
132  for (int i = 0; i < width; i++)
133  {
134  intValue += buffer[pos+width-1-i] << (8 * i);
135  }
136 
137  pos += width;
138  return intValue;
139 }
140 
141 
142 
151 template<typename T>
152 void addFloatToBuffer(UINT8* buffer, UINT16& pos, T floatValue)
153 {
154  UINT16 width = sizeof(T);
155 
156 
157 
158  pos += width;
159 }
160 
161 
162 } // END namespace colab
163 #endif
unsigned char BYTE
uint16_t UINT16
UINT16 decodeUINT16(BYTE *buffer)
Definition: colab.cpp:142
void addIntegerToBuffer(UINT8 *buffer, UINT16 &pos, T intValue)
Definition: colab.hpp:104
std::string getStringFromBuffer(UINT8 *buffer, UINT16 &pos, UINT16 length)
Definition: colab.cpp:39
void addStringToBuffer(UINT8 *buffer, UINT16 &pos, const std::string &stringValue)
Definition: colab.cpp:21
Definition: colab.cpp:18
void addFrameToBuffer(UINT8 *sendBuffer, UINT8 *cmdBuffer, UINT16 *len)
Definition: colab.cpp:99
std::string getCommandStringFromBuffer(UINT8 *buffer)
Definition: colab.cpp:56
T getIntegerFromBuffer(UINT8 *buffer, UINT16 &pos)
Definition: colab.hpp:124
void addFloatToBuffer(UINT8 *buffer, UINT16 &pos, T floatValue)
Definition: colab.hpp:152
std::string getIdentifierFromBuffer(UINT8 *buffer, UINT16 &nextData, UINT16 bufferLength)
Definition: colab.cpp:61
double getDoubleFromBuffer(UINT8 *buffer, UINT16 &pos)
Definition: colab.cpp:129
uint8_t UINT8


sick_scan
Author(s): Michael Lehning , Jochen Sprickerhof , Martin Günther
autogenerated on Wed May 5 2021 03:05:47