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  , m_deployed_packet_buffer()
43 {
44 }
45 
46 
48 {
49  return m_is_complete;
50 }
51 
53 {
54  return m_buffer_vector.empty();
55 }
56 
58 {
59  m_is_complete = false;
61 }
62 
64 {
65  if (isComplete())
66  {
67  m_is_complete = false;
68  }
69 
70  addToMap(buffer);
72  return isComplete();
73 }
74 
76 {
77  uint32_t currentSize = getCurrentSize();
78  uint32_t remainingSize = m_targetSize - currentSize;
79  m_buffer_vector.push_back(newPacket);
80  if (remainingSize == newPacket.getLength())
81  {
82  m_is_complete = true;
83  }
84 
85  return isComplete();
86 }
87 
89 {
90  if (isComplete())
91  {
92  deployPacket();
93  return true;
94  }
95  return false;
96 }
97 
99 {
100  sick::datastructure::PacketBuffer::VectorBuffer headerless_packet_buffer;
101  for (auto& parsed_packet_buffer : m_buffer_vector)
102  {
103  sick::datastructure::PacketBuffer packet_buffer = parsed_packet_buffer.getBuffer();
104 
105  headerless_packet_buffer.insert(headerless_packet_buffer.end(),
106  packet_buffer.getBuffer().begin(),
107  packet_buffer.getBuffer().end());
108  }
109  m_deployed_packet_buffer.setBuffer(headerless_packet_buffer);
110  m_buffer_vector.clear();
111  return true;
112 }
113 
115 {
116  return m_targetSize;
117 }
118 
119 void TCPPacketMerger::setTargetSize(const uint32_t& targetSize)
120 {
121  m_targetSize = targetSize;
122 }
123 
125 {
126  size_t sum = 0;
127  for (auto it_packet = m_buffer_vector.begin(); it_packet != m_buffer_vector.end(); ++it_packet)
128  {
129  const auto& packet = *it_packet;
130  sum += packet.getLength();
131  }
132  return static_cast<uint32_t>(sum);
133 }
134 
135 } // namespace data_processing
136 } // 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.
void setBuffer(const VectorBuffer &buffer)
Setter for the PacketBuffer.
bool isComplete() const
Check if the packet is complete.
const VectorBuffer & getBuffer() const
Getter to return the VectorBuffer saved in the PacketBuffer.
sick::datastructure::PacketBuffer m_deployed_packet_buffer
TCPPacketMerger()
Constructor of merger.
size_t getLength() const
Returns length of the current PacketBuffer.
bool addToMap(const sick::datastructure::PacketBuffer &newPacket)
std::vector< uint8_t > VectorBuffer
Typedef for a vector buffer, to sort the incoming packets.
Definition: PacketBuffer.h:71
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 Thu May 9 2019 02:41:08