ParseTCPPacket.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 
38 
39 namespace sick {
40 namespace data_processing {
41 
43 
45 {
46  // Keep our own copy of the shared_ptr to keep the iterators valid
47  const std::shared_ptr<std::vector<uint8_t> const> vec_ptr = buffer.getBuffer();
48  std::vector<uint8_t>::const_iterator data_ptr = vec_ptr->begin();
49  return readLength(data_ptr) + 8; // for STX and Length which is not included in length datafield
50 }
51 
53 {
54  // Keep our own copy of the shared_ptr to keep the iterators valid
55  const std::shared_ptr<std::vector<uint8_t> const> vec_ptr = buffer.getBuffer();
56  std::vector<uint8_t>::const_iterator data_ptr = vec_ptr->begin();
57  return readRequestID(data_ptr);
58 }
59 
60 
62  sick::cola2::Command& command) const
63 {
64  setCommandValuesFromPacket(buffer, command);
65 
66  std::vector<uint8_t> byte_vector = readData(buffer);
67  command.setDataVector(byte_vector);
68 
69  return true;
70 }
71 
73  sick::cola2::Command& command) const
74 {
75  // Keep our own copy of the shared_ptr to keep the iterators valid
76  const std::shared_ptr<std::vector<uint8_t> const> vec_ptr = buffer.getBuffer();
77  std::vector<uint8_t>::const_iterator data_ptr = vec_ptr->begin();
78  command.setSessionID(readSessionID(data_ptr));
79  command.setRequestID(readRequestID(data_ptr));
80  command.setCommandType(readCommandType(data_ptr));
81  command.setCommandMode(readCommandMode(data_ptr));
82 }
83 
84 uint32_t ParseTCPPacket::readSTx(std::vector<uint8_t>::const_iterator data_ptr) const
85 {
86  return read_write_helper::readUint32BigEndian(data_ptr + 0);
87 }
88 
89 uint32_t ParseTCPPacket::readLength(std::vector<uint8_t>::const_iterator data_ptr) const
90 {
91  return read_write_helper::readUint32BigEndian(data_ptr + 4);
92 }
93 
94 uint8_t ParseTCPPacket::readHubCntr(std::vector<uint8_t>::const_iterator data_ptr) const
95 {
96  return read_write_helper::readUint8BigEndian(data_ptr + 8);
97 }
98 uint8_t ParseTCPPacket::readNoC(std::vector<uint8_t>::const_iterator data_ptr) const
99 {
100  return read_write_helper::readUint8BigEndian(data_ptr + 9);
101 }
102 uint32_t ParseTCPPacket::readSessionID(std::vector<uint8_t>::const_iterator data_ptr) const
103 {
104  return read_write_helper::readUint32BigEndian(data_ptr + 10);
105 }
106 
107 uint16_t ParseTCPPacket::readRequestID(std::vector<uint8_t>::const_iterator data_ptr) const
108 {
109  return read_write_helper::readUint16BigEndian(data_ptr + 14);
110 }
111 
112 uint8_t ParseTCPPacket::readCommandType(std::vector<uint8_t>::const_iterator data_ptr) const
113 {
114  return read_write_helper::readUint8BigEndian(data_ptr + 16);
115 }
116 uint8_t ParseTCPPacket::readCommandMode(std::vector<uint8_t>::const_iterator data_ptr) const
117 {
118  return read_write_helper::readUint8BigEndian(data_ptr + 17);
119 }
120 uint16_t ParseTCPPacket::readErrorCode(std::vector<uint8_t>::const_iterator data_ptr) const
121 {
122  return read_write_helper::readUint16BigEndian(data_ptr + 18);
123 }
124 
125 std::vector<uint8_t> ParseTCPPacket::readData(const datastructure::PacketBuffer& buffer) const
126 {
127  if (buffer.getLength() < 20)
128  {
129  return std::vector<uint8_t>();
130  }
131  // Keep our own copy of the shared_ptr to keep the iterators valid
132  const std::shared_ptr<std::vector<uint8_t> const> vec_ptr = buffer.getBuffer();
133  return std::vector<uint8_t>(vec_ptr->begin() + 20, vec_ptr->end());
134 }
135 
136 } // namespace data_processing
137 } // namespace sick
void setCommandMode(const uint8_t &command_mode)
Sets the command mode.
Definition: Command.cpp:96
void setSessionID(const uint32_t &session_id)
Sets the session ID.
Definition: Command.cpp:106
void setDataVector(const std::vector< uint8_t > &data)
Sets the data vector.
Definition: Command.cpp:152
uint8_t readCommandMode(std::vector< uint8_t >::const_iterator data_ptr) const
bool parseTCPSequence(const datastructure::PacketBuffer &buffer, sick::cola2::Command &command) const
Parse the tcp sequence to get the header information of the cola2 protocol.
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 setRequestID(const uint16_t &request_id)
Sets the request ID of the command.
Definition: Command.cpp:116
ParseTCPPacket()
Constructor of parser.
std::vector< uint8_t > readData(const datastructure::PacketBuffer &buffer) const
uint8_t readUint8BigEndian(std::vector< uint8_t >::const_iterator it)
Read an unsigned 8-bit integer at offset in big endian encoding.
void setCommandType(const uint8_t &command_type)
Sets the command type.
Definition: Command.cpp:86
Base class for commands. Defines the base interface and does the common tasks.
Definition: Command.h:61
uint16_t getRequestID(const datastructure::PacketBuffer &buffer) const
Gets the request ID of the incoming tcp packet.
uint32_t readUint32BigEndian(std::vector< uint8_t >::const_iterator it)
Read an unsigned 32-bit integer at offset in big endian encoding.
uint16_t readErrorCode(std::vector< uint8_t >::const_iterator data_ptr) const
uint32_t getExpectedPacketLength(const datastructure::PacketBuffer &buffer)
Gets the expected packet length for a buffer.
uint16_t readUint16BigEndian(std::vector< uint8_t >::const_iterator it)
Read an unsigned 16-bit integer at offset in big endian encoding.
uint8_t readCommandType(std::vector< uint8_t >::const_iterator data_ptr) const
uint8_t readNoC(std::vector< uint8_t >::const_iterator data_ptr) const
uint8_t readHubCntr(std::vector< uint8_t >::const_iterator data_ptr) const
size_t getLength() const
Returns length of the current PacketBuffer.
uint32_t readSessionID(std::vector< uint8_t >::const_iterator data_ptr) const
uint32_t readSTx(std::vector< uint8_t >::const_iterator data_ptr) const
uint32_t readLength(std::vector< uint8_t >::const_iterator data_ptr) const
void setCommandValuesFromPacket(const sick::datastructure::PacketBuffer &buffer, sick::cola2::Command &command) const
uint16_t readRequestID(std::vector< uint8_t >::const_iterator data_ptr) const


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