ParseIntrusionData.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)
45 {
46  datastructure::IntrusionData intrusion_data;
47  if (!checkIfPreconditionsAreMet(data))
48  {
49  intrusion_data.setIsEmpty(true);
50  return intrusion_data;
51  }
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()->getIntrusionDataBlockOffset();
57  setNumScanPoints(data.getDerivedValuesPtr()->getNumberOfBeams());
58  setDataInIntrusionData(data_ptr, intrusion_data);
59  return intrusion_data;
60 }
61 
63 {
65  {
66  return false;
67  }
69  {
70  return false;
71  }
72  return true;
73 }
74 
76 {
77  return !(data.getDataHeaderPtr()->getIntrusionDataBlockOffset() == 0 &&
78  data.getDataHeaderPtr()->getIntrusionDataBlockSize() == 0);
79 }
80 
82  const datastructure::Data& data) const
83 {
84  if (data.getDataHeaderPtr()->isEmpty())
85  {
86  return false;
87  }
88  if (data.getDerivedValuesPtr()->isEmpty())
89  {
90  return false;
91  }
92  return true;
93 }
94 
96 {
97  return m_num_scan_points;
98 }
99 
100 void ParseIntrusionData::setNumScanPoints(const uint16_t& num_scan_points)
101 {
102  m_num_scan_points = num_scan_points;
103 }
104 
105 void ParseIntrusionData::setDataInIntrusionData(std::vector<uint8_t>::const_iterator data_ptr,
106  datastructure::IntrusionData& intrusion_data) const
107 {
108  std::vector<sick::datastructure::IntrusionDatum> intrusion_datums;
109  setDataInIntrusionDatums(data_ptr, intrusion_datums);
110  intrusion_data.setIntrusionDataVector(intrusion_datums);
111 }
112 
114  std::vector<uint8_t>::const_iterator data_ptr,
115  std::vector<sick::datastructure::IntrusionDatum>& intrusion_datums) const
116 {
117  uint16_t offset = 0;
118  // Repeats for 24 CutOffPaths
119  for (uint8_t i_set = 0; i_set < 24; ++i_set)
120  {
122  setSizeInIntrusionDatum(offset, data_ptr, datum);
123  offset += 4;
124  setFlagsInIntrusionDatum(offset, data_ptr, datum);
125  offset += datum.getSize();
126  intrusion_datums.push_back(datum);
127  }
128 }
129 
130 
131 uint16_t
133  std::vector<uint8_t>::const_iterator data_ptr,
135 {
136  uint32_t num_bytes_to_read = read_write_helper::readUint32LittleEndian(data_ptr + offset);
137  datum.setSize(num_bytes_to_read);
138  return offset;
139 }
140 
141 uint16_t
143  std::vector<uint8_t>::const_iterator data_ptr,
145 {
146  uint32_t num_read_flags = 0;
147  std::vector<bool> flags;
148  for (uint16_t num_read_bytes = 0;
149  (num_read_bytes < datum.getSize()) && (num_read_flags < m_num_scan_points);
150  num_read_bytes++)
151  {
152  uint8_t bitset = read_write_helper::readUint8LittleEndian(data_ptr + offset + num_read_bytes);
153  for (uint32_t i_bit = 0; (i_bit < 8) && (num_read_flags < m_num_scan_points);
154  i_bit++, num_read_flags++)
155  {
156  flags.push_back(static_cast<bool>(bitset & (0x01 << i_bit)));
157  }
158  }
159  datum.setFlagsVector(flags);
160  return offset;
161 }
162 
163 } // namespace data_processing
164 } // namespace sick
void setDataInIntrusionDatums(std::vector< uint8_t >::const_iterator data_ptr, std::vector< sick::datastructure::IntrusionDatum > &intrusion_datums) const
bool checkIfIntrusionDataIsPublished(const datastructure::Data &data) const
datastructure::IntrusionData parseUDPSequence(const datastructure::PacketBuffer &buffer, datastructure::Data &data)
Parse a udp sequence to read the intrusion data if enabled.
int32_t getSize() const
Returns size of flag vector.
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 setDataInIntrusionData(std::vector< uint8_t >::const_iterator data_ptr, datastructure::IntrusionData &intrusion_data) const
Class containing a single IntrusionDatum.
uint16_t setSizeInIntrusionDatum(const uint16_t &offset, std::vector< uint8_t >::const_iterator data_ptr, sick::datastructure::IntrusionDatum &datum) const
void setFlagsVector(const std::vector< bool > &flags_vector)
Setter for the flag vector.
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
uint32_t readUint32LittleEndian(std::vector< uint8_t >::const_iterator it)
Read an unsigned 32-bit integer at offset in little endian encoding.
Class containing all IntrusionDatums.
Definition: IntrusionData.h:48
void setIntrusionDataVector(const std::vector< IntrusionDatum > &intrusion_data_vector)
Setter for the vector of IntrusionDatums.
bool checkIfPreconditionsAreMet(const datastructure::Data &data) const
bool checkIfDataContainsNeededParsedBlocks(const datastructure::Data &data) const
uint16_t setFlagsInIntrusionDatum(const uint16_t &offset, std::vector< uint8_t >::const_iterator data_ptr, sick::datastructure::IntrusionDatum &datum) const
std::shared_ptr< DataHeader > getDataHeaderPtr() const
Gets the data header.
Definition: Data.cpp:42
void setIsEmpty(bool is_empty)
Set if intrusion data has been enabled.
void setSize(const int32_t &size)
Setter of the size for the flag vector.
ParseIntrusionData()
Constructor of the parser.
std::shared_ptr< DerivedValues > getDerivedValuesPtr() const
Gets the derived values.
Definition: Data.cpp:64
void setNumScanPoints(const uint16_t &num_scan_points)


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