hardware.hpp
Go to the documentation of this file.
1 
9 /*****************************************************************************
10 ** Preprocessor
11 *****************************************************************************/
12 
13 #ifndef KOBUKI_HW_DATA_HPP__
14 #define KOBUKI_HW_DATA_HPP__
15 
16 /*****************************************************************************
17 ** Include
18 *****************************************************************************/
19 
20 #include "../packet_handler/payload_base.hpp"
21 #include "../packet_handler/payload_headers.hpp"
22 
23 /*****************************************************************************
24 ** Namespace
25 *****************************************************************************/
26 
27 namespace kobuki
28 {
29 
30 /*****************************************************************************
31 ** Interface
32 *****************************************************************************/
33 
35 {
36 public:
38  struct Data {
39  uint32_t version;
40  } data;
41 
42  // methods
43  bool serialise(ecl::PushAndPop<unsigned char> & byteStream)
44  {
45  unsigned char length = 4;
46  buildBytes(Header::Hardware, byteStream);
47  buildBytes(length, byteStream);
48  buildBytes(data.version, byteStream);
49  return true;
50  }
51 
52  bool deserialise(ecl::PushAndPop<unsigned char> & byteStream)
53  {
54  if (byteStream.size() < length+2)
55  {
56  //std::cout << "kobuki_node: kobuki_hw: deserialise failed. not enough byte stream." << std::endl;
57  return false;
58  }
59 
60  unsigned char header_id, length_packed;
61  buildVariable(header_id, byteStream);
62  buildVariable(length_packed, byteStream);
63  if( header_id != Header::Hardware ) return false;
64  if( length_packed != 2 and length_packed != 4) return false;
65 
66  // TODO First 3 firmware versions coded version number on 2 bytes, so we need convert manually to our new
67  // 4 bytes system; remove this horrible, dirty hack as soon as we upgrade the firmware to 1.1.2 or 1.2.0
68  if (length_packed == 2)
69  {
70  uint16_t old_style_version = 0;
71  buildVariable(old_style_version, byteStream);
72 
73  if (old_style_version == 104)
74  data.version = 0x00010004;//65540; // 1.0.4
75  }
76  else
77  {
78  buildVariable(data.version, byteStream);
79  }
80 
81  //showMe();
82  return constrain();
83  }
84 
85  bool constrain()
86  {
87  return true;
88  }
89 
90  void showMe()
91  {
92  }
93 };
94 
95 } // namespace kobuki
96 
97 #endif /* KOBUKI_HW_DATA_HPP__ */
98 
bool deserialise(ecl::PushAndPop< unsigned char > &byteStream)
Definition: hardware.hpp:52
bool constrain()
Definition: hardware.hpp:85
const unsigned char length
Provides base class for payloads.
payloadBase(const bool is_dynamic_=false, const unsigned char length_=0)
void buildVariable(T &V, ecl::PushAndPop< unsigned char > &buffer)
void buildBytes(const T &V, ecl::PushAndPop< unsigned char > &buffer)
struct kobuki::Hardware::Data data
bool serialise(ecl::PushAndPop< unsigned char > &byteStream)
Definition: hardware.hpp:43


kobuki_driver
Author(s): Daniel Stonier , Younghun Ju , Jorge Santos Simon
autogenerated on Mon Mar 27 2017 01:02:59