firmware.hpp
Go to the documentation of this file.
1 
9 /*****************************************************************************
10 ** Preprocessor
11 *****************************************************************************/
12 
13 #ifndef KOBUKI_FW_DATA_HPP__
14 #define KOBUKI_FW_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 ** Constants
25 *****************************************************************************/
26 
27 #define CURRENT_FIRMWARE_MAJOR_VERSION 1
28 #define CURRENT_FIRMWARE_MINOR_VERSION 2
29 // patch number is ignored; don't need to be updated
30 
31 /*****************************************************************************
32 ** Namespace
33 *****************************************************************************/
34 
35 namespace kobuki
36 {
37 
38 /*****************************************************************************
39 ** Interface
40 *****************************************************************************/
41 
43 {
44 public:
46  struct Data {
47  uint32_t version;
48  } data;
49 
50  // methods
51  bool serialise(ecl::PushAndPop<unsigned char> & byteStream)
52  {
53  unsigned char length = 4;
54  buildBytes(Header::Firmware, byteStream);
55  buildBytes(length, byteStream);
56  buildBytes(data.version, byteStream);
57  return true;
58  }
59 
60  bool deserialise(ecl::PushAndPop<unsigned char> & byteStream)
61  {
62  if (byteStream.size() < length+2)
63  {
64  //std::cout << "kobuki_node: kobuki_fw: deserialise failed. not enough byte stream." << std::endl;
65  return false;
66  }
67 
68  unsigned char header_id, length_packed;
69  buildVariable(header_id, byteStream);
70  buildVariable(length_packed, byteStream);
71  if( header_id != Header::Firmware ) return false;
72  if( length_packed != 2 and length_packed != 4) return false;
73 
74  // TODO First 3 firmware versions coded version number on 2 bytes, so we need convert manually to our new
75  // 4 bytes system; remove this horrible, dirty hack as soon as we upgrade the firmware to 1.1.2 or 1.2.0
76  if (length_packed == 2)
77  {
78  uint16_t old_style_version = 0;
79  buildVariable(old_style_version, byteStream);
80 
81  if (old_style_version == 123)
82  data.version = 65536; // 1.0.0
83  else if ((old_style_version == 10100) || (old_style_version == 110))
84  data.version = 65792; // 1.1.0
85  else if ((old_style_version == 10101) || (old_style_version == 111))
86  data.version = 65793; // 1.1.1
87  }
88  else
89  {
90  buildVariable(data.version, byteStream);
91  }
92 
93  //showMe();
94  return constrain();
95  }
96 
97  bool constrain()
98  {
99  return true;
100  }
101 
102  void showMe()
103  {
104  }
105 
106  std::string current_version()
107  {
108  std::stringstream ss;
110 
111  return std::string(ss.str());
112  }
113 
114  std::string flashed_version()
115  {
116  std::stringstream ss;
117  ss << flashed_major_version() << "." << flashed_minor_version() << "." << (data.version & 0x000000FF);
118 
119  return std::string(ss.str());
120  }
121 
124 
125  int flashed_major_version() { return ((data.version & 0x00FF0000) >> 16); }
126  int flashed_minor_version() { return ((data.version & 0x0000FF00) >> 8); }
127 
129  {
130  // Return a negative value if firmware's major version is older than that of the driver,
131  // 0 if both are the same, and a positive value if firmware's major version is newer
132  uint32_t flashed_version = ((data.version & 0x00FF0000) >> 16);
133  return flashed_version - CURRENT_FIRMWARE_MAJOR_VERSION;
134  }
135 
137  {
138  // Return a negative value if firmware's minor version is older than that of the driver,
139  // 0 if both are the same, and a positive value if firmware's minor version is newer
140  uint32_t flashed_version = ((data.version & 0x0000FF00) >> 8);
141  return flashed_version - CURRENT_FIRMWARE_MINOR_VERSION;
142  }
143 };
144 
145 } // namespace kobuki
146 
147 #endif /* KOBUKI_FW_DATA_HPP__ */
148 
std::string flashed_version()
Definition: firmware.hpp:114
std::string current_version()
Definition: firmware.hpp:106
const unsigned char length
int check_major_version()
Definition: firmware.hpp:128
int current_major_version()
Definition: firmware.hpp:122
Provides base class for payloads.
#define CURRENT_FIRMWARE_MINOR_VERSION
Definition: firmware.hpp:28
payloadBase(const bool is_dynamic_=false, const unsigned char length_=0)
int check_minor_version()
Definition: firmware.hpp:136
int current_minor_version()
Definition: firmware.hpp:123
struct kobuki::Firmware::Data data
int flashed_major_version()
Definition: firmware.hpp:125
bool serialise(ecl::PushAndPop< unsigned char > &byteStream)
Definition: firmware.hpp:51
int flashed_minor_version()
Definition: firmware.hpp:126
bool constrain()
Definition: firmware.hpp:97
void buildVariable(T &V, ecl::PushAndPop< unsigned char > &buffer)
bool deserialise(ecl::PushAndPop< unsigned char > &byteStream)
Definition: firmware.hpp:60
#define CURRENT_FIRMWARE_MAJOR_VERSION
Definition: firmware.hpp:27
void buildBytes(const T &V, ecl::PushAndPop< unsigned char > &buffer)


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