ParseApplicationData.cpp
Go to the documentation of this file.
1 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
2 
3 // -- BEGIN LICENSE BLOCK ----------------------------------------------
4 
24 // -- END LICENSE BLOCK ------------------------------------------------
25 
26 //----------------------------------------------------------------------
33 //----------------------------------------------------------------------
34 
36 
37 namespace sick {
38 namespace data_processing {
39 
41 
44  datastructure::Data& data) const
45 {
46  datastructure::ApplicationData application_data;
47 
48  if (!checkIfPreconditionsAreMet(data))
49  {
50  application_data.setIsEmpty(true);
51  return application_data;
52  }
53  // Keep our own copy of the shared_ptr to keep the iterators valid
54  const std::shared_ptr<std::vector<uint8_t> const> vec_ptr = buffer.getBuffer();
55  std::vector<uint8_t>::const_iterator data_ptr =
56  vec_ptr->begin() + data.getDataHeaderPtr()->getApplicationDataBlockOffset();
57 
58  setDataInApplicationData(data_ptr, application_data);
59  return application_data;
60 }
61 
63 {
65  {
66  return false;
67  }
69  {
70  return false;
71  }
72  return true;
73 }
74 
76 {
77  return !(data.getDataHeaderPtr()->getApplicationDataBlockOffset() == 0 &&
78  data.getDataHeaderPtr()->getApplicationDataBlockSize() == 0);
79 }
80 
82  const datastructure::Data& data) const
83 {
84  return !(data.getDataHeaderPtr()->isEmpty());
85 }
86 
88  std::vector<uint8_t>::const_iterator data_ptr,
89  datastructure::ApplicationData& application_data) const
90 {
91  setApplicationInputsInApplicationData(data_ptr, application_data);
92  setApplicationOutputsInApplicationData(data_ptr, application_data);
93 }
94 
96  std::vector<uint8_t>::const_iterator data_ptr,
97  datastructure::ApplicationData& application_data) const
98 {
100  setDataInApplicationInputs(data_ptr, inputs);
101  application_data.setInputs(inputs);
102 }
103 
105  std::vector<uint8_t>::const_iterator data_ptr,
106  datastructure::ApplicationData& application_data) const
107 {
109  setDataInApplicationOutputs(data_ptr, outputs);
110  application_data.setOutputs(outputs);
111 }
112 
114  std::vector<uint8_t>::const_iterator data_ptr, datastructure::ApplicationInputs& inputs) const
115 {
116  setUnsafeInputsInApplicationInputs(data_ptr, inputs);
119  setSleepModeInputInApplicationInputs(data_ptr, inputs);
120 }
121 
123  std::vector<uint8_t>::const_iterator data_ptr, datastructure::ApplicationOutputs& outputs) const
124 {
127  setSleepModeOutputInApplicationOutputs(data_ptr, outputs);
128  setErrorFlagsInApplicationOutputs(data_ptr, outputs);
131  setOutputFlagsinApplicationOutput(data_ptr, outputs);
132 }
133 
135  std::vector<uint8_t>::const_iterator data_ptr, datastructure::ApplicationInputs& inputs) const
136 {
138  setUnsafeInputsFlagsInApplicationInputs(data_ptr, inputs);
139 }
140 
142  std::vector<uint8_t>::const_iterator data_ptr, datastructure::ApplicationInputs& inputs) const
143 {
144  uint32_t word32 = read_write_helper::readUint32LittleEndian(data_ptr + 0);
145  std::vector<bool> input_sources;
146  for (uint8_t i = 0; i < 32; i++)
147  {
148  input_sources.push_back(static_cast<bool>(word32 & (0x01 << i)));
149  }
150  inputs.setUnsafeInputsInputSourcesVector(input_sources);
151 }
152 
154  std::vector<uint8_t>::const_iterator data_ptr, datastructure::ApplicationInputs& inputs) const
155 {
156  uint32_t word32 = read_write_helper::readUint32LittleEndian(data_ptr + 4);
157  std::vector<bool> input_flags;
158  for (uint8_t i = 0; i < 32; i++)
159  {
160  input_flags.push_back(static_cast<bool>(word32 & (0x01 << i)));
161  }
162  inputs.setUnsafeInputsFlagsVector(input_flags);
163 }
164 
166  std::vector<uint8_t>::const_iterator data_ptr, datastructure::ApplicationInputs& inputs) const
167 {
170 }
171 
173  std::vector<uint8_t>::const_iterator data_ptr, datastructure::ApplicationInputs& inputs) const
174 {
175  std::vector<uint16_t> monitoring_cases;
176  for (uint8_t i = 0; i < 20; i++)
177  {
178  monitoring_cases.push_back(read_write_helper::readUint16LittleEndian(data_ptr + 12 + i * 2));
179  }
180  inputs.setMonitoringCaseVector(monitoring_cases);
181 }
182 
183 
185  std::vector<uint8_t>::const_iterator data_ptr, datastructure::ApplicationInputs& inputs) const
186 {
187  uint32_t word32 = read_write_helper::readUint32LittleEndian(data_ptr + 52);
188  std::vector<bool> monitoring_flags;
189  // 20 for each case one
190  for (uint8_t i = 0; i < 20; i++)
191  {
192  monitoring_flags.push_back(static_cast<bool>(word32 & (0x01 << i)));
193  }
194  inputs.setMonitoringCaseFlagsVector(monitoring_flags);
195 }
196 
198  std::vector<uint8_t>::const_iterator data_ptr, datastructure::ApplicationInputs& inputs) const
199 {
200  setLinearVelocity0InApplicationInputs(data_ptr, inputs);
201  setLinearVelocity1InApplicationInputs(data_ptr, inputs);
203 }
204 
206  std::vector<uint8_t>::const_iterator data_ptr, datastructure::ApplicationInputs& inputs) const
207 {
209 }
210 
212  std::vector<uint8_t>::const_iterator data_ptr, datastructure::ApplicationInputs& inputs) const
213 {
215 }
216 
218  std::vector<uint8_t>::const_iterator data_ptr, datastructure::ApplicationInputs& inputs) const
219 {
220  uint8_t word8 = read_write_helper::readUint8LittleEndian(data_ptr + 60);
221 
222  inputs.setVelocity0Valid(static_cast<bool>(word8 & (0x01 << 0)));
223  inputs.setVelocity1Valid(static_cast<bool>(word8 & (0x01 << 1)));
224  // reserved bits 2,3
225  inputs.setVelocity0TransmittedSafely(static_cast<bool>(word8 & (0x01 << 4)));
226  inputs.setVelocity1TransmittedSafely(static_cast<bool>(word8 & (0x01 << 5)));
227 }
228 
230  std::vector<uint8_t>::const_iterator data_ptr, datastructure::ApplicationInputs& inputs) const
231 {
233 }
234 
235 
237  std::vector<uint8_t>::const_iterator data_ptr, datastructure::ApplicationOutputs& outputs) const
238 {
242 }
243 
245  std::vector<uint8_t>::const_iterator data_ptr, datastructure::ApplicationOutputs& outputs) const
246 {
247  uint32_t word32 = read_write_helper::readUint32LittleEndian(data_ptr + 140);
248 
249  std::vector<bool> eval_out;
250  for (uint8_t i = 0; i < 20; i++)
251  {
252  eval_out.push_back(static_cast<bool>(word32 & (0x01 << i)));
253  }
254  outputs.setEvalOutVector(eval_out);
255 }
256 
258  std::vector<uint8_t>::const_iterator data_ptr, datastructure::ApplicationOutputs& outputs) const
259 {
260  uint32_t word32 = read_write_helper::readUint32LittleEndian(data_ptr + 144);
261 
262  std::vector<bool> eval_out_is_safe;
263  for (uint8_t i = 0; i < 20; i++)
264  {
265  eval_out_is_safe.push_back(static_cast<bool>(word32 & (0x01 << i)));
266  }
267  outputs.setEvalOutIsSafeVector(eval_out_is_safe);
268 }
269 
270 
272  std::vector<uint8_t>::const_iterator data_ptr, datastructure::ApplicationOutputs& outputs) const
273 {
274  uint32_t word32 = read_write_helper::readUint32LittleEndian(data_ptr + 148);
275 
276  std::vector<bool> eval_out_is_valid;
277  for (uint8_t i = 0; i < 20; i++)
278  {
279  eval_out_is_valid.push_back(static_cast<bool>(word32 & (0x01 << i)));
280  }
281  outputs.setEvalOutIsValidVector(eval_out_is_valid);
282 }
283 
285  std::vector<uint8_t>::const_iterator data_ptr, datastructure::ApplicationOutputs& outputs) const
286 {
289 }
290 
292  std::vector<uint8_t>::const_iterator data_ptr, datastructure::ApplicationOutputs& outputs) const
293 {
294  std::vector<uint16_t> output_monitoring_cases;
295 
296  for (uint8_t i = 0; i < 20; i++)
297  {
298  output_monitoring_cases.push_back(
299  read_write_helper::readUint16LittleEndian(data_ptr + 152 + i * 2));
300  }
301  outputs.setMonitoringCaseVector(output_monitoring_cases);
302 }
303 
304 
306  std::vector<uint8_t>::const_iterator data_ptr, datastructure::ApplicationOutputs& outputs) const
307 {
308  uint32_t word32 = read_write_helper::readUint32LittleEndian(data_ptr + 192);
309 
310  std::vector<bool> output_monitoring_flags;
311  // 20 for each case one
312  for (uint8_t i = 0; i < 20; i++)
313  {
314  output_monitoring_flags.push_back(static_cast<bool>(word32 & (0x01 << i)));
315  }
316  outputs.setMonitoringCaseFlagsVector(output_monitoring_flags);
317 }
318 
320  std::vector<uint8_t>::const_iterator data_ptr, datastructure::ApplicationOutputs& outputs) const
321 {
323 }
324 
326  std::vector<uint8_t>::const_iterator data_ptr, datastructure::ApplicationOutputs& outputs) const
327 {
328  uint8_t word8 = read_write_helper::readUint8LittleEndian(data_ptr + 194);
329 
330  outputs.setHostErrorFlagContaminationWarning(static_cast<bool>(word8 & (0x01 << 0)));
331  outputs.setHostErrorFlagContaminationError(static_cast<bool>(word8 & (0x01 << 1)));
332  outputs.setHostErrorFlagManipulationError(static_cast<bool>(word8 & (0x01 << 2)));
333  outputs.setHostErrorFlagGlare(static_cast<bool>(word8 & (0x01 << 3)));
334  outputs.setHostErrorFlagReferenceContourIntruded(static_cast<bool>(word8 & (0x01 << 4)));
335  outputs.setHostErrorFlagCriticalError(static_cast<bool>(word8 & (0x01 << 5)));
336 }
337 
339  std::vector<uint8_t>::const_iterator data_ptr, datastructure::ApplicationOutputs& outputs) const
340 {
341  setLinearVelocity0InApplicationOutputs(data_ptr, outputs);
342  setLinearVelocity1InApplicationOutputs(data_ptr, outputs);
344 }
345 
347  std::vector<uint8_t>::const_iterator data_ptr, datastructure::ApplicationOutputs& outputs) const
348 {
350 }
351 
353  std::vector<uint8_t>::const_iterator data_ptr, datastructure::ApplicationOutputs& outputs) const
354 {
356 }
357 
359  std::vector<uint8_t>::const_iterator data_ptr, datastructure::ApplicationOutputs& outputs) const
360 {
361  uint8_t word8 = read_write_helper::readUint8LittleEndian(data_ptr + 204);
362 
363  outputs.setVelocity0Valid(static_cast<bool>(word8 & (0x01 << 0)));
364  outputs.setVelocity1Valid(static_cast<bool>(word8 & (0x01 << 1)));
365  // reserved bits 2,3
366  outputs.setVelocity0TransmittedSafely(static_cast<bool>(word8 & (0x01 << 4)));
367  outputs.setVelocity1TransmittedSafely(static_cast<bool>(word8 & (0x01 << 5)));
368  // reserved bits 6,7
369 }
370 
372  std::vector<uint8_t>::const_iterator data_ptr, datastructure::ApplicationOutputs& outputs) const
373 {
374  setResultingVelocityInApplicationOutputs(data_ptr, outputs);
376 }
377 
379  std::vector<uint8_t>::const_iterator data_ptr, datastructure::ApplicationOutputs& outputs) const
380 {
381  std::vector<int16_t> resulting_velocities;
382  for (uint8_t i = 0; i < 20; i++)
383  {
384  resulting_velocities.push_back(
385  read_write_helper::readInt16LittleEndian(data_ptr + 208 + i * 2));
386  }
387  outputs.setResultingVelocityVector(resulting_velocities);
388 }
389 
391  std::vector<uint8_t>::const_iterator data_ptr, datastructure::ApplicationOutputs& outputs) const
392 {
393  uint32_t word32 = read_write_helper::readUint32LittleEndian(data_ptr + 248);
394 
395  std::vector<bool> resulting_velocities_flags;
396  // 20 for each case one
397  for (uint8_t i = 0; i < 20; i++)
398  {
399  resulting_velocities_flags.push_back(static_cast<bool>(word32 & (0x01 << i)));
400  }
401  outputs.setResultingVelocityIsValidVector(resulting_velocities_flags);
402 }
403 
405  std::vector<uint8_t>::const_iterator data_ptr, datastructure::ApplicationOutputs& outputs) const
406 {
407  uint8_t word8 = read_write_helper::readUint8LittleEndian(data_ptr + 259);
408 
409  outputs.setFlagsSleepModeOutputIsValid(static_cast<bool>(word8 & (0x01 << 0)));
410  outputs.setFlagsHostErrorFlagsAreValid(static_cast<bool>(word8 & (0x01 << 1)));
411 }
412 
413 
414 } // namespace data_processing
415 } // namespace sick
void setLinearVelocity0InApplicationInputs(std::vector< uint8_t >::const_iterator data_ptr, datastructure::ApplicationInputs &inputs) const
void setVelocity1TransmittedSafely(bool velocity_1_transmitted_safely)
Sets if the second linear velocity output is transmitted safely.
void setIsEmpty(bool is_empty)
Sets if application data is empty.
void setHostErrorFlagGlare(bool host_error_flag_glare)
Sets if glare is present.
void setResultingVelocityIsValidVector(const std::vector< bool > &resulting_velocity_is_valid_vector)
Sets if the resulting velocities are valid.
bool checkIfDataContainsNeededParsedBlocks(const datastructure::Data &data) const
void setLinearVelocityOutoutsInApplicationOutputs(std::vector< uint8_t >::const_iterator data_ptr, datastructure::ApplicationOutputs &outputs) const
A packetbuffer for the raw data from the sensor.
Definition: PacketBuffer.h:61
std::shared_ptr< std::vector< uint8_t > const > getBuffer() const
Getter to return a copy of the data saved in the PacketBuffer.
void setUnsafeInputsInApplicationInputs(std::vector< uint8_t >::const_iterator data_ptr, datastructure::ApplicationInputs &inputs) const
void setLinearVelocityFlagsInApplicationInputs(std::vector< uint8_t >::const_iterator data_ptr, datastructure::ApplicationInputs &inputs) const
void setResultingVelocityVector(const std::vector< int16_t > &resulting_velocity_vector)
Sets the resulting velocity for each monitoring case table.
void setVelocity0Valid(bool velocity_0_valid)
Sets if the first linear velocity output is valid.
void setErrorFlagsInApplicationOutputs(std::vector< uint8_t >::const_iterator data_ptr, datastructure::ApplicationOutputs &outputs) const
The applications inputs from a udp data packet.
void setEvaluationPathsOutputsIsSafeInApplicationOutputs(std::vector< uint8_t >::const_iterator data_ptr, datastructure::ApplicationOutputs &outputs) const
void setLinearVelocity1InApplicationInputs(std::vector< uint8_t >::const_iterator data_ptr, datastructure::ApplicationInputs &inputs) const
void setMonitoringCaseVector(const std::vector< uint16_t > &monitoring_case_vector)
Sets the currently active monitoring case numbers.
void setVelocity1(const int16_t &velocity_1)
Sets the second linear velocity input.
void setVelocity0TransmittedSafely(bool velocity_0_transmitted_safely)
Sets if first linear velocity input is transmitted safely.
void setSleepModeOutputInApplicationOutputs(std::vector< uint8_t >::const_iterator data_ptr, datastructure::ApplicationOutputs &outputs) const
void setVelocity1Valid(bool velocity_1_valid)
Sets if the second linear velocity output is valid.
void setApplicationInputsInApplicationData(std::vector< uint8_t >::const_iterator data_ptr, datastructure::ApplicationData &application_data) const
uint8_t readUint8LittleEndian(std::vector< uint8_t >::const_iterator it)
Read an unsigned 8-bit integer at offset in big little encoding.
The data class containing all data blocks of a measurement.
Definition: Data.h:55
The application io class, bundles application input and output.
void setSleepModeOutput(const int8_t &sleep_mode_output)
Sets the state of the sleep mode.
void setDataInApplicationData(std::vector< uint8_t >::const_iterator data_ptr, datastructure::ApplicationData &application_data) const
void setMonitoringCaseVector(const std::vector< uint16_t > &monitoring_case_vector)
Sets the monitoring case vector.
void setVelocity0(const int16_t &velocity_0)
Sets the first linear velocity output.
void setDataInApplicationInputs(std::vector< uint8_t >::const_iterator data_ptr, datastructure::ApplicationInputs &inputs) const
uint32_t readUint32LittleEndian(std::vector< uint8_t >::const_iterator it)
Read an unsigned 32-bit integer at offset in little endian encoding.
void setMonitoringCaseFlagsInApplicationOutputs(std::vector< uint8_t >::const_iterator data_ptr, datastructure::ApplicationOutputs &outputs) const
void setHostErrorFlagReferenceContourIntruded(bool host_error_flag_reference_contour_intruded)
Sets if a reference contour is intruded.
void setVelocity0TransmittedSafely(bool velocity_0_transmitted_safely)
Sets if the first linear velocity output is transmitted safely.
void setEvalOutIsValidVector(const std::vector< bool > &eval_out_is_valid_vector)
Sets if an output path is valid.
void setInputs(const ApplicationInputs &inputs)
Sets the application input.
void setHostErrorFlagContaminationWarning(bool host_error_flag_contamination_warning)
Sets if a contamination warning is present.
void setSleepModeInput(const int8_t &sleep_mode_input)
Sets the state of the sleep mode.
void setHostErrorFlagCriticalError(bool host_error_flag_critical_error)
Sets if a critical error is present.
void setUnsafeInputsFlagsInApplicationInputs(std::vector< uint8_t >::const_iterator data_ptr, datastructure::ApplicationInputs &inputs) const
void setMonitoringCaseNumbersInApplicationOutputs(std::vector< uint8_t >::const_iterator data_ptr, datastructure::ApplicationOutputs &outputs) const
void setVelocity0(const int16_t &velocity_0)
Sets the first linear velocity input.
void setMonitoringCaseInputsInApplicationInputs(std::vector< uint8_t >::const_iterator data_ptr, datastructure::ApplicationInputs &inputs) const
void setEvalOutIsSafeVector(const std::vector< bool > &eval_out_is_safe_vector)
Sets if an cut-off path is safe.
void setFlagsSleepModeOutputIsValid(bool flags_sleep_mode_output_is_valid)
Sets if the sleep mode is valid.
void setMonitoringCaseFlagsVector(const std::vector< bool > &monitoring_case_flags_vector)
Set is the corresponding monitoring case number is valid.
void setHostErrorFlagContaminationError(bool host_error_flag_contamination_error)
Sets if a contamination error is present.
void setHostErrorFlagManipulationError(bool host_error_flag_manipulation_error)
Sets if a manipulation error is present.
void setUnsafeInputsFlagsVector(const std::vector< bool > &unsafe_inputs_flags_vector)
Sets the unsafe input sources flags.
void setEvaluationPathsOutputsValidFlagsInApplicationOutputs(std::vector< uint8_t >::const_iterator data_ptr, datastructure::ApplicationOutputs &outputs) const
void setDataInApplicationOutputs(std::vector< uint8_t >::const_iterator data_ptr, datastructure::ApplicationOutputs &outputs) const
void setResultingVelocityFlagsInApplicationOutputs(std::vector< uint8_t >::const_iterator data_ptr, datastructure::ApplicationOutputs &outputs) const
datastructure::ApplicationData parseUDPSequence(const sick::datastructure::PacketBuffer &buffer, datastructure::Data &data) const
Parses the application data from the packet buffer.
void setVelocity1Valid(bool velocity_1_valid)
If second linear velocity input is valid.
bool checkIfApplicationDataIsPublished(const datastructure::Data &data) const
bool checkIfPreconditionsAreMet(const datastructure::Data &data) const
void setEvalOutVector(const std::vector< bool > &eval_out_vector)
Set the state of the non safe cut-off paths.
void setMonitoringCaseNumbersInApplicationInputs(std::vector< uint8_t >::const_iterator data_ptr, datastructure::ApplicationInputs &inputs) const
void setLinearVelocity0InApplicationOutputs(std::vector< uint8_t >::const_iterator data_ptr, datastructure::ApplicationOutputs &outputs) const
void setApplicationOutputsInApplicationData(std::vector< uint8_t >::const_iterator data_ptr, datastructure::ApplicationData &application_data) const
void setEvalutaionPathsOutputsInApplicationOutputs(std::vector< uint8_t >::const_iterator data_ptr, datastructure::ApplicationOutputs &outputs) const
The application outputs from a udp data packet.
void setOutputFlagsinApplicationOutput(std::vector< uint8_t >::const_iterator data_ptr, datastructure::ApplicationOutputs &outputs) const
void setOutputs(const ApplicationOutputs &outputs)
Sets the application output.
void setVelocity1TransmittedSafely(bool velocity_1_transmitted_safely)
Sets if second linear velocity input is transmitted safely.
void setMonitoringCaseOutputsInApplicationOutputs(std::vector< uint8_t >::const_iterator data_ptr, datastructure::ApplicationOutputs &outputs) const
void setMonitoringCaseFlagsVector(const std::vector< bool > &monitoring_case_flags_vector)
Sets the monitoring case flags.
void setLinearVelocity1InApplicationOutputs(std::vector< uint8_t >::const_iterator data_ptr, datastructure::ApplicationOutputs &outputs) const
void setResultingVelocityOutputsInApplicationOutputs(std::vector< uint8_t >::const_iterator data_ptr, datastructure::ApplicationOutputs &outputs) const
void setFlagsHostErrorFlagsAreValid(bool flags_host_error_flags_are_valid)
Sets if the error flags are valid.
void setLinearVelocityInputsInApplicationInputs(std::vector< uint8_t >::const_iterator data_ptr, datastructure::ApplicationInputs &inputs) const
void setEvaluationPathsOutputsEvalOutInApplicationOutputs(std::vector< uint8_t >::const_iterator data_ptr, datastructure::ApplicationOutputs &outputs) const
std::shared_ptr< DataHeader > getDataHeaderPtr() const
Gets the data header.
Definition: Data.cpp:42
void setUnsafeInputsInputSourcesVector(const std::vector< bool > &unsafe_inputs_input_sources_vector)
Sets the unsafe input sources.
void setVelocity0Valid(bool velocity_0_valid)
Sets if first linear velocity input is valid.
uint16_t readUint16LittleEndian(std::vector< uint8_t >::const_iterator it)
Read an unsigned 16-bit integer at offset in little endian encoding.
void setResultingVelocityInApplicationOutputs(std::vector< uint8_t >::const_iterator data_ptr, datastructure::ApplicationOutputs &outputs) const
void setVelocity1(const int16_t &velocity_1)
Sets the second linear velocity output.
void setLinearVelocityFlagsInApplicationOutputs(std::vector< uint8_t >::const_iterator data_ptr, datastructure::ApplicationOutputs &outputs) const
void setSleepModeInputInApplicationInputs(std::vector< uint8_t >::const_iterator data_ptr, datastructure::ApplicationInputs &inputs) const
void setMonitoringCaseFlagsInApplicationInputs(std::vector< uint8_t >::const_iterator data_ptr, datastructure::ApplicationInputs &inputs) const
int16_t readInt16LittleEndian(std::vector< uint8_t >::const_iterator it)
Read a signed 16-bit integer at offset in little endian encoding.
void setUnsafeInputsSourcesInApplicationInputs(std::vector< uint8_t >::const_iterator data_ptr, datastructure::ApplicationInputs &inputs) const


sick_safetyscanners
Author(s): Lennart Puck
autogenerated on Fri Apr 2 2021 02:45:41