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  , m_deployed_packet_buffer()
43 {
44 }
45 
46 
48 {
49  return m_is_complete;
50 }
51 
53 {
54  m_is_complete = false;
56 }
57 
59 {
60  if (isComplete())
61  {
62  m_is_complete = false;
63  }
65  sick::data_processing::ParseDatagramHeader datagram_header_parser;
66  datagram_header_parser.parseUDPSequence(buffer, datagram_header);
67  addToMap(buffer, datagram_header);
68  deployPacketIfComplete(datagram_header);
69 
70  return isComplete();
71 }
72 
74  const datastructure::DatagramHeader& header)
75 {
76  sick::datastructure::ParsedPacketBuffer parsed_packet_buffer(buffer, header);
77  auto it = m_parsed_packet_buffer_map.find(header.getIdentification());
78  if (it != m_parsed_packet_buffer_map.end())
79  {
80  it->second.push_back(parsed_packet_buffer);
81  }
82  else
83  {
85  vec.push_back(parsed_packet_buffer);
87  }
88  return true;
89 }
90 
92 {
93  auto it = m_parsed_packet_buffer_map.find(header.getIdentification());
94 
95  if (it == m_parsed_packet_buffer_map.end())
96  {
97  return false;
98  }
99  if (!checkIfComplete(header))
100  return false;
101 
104  sick::datastructure::PacketBuffer::VectorBuffer headerless_packet_buffer =
106  m_deployed_packet_buffer.setBuffer(headerless_packet_buffer);
107  return true;
108 }
109 
111 {
112  uint32_t total_length = header.getTotalLength();
115  uint32_t cur_length = calcualteCurrentLengthOfParsedPacketBuffer(vec);
116  if (cur_length != total_length)
117  {
118  return false;
119  }
120  m_is_complete = true;
121  return true;
122 }
123 
126 {
127  uint32_t cur_length = 0;
128 
129  for (auto& parsed_packet_buffer : vec)
130  {
131  sick::datastructure::PacketBuffer packet_buffer = parsed_packet_buffer.getPacketBuffer();
132  cur_length += (packet_buffer.getLength() - sick::datastructure::DatagramHeader::HEADER_SIZE);
133  }
134  return cur_length;
135 }
136 
140 {
141  auto it = m_parsed_packet_buffer_map.find(header.getIdentification());
143  std::sort(
145  return vec;
146 }
147 
150 {
151  sick::datastructure::PacketBuffer::VectorBuffer headerless_packet_buffer;
152  for (auto& parsed_packet_buffer : vec)
153  {
154  sick::datastructure::PacketBuffer packet_buffer = parsed_packet_buffer.getPacketBuffer();
155 
156  headerless_packet_buffer.insert(headerless_packet_buffer.end(),
157  packet_buffer.getBuffer().begin() +
159  packet_buffer.getBuffer().end());
160  }
161  return headerless_packet_buffer;
162 }
163 
164 
165 } // namespace data_processing
166 } // 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
bool addToMap(const sick::datastructure::PacketBuffer &buffer, const sick::datastructure::DatagramHeader &header)
bool checkIfComplete(sick::datastructure::DatagramHeader &header)
void setBuffer(const VectorBuffer &buffer)
Setter for the PacketBuffer.
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.
const VectorBuffer & getBuffer() const
Getter to return the VectorBuffer saved in the PacketBuffer.
sick::datastructure::PacketBuffer::VectorBuffer removeHeaderFromParsedPacketBuffer(const sick::datastructure::ParsedPacketBuffer::ParsedPacketBufferVector &vec)
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
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.
std::vector< uint8_t > VectorBuffer
Typedef for a vector buffer, to sort the incoming packets.
Definition: PacketBuffer.h:71
static const uint32_t HEADER_SIZE
Parser for the datagram header.


sick_safetyscanners
Author(s): Lennart Puck
autogenerated on Thu May 9 2019 02:41:08