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 
34 class Hardware : public packet_handler::payloadBase
35 {
36 public:
37  Hardware() : packet_handler::payloadBase(true, 2) {};
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 
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 
packet_handler::payloadBase::length
const unsigned char length
Definition: payload_base.hpp:73
kobuki::Hardware::serialise
bool serialise(ecl::PushAndPop< unsigned char > &byteStream)
Definition: hardware.hpp:57
kobuki
Definition: command.hpp:31
packet_handler::payloadBase::payloadBase
payloadBase(const bool is_dynamic_=false, const unsigned char length_=0)
Definition: payload_base.hpp:78
kobuki::Hardware::constrain
bool constrain()
Definition: hardware.hpp:99
packet_handler::payloadBase
Provides base class for payloads.
Definition: payload_base.hpp:44
kobuki::Hardware::Data::version
uint32_t version
Definition: hardware.hpp:53
kobuki::Hardware::Hardware
Hardware()
Definition: hardware.hpp:51
packet_handler::payloadBase::buildVariable
void buildVariable(T &V, ecl::PushAndPop< unsigned char > &buffer)
Definition: payload_base.hpp:96
kobuki::Hardware::data
struct kobuki::Hardware::Data data
kobuki::Hardware::showMe
void showMe()
Definition: hardware.hpp:104
kobuki::Hardware::deserialise
bool deserialise(ecl::PushAndPop< unsigned char > &byteStream)
Definition: hardware.hpp:66
packet_handler::payloadBase::buildBytes
void buildBytes(const T &V, ecl::PushAndPop< unsigned char > &buffer)
Definition: payload_base.hpp:110
kobuki::Header::Hardware
@ Hardware
Definition: payload_headers.hpp:54
ecl::PushAndPop< unsigned char >
packet_handler
Definition: payload_base.hpp:27
ecl::PushAndPop::size
unsigned int size() const


kobuki_driver
Author(s): Daniel Stonier , Younghun Ju , Jorge Santos Simon
autogenerated on Wed Mar 2 2022 00:26:14