ReadWriteHelper.cpp
Go to the documentation of this file.
1 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
2 
3 // -- BEGIN LICENSE BLOCK ----------------------------------------------
4 
24 // -- END LICENSE BLOCK ------------------------------------------------
25 
26 //----------------------------------------------------------------------
33 //----------------------------------------------------------------------
34 
36 
37 namespace sick {
38 namespace data_processing {
39 
41 
42 //*************
43 // UINT 8
44 
45 uint8_t ReadWriteHelper::readuint8_t(const uint8_t*& buf, const uint16_t offset) const
46 {
47  uint8_t value = buf[offset];
48  return value;
49 }
50 
51 uint8_t ReadWriteHelper::readuint8_tLittleEndian(const uint8_t*& buf, const uint16_t offset) const
52 {
53  return readuint8_t(buf, offset);
54 }
55 
56 uint8_t ReadWriteHelper::readuint8_tBigEndian(const uint8_t*& buf, const uint16_t offset) const
57 {
58  return readuint8_t(buf, offset);
59 }
60 
61 void ReadWriteHelper::writeuint8_t(uint8_t*& buf, const uint8_t v, const uint16_t offset) const
62 {
63  buf[offset] = v;
64 }
65 
67  const uint8_t v,
68  const uint16_t offset) const
69 {
70  writeuint8_t(buf, v, offset);
71 }
72 
74  const uint8_t v,
75  const uint16_t offset) const
76 {
77  writeuint8_t(buf, v, offset);
78 }
79 
80 
81 //*******
82 // int8_t
83 
84 int8_t ReadWriteHelper::readint8_t(const uint8_t*& buffer, const uint16_t offset) const
85 {
86  return readuint8_t(buffer, offset);
87 }
88 
89 
90 int8_t ReadWriteHelper::readint8_tLittleEndian(const uint8_t*& buf, const uint16_t offset) const
91 {
92  return readint8_t(buf, offset);
93 }
94 
95 int8_t ReadWriteHelper::readint8_tBigEndian(const uint8_t*& buf, const uint16_t offset) const
96 {
97  return readint8_t(buf, offset);
98 }
99 
100 void ReadWriteHelper::writeint8_t(uint8_t*& buf, const uint8_t v, const uint16_t offset) const
101 {
102  writeuint8_t(buf, v, offset);
103 }
104 
106  const uint8_t v,
107  const uint16_t offset) const
108 {
109  writeint8_t(buf, v, offset);
110 }
111 
113  const uint8_t v,
114  const uint16_t offset) const
115 {
116  writeint8_t(buf, v, offset);
117 }
118 
119 //*******
120 // uint16_t
121 
122 uint16_t ReadWriteHelper::readuint16_tLittleEndian(const uint8_t*& buf, const uint16_t offset) const
123 {
124  return (buf[offset + 1] << 8) + buf[offset];
125 }
126 
127 uint16_t ReadWriteHelper::readuint16_tBigEndian(const uint8_t*& buf, const uint16_t offset) const
128 {
129  return (buf[offset] << 8) + buf[offset + 1];
130 }
131 
133  const uint16_t v,
134  const uint16_t offset) const
135 {
136  buf[offset] = (v & 0xff00) >> 8;
137  buf[offset + 1] = v & 0xff;
138 }
139 
141  const uint16_t v,
142  const uint16_t offset) const
143 {
144  buf[offset + 1] = (v & 0xff00) >> 8;
145  buf[offset] = v & 0xff;
146 }
147 
148 //*******
149 // int16_t
150 
151 int16_t ReadWriteHelper::readint16_tLittleEndian(const uint8_t*& buf, const uint16_t offset) const
152 {
153  return readuint16_tLittleEndian(buf, offset);
154 }
155 
156 int16_t ReadWriteHelper::readint16_tBigEndian(const uint8_t*& buf, const uint16_t offset) const
157 {
158  return readuint16_tBigEndian(buf, offset);
159 }
160 
161 
162 //*******
163 // uint32_t
164 
165 
166 uint32_t ReadWriteHelper::readuint32_tLittleEndian(const uint8_t*& buf, const uint16_t offset) const
167 {
168  return (buf[offset + 3] << 24) + (buf[offset + 2] << 16) + (buf[offset + 1] << 8) + buf[offset];
169 }
170 
171 uint32_t ReadWriteHelper::readuint32_tBigEndian(const uint8_t*& buf, const uint16_t offset) const
172 {
173  return (buf[offset] << 24) + (buf[offset + 1] << 16) + (buf[offset + 2] << 8) + buf[offset + 3];
174 }
175 
177  const uint32_t v,
178  const uint16_t offset) const
179 {
180  buf[offset + 3] = (v & 0xff000000) >> 24;
181  buf[offset + 2] = (v & 0xff0000) >> 16;
182  buf[offset + 1] = (v & 0xff00) >> 8;
183  buf[offset] = v & 0xff;
184 }
185 
187  const uint32_t v,
188  const uint16_t offset) const
189 {
190  buf[offset] = (v & 0xff000000) >> 24;
191  buf[offset + 1] = (v & 0xff0000) >> 16;
192  buf[offset + 2] = (v & 0xff00) >> 8;
193  buf[offset + 3] = v & 0xff;
194 }
195 
196 
197 //*******
198 // int32_t
199 
200 int32_t ReadWriteHelper::readint32_tLittleEndian(const uint8_t*& buf, const uint16_t offset) const
201 {
202  return readuint32_tLittleEndian(buf, offset);
203 }
204 
205 int32_t ReadWriteHelper::readint32_tBigEndian(const uint8_t*& buf, const uint16_t offset) const
206 {
207  return readuint32_tBigEndian(buf, offset);
208 }
209 
210 
211 } // namespace data_processing
212 } // namespace sick
uint16_t readuint16_tBigEndian(const uint8_t *&buf, const uint16_t offset) const
Read an unsigned 16-bit integer at offset in big endian encoding.
uint8_t readuint8_tBigEndian(const uint8_t *&buf, const uint16_t offset) const
Read an unsigned 8-bit integer at offset in big endian encoding.
int16_t readint16_tBigEndian(const uint8_t *&buf, const uint16_t offset) const
Read a signed 16-bit integer at offset in big endian encoding.
int16_t readint16_tLittleEndian(const uint8_t *&buf, const uint16_t offset) const
Read a signed 16-bit integer at offset in little endian encoding.
uint32_t readuint32_tLittleEndian(const uint8_t *&buf, const uint16_t offset) const
Read an unsigned 32-bit integer at offset in little endian encoding.
void writeuint8_tLittleEndian(uint8_t *&buf, const uint8_t v, const uint16_t offset) const
Writes an unsigned 8-bit integer to a buffer at offset in little endian encoding. ...
void writeuint32_tLittleEndian(uint8_t *&buf, const uint32_t v, const uint16_t offset) const
Writes an unsigned 32-bit integer to a buffer at offset in little endian encoding.
int8_t readint8_tBigEndian(const uint8_t *&buf, const uint16_t offset) const
Read a signed 8-bit integer at offset in big endian encoding.
void writeint8_tBigEndian(uint8_t *&buf, const uint8_t v, const uint16_t offset) const
Writes a signed 8-bit integer to a buffer at offset in big endian encoding.
int32_t readint32_tBigEndian(const uint8_t *&buf, const uint16_t offset) const
Read an unsigned 32-bit integer at offset in big endian encoding.
void writeuint16_tLittleEndian(uint8_t *&buf, const uint16_t v, const uint16_t offset) const
Writes an unsigned 16-bit integer to a buffer at offset in little endian encoding.
void writeuint16_tBigEndian(uint8_t *&buf, const uint16_t v, const uint16_t offset) const
Writes an unsigned 16-bit integer to a buffer at offset in big endian encoding.
int8_t readint8_t(const uint8_t *&buffer, const uint16_t offset) const
Read a signed 8-bit integer at offset.
void writeuint8_t(uint8_t *&buf, const uint8_t v, const uint16_t offset) const
Writes an unsigned 8-bit integer to a buffer at offset.
uint8_t readuint8_tLittleEndian(const uint8_t *&buf, const uint16_t offset) const
Read an unsigned 8-bit integer at offset in big little encoding.
void writeint8_tLittleEndian(uint8_t *&buf, const uint8_t v, const uint16_t offset) const
Writes a signed 8-bit integer to a buffer at offset in little endian encoding.
uint32_t readuint32_tBigEndian(const uint8_t *&buf, const uint16_t offset) const
Read an unsigned 32-bit integer at offset in big endian encoding.
void writeint8_t(uint8_t *&buf, const uint8_t v, const uint16_t offset) const
Writes a signed 8-bit integer to a buffer at offset.
int32_t readint32_tLittleEndian(const uint8_t *&buf, const uint16_t offset) const
Read an unsigned 32-bit integer at offset in little endian encoding.
int8_t readint8_tLittleEndian(const uint8_t *&buf, const uint16_t offset) const
Read a signed 8-bit integer at offset in little endian encoding.
ReadWriteHelper()
Constructor of read and write helper class.
uint16_t readuint16_tLittleEndian(const uint8_t *&buf, const uint16_t offset) const
Read an unsigned 16-bit integer at offset in little endian encoding.
uint8_t readuint8_t(const uint8_t *&buf, const uint16_t offset) const
Read an unsigned 8-bit integer at offset.
void writeuint32_tBigEndian(uint8_t *&buf, const uint32_t v, const uint16_t offset) const
Writes an unsigned 32-bit integer to a buffer at offset in big endian encoding.
void writeuint8_tBigEndian(uint8_t *&buf, const uint8_t v, const uint16_t offset) const
Writes an unsigned 8-bit integer to a buffer at offset in big endian encoding.


sick_safetyscanners
Author(s): Lennart Puck
autogenerated on Thu May 9 2019 02:41:08