UDPPacketMerger.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  : m_is_complete(false)
42 {
43 }
44 
45 
47 {
48  return m_is_complete;
49 }
50 
52 {
53  m_is_complete = false;
55 }
56 
58 {
59  // Protect the internal memory for duplciate calls
60  std::lock_guard<std::mutex> lock(m_buffer_mutex);
61 
62  if (isComplete())
63  {
64  m_is_complete = false;
65  }
67  sick::data_processing::ParseDatagramHeader datagram_header_parser;
68  datagram_header_parser.parseUDPSequence(buffer, datagram_header);
69  addToMap(buffer, datagram_header);
70  deployPacketIfComplete(datagram_header);
71 
72  return isComplete();
73 }
74 
76  const datastructure::DatagramHeader& header)
77 {
78  sick::datastructure::ParsedPacketBuffer parsed_packet_buffer(buffer, header);
79  auto it = m_parsed_packet_buffer_map.find(header.getIdentification());
80  if (it != m_parsed_packet_buffer_map.end())
81  {
82  it->second.push_back(parsed_packet_buffer);
83  }
84  else
85  {
87  vec.push_back(parsed_packet_buffer);
89  }
90  return true;
91 }
92 
94 {
95  auto it = m_parsed_packet_buffer_map.find(header.getIdentification());
96 
97  if (it == m_parsed_packet_buffer_map.end())
98  {
99  return false;
100  }
101  if (!checkIfComplete(header))
102  {
103  return false;
104  }
105 
108  std::vector<uint8_t> headerless_packet_buffer = removeHeaderFromParsedPacketBuffer(vec);
109  m_deployed_packet_buffer.setBuffer(headerless_packet_buffer);
111  return true;
112 }
113 
115 {
116  uint32_t total_length = header.getTotalLength();
119  uint32_t cur_length = calcualteCurrentLengthOfParsedPacketBuffer(vec);
120  if (cur_length != total_length)
121  {
122  return false;
123  }
124  m_is_complete = true;
125  return true;
126 }
127 
130 {
131  uint32_t cur_length = 0;
132 
133  for (auto& parsed_packet_buffer : vec)
134  {
135  sick::datastructure::PacketBuffer packet_buffer = parsed_packet_buffer.getPacketBuffer();
136  cur_length += (packet_buffer.getLength() - sick::datastructure::DatagramHeader::HEADER_SIZE);
137  }
138  return cur_length;
139 }
140 
144 {
145  auto it = m_parsed_packet_buffer_map.find(header.getIdentification());
147  std::sort(
149  return vec;
150 }
151 
154 {
155  std::vector<uint8_t> headerless_packet_buffer;
156  for (auto& parsed_packet_buffer : vec)
157  {
158  sick::datastructure::PacketBuffer packet_buffer = parsed_packet_buffer.getPacketBuffer();
159 
160  // This insert is memory safe because we constructed the buffer in this function
161  const std::shared_ptr<std::vector<uint8_t> const> vec_ptr = packet_buffer.getBuffer();
162  headerless_packet_buffer.insert(headerless_packet_buffer.end(),
163  vec_ptr->begin() +
165  vec_ptr->end());
166  }
167  return headerless_packet_buffer;
168 }
169 
170 
171 } // namespace data_processing
172 } // namespace sick
bool deployPacketIfComplete(datastructure::DatagramHeader &header)
sick::datastructure::PacketBuffer getDeployedPacketBuffer()
Get the latest complete data packet.
Struct of a PacketBuffer with a parsed header.
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.
bool addToMap(const sick::datastructure::PacketBuffer &buffer, const sick::datastructure::DatagramHeader &header)
bool checkIfComplete(sick::datastructure::DatagramHeader &header)
bool addUDPPacket(const sick::datastructure::PacketBuffer &buffer)
Adds a udp packet to the packet map, when a data packet is complete it will return true...
bool isComplete() const
Returns if a data packet is complete.
std::map< uint32_t, sick::datastructure::ParsedPacketBuffer::ParsedPacketBufferVector > m_parsed_packet_buffer_map
uint32_t calcualteCurrentLengthOfParsedPacketBuffer(const sick::datastructure::ParsedPacketBuffer::ParsedPacketBufferVector &vec)
UDPPacketMerger()
Constructor of udp packet merger.
static bool sortForIncreasingOffset(const ParsedPacketBuffer &ppb1, const ParsedPacketBuffer &ppb2)
Static function to sort ParsedPacketBuffers.
size_t getLength() const
Returns length of the current PacketBuffer.
uint32_t getIdentification() const
Gets the identification of the data.
sick::datastructure::ParsedPacketBuffer::ParsedPacketBufferVector getSortedParsedPacketBufferForIdentification(const sick::datastructure::DatagramHeader &header)
std::vector< ParsedPacketBuffer > ParsedPacketBufferVector
void setBuffer(const std::vector< uint8_t > &buffer)
Setter for the PacketBuffer.
bool parseUDPSequence(const datastructure::PacketBuffer &buffer, sick::datastructure::DatagramHeader &header) const
Parses the udp sequence to get the identification and the offset for the datagram header...
sick::datastructure::PacketBuffer m_deployed_packet_buffer
Contains the contents of a udp datagram header. Used to match the datagrams together to form a comple...
uint32_t getTotalLength() const
Gets the total length of the data packet.
static const uint32_t HEADER_SIZE
std::vector< uint8_t > removeHeaderFromParsedPacketBuffer(const sick::datastructure::ParsedPacketBuffer::ParsedPacketBufferVector &vec)
Parser for the datagram header.


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