Kobuki 1.0.0
C++ API for the Kobuki research robot
Loading...
Searching...
No Matches
hardware.hpp
Go to the documentation of this file.
1
9/*****************************************************************************
10** Preprocessor
11*****************************************************************************/
12
13#ifndef KOBUKI_CORE_HW_DATA_HPP__
14#define KOBUKI_CORE_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
27namespace kobuki
28{
29
30/*****************************************************************************
31** Interface
32*****************************************************************************/
33
35{
36public:
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() < static_cast<unsigned int>(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(0x00), length_packed(0x00);
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_CORE_HW_DATA_HPP__ */
98
Definition hardware.hpp:35
Provides base class for payloads.
Definition payload_base.hpp:39
const unsigned char length
Definition payload_base.hpp:59
Definition hardware.hpp:38