gp_input.hpp
Go to the documentation of this file.
1 
9 /*****************************************************************************
10 ** Preprocessor
11 *****************************************************************************/
12 
13 #ifndef KOBUKI_GP_INPUT_HPP__
14 #define KOBUKI_GP_INPUT_HPP__
15 
16 /*****************************************************************************
17 ** Include
18 *****************************************************************************/
19 
20 #include <vector>
21 #include "../packet_handler/payload_base.hpp"
22 #include "../packet_handler/payload_headers.hpp"
23 
24 /*****************************************************************************
25 ** Namespace
26 *****************************************************************************/
27 
28 namespace kobuki
29 {
30 
31 /*****************************************************************************
32 ** Interface
33 *****************************************************************************/
34 
36 {
37 public:
38  GpInput() : packet_handler::payloadBase(false, 16) {};
39  struct Data {
40  Data() : analog_input(4) {}
41  uint16_t digital_input;
47  std::vector<uint16_t> analog_input;
48  } data;
49 
51  {
52  buildBytes(Header::GpInput, byteStream);
53  buildBytes(length, byteStream);
54  buildBytes(data.digital_input, byteStream);
55  for (unsigned int i = 0; i < data.analog_input.size(); ++i)
56  {
57  buildBytes(data.analog_input[i], byteStream);
58  }
59  for (unsigned int i = 0; i < 3; ++i)
60  {
61  buildBytes(0x0000, byteStream); //dummy
62  }
63  return true;
64  }
65 
67  {
68  if (byteStream.size() < length+2)
69  {
70  //std::cout << "kobuki_node: kobuki_inertia: deserialise failed. not enough byte stream." << std::endl;
71  return false;
72  }
73 
74  unsigned char header_id, length_packed;
75  buildVariable(header_id, byteStream);
76  buildVariable(length_packed, byteStream);
77  if( header_id != Header::GpInput ) return false;
78  if( length_packed != length ) return false;
79 
80  buildVariable(data.digital_input, byteStream);
81 
82  //for (unsigned int i = 0; i < data.analog_input.size(); ++i)
83  // It's actually sending seven 16-bit variables.
84  // 0-3 : the analog pin inputs
85  // 4 : ???
86  // 5-6 : 0
87  for (unsigned int i = 0; i < 4; ++i)
88  {
89  buildVariable(data.analog_input[i], byteStream);
90  }
91  for (unsigned int i = 0; i < 3; ++i) {
92  uint16_t dummy;
93  buildVariable(dummy, byteStream);
94  }
95 
96  //showMe();
97  return constrain();
98  }
99 
100  bool constrain()
101  {
102  return true;
103  }
104 
105  void showMe()
106  {
107  }
108 };
109 
110 } // namespace kobuki
111 
112 #endif /* KOBUKI_GP_INPUT_HPP__ */
113 
bool deserialise(ecl::PushAndPop< unsigned char > &byteStream)
Definition: gp_input.hpp:66
bool constrain()
Definition: gp_input.hpp:100
unsigned int size() const
const unsigned char length
std::vector< uint16_t > analog_input
Definition: gp_input.hpp:47
Provides base class for payloads.
bool serialise(ecl::PushAndPop< unsigned char > &byteStream)
Definition: gp_input.hpp:50
payloadBase(const bool is_dynamic_=false, const unsigned char length_=0)
void buildVariable(T &V, ecl::PushAndPop< unsigned char > &buffer)
uint16_t digital_input
Definition: gp_input.hpp:41
void buildBytes(const T &V, ecl::PushAndPop< unsigned char > &buffer)
struct kobuki::GpInput::Data data


kobuki_driver
Author(s): Daniel Stonier , Younghun Ju , Jorge Santos Simon
autogenerated on Fri Sep 18 2020 03:22:01