ParseFieldSetsData.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 
44 
46  sick::datastructure::FieldSets& field_sets) const
47 {
48  // Keep our own copy of the shared_ptr to keep the iterators valid
49  const std::shared_ptr<std::vector<uint8_t> const> vec_ptr = buffer.getBuffer();
50  std::vector<uint8_t>::const_iterator data_ptr = vec_ptr->begin();
51  field_sets.setVersionCVersion(readVersionIndicator(data_ptr));
52  field_sets.setVersionMajorVersionNumber(readMajorNumber(data_ptr));
53  field_sets.setVersionMinorVersionNumber(readMinorNumber(data_ptr));
54  field_sets.setVersionReleaseNumber(readReleaseNumber(data_ptr));
55  uint32_t array_length = readArrayLength(data_ptr);
56  field_sets.setNameLength(readNameLength(data_ptr, array_length));
57  field_sets.setFieldName(readFieldName(data_ptr, array_length));
58  field_sets.setIsDefined(readIsDefined(data_ptr, array_length));
59  return true;
60 }
61 
62 std::string
63 ParseFieldSetsData::readVersionIndicator(std::vector<uint8_t>::const_iterator data_ptr) const
64 {
65  std::string result;
66  result.push_back(read_write_helper::readUint8(data_ptr + 0));
67  return result;
68 }
69 
70 uint8_t ParseFieldSetsData::readMajorNumber(std::vector<uint8_t>::const_iterator data_ptr) const
71 {
72  return read_write_helper::readUint8(data_ptr + 1);
73 }
74 
75 uint8_t ParseFieldSetsData::readMinorNumber(std::vector<uint8_t>::const_iterator data_ptr) const
76 {
77  return read_write_helper::readUint8(data_ptr + 2);
78 }
79 
80 uint8_t ParseFieldSetsData::readReleaseNumber(std::vector<uint8_t>::const_iterator data_ptr) const
81 {
82  return read_write_helper::readUint8(data_ptr + 3);
83 }
84 
85 uint32_t ParseFieldSetsData::readArrayLength(std::vector<uint8_t>::const_iterator data_ptr) const
86 {
87  return read_write_helper::readUint32LittleEndian(data_ptr + 4);
88 }
89 
90 
91 std::vector<std::string>
92 ParseFieldSetsData::readFieldName(std::vector<uint8_t>::const_iterator data_ptr,
93  uint32_t array_length) const
94 {
95  std::vector<std::string> result;
96  for (uint32_t i = 0; i < array_length; i++)
97  {
98  uint32_t name_length = read_write_helper::readUint32LittleEndian(data_ptr + 8 + i * 104);
99  std::string name;
100  for (uint8_t j = 0; j < name_length; j++)
101  {
102  name.push_back(read_write_helper::readUint8(data_ptr + 12 + i * 104 + j));
103  }
104  result.push_back(name);
105  }
106  return result;
107 }
108 
109 std::vector<uint32_t>
110 ParseFieldSetsData::readNameLength(std::vector<uint8_t>::const_iterator data_ptr,
111  uint32_t array_length) const
112 {
113  std::vector<uint32_t> result;
114  for (uint32_t i = 0; i < array_length; i++)
115  {
116  result.push_back(read_write_helper::readUint32LittleEndian(data_ptr + 8 + i * 104));
117  }
118  return result;
119 }
120 std::vector<bool> ParseFieldSetsData::readIsDefined(std::vector<uint8_t>::const_iterator data_ptr,
121  uint32_t array_length) const
122 {
123  std::vector<bool> result;
124  for (uint32_t i = 0; i < array_length; i++)
125  {
126  uint8_t byte = read_write_helper::readUint8LittleEndian(data_ptr + 44 + i * 104);
127 
128  result.push_back(static_cast<bool>(byte & (0x01 << 0)));
129  }
130  return result;
131 }
132 } // namespace data_processing
133 } // namespace sick
void setFieldName(const std::vector< std::string > &field_name)
Sets the field name for the scanner.
Definition: FieldSets.cpp:97
uint8_t readReleaseNumber(std::vector< uint8_t >::const_iterator data_ptr) const
std::vector< uint32_t > readNameLength(std::vector< uint8_t >::const_iterator data_ptr, uint32_t array_length) const
std::string readVersionIndicator(std::vector< uint8_t >::const_iterator data_ptr) const
Class containing the field name of a laser scanner.
Definition: FieldSets.h:47
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.
uint8_t readMinorNumber(std::vector< uint8_t >::const_iterator data_ptr) const
void setVersionReleaseNumber(const uint8_t &version_release_number)
Sets the version release number for the scanner.
Definition: FieldSets.cpp:77
uint8_t readUint8LittleEndian(std::vector< uint8_t >::const_iterator it)
Read an unsigned 8-bit integer at offset in big little encoding.
uint32_t readUint32LittleEndian(std::vector< uint8_t >::const_iterator it)
Read an unsigned 32-bit integer at offset in little endian encoding.
void setNameLength(const std::vector< uint32_t > &name_length)
Sets the length of the field name.
Definition: FieldSets.cpp:87
void setVersionCVersion(const std::string &version_c_version)
Sets the version indicator for the scanner.
Definition: FieldSets.cpp:47
std::vector< std::string > readFieldName(std::vector< uint8_t >::const_iterator data_ptr, uint32_t array_length) const
void setVersionMinorVersionNumber(const uint8_t &version_minor_version_number)
Sets the minor version number for the scanner.
Definition: FieldSets.cpp:67
void setIsDefined(const std::vector< bool > &is_defined)
Sets if the fields are defined.
Definition: FieldSets.cpp:107
bool parseTCPSequence(const datastructure::PacketBuffer &buffer, datastructure::FieldSets &field_sets) const
Parses a tcp sequence to read the field sets of the sensor.
uint8_t readUint8(std::vector< uint8_t >::const_iterator it)
Read an unsigned 8-bit integer at offset.
std::vector< bool > readIsDefined(std::vector< uint8_t >::const_iterator data_ptr, uint32_t array_length) const
uint8_t readMajorNumber(std::vector< uint8_t >::const_iterator data_ptr) const
void setVersionMajorVersionNumber(const uint8_t &version_major_version_number)
Sets the major version number for the scanner.
Definition: FieldSets.cpp:57
uint32_t readArrayLength(std::vector< uint8_t >::const_iterator data_ptr) const
ParseFieldSetsData()
Constructor of the parser.


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