00001
00002
00003
00004
00024
00025
00026
00033
00034
00035 #include <sick_safetyscanners/data_processing/ParseApplicationData.h>
00036
00037 namespace sick {
00038 namespace data_processing {
00039
00040 ParseApplicationData::ParseApplicationData()
00041 {
00042 m_reader_ptr = std::make_shared<sick::data_processing::ReadWriteHelper>();
00043 }
00044
00045 datastructure::ApplicationData
00046 ParseApplicationData::parseUDPSequence(const datastructure::PacketBuffer& buffer,
00047 datastructure::Data& data) const
00048 {
00049 datastructure::ApplicationData application_data;
00050
00051 if (!checkIfPreconditionsAreMet(data))
00052 {
00053 application_data.setIsEmpty(true);
00054 return application_data;
00055 }
00056 const uint8_t* data_ptr(buffer.getBuffer().data() +
00057 data.getDataHeaderPtr()->getApplicationDataBlockOffset());
00058
00059 setDataInApplicationData(data_ptr, application_data);
00060 return application_data;
00061 }
00062
00063 bool ParseApplicationData::checkIfPreconditionsAreMet(const datastructure::Data& data) const
00064 {
00065 if (!checkIfApplicationDataIsPublished(data))
00066 {
00067 return false;
00068 }
00069 if (!checkIfDataContainsNeededParsedBlocks(data))
00070 {
00071 return false;
00072 }
00073 return true;
00074 }
00075
00076 bool ParseApplicationData::checkIfApplicationDataIsPublished(const datastructure::Data& data) const
00077 {
00078 if (data.getDataHeaderPtr()->getApplicationDataBlockOffset() == 0 &&
00079 data.getDataHeaderPtr()->getApplicationDataBlockSize() == 0)
00080 {
00081 return false;
00082 }
00083 return true;
00084 }
00085
00086 bool ParseApplicationData::checkIfDataContainsNeededParsedBlocks(
00087 const datastructure::Data& data) const
00088 {
00089 if (data.getDataHeaderPtr()->isEmpty())
00090 {
00091 return false;
00092 }
00093 return true;
00094 }
00095
00096 void ParseApplicationData::setDataInApplicationData(
00097 const uint8_t*& data_ptr, datastructure::ApplicationData& application_data) const
00098 {
00099 setApplicationInputsInApplicationData(data_ptr, application_data);
00100 setApplicationOutputsInApplicationData(data_ptr, application_data);
00101 }
00102
00103 void ParseApplicationData::setApplicationInputsInApplicationData(
00104 const uint8_t*& data_ptr, datastructure::ApplicationData& application_data) const
00105 {
00106 datastructure::ApplicationInputs inputs;
00107 setDataInApplicationInputs(data_ptr, inputs);
00108 application_data.setInputs(inputs);
00109 }
00110
00111 void ParseApplicationData::setApplicationOutputsInApplicationData(
00112 const uint8_t*& data_ptr, datastructure::ApplicationData& application_data) const
00113 {
00114 datastructure::ApplicationOutputs outputs;
00115 setDataInApplicationOutputs(data_ptr, outputs);
00116 application_data.setOutputs(outputs);
00117 }
00118
00119 void ParseApplicationData::setDataInApplicationInputs(
00120 const uint8_t*& data_ptr, datastructure::ApplicationInputs& inputs) const
00121 {
00122 setUnsafeInputsInApplicationInputs(data_ptr, inputs);
00123 setMonitoringCaseInputsInApplicationInputs(data_ptr, inputs);
00124 setLinearVelocityInputsInApplicationInputs(data_ptr, inputs);
00125 setSleepModeInputInApplicationInputs(data_ptr, inputs);
00126 }
00127
00128 void ParseApplicationData::setDataInApplicationOutputs(
00129 const uint8_t*& data_ptr, datastructure::ApplicationOutputs& outputs) const
00130 {
00131 setEvalutaionPathsOutputsInApplicationOutputs(data_ptr, outputs);
00132 setMonitoringCaseOutputsInApplicationOutputs(data_ptr, outputs);
00133 setSleepModeOutputInApplicationOutputs(data_ptr, outputs);
00134 setErrorFlagsInApplicationOutputs(data_ptr, outputs);
00135 setLinearVelocityOutoutsInApplicationOutputs(data_ptr, outputs);
00136 setResultingVelocityOutputsInApplicationOutputs(data_ptr, outputs);
00137 setOutputFlagsinApplicationOutput(data_ptr, outputs);
00138 }
00139
00140 void ParseApplicationData::setUnsafeInputsInApplicationInputs(
00141 const uint8_t*& data_ptr, datastructure::ApplicationInputs& inputs) const
00142 {
00143 setUnsafeInputsSourcesInApplicationInputs(data_ptr, inputs);
00144 setUnsafeInputsFlagsInApplicationInputs(data_ptr, inputs);
00145 }
00146
00147 void ParseApplicationData::setUnsafeInputsSourcesInApplicationInputs(
00148 const uint8_t*& data_ptr, datastructure::ApplicationInputs& inputs) const
00149 {
00150 uint32_t word32 = m_reader_ptr->readuint32_tLittleEndian(data_ptr, 0);
00151 std::vector<bool> input_sources;
00152 for (uint8_t i = 0; i < 32; i++)
00153 {
00154 input_sources.push_back(static_cast<bool>(word32 & (0x01 << i)));
00155 }
00156 inputs.setUnsafeInputsInputSourcesVector(input_sources);
00157 }
00158
00159 void ParseApplicationData::setUnsafeInputsFlagsInApplicationInputs(
00160 const uint8_t*& data_ptr, datastructure::ApplicationInputs& inputs) const
00161 {
00162 uint32_t word32 = m_reader_ptr->readuint32_tLittleEndian(data_ptr, 4);
00163 std::vector<bool> input_flags;
00164 for (uint8_t i = 0; i < 32; i++)
00165 {
00166 input_flags.push_back(static_cast<bool>(word32 & (0x01 << i)));
00167 }
00168 inputs.setUnsafeInputsFlagsVector(input_flags);
00169 }
00170
00171 void ParseApplicationData::setMonitoringCaseInputsInApplicationInputs(
00172 const uint8_t*& data_ptr, datastructure::ApplicationInputs& inputs) const
00173 {
00174 setMonitoringCaseNumbersInApplicationInputs(data_ptr, inputs);
00175 setMonitoringCaseFlagsInApplicationInputs(data_ptr, inputs);
00176 }
00177
00178 void ParseApplicationData::setMonitoringCaseNumbersInApplicationInputs(
00179 const uint8_t*& data_ptr, datastructure::ApplicationInputs& inputs) const
00180 {
00181 std::vector<uint16_t> monitoring_cases;
00182 for (uint8_t i = 0; i < 20; i++)
00183 {
00184 monitoring_cases.push_back(m_reader_ptr->readuint16_tLittleEndian(data_ptr, 12 + i * 2));
00185 }
00186 inputs.setMonitoringCaseVector(monitoring_cases);
00187 }
00188
00189
00190 void ParseApplicationData::setMonitoringCaseFlagsInApplicationInputs(
00191 const uint8_t*& data_ptr, datastructure::ApplicationInputs& inputs) const
00192 {
00193 uint32_t word32 = m_reader_ptr->readuint32_tLittleEndian(data_ptr, 52);
00194 std::vector<bool> monitoring_flags;
00195
00196 for (uint8_t i = 0; i < 20; i++)
00197 {
00198 monitoring_flags.push_back(static_cast<bool>(word32 & (0x01 << i)));
00199 }
00200 inputs.setMonitoringCaseFlagsVector(monitoring_flags);
00201 }
00202
00203 void ParseApplicationData::setLinearVelocityInputsInApplicationInputs(
00204 const uint8_t*& data_ptr, datastructure::ApplicationInputs& inputs) const
00205 {
00206 setLinearVelocity0InApplicationInputs(data_ptr, inputs);
00207 setLinearVelocity1InApplicationInputs(data_ptr, inputs);
00208 setLinearVelocityFlagsInApplicationInputs(data_ptr, inputs);
00209 }
00210
00211 void ParseApplicationData::setLinearVelocity0InApplicationInputs(
00212 const uint8_t*& data_ptr, datastructure::ApplicationInputs& inputs) const
00213 {
00214 inputs.setVelocity0(m_reader_ptr->readuint16_tLittleEndian(data_ptr, 56));
00215 }
00216
00217 void ParseApplicationData::setLinearVelocity1InApplicationInputs(
00218 const uint8_t*& data_ptr, datastructure::ApplicationInputs& inputs) const
00219 {
00220 inputs.setVelocity1(m_reader_ptr->readuint16_tLittleEndian(data_ptr, 58));
00221 }
00222
00223 void ParseApplicationData::setLinearVelocityFlagsInApplicationInputs(
00224 const uint8_t*& data_ptr, datastructure::ApplicationInputs& inputs) const
00225 {
00226 uint8_t word8 = m_reader_ptr->readuint8_tLittleEndian(data_ptr, 60);
00227
00228 inputs.setVelocity0Valid(static_cast<bool>(word8 & (0x01 << 0)));
00229 inputs.setVelocity1Valid(static_cast<bool>(word8 & (0x01 << 1)));
00230
00231 inputs.setVelocity0TransmittedSafely(static_cast<bool>(word8 & (0x01 << 4)));
00232 inputs.setVelocity1TransmittedSafely(static_cast<bool>(word8 & (0x01 << 5)));
00233 }
00234
00235 void ParseApplicationData::setSleepModeInputInApplicationInputs(
00236 const uint8_t*& data_ptr, datastructure::ApplicationInputs& inputs) const
00237 {
00238 inputs.setSleepModeInput(m_reader_ptr->readuint8_tLittleEndian(data_ptr, 74));
00239 }
00240
00241
00242 void ParseApplicationData::setEvalutaionPathsOutputsInApplicationOutputs(
00243 const uint8_t*& data_ptr, datastructure::ApplicationOutputs& outputs) const
00244 {
00245 setEvaluationPathsOutputsEvalOutInApplicationOutputs(data_ptr, outputs);
00246 setEvaluationPathsOutputsIsSafeInApplicationOutputs(data_ptr, outputs);
00247 setEvaluationPathsOutputsValidFlagsInApplicationOutputs(data_ptr, outputs);
00248 }
00249
00250 void ParseApplicationData::setEvaluationPathsOutputsEvalOutInApplicationOutputs(
00251 const uint8_t*& data_ptr, datastructure::ApplicationOutputs& outputs) const
00252 {
00253 uint32_t word32 = m_reader_ptr->readuint32_tLittleEndian(data_ptr, 140);
00254
00255 std::vector<bool> eval_out;
00256 for (uint8_t i = 0; i < 20; i++)
00257 {
00258 eval_out.push_back(word32 & (0x01 << i));
00259 }
00260 outputs.setEvalOutVector(eval_out);
00261 }
00262
00263 void ParseApplicationData::setEvaluationPathsOutputsIsSafeInApplicationOutputs(
00264 const uint8_t*& data_ptr, datastructure::ApplicationOutputs& outputs) const
00265 {
00266 uint32_t word32 = m_reader_ptr->readuint32_tLittleEndian(data_ptr, 144);
00267
00268 std::vector<bool> eval_out_is_safe;
00269 for (uint8_t i = 0; i < 20; i++)
00270 {
00271 eval_out_is_safe.push_back(word32 & (0x01 << i));
00272 }
00273 outputs.setEvalOutIsSafeVector(eval_out_is_safe);
00274 }
00275
00276
00277 void ParseApplicationData::setEvaluationPathsOutputsValidFlagsInApplicationOutputs(
00278 const uint8_t*& data_ptr, datastructure::ApplicationOutputs& outputs) const
00279 {
00280 uint32_t word32 = m_reader_ptr->readuint32_tLittleEndian(data_ptr, 148);
00281
00282 std::vector<bool> eval_out_is_valid;
00283 for (uint8_t i = 0; i < 20; i++)
00284 {
00285 eval_out_is_valid.push_back(word32 & (0x01 << i));
00286 }
00287 outputs.setEvalOutIsValidVector(eval_out_is_valid);
00288 }
00289
00290 void ParseApplicationData::setMonitoringCaseOutputsInApplicationOutputs(
00291 const uint8_t*& data_ptr, datastructure::ApplicationOutputs& outputs) const
00292 {
00293 setMonitoringCaseNumbersInApplicationOutputs(data_ptr, outputs);
00294 setMonitoringCaseFlagsInApplicationOutputs(data_ptr, outputs);
00295 }
00296
00297 void ParseApplicationData::setMonitoringCaseNumbersInApplicationOutputs(
00298 const uint8_t*& data_ptr, datastructure::ApplicationOutputs& outputs) const
00299 {
00300 std::vector<uint16_t> output_monitoring_cases;
00301
00302 for (uint8_t i = 0; i < 20; i++)
00303 {
00304 output_monitoring_cases.push_back(
00305 m_reader_ptr->readuint16_tLittleEndian(data_ptr, 152 + i * 2));
00306 }
00307 outputs.setMonitoringCaseVector(output_monitoring_cases);
00308 }
00309
00310
00311 void ParseApplicationData::setMonitoringCaseFlagsInApplicationOutputs(
00312 const uint8_t*& data_ptr, datastructure::ApplicationOutputs& outputs) const
00313 {
00314 uint32_t word32 = m_reader_ptr->readuint32_tLittleEndian(data_ptr, 192);
00315
00316 std::vector<bool> output_monitoring_flags;
00317
00318 for (uint8_t i = 0; i < 20; i++)
00319 {
00320 output_monitoring_flags.push_back(static_cast<bool>(word32 & (0x01 << i)));
00321 }
00322 outputs.setMonitoringCaseFlagsVector(output_monitoring_flags);
00323 }
00324
00325 void ParseApplicationData::setSleepModeOutputInApplicationOutputs(
00326 const uint8_t*& data_ptr, datastructure::ApplicationOutputs& outputs) const
00327 {
00328 outputs.setSleepModeOutput(m_reader_ptr->readuint8_tLittleEndian(data_ptr, 193));
00329 }
00330
00331 void ParseApplicationData::setErrorFlagsInApplicationOutputs(
00332 const uint8_t*& data_ptr, datastructure::ApplicationOutputs& outputs) const
00333 {
00334 uint8_t word8 = m_reader_ptr->readuint8_tLittleEndian(data_ptr, 194);
00335
00336 outputs.setHostErrorFlagContaminationWarning(static_cast<bool>(word8 & (0x01 << 0)));
00337 outputs.setHostErrorFlagContaminationError(static_cast<bool>(word8 & (0x01 << 1)));
00338 outputs.setHostErrorFlagManipulationError(static_cast<bool>(word8 & (0x01 << 2)));
00339 outputs.setHostErrorFlagGlare(static_cast<bool>(word8 & (0x01 << 3)));
00340 outputs.setHostErrorFlagReferenceContourIntruded(static_cast<bool>(word8 & (0x01 << 4)));
00341 outputs.setHostErrorFlagCriticalError(static_cast<bool>(word8 & (0x01 << 5)));
00342 }
00343
00344 void ParseApplicationData::setLinearVelocityOutoutsInApplicationOutputs(
00345 const uint8_t*& data_ptr, datastructure::ApplicationOutputs& outputs) const
00346 {
00347 setLinearVelocity0InApplicationOutputs(data_ptr, outputs);
00348 setLinearVelocity1InApplicationOutputs(data_ptr, outputs);
00349 setLinearVelocityFlagsInApplicationOutputs(data_ptr, outputs);
00350 }
00351
00352 void ParseApplicationData::setLinearVelocity0InApplicationOutputs(
00353 const uint8_t*& data_ptr, datastructure::ApplicationOutputs& outputs) const
00354 {
00355 outputs.setVelocity0(m_reader_ptr->readuint16_tLittleEndian(data_ptr, 200));
00356 }
00357
00358 void ParseApplicationData::setLinearVelocity1InApplicationOutputs(
00359 const uint8_t*& data_ptr, datastructure::ApplicationOutputs& outputs) const
00360 {
00361 outputs.setVelocity1(m_reader_ptr->readuint16_tLittleEndian(data_ptr, 202));
00362 }
00363
00364 void ParseApplicationData::setLinearVelocityFlagsInApplicationOutputs(
00365 const uint8_t*& data_ptr, datastructure::ApplicationOutputs& outputs) const
00366 {
00367 uint8_t word8 = m_reader_ptr->readuint8_tLittleEndian(data_ptr, 204);
00368
00369 outputs.setVelocity0Valid(static_cast<bool>(word8 & (0x01 << 0)));
00370 outputs.setVelocity1Valid(static_cast<bool>(word8 & (0x01 << 1)));
00371
00372 outputs.setVelocity0TransmittedSafely(static_cast<bool>(word8 & (0x01 << 4)));
00373 outputs.setVelocity1TransmittedSafely(static_cast<bool>(word8 & (0x01 << 5)));
00374
00375 }
00376
00377 void ParseApplicationData::setResultingVelocityOutputsInApplicationOutputs(
00378 const uint8_t*& data_ptr, datastructure::ApplicationOutputs& outputs) const
00379 {
00380 setResultingVelocityInApplicationOutputs(data_ptr, outputs);
00381 setResultingVelocityFlagsInApplicationOutputs(data_ptr, outputs);
00382 }
00383
00384 void ParseApplicationData::setResultingVelocityInApplicationOutputs(
00385 const uint8_t*& data_ptr, datastructure::ApplicationOutputs& outputs) const
00386 {
00387 std::vector<int16_t> resulting_velocities;
00388 for (uint8_t i = 0; i < 20; i++)
00389 {
00390 resulting_velocities.push_back(m_reader_ptr->readint16_tLittleEndian(data_ptr, 208 + i * 2));
00391 }
00392 outputs.setResultingVelocityVector(resulting_velocities);
00393 }
00394
00395 void ParseApplicationData::setResultingVelocityFlagsInApplicationOutputs(
00396 const uint8_t*& data_ptr, datastructure::ApplicationOutputs& outputs) const
00397 {
00398 uint32_t word32 = m_reader_ptr->readuint32_tLittleEndian(data_ptr, 248);
00399
00400 std::vector<bool> resulting_velocities_flags;
00401
00402 for (uint8_t i = 0; i < 20; i++)
00403 {
00404 resulting_velocities_flags.push_back(static_cast<bool>(word32 & (0x01 << i)));
00405 }
00406 outputs.setResultingVelocityIsValidVector(resulting_velocities_flags);
00407 }
00408
00409 void ParseApplicationData::setOutputFlagsinApplicationOutput(
00410 const uint8_t*& data_ptr, datastructure::ApplicationOutputs& outputs) const
00411 {
00412 uint8_t word8 = m_reader_ptr->readuint8_tLittleEndian(data_ptr, 259);
00413
00414 outputs.setFlagsSleepModeOutputIsValid(static_cast<bool>(word8 & (0x01 << 0)));
00415 outputs.setFlagsHostErrorFlagsAreValid(static_cast<bool>(word8 & (0x01 << 1)));
00416 }
00417
00418
00419 }
00420 }