Command.cpp
Go to the documentation of this file.
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/Command.h>
00036 
00037 #include <sick_safetyscanners/cola2/Cola2Session.h>
00038 
00039 
00040 namespace sick {
00041 namespace cola2 {
00042 
00043 Command::Command(Cola2Session& session, const uint16_t& command_type, const uint16_t& command_mode)
00044   : m_session(session)
00045   , m_command_mode(command_mode)
00046   , m_command_type(command_type)
00047 {
00048   m_session_id     = m_session.getSessionID();
00049   m_request_id     = m_session.getNextRequestID();
00050   m_tcp_parser_ptr = std::make_shared<sick::data_processing::ParseTCPPacket>();
00051   m_writer_ptr     = std::make_shared<sick::data_processing::ReadWriteHelper>();
00052 }
00053 
00054 void Command::lockExecutionMutex()
00055 {
00056   m_execution_mutex.lock();
00057 }
00058 
00059 void Command::constructTelegram(datastructure::PacketBuffer::VectorBuffer& telegram) const
00060 {
00061   addTelegramData(telegram);
00062   addTelegramHeader(telegram);
00063 }
00064 
00065 void Command::processReplyBase(const datastructure::PacketBuffer::VectorBuffer& packet)
00066 {
00067   m_tcp_parser_ptr->parseTCPSequence(packet, *this);
00068   m_was_successful = processReply();
00069   m_execution_mutex.unlock();
00070 }
00071 
00072 void Command::waitForCompletion()
00073 {
00074   boost::mutex::scoped_lock lock(m_execution_mutex);
00075 }
00076 
00077 bool Command::wasSuccessful() const
00078 {
00079   return m_was_successful;
00080 }
00081 
00082 uint8_t Command::getCommandType() const
00083 {
00084   return m_command_type;
00085 }
00086 
00087 void Command::setCommandType(const uint8_t& command_type)
00088 {
00089   m_command_type = command_type;
00090 }
00091 
00092 uint8_t Command::getCommandMode() const
00093 {
00094   return m_command_mode;
00095 }
00096 
00097 void Command::setCommandMode(const uint8_t& command_mode)
00098 {
00099   m_command_mode = command_mode;
00100 }
00101 
00102 uint32_t Command::getSessionID() const
00103 {
00104   return m_session_id;
00105 }
00106 
00107 void Command::setSessionID(const uint32_t& session_id)
00108 {
00109   m_session_id = session_id;
00110 }
00111 
00112 uint16_t Command::getRequestID() const
00113 {
00114   return m_request_id;
00115 }
00116 
00117 void Command::setRequestID(const uint16_t& request_id)
00118 {
00119   m_request_id = request_id;
00120 }
00121 
00122 void Command::addTelegramHeader(datastructure::PacketBuffer::VectorBuffer& telegram) const
00123 {
00124   datastructure::PacketBuffer::VectorBuffer header = prepareHeader();
00125   uint8_t* data_ptr                                = header.data();
00126   writeDataToDataPtr(data_ptr, telegram);
00127   telegram.insert(telegram.begin(), header.begin(), header.end());
00128 }
00129 
00130 sick::datastructure::PacketBuffer::VectorBuffer Command::prepareHeader() const
00131 {
00132   datastructure::PacketBuffer::VectorBuffer header;
00133   header.resize(18);
00134   return header;
00135 }
00136 
00137 std::vector<uint8_t> Command::getDataVector() const
00138 {
00139   return m_data_vector;
00140 }
00141 
00142 void Command::setDataVector(const std::vector<uint8_t>& data)
00143 {
00144   m_data_vector = data;
00145 }
00146 
00147 void Command::writeDataToDataPtr(uint8_t*& data_ptr,
00148                                  datastructure::PacketBuffer::VectorBuffer& telegram) const
00149 {
00150   writeCola2StxToDataPtr(data_ptr);
00151   writeLengthToDataPtr(data_ptr, telegram);
00152   writeCola2HubCntrToDataPtr(data_ptr);
00153   writeCola2NoCToDataPtr(data_ptr);
00154   writeSessionIdToDataPtr(data_ptr);
00155   writeRequestIdToDataPtr(data_ptr);
00156   writeCommandTypeToDataPtr(data_ptr);
00157   writeCommandModeToDataPtr(data_ptr);
00158 }
00159 
00160 void Command::writeCola2StxToDataPtr(uint8_t*& data_ptr) const
00161 {
00162   uint32_t cola2_stx = 0x02020202;
00163   m_writer_ptr->writeuint32_tBigEndian(data_ptr, cola2_stx, 0);
00164 }
00165 
00166 void Command::writeLengthToDataPtr(uint8_t*& data_ptr,
00167                                    datastructure::PacketBuffer::VectorBuffer& telegram) const
00168 {
00169   uint32_t length = 10 + telegram.size();
00170   m_writer_ptr->writeuint32_tBigEndian(data_ptr, length, 4);
00171 }
00172 
00173 void Command::writeCola2HubCntrToDataPtr(uint8_t*& data_ptr) const
00174 {
00175   uint8_t cola2_hub_cntr = 0x00;
00176   m_writer_ptr->writeuint8_tBigEndian(data_ptr, cola2_hub_cntr, 8);
00177 }
00178 
00179 void Command::writeCola2NoCToDataPtr(uint8_t*& data_ptr) const
00180 {
00181   uint8_t cola2_noc = 0x00;
00182   m_writer_ptr->writeuint8_tBigEndian(data_ptr, cola2_noc, 9);
00183 }
00184 
00185 void Command::writeSessionIdToDataPtr(uint8_t*& data_ptr) const
00186 {
00187   m_writer_ptr->writeuint32_tBigEndian(data_ptr, getSessionID(), 10);
00188 }
00189 
00190 void Command::writeRequestIdToDataPtr(uint8_t*& data_ptr) const
00191 {
00192   m_writer_ptr->writeuint16_tBigEndian(data_ptr, getRequestID(), 14);
00193 }
00194 
00195 void Command::writeCommandTypeToDataPtr(uint8_t*& data_ptr) const
00196 {
00197   m_writer_ptr->writeuint8_tBigEndian(data_ptr, getCommandType(), 16);
00198 }
00199 
00200 void Command::writeCommandModeToDataPtr(uint8_t*& data_ptr) const
00201 {
00202   m_writer_ptr->writeuint8_tBigEndian(data_ptr, getCommandMode(), 17);
00203 }
00204 
00205 } // namespace cola2
00206 } // namespace sick


sick_safetyscanners
Author(s): Lennart Puck
autogenerated on Tue May 7 2019 03:27:36