colaa.hpp
Go to the documentation of this file.
1 //
2 // colaa.hpp
3 //
4 // (c) 2011 SICK AG, Hamburg, Germany
5 //
6 
7 #ifndef COLAA_HPP
8 #define COLAA_HPP
9 
11 // #include <boost/tokenizer.hpp>
12 
17 namespace colaa
18 {
19 
20 // typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
21 // typedef boost::char_separator<char> separator_type;
22 
25 
26 void addFrameToBuffer(UINT8* sendBuffer, UINT8* cmdBuffer, UINT16* len);
27 UINT16 addUINT8ToBuffer(UINT8* buffer, UINT8 value);
28 UINT16 addUINT16ToBuffer(UINT8* buffer, UINT16 value);
29 UINT16 addINT8ToBuffer(UINT8* buffer, INT8 value);
30 UINT16 addINT32ToBuffer(UINT8* buffer, INT32 value);
31 UINT16 addUINT32ToBuffer(UINT8* buffer, UINT32 value);
32 UINT16 addStringToBuffer(UINT8* buffer, const std::string& text);
33 std::string getNextStringToken(std::string* rxData);
34 
35 namespace detail
36 {
37 UINT16 writeToBuffer(BYTE* buffer, double value);
38 inline UINT16 writeToBuffer(BYTE* buffer, UINT8 value) { return addUINT8ToBuffer(buffer, value); }
39 inline UINT16 writeToBuffer(BYTE* buffer, INT8 value) { return addINT8ToBuffer(buffer, value); }
40 inline UINT16 writeToBuffer(BYTE* buffer, UINT16 value) { return addUINT16ToBuffer(buffer, value); }
41 inline UINT16 writeToBuffer(BYTE* buffer, INT16 value) { return addUINT16ToBuffer(buffer, value); }
42 inline UINT16 writeToBuffer(BYTE* buffer, UINT32 value) { return addUINT32ToBuffer(buffer, value); }
43 inline UINT16 writeToBuffer(BYTE* buffer, INT32 value) { return addINT32ToBuffer(buffer, value); }
44 inline UINT16 writeToBuffer(BYTE* buffer, const std::string& value) { return addStringToBuffer(buffer, value); }
45 }
46 
47 double decodeReal(std::string* rxData);
48 INT16 decodeINT16(std::string* rxData);
49 INT32 decodeINT32(std::string* rxData);
50 UINT32 decodeUINT32(std::string* rxData);
51 UINT16 decodeUINT16(std::string* rxData);
52 UINT8 decodeUINT8(std::string* rxData);
53 UINT32 decodeXByte(std::string* rxData, UINT16 len);
54 std::string decodeString(std::string* rxData, UINT16 len = 0);
55 std::string convertRxBufferToString(UINT8* buffer, UINT16 bufferLen);
56 
58 double decodeReal(const std::string& rxData);
59 INT16 decodeINT16(const std::string& rxData);
60 INT32 decodeINT32(const std::string& rxData);
61 UINT8 decodeUINT8(const std::string& rxData);
62 UINT16 decodeUINT16(const std::string& rxData);
63 UINT32 decodeUINT32(const std::string& rxData);
64 
65 //
66 UINT16 decodeUINT16(BYTE* buffer);
67 
68 namespace detail
69 {
71 template<typename T>
72 inline T read (const std::string& str)
73 {
74 // BOOST_STATIC_ASSERT(sizeof(T) == 0); // must not be instantiated
75  return T(); // to avoid additional compiler errors
76 }
77 template<> inline double read<double>(const std::string& rxData) { return decodeReal(rxData); }
78 template<> inline INT16 read<INT16>(const std::string& rxData) { return decodeINT16(rxData); }
79 template<> inline INT32 read<INT32>(const std::string& rxData) { return decodeINT32(rxData); }
80 template<> inline INT8 read<INT8>(const std::string& rxData) { return decodeUINT8(rxData); }
81 template<> inline UINT8 read<UINT8>(const std::string& rxData) { return decodeUINT8(rxData); }
82 template<> inline UINT32 read<UINT32>(const std::string& rxData) { return decodeUINT32(rxData); }
83 template<> inline UINT16 read<UINT16>(const std::string& rxData) { return decodeUINT16(rxData); }
84 template<> inline std::string read<std::string>(const std::string& rxData) { return rxData; }
85 }
86 
87 //
88 // Lese ein XByte-Array bekannter Laenge (1..4 Bytes) und verpacke es als UINT32-Wert.
89 // Das 1. empfangene Byte steht in den unteren 8 Bit des Ergebniswerts, usw.
90 //
91 // HINWEIS: der Iterator wird weitergeschoben len-1 mal. Um das naechste Element zu lesen
92 // muss vorher ++tok aufgerufen werden.
93 //
94 // @param begin = Startpunkt, von wo aus einzelne Stringtokens in Zahlen verwandelt werden
95 // @param end = Ende des containers, ueber den iteriert wird
96 // @param len = Anzahl der Bytes (= Array-Elemente)
97 //
98 //UINT32 decodeXByte(tokenizer::const_iterator& tok, const tokenizer::const_iterator& end, UINT16 len);
99 
100 } // END namespace colaa
101 #endif
UINT8 nibbleToAscii(UINT8 value)
Definition: colaa.cpp:53
double read< double >(const std::string &rxData)
Definition: colaa.hpp:77
std::string decodeString(std::string *rxData, UINT16 len)
Definition: colaa.cpp:603
INT16 decodeINT16(std::string *rxData)
Definition: colaa.cpp:472
unsigned char BYTE
INT8 read< INT8 >(const std::string &rxData)
Definition: colaa.hpp:80
uint16_t UINT16
std::string getNextStringToken(std::string *rxData)
Definition: colaa.cpp:246
Definition: colaa.cpp:21
T read(const std::string &str)
General template which is unimplemented; implemented specializations follow below.
Definition: colaa.hpp:72
std::string convertRxBufferToString(UINT8 *buffer, UINT16 bufferLen)
Definition: colaa.cpp:793
UINT8 read< UINT8 >(const std::string &rxData)
Definition: colaa.hpp:81
UINT16 addINT8ToBuffer(UINT8 *buffer, INT8 value)
Definition: colaa.cpp:139
INT32 read< INT32 >(const std::string &rxData)
Definition: colaa.hpp:79
uint32_t UINT32
UINT16 addUINT8ToBuffer(UINT8 *buffer, UINT8 value)
Definition: colaa.cpp:111
UINT16 read< UINT16 >(const std::string &rxData)
Definition: colaa.hpp:83
UINT8 decodeUINT8(std::string *rxData)
Definition: colaa.cpp:649
UINT32 decodeXByte(std::string *rxData, UINT16 len)
Definition: colaa.cpp:735
UINT16 addINT32ToBuffer(UINT8 *buffer, INT32 value)
Definition: colaa.cpp:185
void addFrameToBuffer(UINT8 *sendBuffer, UINT8 *cmdBuffer, UINT16 *len)
Definition: colaa.cpp:82
int32_t INT32
INT16 read< INT16 >(const std::string &rxData)
Definition: colaa.hpp:78
UINT16 addStringToBuffer(UINT8 *buffer, const std::string &text)
Definition: colaa.cpp:224
UINT16 writeToBuffer(BYTE *buffer, double value)
Definition: colaa.cpp:234
int8_t INT8
INT32 decodeINT32(std::string *rxData)
Definition: colaa.cpp:483
UINT32 read< UINT32 >(const std::string &rxData)
Definition: colaa.hpp:82
int16_t INT16
UINT16 addUINT16ToBuffer(UINT8 *buffer, UINT16 value)
Definition: colaa.cpp:125
UINT16 addUINT32ToBuffer(UINT8 *buffer, UINT32 value)
Definition: colaa.cpp:200
double decodeReal(std::string *rxData)
Definition: colaa.cpp:332
UINT16 decodeUINT16(BYTE *buffer)
Definition: colaa.cpp:627
UINT32 decodeUINT32(std::string *rxData)
Definition: colaa.cpp:434
UINT16 getValueOfChar(UINT8 c)
Definition: colaa.cpp:27
uint8_t UINT8


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