gp_input.hpp
Go to the documentation of this file.
00001 
00009 /*****************************************************************************
00010 ** Preprocessor
00011 *****************************************************************************/
00012 
00013 #ifndef KOBUKI_GP_INPUT_HPP__
00014 #define KOBUKI_GP_INPUT_HPP__
00015 
00016 /*****************************************************************************
00017 ** Include
00018 *****************************************************************************/
00019 
00020 #include <vector>
00021 #include "../packet_handler/payload_base.hpp"
00022 #include "../packet_handler/payload_headers.hpp"
00023 
00024 /*****************************************************************************
00025 ** Namespace
00026 *****************************************************************************/
00027 
00028 namespace kobuki
00029 {
00030 
00031 /*****************************************************************************
00032 ** Interface
00033 *****************************************************************************/
00034 
00035 class GpInput : public packet_handler::payloadBase
00036 {
00037 public:
00038   GpInput() : packet_handler::payloadBase(false, 16) {};
00039   struct Data {
00040     Data() : analog_input(4) {}
00041     uint16_t digital_input;
00047     std::vector<uint16_t> analog_input;
00048   } data;
00049 
00050   bool serialise(ecl::PushAndPop<unsigned char> & byteStream)
00051   {
00052     buildBytes(Header::GpInput, byteStream);
00053     buildBytes(length, byteStream);
00054     buildBytes(data.digital_input, byteStream);
00055     for (unsigned int i = 0; i < data.analog_input.size(); ++i)
00056     {
00057       buildBytes(data.analog_input[i], byteStream);
00058     }
00059     for (unsigned int i = 0; i < 3; ++i)
00060     {
00061       buildBytes(0x0000, byteStream); //dummy
00062     }
00063     return true;
00064   }
00065 
00066   bool deserialise(ecl::PushAndPop<unsigned char> & byteStream)
00067   {
00068     if (byteStream.size() < length+2)
00069     {
00070       //std::cout << "kobuki_node: kobuki_inertia: deserialise failed. not enough byte stream." << std::endl;
00071       return false;
00072     }
00073 
00074     unsigned char header_id, length_packed;
00075     buildVariable(header_id, byteStream);
00076     buildVariable(length_packed, byteStream);
00077     if( header_id != Header::GpInput ) return false;
00078     if( length_packed != length ) return false;
00079 
00080     buildVariable(data.digital_input, byteStream);
00081 
00082     //for (unsigned int i = 0; i < data.analog_input.size(); ++i)
00083     // It's actually sending seven 16-bit variables.
00084     // 0-3 : the analog pin inputs
00085     // 4 : ???
00086     // 5-6 : 0
00087     for (unsigned int i = 0; i < 4; ++i)
00088     {
00089       buildVariable(data.analog_input[i], byteStream);
00090     }
00091     for (unsigned int i = 0; i < 3; ++i) {
00092       uint16_t dummy;
00093       buildVariable(dummy, byteStream);
00094     }
00095 
00096     //showMe();
00097     return constrain();
00098   }
00099 
00100   bool constrain()
00101   {
00102     return true;
00103   }
00104 
00105   void showMe()
00106   {
00107   }
00108 };
00109 
00110 } // namespace kobuki
00111 
00112 #endif /* KOBUKI_GP_INPUT_HPP__ */
00113 


kobuki_driver
Author(s): Daniel Stonier , Younghun Ju , Jorge Santos Simon
autogenerated on Thu Jun 6 2019 20:24:37