Kobuki 1.0.0
C++ API for the Kobuki research robot
Loading...
Searching...
No Matches
payload_base.hpp
Go to the documentation of this file.
1
9/*****************************************************************************
10 ** Ifdefs
11 *****************************************************************************/
12
13#ifndef ROBOT_DATA_HPP_
14#define ROBOT_DATA_HPP_
15
16/*****************************************************************************
17 ** Includes
18 *****************************************************************************/
19
20#include <ecl/containers.hpp>
21#include <stdint.h>
22
23/*****************************************************************************
24 ** Namespaces
25 *****************************************************************************/
26
27namespace packet_handler
28{
29
30/*****************************************************************************
31 ** Interface
32 *****************************************************************************/
39{
40public:
41
46 bool yes;
47
52 const bool is_dynamic;
53
59 const unsigned char length;
60
61 /*
62 * construct and destruct
63 */
64 payloadBase(const bool is_dynamic_ = false, const unsigned char length_ = 0 )
65 : yes(false)
66 , is_dynamic(is_dynamic_)
67 , length(length_)
68 {};
69 virtual ~payloadBase() {};
70
71 /*
72 * serialisation
73 */
74 virtual bool serialise(ecl::PushAndPop<unsigned char> & byteStream)=0;
75 virtual bool deserialise(ecl::PushAndPop<unsigned char> & byteStream)=0;
76
77 // utilities
78 // todo; let's put more useful converters here. Or we may use generic converters
79protected:
80 // below funciton should be replaced wiht converter
81 template<typename T>
82 void buildVariable(T & V, ecl::PushAndPop<unsigned char> & buffer)
83 {
84 if (buffer.size() < sizeof(T))
85 return;
86 V = static_cast<unsigned char>(buffer.pop_front());
87
88 unsigned int size_value(sizeof(T));
89 for (unsigned int i = 1; i < size_value; i++)
90 {
91 V |= ((static_cast<unsigned char>(buffer.pop_front())) << (8 * i));
92 }
93 }
94
95 template<typename T>
96 void buildBytes(const T & V, ecl::PushAndPop<unsigned char> & buffer)
97 {
98 unsigned int size_value(sizeof(T));
99 for (unsigned int i = 0; i < size_value; i++)
100 {
101 buffer.push_back(static_cast<unsigned char>((V >> (i * 8)) & 0xff));
102 }
103 }
104};
105
106}
107
108// namespace packet_handler
109
110#endif /* ROBOT_DATA_HPP_ */
Provides base class for payloads.
Definition payload_base.hpp:39
const bool is_dynamic
Definition payload_base.hpp:52
const unsigned char length
Definition payload_base.hpp:59
bool yes
Definition payload_base.hpp:46