27 #include <gtest/gtest.h> 28 #include <boost/make_shared.hpp> 36 using boost::make_shared;
55 ts = make_shared<TestSocket>();
56 ts_io = make_shared<TestSocket>();
57 os32c =
OS32C(ts, ts_io);
67 EXPECT_EQ(0, OS32C::calcBeamNumber(2.359685166149626));
68 EXPECT_EQ(0, OS32C::calcBeamNumber(2.356194491937674));
70 EXPECT_EQ(1, OS32C::calcBeamNumber(2.3561944901748917));
71 EXPECT_EQ(1, OS32C::calcBeamNumber(2.3492131733589003));
72 EXPECT_EQ(338, OS32C::calcBeamNumber(0.0034906583294557337));
73 EXPECT_EQ(338, OS32C::calcBeamNumber(0));
74 EXPECT_EQ(338, OS32C::calcBeamNumber(-0.0034906583294557337));
75 EXPECT_EQ(675, OS32C::calcBeamNumber(-2.3492131733589003));
76 EXPECT_EQ(675, OS32C::calcBeamNumber(-2.3561944901748917));
78 EXPECT_EQ(676, OS32C::calcBeamNumber(-2.356194491937674));
79 EXPECT_EQ(676, OS32C::calcBeamNumber(-2.359685166149626));
84 EXPECT_DOUBLE_EQ(2.3596851486963333, OS32C::calcBeamCentre(0));
85 EXPECT_DOUBLE_EQ(2.3527038316883564, OS32C::calcBeamCentre(1));
86 EXPECT_NEAR(0, OS32C::calcBeamCentre(338), 0.00000000001);
87 EXPECT_DOUBLE_EQ(-2.3527038316883564, OS32C::calcBeamCentre(675));
88 EXPECT_DOUBLE_EQ(-2.3596851486963333, OS32C::calcBeamCentre(676));
94 memset(buffer, 0xAA,
sizeof(buffer));
96 os32c.calcBeamMask(OS32C::ANGLE_MAX, OS32C::ANGLE_MIN, mask);
97 EXPECT_DOUBLE_EQ(2.3596851486963333, os32c.start_angle_);
98 EXPECT_DOUBLE_EQ(-2.3596851486963333, os32c.end_angle_);
99 for (
size_t i = 0; i < 4; ++i)
101 EXPECT_EQ(0xAA, buffer[i]);
103 for (
size_t i = 0; i < 84; ++i)
105 EXPECT_EQ(0xFF, mask[i]);
107 EXPECT_EQ(0x1F, mask[84]);
108 EXPECT_EQ(0, mask[85]);
109 EXPECT_EQ(0, mask[86]);
110 EXPECT_EQ(0, mask[87]);
111 for (
size_t i = 92; i < 96; ++i)
113 EXPECT_EQ(0xAA, buffer[i]);
120 memset(buffer, 0xAA,
sizeof(buffer));
122 os32c.calcBeamMask(0.7853981633974483, -0.7853981633974483, mask);
123 EXPECT_DOUBLE_EQ(0.788888821901437, os32c.start_angle_);
124 EXPECT_DOUBLE_EQ(-0.7819075048934596, os32c.end_angle_);
125 for (
size_t i = 0; i < 4; ++i)
127 EXPECT_EQ(0xAA, buffer[i]);
129 for (
size_t i = 0; i < 28; ++i)
131 EXPECT_EQ(0, mask[i]);
133 EXPECT_EQ(0xFE, mask[28]);
134 for (
size_t i = 29; i < 56; ++i)
136 EXPECT_EQ(0xFF, mask[i]);
138 EXPECT_EQ(0x07, mask[56]);
139 for (
size_t i = 57; i < 88; ++i)
141 EXPECT_EQ(0, mask[i]);
143 for (
size_t i = 92; i < 96; ++i)
145 EXPECT_EQ(0xAA, buffer[i]);
152 memset(buffer, 0xAA,
sizeof(buffer));
154 os32c.calcBeamMask(0.6911503837897546, -0.7051130178057091, mask);
155 EXPECT_DOUBLE_EQ(0.6911503837897546, os32c.start_angle_);
156 EXPECT_DOUBLE_EQ(-0.70511301780570967, os32c.end_angle_);
157 for (
size_t i = 0; i < 4; ++i)
159 EXPECT_EQ(0xAA, buffer[i]);
161 for (
size_t i = 0; i < 29; ++i)
163 EXPECT_EQ(0, mask[i]);
165 EXPECT_EQ(0x80, mask[29]);
166 for (
size_t i = 30; i < 55; ++i)
168 EXPECT_EQ(0xFF, mask[i]);
170 for (
size_t i = 55; i < 88; ++i)
172 EXPECT_EQ(0, mask[i]);
174 for (
size_t i = 92; i < 96; ++i)
176 EXPECT_EQ(0xAA, buffer[i]);
183 memset(buffer, 0xAA,
sizeof(buffer));
185 EXPECT_THROW(os32c.calcBeamMask(2.3631758089456514, -0.7051130178057091, mask), std::invalid_argument);
186 EXPECT_THROW(os32c.calcBeamMask(0.6911503837897546, -2.3631758089456514, mask), std::invalid_argument);
187 EXPECT_THROW(os32c.calcBeamMask(0.6911503837897546, 0.6911503837897546, mask), std::invalid_argument);
188 EXPECT_THROW(os32c.calcBeamMask(0.6911503837897546, 0.6841690685271065, mask), std::invalid_argument);
194 char reg_resp_packet[] = {
195 0x65, 0x00, 0x04, 0x00, 0x05, 0x00, 0x00, 0x00,
196 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
197 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
198 0x01, 0x00, 0x00, 0x00,
202 ts->rx_buffer = buffer(reg_resp_packet);
203 os32c.open(
"example_host");
204 EXPECT_TRUE(ts->is_open);
205 EXPECT_EQ(
"example_host", ts->hostname);
206 EXPECT_EQ(
"44818", ts->port);
207 EXPECT_EQ(5, os32c.getSessionID());
211 memset(ts->tx_buffer, 0,
sizeof(ts->tx_count));
215 uint8_t resp_packet[] = {
216 0x6F, 0x00, 0x14, 0x00, 0x05, 0x00, 0x00, 0x00,
217 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
218 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
219 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00,
220 0x00, 0x00, 0x00, 0x00, 0xB2, 0x00, 0x04, 0x00,
221 0x90, 0x00, 0x00, 0x00,
224 ts->rx_buffer = buffer(resp_packet);
226 os32c.selectBeams(OS32C::ANGLE_MAX, OS32C::ANGLE_MIN);
229 EXPECT_EQ(136, ts->tx_count);
231 EXPECT_EQ(0x6F, ts->tx_buffer[0]);
232 EXPECT_EQ(0x00, ts->tx_buffer[1]);
233 EXPECT_EQ(0x70, ts->tx_buffer[2]);
234 EXPECT_EQ(0x00, ts->tx_buffer[3]);
235 EXPECT_EQ(0x05, ts->tx_buffer[4]);
236 EXPECT_EQ(0x00, ts->tx_buffer[5]);
237 EXPECT_EQ(0x00, ts->tx_buffer[6]);
238 EXPECT_EQ(0x00, ts->tx_buffer[7]);
239 EXPECT_EQ(0x00, ts->tx_buffer[8]);
240 EXPECT_EQ(0x00, ts->tx_buffer[9]);
241 EXPECT_EQ(0x00, ts->tx_buffer[10]);
242 EXPECT_EQ(0x00, ts->tx_buffer[11]);
243 EXPECT_EQ(0x00, ts->tx_buffer[12]);
244 EXPECT_EQ(0x00, ts->tx_buffer[13]);
245 EXPECT_EQ(0x00, ts->tx_buffer[14]);
246 EXPECT_EQ(0x00, ts->tx_buffer[15]);
247 EXPECT_EQ(0x00, ts->tx_buffer[16]);
248 EXPECT_EQ(0x00, ts->tx_buffer[17]);
249 EXPECT_EQ(0x00, ts->tx_buffer[18]);
250 EXPECT_EQ(0x00, ts->tx_buffer[19]);
251 EXPECT_EQ(0x00, ts->tx_buffer[20]);
252 EXPECT_EQ(0x00, ts->tx_buffer[21]);
253 EXPECT_EQ(0x00, ts->tx_buffer[22]);
254 EXPECT_EQ(0x00, ts->tx_buffer[23]);
255 EXPECT_EQ(0x00, ts->tx_buffer[24]);
256 EXPECT_EQ(0x00, ts->tx_buffer[25]);
257 EXPECT_EQ(0x00, ts->tx_buffer[26]);
258 EXPECT_EQ(0x00, ts->tx_buffer[27]);
259 EXPECT_EQ(0x00, ts->tx_buffer[28]);
260 EXPECT_EQ(0x00, ts->tx_buffer[29]);
261 EXPECT_EQ(0x02, ts->tx_buffer[30]);
262 EXPECT_EQ(0x00, ts->tx_buffer[31]);
263 EXPECT_EQ(0x00, ts->tx_buffer[32]);
264 EXPECT_EQ(0x00, ts->tx_buffer[33]);
265 EXPECT_EQ(0x00, ts->tx_buffer[34]);
266 EXPECT_EQ(0x00, ts->tx_buffer[35]);
267 EXPECT_EQ(0xB2, ts->tx_buffer[36]);
268 EXPECT_EQ(0x00, ts->tx_buffer[37]);
269 EXPECT_EQ(0x60, ts->tx_buffer[38]);
270 EXPECT_EQ(0x00, ts->tx_buffer[39]);
271 EXPECT_EQ(0x10, ts->tx_buffer[40]);
272 EXPECT_EQ(0x03, ts->tx_buffer[41]);
273 EXPECT_EQ(0x20, ts->tx_buffer[42]);
274 EXPECT_EQ(0x73, ts->tx_buffer[43]);
275 EXPECT_EQ(0x24, ts->tx_buffer[44]);
276 EXPECT_EQ(0x01, ts->tx_buffer[45]);
277 EXPECT_EQ(0x30, ts->tx_buffer[46]);
278 EXPECT_EQ(0x0C, ts->tx_buffer[47]);
280 EXPECT_EQ(0xFF, ts->tx_buffer[48]);
281 EXPECT_EQ(0xFF, ts->tx_buffer[49]);
282 EXPECT_EQ(0xFF, ts->tx_buffer[50]);
283 EXPECT_EQ(0xFF, ts->tx_buffer[51]);
284 EXPECT_EQ(0xFF, ts->tx_buffer[52]);
285 EXPECT_EQ(0xFF, ts->tx_buffer[53]);
286 EXPECT_EQ(0xFF, ts->tx_buffer[54]);
287 EXPECT_EQ(0xFF, ts->tx_buffer[55]);
288 EXPECT_EQ(0xFF, ts->tx_buffer[56]);
289 EXPECT_EQ(0xFF, ts->tx_buffer[57]);
290 EXPECT_EQ(0xFF, ts->tx_buffer[58]);
291 EXPECT_EQ(0xFF, ts->tx_buffer[59]);
292 EXPECT_EQ(0xFF, ts->tx_buffer[60]);
293 EXPECT_EQ(0xFF, ts->tx_buffer[61]);
294 EXPECT_EQ(0xFF, ts->tx_buffer[62]);
295 EXPECT_EQ(0xFF, ts->tx_buffer[63]);
296 EXPECT_EQ(0xFF, ts->tx_buffer[64]);
297 EXPECT_EQ(0xFF, ts->tx_buffer[65]);
298 EXPECT_EQ(0xFF, ts->tx_buffer[66]);
299 EXPECT_EQ(0xFF, ts->tx_buffer[67]);
300 EXPECT_EQ(0xFF, ts->tx_buffer[68]);
301 EXPECT_EQ(0xFF, ts->tx_buffer[69]);
302 EXPECT_EQ(0xFF, ts->tx_buffer[70]);
303 EXPECT_EQ(0xFF, ts->tx_buffer[71]);
304 EXPECT_EQ(0xFF, ts->tx_buffer[72]);
305 EXPECT_EQ(0xFF, ts->tx_buffer[73]);
306 EXPECT_EQ(0xFF, ts->tx_buffer[74]);
307 EXPECT_EQ(0xFF, ts->tx_buffer[75]);
308 EXPECT_EQ(0xFF, ts->tx_buffer[76]);
309 EXPECT_EQ(0xFF, ts->tx_buffer[77]);
310 EXPECT_EQ(0xFF, ts->tx_buffer[78]);
311 EXPECT_EQ(0xFF, ts->tx_buffer[79]);
312 EXPECT_EQ(0xFF, ts->tx_buffer[80]);
313 EXPECT_EQ(0xFF, ts->tx_buffer[81]);
314 EXPECT_EQ(0xFF, ts->tx_buffer[82]);
315 EXPECT_EQ(0xFF, ts->tx_buffer[83]);
316 EXPECT_EQ(0xFF, ts->tx_buffer[84]);
317 EXPECT_EQ(0xFF, ts->tx_buffer[85]);
318 EXPECT_EQ(0xFF, ts->tx_buffer[86]);
319 EXPECT_EQ(0xFF, ts->tx_buffer[87]);
320 EXPECT_EQ(0xFF, ts->tx_buffer[88]);
321 EXPECT_EQ(0xFF, ts->tx_buffer[89]);
322 EXPECT_EQ(0xFF, ts->tx_buffer[90]);
323 EXPECT_EQ(0xFF, ts->tx_buffer[91]);
324 EXPECT_EQ(0xFF, ts->tx_buffer[92]);
325 EXPECT_EQ(0xFF, ts->tx_buffer[93]);
326 EXPECT_EQ(0xFF, ts->tx_buffer[94]);
327 EXPECT_EQ(0xFF, ts->tx_buffer[95]);
328 EXPECT_EQ(0xFF, ts->tx_buffer[96]);
329 EXPECT_EQ(0xFF, ts->tx_buffer[97]);
330 EXPECT_EQ(0xFF, ts->tx_buffer[98]);
331 EXPECT_EQ(0xFF, ts->tx_buffer[99]);
332 EXPECT_EQ(0xFF, ts->tx_buffer[100]);
333 EXPECT_EQ(0xFF, ts->tx_buffer[101]);
334 EXPECT_EQ(0xFF, ts->tx_buffer[102]);
335 EXPECT_EQ(0xFF, ts->tx_buffer[103]);
336 EXPECT_EQ(0xFF, ts->tx_buffer[104]);
337 EXPECT_EQ(0xFF, ts->tx_buffer[105]);
338 EXPECT_EQ(0xFF, ts->tx_buffer[106]);
339 EXPECT_EQ(0xFF, ts->tx_buffer[107]);
340 EXPECT_EQ(0xFF, ts->tx_buffer[108]);
341 EXPECT_EQ(0xFF, ts->tx_buffer[109]);
342 EXPECT_EQ(0xFF, ts->tx_buffer[110]);
343 EXPECT_EQ(0xFF, ts->tx_buffer[111]);
344 EXPECT_EQ(0xFF, ts->tx_buffer[112]);
345 EXPECT_EQ(0xFF, ts->tx_buffer[113]);
346 EXPECT_EQ(0xFF, ts->tx_buffer[114]);
347 EXPECT_EQ(0xFF, ts->tx_buffer[115]);
348 EXPECT_EQ(0xFF, ts->tx_buffer[116]);
349 EXPECT_EQ(0xFF, ts->tx_buffer[117]);
350 EXPECT_EQ(0xFF, ts->tx_buffer[118]);
351 EXPECT_EQ(0xFF, ts->tx_buffer[119]);
352 EXPECT_EQ(0xFF, ts->tx_buffer[120]);
353 EXPECT_EQ(0xFF, ts->tx_buffer[121]);
354 EXPECT_EQ(0xFF, ts->tx_buffer[122]);
355 EXPECT_EQ(0xFF, ts->tx_buffer[123]);
356 EXPECT_EQ(0xFF, ts->tx_buffer[124]);
357 EXPECT_EQ(0xFF, ts->tx_buffer[125]);
358 EXPECT_EQ(0xFF, ts->tx_buffer[126]);
359 EXPECT_EQ(0xFF, ts->tx_buffer[127]);
360 EXPECT_EQ(0xFF, ts->tx_buffer[128]);
361 EXPECT_EQ(0xFF, ts->tx_buffer[129]);
362 EXPECT_EQ(0xFF, ts->tx_buffer[130]);
363 EXPECT_EQ(0xFF, ts->tx_buffer[131]);
364 EXPECT_EQ(0x1F, ts->tx_buffer[132]);
365 EXPECT_EQ(0x00, ts->tx_buffer[133]);
366 EXPECT_EQ(0x00, ts->tx_buffer[134]);
367 EXPECT_EQ(0x00, ts->tx_buffer[135]);
411 sensor_msgs::LaserScan ls;
412 OS32C::convertToLaserScan(rr, &ls);
413 EXPECT_FLOAT_EQ(42898E-9, ls.time_increment);
414 EXPECT_FLOAT_EQ(1.0, ls.ranges[0]);
415 EXPECT_FLOAT_EQ(1.253, ls.ranges[1]);
416 EXPECT_FLOAT_EQ(1.0, ls.ranges[2]);
417 EXPECT_FLOAT_EQ(0.0, ls.ranges[3]);
418 EXPECT_FLOAT_EQ(48.750, ls.ranges[4]);
419 EXPECT_FLOAT_EQ(49.999, ls.ranges[5]);
420 EXPECT_FLOAT_EQ(50.001, ls.ranges[6]);
421 EXPECT_FLOAT_EQ(48.135, ls.ranges[7]);
422 EXPECT_FLOAT_EQ(50.000, ls.ranges[8]);
423 EXPECT_FLOAT_EQ(50.000, ls.ranges[9]);
424 EXPECT_FLOAT_EQ(44000, ls.intensities[0]);
425 EXPECT_FLOAT_EQ(42123, ls.intensities[1]);
426 EXPECT_FLOAT_EQ(53987, ls.intensities[2]);
427 EXPECT_FLOAT_EQ(0, ls.intensities[3]);
428 EXPECT_FLOAT_EQ(123, ls.intensities[4]);
429 EXPECT_FLOAT_EQ(555, ls.intensities[5]);
430 EXPECT_FLOAT_EQ(65535, ls.intensities[6]);
431 EXPECT_FLOAT_EQ(1013, ls.intensities[7]);
432 EXPECT_FLOAT_EQ(0, ls.intensities[8]);
433 EXPECT_FLOAT_EQ(0, ls.intensities[9]);
440 uint8_t io_packet[] = {
441 0x02, 0x00, 0x02, 0x80, 0x08, 0x00, 0x04, 0x00,
442 0x02, 0x00, 0x15, 0x00, 0x00, 0x00, 0xB1, 0x00,
443 0x62, 0x00, 0xA1, 0x00, 0x76, 0x53, 0x04, 0x00,
444 0x64, 0x96, 0x00, 0x00, 0x18, 0xBE, 0x97, 0x8A,
445 0x19, 0xA7, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00,
446 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
447 0x00, 0x00, 0x08, 0x07, 0x88, 0x33, 0xAE, 0x31,
448 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
449 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00,
450 0x00, 0x00, 0x14, 0x00, 0x52, 0x08, 0x42, 0x08,
451 0x52, 0x08, 0x40, 0x08, 0x52, 0x08, 0x40, 0x08,
452 0x53, 0x08, 0x58, 0x08, 0x52, 0x08, 0x40, 0x08,
453 0x58, 0x08, 0x58, 0x08, 0x58, 0x08, 0x5E, 0x08,
454 0x67, 0x08, 0x5D, 0x08, 0x67, 0x08, 0x5E, 0x08,
455 0x5E, 0x08, 0x6F, 0x08,
459 ts_io->rx_buffer = buffer(io_packet);
vector< EIP_UINT > measurement_data
vector< EIP_UINT > reflectance_data
shared_ptr< TestSocket > ts
MeasurementReportHeader header
MeasurementReportHeader header
virtual size_t getLength() const
TEST_F(OS32CTest, test_receive_measurement_report)
shared_ptr< TestSocket > ts_io
vector< EIP_UINT > range_data