ParseDerivedValues.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/ParseDerivedValues.h>
00036 
00037 namespace sick {
00038 namespace data_processing {
00039 
00040 ParseDerivedValues::ParseDerivedValues()
00041 {
00042   m_reader_ptr = std::make_shared<sick::data_processing::ReadWriteHelper>();
00043 }
00044 
00045 datastructure::DerivedValues
00046 ParseDerivedValues::parseUDPSequence(const datastructure::PacketBuffer& buffer,
00047                                      datastructure::Data& data) const
00048 {
00049   datastructure::DerivedValues derived_values;
00050 
00051 
00052   if (!checkIfPreconditionsAreMet(data))
00053   {
00054     derived_values.setIsEmpty(true);
00055     return derived_values;
00056   }
00057   const uint8_t* data_ptr(buffer.getBuffer().data() +
00058                           data.getDataHeaderPtr()->getDerivedValuesBlockOffset());
00059   setDataInDerivedValues(data_ptr, derived_values);
00060   return derived_values;
00061 }
00062 
00063 bool ParseDerivedValues::checkIfPreconditionsAreMet(const datastructure::Data& data) const
00064 {
00065   if (!checkIfDerivedValuesIsPublished(data))
00066   {
00067     return false;
00068   }
00069   if (!checkIfDataContainsNeededParsedBlocks(data))
00070   {
00071     return false;
00072   }
00073 
00074   return true;
00075 }
00076 
00077 bool ParseDerivedValues::checkIfDerivedValuesIsPublished(const datastructure::Data& data) const
00078 {
00079   if (data.getDataHeaderPtr()->getDerivedValuesBlockOffset() == 0 &&
00080       data.getDataHeaderPtr()->getDerivedValuesBlockSize() == 0)
00081   {
00082     return false;
00083   }
00084   return true;
00085 }
00086 
00087 bool ParseDerivedValues::checkIfDataContainsNeededParsedBlocks(
00088   const datastructure::Data& data) const
00089 {
00090   if (data.getDataHeaderPtr()->isEmpty())
00091   {
00092     return false;
00093   }
00094   return true;
00095 }
00096 
00097 void ParseDerivedValues::setDataInDerivedValues(const uint8_t*& data_ptr,
00098                                                 datastructure::DerivedValues& derived_values) const
00099 {
00100   setMultiplicationFactorInDerivedValues(data_ptr, derived_values);
00101   setNumberOfBeamsInDerivedValues(data_ptr, derived_values);
00102   setScanTimeInDerivedValues(data_ptr, derived_values);
00103   setStartAngleInDerivedValues(data_ptr, derived_values);
00104   setAngularBeamResolutionInDerivedValues(data_ptr, derived_values);
00105   setInterbeamPeriodInDerivedValues(data_ptr, derived_values);
00106 }
00107 
00108 void ParseDerivedValues::setMultiplicationFactorInDerivedValues(
00109   const uint8_t*& data_ptr, datastructure::DerivedValues& derived_values) const
00110 {
00111   derived_values.setMultiplicationFactor(m_reader_ptr->readuint16_tLittleEndian(data_ptr, 0));
00112 }
00113 
00114 void ParseDerivedValues::setNumberOfBeamsInDerivedValues(
00115   const uint8_t*& data_ptr, datastructure::DerivedValues& derived_values) const
00116 {
00117   derived_values.setNumberOfBeams(m_reader_ptr->readuint16_tLittleEndian(data_ptr, 2));
00118 }
00119 
00120 void ParseDerivedValues::setScanTimeInDerivedValues(
00121   const uint8_t*& data_ptr, datastructure::DerivedValues& derived_values) const
00122 {
00123   derived_values.setScanTime(m_reader_ptr->readuint16_tLittleEndian(data_ptr, 4));
00124 }
00125 
00126 void ParseDerivedValues::setStartAngleInDerivedValues(
00127   const uint8_t*& data_ptr, datastructure::DerivedValues& derived_values) const
00128 {
00129   derived_values.setStartAngle(m_reader_ptr->readint32_tLittleEndian(data_ptr, 8));
00130 }
00131 
00132 void ParseDerivedValues::setAngularBeamResolutionInDerivedValues(
00133   const uint8_t*& data_ptr, datastructure::DerivedValues& derived_values) const
00134 {
00135   derived_values.setAngularBeamResolution(m_reader_ptr->readint32_tLittleEndian(data_ptr, 12));
00136 }
00137 
00138 void ParseDerivedValues::setInterbeamPeriodInDerivedValues(
00139   const uint8_t*& data_ptr, datastructure::DerivedValues& derived_values) const
00140 {
00141   derived_values.setInterbeamPeriod(m_reader_ptr->readuint32_tLittleEndian(data_ptr, 16));
00142 }
00143 
00144 } // namespace data_processing
00145 } // namespace sick


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