ParseFieldHeaderData.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  datastructure::FieldData& field_data) 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  bool valid = isValid(data_ptr);
52  field_data.setIsValid(valid);
53 
54  if (valid)
55  {
56  setFieldType(data_ptr, field_data);
57  uint16_t set_index = readSetIndex(data_ptr);
58  field_data.setFieldSetIndex(set_index);
59  field_data.setVersionCVersion(readVersionIndicator(data_ptr));
60  field_data.setVersionMajorVersionNumber(readMajorNumber(data_ptr));
61  field_data.setVersionMinorVersionNumber(readMinorNumber(data_ptr));
62  field_data.setVersionReleaseNumber(readReleaseNumber(data_ptr));
63  field_data.setIsDefined(readIsDefined(data_ptr));
64  field_data.setEvalMethod(readEvalMethod(data_ptr));
65  field_data.setMultiSampling(readMultiSampling(data_ptr));
66  field_data.setObjectResolution(readObjectResolution(data_ptr));
67  field_data.setNameLength(readNameLength(data_ptr));
68  field_data.setFieldName(readFieldName(data_ptr));
69  }
70  return true;
71 }
72 
73 bool ParseFieldHeaderData::isValid(std::vector<uint8_t>::const_iterator data_ptr) const
74 {
75  bool res = false;
76  uint8_t byte = read_write_helper::readUint8(data_ptr + 0);
77  if (byte == 'R' || byte == 'Y')
78  {
79  res = true;
80  }
81 
82  return res;
83 }
84 
85 void ParseFieldHeaderData::setFieldType(std::vector<uint8_t>::const_iterator data_ptr,
86  datastructure::FieldData& field_data) const
87 {
88  uint8_t field_type = readEvalMethod(data_ptr);
89  field_data.setIsWarningField(false);
90  field_data.setIsProtectiveField(false);
91  if (field_type == 4 || field_type == 14)
92  {
93  field_data.setIsProtectiveField(true);
94  }
95  else if (field_type == 5 || field_type == 15)
96  {
97  field_data.setIsWarningField(true);
98  }
99 }
100 
101 std::string
102 ParseFieldHeaderData::readVersionIndicator(std::vector<uint8_t>::const_iterator data_ptr) const
103 {
104  std::string result;
105  result.push_back(read_write_helper::readUint8(data_ptr + 0));
106  return result;
107 }
108 
109 uint8_t ParseFieldHeaderData::readMajorNumber(std::vector<uint8_t>::const_iterator data_ptr) const
110 {
111  return read_write_helper::readUint8(data_ptr + 1);
112 }
113 
114 uint8_t ParseFieldHeaderData::readMinorNumber(std::vector<uint8_t>::const_iterator data_ptr) const
115 {
116  return read_write_helper::readUint8(data_ptr + 2);
117 }
118 
119 uint8_t ParseFieldHeaderData::readReleaseNumber(std::vector<uint8_t>::const_iterator data_ptr) const
120 {
121  return read_write_helper::readUint8(data_ptr + 3);
122 }
123 
124 bool ParseFieldHeaderData::readIsDefined(std::vector<uint8_t>::const_iterator data_ptr) const
125 {
126  // TODO
127  return read_write_helper::readUint8(data_ptr + 72);
128 }
129 
130 uint8_t ParseFieldHeaderData::readEvalMethod(std::vector<uint8_t>::const_iterator data_ptr) const
131 {
132  return read_write_helper::readUint8(data_ptr + 73);
133 }
134 
135 
136 uint16_t
137 ParseFieldHeaderData::readMultiSampling(std::vector<uint8_t>::const_iterator data_ptr) const
138 {
139  return read_write_helper::readUint16LittleEndian(data_ptr + 74);
140 }
141 
142 uint16_t
143 ParseFieldHeaderData::readObjectResolution(std::vector<uint8_t>::const_iterator data_ptr) const
144 {
145  return read_write_helper::readUint16LittleEndian(data_ptr + 78);
146 }
147 
148 uint16_t ParseFieldHeaderData::readSetIndex(std::vector<uint8_t>::const_iterator data_ptr) const
149 {
150  return read_write_helper::readUint16LittleEndian(data_ptr + 82);
151 }
152 
153 
154 uint32_t ParseFieldHeaderData::readNameLength(std::vector<uint8_t>::const_iterator data_ptr) const
155 {
156  return read_write_helper::readUint32LittleEndian(data_ptr + 84);
157 }
158 
159 
160 std::string ParseFieldHeaderData::readFieldName(std::vector<uint8_t>::const_iterator data_ptr) const
161 {
162  uint32_t name_length = read_write_helper::readUint32LittleEndian(data_ptr + 84);
163  std::string name;
164  for (uint8_t i = 0; i < name_length; i++)
165  {
166  name.push_back(read_write_helper::readUint8(data_ptr + 88 + i));
167  }
168  return name;
169 }
170 } // namespace data_processing
171 } // namespace sick
void setNameLength(const uint32_t &name_length)
Sets the length of the field name.
Definition: FieldData.cpp:147
void setFieldType(std::vector< uint8_t >::const_iterator data_ptr, datastructure::FieldData &field_data) const
void setMultiSampling(const uint16_t &multi_sampling)
Sets the configured multiple sampling of the field.
Definition: FieldData.cpp:117
void setEvalMethod(const uint8_t &eval_method)
Sets the configured eval method.
Definition: FieldData.cpp:107
uint8_t readMajorNumber(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: FieldData.cpp:87
void setIsValid(bool is_valid)
Sets if the field data is valid.
Definition: FieldData.cpp:47
uint16_t readSetIndex(std::vector< uint8_t >::const_iterator data_ptr) const
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 setIsDefined(bool is_defined)
Sets if the field data is defined.
Definition: FieldData.cpp:97
bool isValid(std::vector< uint8_t >::const_iterator data_ptr) const
std::string readVersionIndicator(std::vector< uint8_t >::const_iterator data_ptr) const
Field data for warning and protective fields.
Definition: FieldData.h:48
void setVersionCVersion(const std::string &version_c_version)
Sets the version indicator for the scanner.
Definition: FieldData.cpp:57
std::string readFieldName(std::vector< uint8_t >::const_iterator data_ptr) const
uint8_t readMinorNumber(std::vector< uint8_t >::const_iterator data_ptr) const
void setIsProtectiveField(bool is_protective_field)
Set if a field is protective field.
Definition: FieldData.cpp:178
uint32_t readUint32LittleEndian(std::vector< uint8_t >::const_iterator it)
Read an unsigned 32-bit integer at offset in little endian encoding.
uint8_t readReleaseNumber(std::vector< uint8_t >::const_iterator data_ptr) const
uint32_t readNameLength(std::vector< uint8_t >::const_iterator data_ptr) const
void setObjectResolution(const uint16_t &object_resolution)
Sets the configured object resolution.
Definition: FieldData.cpp:127
void setIsWarningField(bool is_warning_field)
Set if a field is a warning field.
Definition: FieldData.cpp:168
uint16_t readMultiSampling(std::vector< uint8_t >::const_iterator data_ptr) const
def field_type(f)
void setFieldName(const std::string &field_name)
Sets the field name.
Definition: FieldData.cpp:157
uint16_t readObjectResolution(std::vector< uint8_t >::const_iterator data_ptr) const
void setFieldSetIndex(const uint16_t &field_set_index)
Sets the index of the field set where the field belongs to.
Definition: FieldData.cpp:137
bool readIsDefined(std::vector< uint8_t >::const_iterator data_ptr) const
uint8_t readUint8(std::vector< uint8_t >::const_iterator it)
Read an unsigned 8-bit integer at offset.
uint16_t readUint16LittleEndian(std::vector< uint8_t >::const_iterator it)
Read an unsigned 16-bit integer at offset in little endian encoding.
bool parseTCPSequence(const datastructure::PacketBuffer &buffer, datastructure::FieldData &field_data) const
Parses a tcp sequence to read the header for a warning or protective field.
void setVersionMinorVersionNumber(const uint8_t &version_minor_version_number)
Sets the minor version number for the scanner.
Definition: FieldData.cpp:77
void setVersionMajorVersionNumber(const uint8_t &version_major_version_number)
Sets the major version number for the scanner.
Definition: FieldData.cpp:67
uint8_t readEvalMethod(std::vector< uint8_t >::const_iterator data_ptr) const


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