firmware.hpp
Go to the documentation of this file.
00001 
00009 /*****************************************************************************
00010 ** Preprocessor
00011 *****************************************************************************/
00012 
00013 #ifndef KOBUKI_FW_DATA_HPP__
00014 #define KOBUKI_FW_DATA_HPP__
00015 
00016 /*****************************************************************************
00017 ** Include
00018 *****************************************************************************/
00019 
00020 #include "../packet_handler/payload_base.hpp"
00021 #include "../packet_handler/payload_headers.hpp"
00022 
00023 /*****************************************************************************
00024 ** Constants
00025 *****************************************************************************/
00026 
00027 #define CURRENT_FIRMWARE_MAJOR_VERSION  1
00028 #define CURRENT_FIRMWARE_MINOR_VERSION  2
00029 // patch number is ignored; don't need to be updated
00030 
00031 /*****************************************************************************
00032 ** Namespace
00033 *****************************************************************************/
00034 
00035 namespace kobuki
00036 {
00037 
00038 /*****************************************************************************
00039 ** Interface
00040 *****************************************************************************/
00041 
00042 class Firmware : public packet_handler::payloadBase
00043 {
00044 public:
00045   Firmware() : packet_handler::payloadBase(true, 2) {};
00046   struct Data {
00047     uint32_t version;
00048   } data;
00049 
00050   // methods
00051   bool serialise(ecl::PushAndPop<unsigned char> & byteStream)
00052   {
00053     unsigned char length = 4;
00054     buildBytes(Header::Firmware, byteStream);
00055     buildBytes(length, byteStream);
00056     buildBytes(data.version, byteStream);
00057     return true;
00058   }
00059 
00060   bool deserialise(ecl::PushAndPop<unsigned char> & byteStream)
00061   {
00062     if (byteStream.size() < length+2)
00063     {
00064       //std::cout << "kobuki_node: kobuki_fw: deserialise failed. not enough byte stream." << std::endl;
00065       return false;
00066     }
00067 
00068     unsigned char header_id, length_packed;
00069     buildVariable(header_id, byteStream);
00070     buildVariable(length_packed, byteStream);
00071     if( header_id != Header::Firmware ) return false;
00072     if( length_packed != 2 and length_packed != 4) return false;
00073 
00074     // TODO First 3 firmware versions coded version number on 2 bytes, so we need convert manually to our new
00075     // 4 bytes system; remove this horrible, dirty hack as soon as we upgrade the firmware to 1.1.2 or 1.2.0
00076     if (length_packed == 2)
00077     {
00078       uint16_t old_style_version = 0;
00079       buildVariable(old_style_version, byteStream);
00080 
00081       if (old_style_version == 123)
00082         data.version = 65536; // 1.0.0
00083       else if ((old_style_version == 10100) || (old_style_version == 110))
00084         data.version = 65792; // 1.1.0
00085       else if ((old_style_version == 10101) || (old_style_version == 111))
00086         data.version = 65793; // 1.1.1
00087     }
00088     else
00089     {
00090       buildVariable(data.version, byteStream);
00091     }
00092 
00093     //showMe();
00094     return constrain();
00095   }
00096 
00097   bool constrain()
00098   {
00099     return true;
00100   }
00101 
00102   void showMe()
00103   {
00104   }
00105 
00106   std::string current_version()
00107   {
00108     std::stringstream ss;
00109     ss << CURRENT_FIRMWARE_MAJOR_VERSION << "." << CURRENT_FIRMWARE_MINOR_VERSION << ".x";
00110 
00111     return std::string(ss.str());
00112   }
00113 
00114   std::string flashed_version()
00115   {
00116     std::stringstream ss;
00117     ss << flashed_major_version() << "." << flashed_minor_version() << "." << (data.version & 0x000000FF);
00118 
00119     return std::string(ss.str());
00120   }
00121 
00122   int current_major_version() { return CURRENT_FIRMWARE_MAJOR_VERSION; }
00123   int current_minor_version() { return CURRENT_FIRMWARE_MINOR_VERSION; }
00124 
00125   int flashed_major_version() { return ((data.version & 0x00FF0000) >> 16); }
00126   int flashed_minor_version() { return ((data.version & 0x0000FF00) >> 8);  }
00127 
00128   int check_major_version()
00129   {
00130     // Return a negative value if firmware's major version is older than that of the driver,
00131     // 0 if both are the same, and a positive value if firmware's major version is newer
00132     uint32_t flashed_version = ((data.version & 0x00FF0000) >> 16);
00133     return flashed_version - CURRENT_FIRMWARE_MAJOR_VERSION;
00134   }
00135 
00136   int check_minor_version()
00137   {
00138     // Return a negative value if firmware's minor version is older than that of the driver,
00139     // 0 if both are the same, and a positive value if firmware's minor version is newer
00140     uint32_t flashed_version = ((data.version & 0x0000FF00) >> 8);
00141     return flashed_version - CURRENT_FIRMWARE_MINOR_VERSION;
00142   }
00143 };
00144 
00145 } // namespace kobuki
00146 
00147 #endif /* KOBUKI_FW_DATA_HPP__ */
00148 


kobuki_driver
Author(s): Daniel Stonier , Younghun Ju , Jorge Santos Simon
autogenerated on Thu Aug 27 2015 13:43:58