firmware.cpp
Go to the documentation of this file.
1 
9 /*****************************************************************************
10  ** Includes
11  *****************************************************************************/
12 
13 #include <cmath>
14 #include <ecl/math.hpp>
15 #include <ecl/geometry/angle.hpp>
16 #include <ecl/time/sleep.hpp>
17 #include <ecl/converters.hpp>
18 #include <ecl/sigslots.hpp>
19 #include <ecl/geometry/angle.hpp>
20 #include <ecl/time/timestamp.hpp>
21 #include <stdexcept>
22 #include "../../include/kobuki_driver/kobuki.hpp"
23 #include "../../include/kobuki_driver/packet_handler/payload_headers.hpp"
24 
25 /*****************************************************************************
26  ** Namespaces
27  *****************************************************************************/
28 
29 namespace kobuki
30 {
31 
32 
33 /*****************************************************************************
34  ** Constants
35  *****************************************************************************/
36 
37 const uint32_t Firmware::COMPATIBLE_MAJOR_VERSION = 1;
38 const std::vector<uint32_t> Firmware::RECOMMENDED_VERSIONS = { 0x010104, 0x010200 };
39 
40 /*****************************************************************************
41  ** Serialisation
42  *****************************************************************************/
43 
45 {
46  if (byteStream.size() < length+2)
47  {
48  //std::cout << "kobuki_node: kobuki_fw: deserialise failed. not enough byte stream." << std::endl;
49  return false;
50  }
51 
52  unsigned char header_id, length_packed;
53  buildVariable(header_id, byteStream);
54  buildVariable(length_packed, byteStream);
55  if( header_id != Header::Firmware ) return false;
56  if( length_packed != 2 and length_packed != 4) return false;
57 
58  // TODO First 3 firmware versions coded version number on 2 bytes, so we need convert manually to our new
59  // 4 bytes system; remove this horrible, dirty hack as soon as we upgrade the firmware to 1.1.2 or 1.2.0
60  if (length_packed == 2)
61  {
62  uint16_t old_style_version = 0;
63  buildVariable(old_style_version, byteStream);
64 
65  if (old_style_version == 123)
66  data.version = 65536; // 1.0.0
67  else if ((old_style_version == 10100) || (old_style_version == 110))
68  data.version = 65792; // 1.1.0
69  else if ((old_style_version == 10101) || (old_style_version == 111))
70  data.version = 65793; // 1.1.1
71  }
72  else
73  {
74  buildVariable(data.version, byteStream);
75  }
76  // override data.version here to hack/test version checking
77  // data.version = 0x020103;
78 
79  //showMe();
80  return constrain();
81 }
82 
83 /*****************************************************************************
84  ** Version Helpers
85  *****************************************************************************/
86 
88 {
89  // Return 0 if detected major version is compatible
90  // Return a positive value if the driver needs to be upgraded
91  // Return a negative value if the firmware needs to be upgraded
93 }
94 
96 {
97  // Return 0 if the version matches a recommended version
98  // Return 1 if the driver needs to be upgraded
99  // Return -1 if the firmware needs to be upgraded
100 
101  // look for match with a recommended version
102  if ( std::find(RECOMMENDED_VERSIONS.begin(), RECOMMENDED_VERSIONS.end(), data.version) != RECOMMENDED_VERSIONS.end()) {
103  return 0;
104  }
105 
106  // if flashed version is > all recommended versions, return 1, else -1
107  for ( uint32_t version : RECOMMENDED_VERSIONS ) {
108  int recommended_major_version = VersionInfo::majorVersion(version);
109  int recommended_minor_version = VersionInfo::minorVersion(version);
110  int recommended_patch_version = VersionInfo::patchVersion(version);
111  if ( majorVersion() > recommended_major_version ) {
112  continue;
113  } else if ( majorVersion() < recommended_major_version ) {
114  return -1;
115  } else if ( minorVersion() > recommended_minor_version ) {
116  continue;
117  } else if ( minorVersion() < recommended_minor_version ) {
118  return -1;
119  } else if ( patchVersion() > recommended_patch_version ) {
120  continue;
121  } else if ( patchVersion() < recommended_patch_version ) {
122  return -1;
123  }
124  }
125  // flashed version is > all recommended versions
126  return 1;
127 }
128 
129 
130 } // namespace kobuki
packet_handler::payloadBase::length
const unsigned char length
Definition: payload_base.hpp:73
kobuki::Firmware::RECOMMENDED_VERSIONS
static const std::vector< uint32_t > RECOMMENDED_VERSIONS
Definition: firmware.hpp:54
kobuki
Definition: command.hpp:31
sigslots.hpp
sleep.hpp
kobuki::Firmware::majorVersion
int majorVersion() const
Definition: firmware.hpp:80
kobuki::Header::Firmware
@ Firmware
Definition: payload_headers.hpp:54
kobuki::Firmware::constrain
bool constrain()
Definition: firmware.hpp:70
kobuki::Firmware::version
const uint32_t & version() const
Definition: firmware.hpp:79
kobuki::Firmware::patchVersion
int patchVersion() const
Definition: firmware.hpp:82
kobuki::VersionInfo::patchVersion
static int patchVersion(const uint32_t &version)
Definition: version_info.hpp:78
math.hpp
kobuki::Firmware::checkMajorVersion
int checkMajorVersion() const
Definition: firmware.cpp:91
packet_handler::payloadBase::buildVariable
void buildVariable(T &V, ecl::PushAndPop< unsigned char > &buffer)
Definition: payload_base.hpp:96
kobuki::Firmware::Data::version
uint32_t version
Definition: firmware.hpp:89
kobuki::Firmware::COMPATIBLE_MAJOR_VERSION
static const uint32_t COMPATIBLE_MAJOR_VERSION
Definition: firmware.hpp:53
angle.hpp
kobuki::Firmware::minorVersion
int minorVersion() const
Definition: firmware.hpp:81
ecl::PushAndPop< unsigned char >
kobuki::VersionInfo::minorVersion
static int minorVersion(const uint32_t &version)
Definition: version_info.hpp:74
kobuki::Firmware::data
Data data
Definition: firmware.hpp:91
kobuki::Firmware::deserialise
bool deserialise(ecl::PushAndPop< unsigned char > &byteStream)
Definition: firmware.cpp:48
kobuki::Firmware::checkRecommendedVersion
int checkRecommendedVersion() const
Definition: firmware.cpp:99
converters.hpp
ecl::PushAndPop::size
unsigned int size() const
timestamp.hpp
kobuki::VersionInfo::majorVersion
static int majorVersion(const uint32_t &version)
Definition: version_info.hpp:70


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