snark
sensors/velodyne/packet.h
1 // This file is part of snark, a generic and flexible library
2 // for robotics research.
3 //
4 // Copyright (C) 2011 The University of Sydney
5 //
6 // snark is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 3 of the License, or (at your option) any later version.
10 //
11 // snark is distributed in the hope that it will be useful, but WITHOUT ANY
12 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
14 // for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with snark. If not, see <http://www.gnu.org/licenses/>.
18 
19 #ifndef SNARK_SENSORS_VELODYNE_PACKET_H_
20 #define SNARK_SENSORS_VELODYNE_PACKET_H_
21 
22 #include <boost/array.hpp>
23 #include <boost/static_assert.hpp>
24 #include <comma/base/types.h>
25 #include <comma/packed/byte.h>
26 #include <comma/packed/little_endian.h>
27 #include <comma/packed/string.h>
28 #include <comma/packed/struct.h>
29 
30 namespace snark { namespace velodyne {
31 
32 struct packet : public comma::packed::packed_struct< packet, 1206 >
33 {
34  struct laser_return : public comma::packed::packed_struct< laser_return, 3 >
35  {
36  comma::packed::uint16 range;
37  comma::packed::byte intensity;
38  };
39 
40  struct laser_block : public comma::packed::packed_struct< laser_block, 2 + 2 + 32 * sizeof( laser_return ) >
41  {
42  comma::packed::string< 2 > id;
43  comma::packed::uint16 rotation;
44  boost::array< laser_return, 32 > lasers;
45  };
46 
47  struct status : public comma::packed::packed_struct< status, 6 >
48  {
49  struct temperature : public comma::packed::packed_struct< temperature, 6 >
50  {
51  comma::packed::byte fractions;
52  comma::packed::byte degrees;
53  comma::packed::string< 4 > text;
54  bool valid() const { return text() == "DegC"; }
55  };
56 
57  struct version : public comma::packed::packed_struct< version, 6 >
58  {
59  comma::packed::string< 2 > padding;
60  comma::packed::uint16 counter;
61  comma::packed::uint16 number;
62  bool valid() const { return ::memcmp( data() + 2, "DegC", 4 ) != 0; }
63  };
64 
65  template < class T > const T& as() const { return reinterpret_cast< const T& >( *this ); }
66  template < class T > T& As() { return reinterpret_cast< T& >( *this ); }
67  boost::array< comma::packed::byte, 6 > value;
68  };
69 
70  static const char* upper_block_id() { return "\xFF\xEE"; }
71 
72  static const char* lower_block_id() { return "\xFF\xDD"; }
73 
74  boost::array< laser_block, 12 > blocks;
75  status status;
76 };
77 
78 } } // namespace snark { namespace velodyne {
79 
80 #endif /*SNARK_SENSORS_VELODYNE_PACKET_H_*/