ParseGeneralSystemState.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/data_processing/ParseGeneralSystemState.h>
00036 
00037 namespace sick {
00038 namespace data_processing {
00039 
00040 ParseGeneralSystemState::ParseGeneralSystemState()
00041 {
00042   m_reader_ptr = std::make_shared<sick::data_processing::ReadWriteHelper>();
00043 }
00044 
00045 datastructure::GeneralSystemState
00046 ParseGeneralSystemState::parseUDPSequence(const datastructure::PacketBuffer& buffer,
00047                                           datastructure::Data& data) const
00048 {
00049   datastructure::GeneralSystemState general_system_state;
00050   if (!checkIfPreconditionsAreMet(data))
00051   {
00052     general_system_state.setIsEmpty(true);
00053     return general_system_state;
00054   }
00055   const uint8_t* data_ptr(buffer.getBuffer().data() +
00056                           data.getDataHeaderPtr()->getGeneralSystemStateBlockOffset());
00057 
00058   setDataInGeneralSystemState(data_ptr, general_system_state);
00059   return general_system_state;
00060 }
00061 
00062 bool ParseGeneralSystemState::checkIfPreconditionsAreMet(const datastructure::Data& data) const
00063 {
00064   if (!checkIfGeneralSystemStateIsPublished(data))
00065   {
00066     return false;
00067   }
00068   if (!checkIfDataContainsNeededParsedBlocks(data))
00069   {
00070     return false;
00071   }
00072 
00073   return true;
00074 }
00075 
00076 bool ParseGeneralSystemState::checkIfGeneralSystemStateIsPublished(
00077   const datastructure::Data& data) const
00078 {
00079   if (data.getDataHeaderPtr()->getGeneralSystemStateBlockOffset() == 0 &&
00080       data.getDataHeaderPtr()->getGeneralSystemStateBlockSize() == 0)
00081   {
00082     return false;
00083   }
00084   return true;
00085 }
00086 
00087 bool ParseGeneralSystemState::checkIfDataContainsNeededParsedBlocks(
00088   const datastructure::Data& data) const
00089 {
00090   if (data.getDataHeaderPtr()->isEmpty())
00091   {
00092     return false;
00093   }
00094   return true;
00095 }
00096 
00097 
00098 void ParseGeneralSystemState::setDataInGeneralSystemState(
00099   const uint8_t*& data_ptr, datastructure::GeneralSystemState& general_system_state) const
00100 {
00101   setStatusBitsInGeneralSystemState(data_ptr, general_system_state);
00102   setSafeCutOffPathInGeneralSystemState(data_ptr, general_system_state);
00103   setNonSafeCutOffPathInGeneralSystemState(data_ptr, general_system_state);
00104   setResetRequiredCutOffPathInGeneralSystemState(data_ptr, general_system_state);
00105   setCurrentMonitoringCasesInGeneralSystemState(data_ptr, general_system_state);
00106   setErrorsInGeneralSystemState(data_ptr, general_system_state);
00107 }
00108 
00109 void ParseGeneralSystemState::setStatusBitsInGeneralSystemState(
00110   const uint8_t*& data_ptr, datastructure::GeneralSystemState& general_system_state) const
00111 {
00112   uint8_t byte = m_reader_ptr->readuint8_tLittleEndian(data_ptr, 0);
00113 
00114   general_system_state.setRunModeActive(static_cast<bool>(byte & (0x01 << 0)));
00115   general_system_state.setStandbyModeActive(static_cast<bool>(byte & (0x01 << 1)));
00116   general_system_state.setContaminationWarning(static_cast<bool>(byte & (0x01 << 2)));
00117   general_system_state.setContaminationError(static_cast<bool>(byte & (0x01 << 3)));
00118   general_system_state.setReferenceContourStatus(static_cast<bool>(byte & (0x01 << 4)));
00119   general_system_state.setManipulationStatus(static_cast<bool>(byte & (0x01 << 5)));
00120   // bit 6 and 7 reserved
00121 }
00122 
00123 void ParseGeneralSystemState::setSafeCutOffPathInGeneralSystemState(
00124   const uint8_t*& data_ptr, datastructure::GeneralSystemState& general_system_state) const
00125 {
00126   std::vector<bool> safe_cut_off_path;
00127 
00128   for (uint8_t i = 0; i < 3; i++)
00129   {
00130     uint8_t byte = m_reader_ptr->readuint8_tLittleEndian(data_ptr, 1 + i);
00131 
00132     for (uint8_t j = 0; j < 8; j++)
00133     {
00134       // as long as there are only 20 instead of 24 cut off paths
00135       if (i == 2 && j > 3)
00136       {
00137         break;
00138       }
00139       safe_cut_off_path.push_back(static_cast<bool>(byte & (0x01 << j)));
00140     }
00141   }
00142   general_system_state.setSafeCutOffPathvector(safe_cut_off_path);
00143 }
00144 
00145 void ParseGeneralSystemState::setNonSafeCutOffPathInGeneralSystemState(
00146   const uint8_t*& data_ptr, datastructure::GeneralSystemState& general_system_state) const
00147 {
00148   std::vector<bool> non_safe_cut_off_path;
00149 
00150   for (uint8_t i = 0; i < 3; i++)
00151   {
00152     uint8_t byte = m_reader_ptr->readuint8_tLittleEndian(data_ptr, 4 + i);
00153 
00154     for (uint8_t j = 0; j < 8; j++)
00155     {
00156       // as long as there are only 20 instead of 24 cut off paths
00157       if (i == 2 && j > 3)
00158       {
00159         break;
00160       }
00161       non_safe_cut_off_path.push_back(static_cast<bool>(byte & (0x01 << j)));
00162     }
00163   }
00164   general_system_state.setNonSafeCutOffPathVector(non_safe_cut_off_path);
00165 }
00166 
00167 void ParseGeneralSystemState::setResetRequiredCutOffPathInGeneralSystemState(
00168   const uint8_t*& data_ptr, datastructure::GeneralSystemState& general_system_state) const
00169 {
00170   std::vector<bool> reset_required_cutoff_path;
00171 
00172   for (uint8_t i = 0; i < 3; i++)
00173   {
00174     uint8_t byte = m_reader_ptr->readuint8_tLittleEndian(data_ptr, 7 + i);
00175 
00176     for (uint8_t j = 0; j < 8; j++)
00177     {
00178       // as long as there are only 20 instead of 24 cut off paths
00179       if (i == 2 && j > 3)
00180       {
00181         break;
00182       }
00183       reset_required_cutoff_path.push_back(static_cast<bool>(byte & (0x01 << j)));
00184     }
00185   }
00186   general_system_state.setResetRequiredCutOffPathVector(reset_required_cutoff_path);
00187 }
00188 
00189 void ParseGeneralSystemState::setCurrentMonitoringCasesInGeneralSystemState(
00190   const uint8_t*& data_ptr, datastructure::GeneralSystemState& general_system_state) const
00191 {
00192   general_system_state.setCurrentMonitoringCaseNoTable_1(
00193     m_reader_ptr->readuint8_tLittleEndian(data_ptr, 10));
00194   general_system_state.setCurrentMonitoringCaseNoTable_2(
00195     m_reader_ptr->readuint8_tLittleEndian(data_ptr, 11));
00196   general_system_state.setCurrentMonitoringCaseNoTable_3(
00197     m_reader_ptr->readuint8_tLittleEndian(data_ptr, 12));
00198   general_system_state.setCurrentMonitoringCaseNoTable_4(
00199     m_reader_ptr->readuint8_tLittleEndian(data_ptr, 13));
00200 }
00201 
00202 void ParseGeneralSystemState::setErrorsInGeneralSystemState(
00203   const uint8_t*& data_ptr, datastructure::GeneralSystemState& general_system_state) const
00204 {
00205   uint8_t byte = m_reader_ptr->readuint8_tLittleEndian(data_ptr, 15);
00206   general_system_state.setApplicationError(static_cast<bool>(byte & (0x01 << 0)));
00207   general_system_state.setDeviceError(static_cast<bool>(byte & (0x01 << 1)));
00208 }
00209 
00210 } // namespace data_processing
00211 } // namespace sick


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