Go to the documentation of this file.00001
00002
00003
00004
00024
00025
00026
00033
00034
00035 #include <sick_safetyscanners/data_processing/ParseMeasurementData.h>
00036
00037 namespace sick {
00038 namespace data_processing {
00039
00040 ParseMeasurementData::ParseMeasurementData()
00041 {
00042 m_reader_ptr = std::make_shared<sick::data_processing::ReadWriteHelper>();
00043 }
00044
00045 datastructure::MeasurementData
00046 ParseMeasurementData::parseUDPSequence(const datastructure::PacketBuffer& buffer,
00047 datastructure::Data& data)
00048 {
00049 datastructure::MeasurementData measurement_data;
00050 if (!checkIfPreconditionsAreMet(data))
00051 {
00052 measurement_data.setIsEmpty(true);
00053 return measurement_data;
00054 }
00055 const uint8_t* data_ptr(buffer.getBuffer().data() +
00056 data.getDataHeaderPtr()->getMeasurementDataBlockOffset());
00057
00058 setStartAngleAndDelta(data);
00059 setDataInMeasurementData(data_ptr, measurement_data);
00060 return measurement_data;
00061 }
00062
00063 bool ParseMeasurementData::checkIfPreconditionsAreMet(const datastructure::Data& data) const
00064 {
00065 if (!checkIfMeasurementDataIsPublished(data))
00066 {
00067 return false;
00068 }
00069 if (!checkIfDataContainsNeededParsedBlocks(data))
00070 {
00071 return false;
00072 }
00073 return true;
00074 }
00075
00076 bool ParseMeasurementData::checkIfMeasurementDataIsPublished(const datastructure::Data& data) const
00077 {
00078 if (data.getDataHeaderPtr()->getMeasurementDataBlockOffset() == 0 &&
00079 data.getDataHeaderPtr()->getMeasurementDataBlockSize() == 0)
00080 {
00081 return false;
00082 }
00083 return true;
00084 }
00085
00086 bool ParseMeasurementData::checkIfDataContainsNeededParsedBlocks(
00087 const datastructure::Data& data) const
00088 {
00089 if (data.getDataHeaderPtr()->isEmpty())
00090 {
00091 return false;
00092 }
00093 if (data.getDerivedValuesPtr()->isEmpty())
00094 {
00095 return false;
00096 }
00097 return true;
00098 }
00099
00100
00101 void ParseMeasurementData::setDataInMeasurementData(
00102 const uint8_t*& data_ptr, datastructure::MeasurementData& measurement_data)
00103 {
00104 setNumberOfBeamsInMeasurementData(data_ptr, measurement_data);
00105 setScanPointsInMeasurementData(data_ptr, measurement_data);
00106 }
00107
00108 void ParseMeasurementData::setNumberOfBeamsInMeasurementData(
00109 const uint8_t*& data_ptr, datastructure::MeasurementData& measurement_data) const
00110 {
00111 measurement_data.setNumberOfBeams(m_reader_ptr->readuint32_tLittleEndian(data_ptr, 0));
00112 }
00113
00114 void ParseMeasurementData::setStartAngleAndDelta(const datastructure::Data& data)
00115 {
00116 m_angle = data.getDerivedValuesPtr()->getStartAngle();
00117 m_angle_delta = data.getDerivedValuesPtr()->getAngularBeamResolution();
00118 }
00119
00120 void ParseMeasurementData::setScanPointsInMeasurementData(
00121 const uint8_t*& data_ptr, datastructure::MeasurementData& measurement_data)
00122 {
00123 for (size_t i = 0; i < measurement_data.getNumberOfBeams(); i++)
00124 {
00125 addScanPointToMeasurementData(i, data_ptr, measurement_data);
00126 m_angle += m_angle_delta;
00127 }
00128 }
00129
00130 void ParseMeasurementData::addScanPointToMeasurementData(
00131 const uint16_t offset,
00132 const uint8_t*& data_ptr,
00133 datastructure::MeasurementData& measurement_data) const
00134 {
00135 int16_t distance = m_reader_ptr->readuint16_tLittleEndian(data_ptr, (4 + offset * 4));
00136 uint8_t reflectivity = m_reader_ptr->readuint8_tLittleEndian(data_ptr, (6 + offset * 4));
00137 uint8_t status = m_reader_ptr->readuint8_tLittleEndian(data_ptr, (7 + offset * 4));
00138 bool valid = status & (0x01 << 0);
00139 bool infinite = status & (0x01 << 1);
00140 bool glare = status & (0x01 << 2);
00141 bool reflector = status & (0x01 << 3);
00142 bool contamination = status & (0x01 << 4);
00143 bool contamination_warning = status & (0x01 << 5);
00144 measurement_data.addScanPoint(sick::datastructure::ScanPoint(m_angle,
00145 distance,
00146 reflectivity,
00147 valid,
00148 infinite,
00149 glare,
00150 reflector,
00151 contamination,
00152 contamination_warning));
00153 }
00154
00155 }
00156 }