TCPPacketMerger.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  return m_buffer_vector.empty();
54 }
55 
57 {
58  m_is_complete = false;
60 }
61 
63 {
64  // Protect the internal memory for duplciate calls
65  std::lock_guard<std::mutex> lock(m_buffer_mutex);
66 
67  if (isComplete())
68  {
69  m_is_complete = false;
70  }
71 
72  addToMap(buffer);
74  return isComplete();
75 }
76 
78 {
79  uint32_t current_size = getCurrentSize();
80  uint32_t remaining_size = m_targetSize - current_size;
81  m_buffer_vector.push_back(new_packet);
82  if (remaining_size == new_packet.getLength())
83  {
84  m_is_complete = true;
85  }
86 
87  return isComplete();
88 }
89 
91 {
92  if (isComplete())
93  {
94  deployPacket();
95  return true;
96  }
97  return false;
98 }
99 
101 {
102  std::vector<uint8_t> headerless_packet_buffer;
103  for (auto& parsed_packet_buffer : m_buffer_vector)
104  {
105  // This insert is memory safe because we constructed the vector in this function
106  const std::shared_ptr<std::vector<uint8_t> const> vec_ptr = parsed_packet_buffer.getBuffer();
107  headerless_packet_buffer.insert(
108  headerless_packet_buffer.end(), vec_ptr->begin(), vec_ptr->end());
109  }
110  m_deployed_packet_buffer.setBuffer(headerless_packet_buffer);
111  m_buffer_vector.clear();
112  return true;
113 }
114 
116 {
117  return m_targetSize;
118 }
119 
120 void TCPPacketMerger::setTargetSize(const uint32_t& targetSize)
121 {
122  m_targetSize = targetSize;
123 }
124 
126 {
127  size_t sum = 0;
128  for (auto it_packet = m_buffer_vector.begin(); it_packet != m_buffer_vector.end(); ++it_packet)
129  {
130  const auto& packet = *it_packet;
131  sum += packet.getLength();
132  }
133 
134  return static_cast<uint32_t>(sum);
135 }
136 
137 } // namespace data_processing
138 } // namespace sick
sick::datastructure::PacketBuffer getDeployedPacketBuffer()
Gets the latest complete data packet.
A packetbuffer for the raw data from the sensor.
Definition: PacketBuffer.h:61
bool addTCPPacket(const sick::datastructure::PacketBuffer &buffer)
Adds a new tcp packet to the merger. Returns true if this tcp packet completes a data packet...
bool isEmpty() const
Checks if the buffer vector is empty.
uint32_t getTargetSize() const
Returns the expected target size of a complete data packet.
bool isComplete() const
Check if the packet is complete.
bool addToMap(const sick::datastructure::PacketBuffer &new_packet)
sick::datastructure::PacketBuffer m_deployed_packet_buffer
TCPPacketMerger()
Constructor of merger.
size_t getLength() const
Returns length of the current PacketBuffer.
void setBuffer(const std::vector< uint8_t > &buffer)
Setter for the PacketBuffer.
void setTargetSize(const uint32_t &targetSize)
Sets the target size of a data packet.
std::vector< sick::datastructure::PacketBuffer > m_buffer_vector


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