ParseFieldHeaderData.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/ParseFieldHeaderData.h>
00036 
00037 #include <sick_safetyscanners/cola2/Command.h>
00038 
00039 namespace sick {
00040 namespace data_processing {
00041 
00042 ParseFieldHeaderData::ParseFieldHeaderData()
00043 {
00044   m_reader_ptr = std::make_shared<sick::data_processing::ReadWriteHelper>();
00045 }
00046 
00047 
00048 bool ParseFieldHeaderData::parseTCPSequence(const datastructure::PacketBuffer& buffer,
00049                                             datastructure::FieldData& field_data) const
00050 {
00051   const uint8_t* data_ptr(buffer.getBuffer().data());
00052   bool valid = isValid(data_ptr);
00053   field_data.setIsValid(valid);
00054 
00055   if (valid)
00056   {
00057     setFieldType(data_ptr, field_data);
00058     uint16_t set_index = readSetIndex(data_ptr);
00059     field_data.setFieldSetIndex(set_index);
00060   }
00061   return true;
00062 }
00063 
00064 bool ParseFieldHeaderData::isValid(const uint8_t*& data_ptr) const
00065 {
00066   bool res     = false;
00067   uint8_t byte = m_reader_ptr->readuint8_t(data_ptr, 0);
00068   if (byte == 'R' || byte == 'Y')
00069   {
00070     res = true;
00071   }
00072 
00073   return res;
00074 }
00075 
00076 void ParseFieldHeaderData::setFieldType(const uint8_t*& data_ptr,
00077                                         datastructure::FieldData& field_data) const
00078 {
00079   uint8_t field_type = readFieldType(data_ptr);
00080   field_data.setIsWarningField(false);
00081   field_data.setIsProtectiveField(false);
00082   if (field_type == 4 || field_type == 14)
00083   {
00084     field_data.setIsProtectiveField(true);
00085   }
00086   else if (field_type == 5 || field_type == 15)
00087   {
00088     field_data.setIsWarningField(true);
00089   }
00090 }
00091 
00092 
00093 uint8_t ParseFieldHeaderData::readFieldType(const uint8_t*& data_ptr) const
00094 {
00095   return m_reader_ptr->readuint8_t(data_ptr, 73);
00096 }
00097 
00098 uint16_t ParseFieldHeaderData::readSetIndex(const uint8_t*& data_ptr) const
00099 {
00100   return m_reader_ptr->readuint16_tLittleEndian(data_ptr, 82);
00101 }
00102 
00103 
00104 } // namespace data_processing
00105 } // namespace sick


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