snark
proprietary_reader.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_PROPRIETARYREADER_H_
20 #define SNARK_SENSORS_VELODYNE_PROPRIETARYREADER_H_
21 
22 #ifndef WIN32
23 #include <stdlib.h>
24 #endif
25 #include <iostream>
26 #include <fstream>
27 #include <boost/array.hpp>
28 #include <boost/date_time/posix_time/posix_time.hpp>
29 #include <boost/noncopyable.hpp>
30 #include <boost/scoped_ptr.hpp>
31 
32 namespace snark {
33 
36 class proprietary_reader : public boost::noncopyable
37 {
38  public:
40  proprietary_reader( const std::string& filename = "-" );
41 
44 
46  const char* read();
47 
49  void close();
50 
52  boost::posix_time::ptime timestamp() const;
53 
54  private:
55  enum
56  {
57  headerSize = 16
58  , timestampSize = 12
59  , payload_size = 1206
60  , footerSize = 4
61  , packetSize = headerSize + timestampSize + payload_size + footerSize
62  , packetNum = 1 // , packetNum = 10 : does not seem to make big impact on the i/o performance
63  };
64  boost::array< char, packetSize * packetNum > m_buffer;
65  std::size_t m_offset;
66  std::size_t m_end;
67  boost::posix_time::ptime m_timestamp;
68  boost::scoped_ptr< std::ifstream > m_ifstream;
69  std::istream* m_istream;
70 };
71 
72 }
73 
74 #endif /*SNARK_SENSORS_VELODYNE_PROPRIETARYREADER_H_*/