ParseMonitoringCaseData.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  const datastructure::PacketBuffer& buffer,
47  sick::datastructure::MonitoringCaseData& monitoring_case_data) const
48 {
49  // Keep our own copy of the shared_ptr to keep the iterators valid
50  const std::shared_ptr<std::vector<uint8_t> const> vec_ptr = buffer.getBuffer();
51  std::vector<uint8_t>::const_iterator data_ptr = vec_ptr->begin();
52  bool valid = isValid(data_ptr);
53  monitoring_case_data.setIsValid(valid);
54  if (valid)
55  {
56  monitoring_case_data.setMonitoringCaseNumber(readMonitoringCaseNumber(data_ptr));
57 
58  std::vector<uint16_t> indices;
59  std::vector<bool> fields_valid;
60  for (uint8_t i = 0; i < 8; i++)
61  {
62  indices.push_back(readFieldIndex(data_ptr, i));
63  fields_valid.push_back(readFieldValid(data_ptr, i));
64  }
65  monitoring_case_data.setFieldIndices(indices);
66  monitoring_case_data.setFieldsValid(fields_valid);
67  }
68  return true;
69 }
70 
71 bool ParseMonitoringCaseData::isValid(std::vector<uint8_t>::const_iterator data_ptr) const
72 {
73  bool res = false;
74  uint8_t byte = read_write_helper::readUint8(data_ptr + 0);
75  if (byte == 'R' || byte == 'Y')
76  {
77  res = true;
78  }
79  return res;
80 }
81 
83  std::vector<uint8_t>::const_iterator data_ptr) const
84 {
85  return read_write_helper::readUint16LittleEndian(data_ptr + 6);
86 }
87 
88 uint16_t ParseMonitoringCaseData::readFieldIndex(std::vector<uint8_t>::const_iterator data_ptr,
89  const uint8_t& index) const
90 {
91  return read_write_helper::readUint16LittleEndian(data_ptr + 158 + (index * 4));
92 }
93 
94 bool ParseMonitoringCaseData::readFieldValid(std::vector<uint8_t>::const_iterator data_ptr,
95  const uint8_t& index) const
96 {
97  uint8_t byte = read_write_helper::readUint8(data_ptr + 157 + (index * 4));
98 
99  return static_cast<bool>(byte & (0x01 << 0));
100 }
101 
102 } // namespace data_processing
103 } // namespace sick
bool parseTCPSequence(const datastructure::PacketBuffer &buffer, datastructure::MonitoringCaseData &monitoring_case_data) const
Parses a tcp sequence and return the monitoring case data.
bool isValid(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.
uint16_t readMonitoringCaseNumber(std::vector< uint8_t >::const_iterator data_ptr) const
void setFieldsValid(const std::vector< bool > &fields_valid)
Sets if the fields are valid.
Stores the data for the different monitoring cases.
void setMonitoringCaseNumber(const uint16_t &monitoring_case_number)
Sets the monitoring case number.
bool readFieldValid(std::vector< uint8_t >::const_iterator data_ptr, const uint8_t &index) const
uint16_t readFieldIndex(std::vector< uint8_t >::const_iterator data_ptr, const uint8_t &index) 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.
void setIsValid(bool is_valid)
Sets if the monitoring case data is valid.
void setFieldIndices(const std::vector< uint16_t > &field_indices)
Sets the field indices.


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