00001 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*- 00002 00003 // -- BEGIN LICENSE BLOCK ---------------------------------------------- 00004 00024 // -- END LICENSE BLOCK ------------------------------------------------ 00025 00026 //---------------------------------------------------------------------- 00033 //---------------------------------------------------------------------- 00034 00035 #include <sick_safetyscanners/cola2/MethodCommand.h> 00036 00037 #include <sick_safetyscanners/cola2/Cola2Session.h> 00038 #include <sick_safetyscanners/cola2/Command.h> 00039 00040 namespace sick { 00041 namespace cola2 { 00042 00043 MethodCommand::MethodCommand(Cola2Session& session, const uint16_t& method_index) 00044 : Command(session, 0x4D, 0x49) // see cola2 manual 0x4D = 'M' and 0x49 = 'I' 00045 , m_method_index(method_index) 00046 { 00047 m_writer_ptr = std::make_shared<sick::data_processing::ReadWriteHelper>(); 00048 } 00049 00050 void MethodCommand::addTelegramData(sick::datastructure::PacketBuffer::VectorBuffer& telegram) const 00051 { 00052 uint16_t prevSize = telegram.size(); 00053 telegram.resize(prevSize + 2); 00054 uint8_t* data_ptr = telegram.data() + prevSize; 00055 m_writer_ptr->writeuint16_tLittleEndian(data_ptr, m_method_index, 0); 00056 } 00057 00058 bool MethodCommand::canBeExecutedWithoutSessionID() const 00059 { 00060 return false; 00061 } 00062 00063 bool MethodCommand::processReply() 00064 { 00065 if ((getCommandType() == 'A' && getCommandMode() == 'I') || 00066 (getCommandType() == 0x41 && getCommandMode() == 0x49)) 00067 { 00068 ROS_INFO("Command Method Acknowledged."); 00069 return true; 00070 } 00071 else 00072 { 00073 ROS_WARN("Command Method Not Accepted."); 00074 return false; 00075 } 00076 } 00077 00078 uint16_t MethodCommand::getMethodIndex() const 00079 { 00080 return m_method_index; 00081 } 00082 00083 void MethodCommand::setMethodIndex(const uint16_t& method_index) 00084 { 00085 m_method_index = method_index; 00086 } 00087 00088 } // namespace cola2 00089 } // namespace sick