ParseMonitoringCaseData.cpp
Go to the documentation of this file.
00001 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
00002 
00003 // -- BEGIN LICENSE BLOCK ----------------------------------------------
00004 
00024 // -- END LICENSE BLOCK ------------------------------------------------
00025 
00026 //----------------------------------------------------------------------
00033 //----------------------------------------------------------------------
00034 
00035 #include <sick_safetyscanners/data_processing/ParseMonitoringCaseData.h>
00036 
00037 #include <sick_safetyscanners/cola2/Command.h>
00038 
00039 namespace sick {
00040 namespace data_processing {
00041 
00042 ParseMonitoringCaseData::ParseMonitoringCaseData()
00043 {
00044   m_reader_ptr = std::make_shared<sick::data_processing::ReadWriteHelper>();
00045 }
00046 
00047 
00048 bool ParseMonitoringCaseData::parseTCPSequence(
00049   const datastructure::PacketBuffer& buffer,
00050   sick::datastructure::MonitoringCaseData& monitoring_case_data) const
00051 {
00052   const uint8_t* data_ptr(buffer.getBuffer().data());
00053   bool valid = isValid(data_ptr);
00054   monitoring_case_data.setIsValid(valid);
00055   if (valid)
00056   {
00057     monitoring_case_data.setMonitoringCaseNumber(readMonitoringCaseNumber(data_ptr));
00058 
00059     std::vector<uint16_t> indices;
00060     std::vector<bool> fields_valid;
00061     for (uint8_t i = 0; i < 8; i++)
00062     {
00063       indices.push_back(readFieldIndex(data_ptr, i));
00064       fields_valid.push_back(readFieldValid(data_ptr, i));
00065     }
00066     monitoring_case_data.setFieldIndices(indices);
00067     monitoring_case_data.setFieldsValid(fields_valid);
00068   }
00069   return true;
00070 }
00071 
00072 bool ParseMonitoringCaseData::isValid(const uint8_t*& data_ptr) const
00073 {
00074   bool res     = false;
00075   uint8_t byte = m_reader_ptr->readuint8_t(data_ptr, 0);
00076   if (byte == 'R' || byte == 'Y')
00077   {
00078     res = true;
00079   }
00080   return res;
00081 }
00082 
00083 uint16_t ParseMonitoringCaseData::readMonitoringCaseNumber(const uint8_t*& data_ptr) const
00084 {
00085   return m_reader_ptr->readuint16_tLittleEndian(data_ptr, 6);
00086 }
00087 
00088 uint16_t ParseMonitoringCaseData::readFieldIndex(const uint8_t*& data_ptr,
00089                                                  const uint8_t index) const
00090 {
00091   return m_reader_ptr->readuint16_tLittleEndian(data_ptr, 158 + (index * 4));
00092 }
00093 
00094 bool ParseMonitoringCaseData::readFieldValid(const uint8_t*& data_ptr, const uint8_t index) const
00095 {
00096   uint8_t byte = m_reader_ptr->readuint8_t(data_ptr, 157 + (index * 4));
00097 
00098   return byte & (0x01 << 0);
00099 }
00100 
00101 } // namespace data_processing
00102 } // namespace sick


sick_safetyscanners
Author(s): Lennart Puck
autogenerated on Tue May 7 2019 03:27:36