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_MAYOR_VERSION  1
00028 #define CURRENT_FIRMWARE_MINOR_VERSION  1
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   struct Data {
00046     uint32_t version;
00047   } data;
00048 
00049   // methods
00050   bool serialise(ecl::PushAndPop<unsigned char> & byteStream)
00051   {
00052     if (!(byteStream.size() > 0))
00053     {
00054       printf("kobuki_node: kobuki_fw: serialise failed. empty byte stream.");
00055       return false;
00056     }
00057 
00058     unsigned char length = 4;
00059     buildBytes(Header::Firmware, byteStream);
00060     buildBytes(length, byteStream);
00061     buildBytes(data.version, byteStream);
00062     return true;
00063   }
00064 
00065   bool deserialise(ecl::PushAndPop<unsigned char> & byteStream)
00066   {
00067     if (!(byteStream.size() > 0))
00068     {
00069       printf("kobuki_node: kobuki_fw: deserialise failed. empty byte stream.");
00070       return false;
00071     }
00072 
00073     unsigned char header_id = 0, length = 0;
00074     buildVariable(header_id, byteStream);
00075     buildVariable(length, byteStream);
00076 
00077     // TODO First 3 firmware versions coded version number on 2 bytes, so we need convert manually to our new
00078     // 4 bytes system; remove this horrible, dirty hack as soon as we upgrade the firmware to 1.1.2 or 1.2.0
00079     if (length == 2)
00080     {
00081       uint16_t old_style_version = 0;
00082       buildVariable(old_style_version, byteStream);
00083 
00084       if (old_style_version == 123)
00085         data.version = 65536; // 1.0.0
00086       else if ((old_style_version == 10100) || (old_style_version == 110))
00087         data.version = 65792; // 1.1.0
00088       else if ((old_style_version == 10101) || (old_style_version == 111))
00089         data.version = 65793; // 1.1.1
00090     }
00091     else
00092     {
00093       buildVariable(data.version, byteStream);
00094     }
00095 
00096     //showMe();
00097     return constrain();
00098   }
00099 
00100   bool constrain()
00101   {
00102     return true;
00103   }
00104 
00105   void showMe()
00106   {
00107     //printf("--[%02x || %03d | %03d | %03d]\n", data.bump, acc[2], acc[1], acc[0] );
00108   }
00109 
00110   std::string current_version()
00111   {
00112     std::stringstream ss;
00113     ss << CURRENT_FIRMWARE_MAYOR_VERSION << "." << CURRENT_FIRMWARE_MINOR_VERSION << ".x";
00114 
00115     return std::string(ss.str());
00116   }
00117 
00118   int check_mayor_version()
00119   {
00120     // Return a negative value if firmware's mayor version is older than that of the driver,
00121     // 0 if both are the same, and a positive value if firmware's mayor version is newer
00122     uint32_t flashed_version = ((data.version & 0x00FF0000) >> 16);
00123     return flashed_version - CURRENT_FIRMWARE_MAYOR_VERSION;
00124   }
00125 
00126   int check_minor_version()
00127   {
00128     // Return a negative value if firmware's minor version is older than that of the driver,
00129     // 0 if both are the same, and a positive value if firmware's minor version is newer
00130     uint32_t flashed_version = ((data.version & 0x0000FF00) >> 8);
00131     return flashed_version - CURRENT_FIRMWARE_MINOR_VERSION;
00132   }
00133 };
00134 
00135 } // namespace kobuki
00136 
00137 #endif /* KOBUKI_FW_DATA_HPP__ */
00138 


kobuki_driver
Author(s): Daniel Stonier , Younghun Ju , Jorge Santos Simon
autogenerated on Mon Oct 6 2014 01:31:10