path.cpp
Go to the documentation of this file.
00001 
00026 #include "odva_ethernetip/path.h"
00027 
00028 #include <boost/asio.hpp>
00029 
00030 namespace eip {
00031 
00032 Path::Path(bool pad_after_length) : pad_after_length_(pad_after_length)
00033 {
00034   path_buf_.reserve(6);
00035 }
00036 
00037 Path::Path(EIP_USINT class_id, EIP_USINT instance_id, EIP_USINT attribute_id,
00038   bool pad_after_length) : pad_after_length_(pad_after_length)
00039 {
00040   path_buf_.reserve(6);
00041   addLogicalClass(class_id);
00042   addLogicalInstance(instance_id);
00043   addLogicalAttribute(attribute_id);
00044 }
00045 
00046 Path::Path(EIP_USINT class_id, EIP_USINT instance_id) : pad_after_length_(false)
00047 {
00048   path_buf_.reserve(4);
00049   addLogicalClass(class_id);
00050   addLogicalInstance(instance_id);
00051 }
00052 
00053 void Path::addSegment(EIP_USINT type, EIP_USINT data)
00054 {
00055   path_buf_.push_back(type);
00056   path_buf_.push_back(data);
00057 }
00058 
00059 void Path::addLogicalClass(EIP_USINT class_id)
00060 {
00061   addSegment(0x20, class_id);
00062 }
00063 
00064 void Path::addLogicalInstance(EIP_USINT instance_id)
00065 {
00066   addSegment(0x24, instance_id);
00067 }
00068 
00069 void Path::addLogicalAttribute(EIP_USINT attribute_id)
00070 {
00071   addSegment(0x30, attribute_id);
00072 }
00073 
00074 void Path::addLogicalConnectionPoint(EIP_USINT connection_id)
00075 {
00076   addSegment(0x2C, connection_id);
00077 }
00078 
00079 size_t Path::getLength() const
00080 {
00081   return sizeof(EIP_USINT) + path_buf_.size() * sizeof(EIP_USINT) + (pad_after_length_ ? 1 : 0);
00082 }
00083 
00084 Writer& Path::serialize(Writer& writer, bool pad_after_length) const
00085 {
00086   EIP_USINT length = path_buf_.size() / 2;
00087   writer.write(length);
00088   if (pad_after_length)
00089   {
00090     EIP_BYTE reserved = 0;
00091     writer.write(reserved);
00092   }
00093   writer.writeBuffer(boost::asio::buffer(path_buf_));
00094   return writer;
00095 }
00096 
00097 } // namespace eip


odva_ethernetip
Author(s): Kareem Shehata
autogenerated on Sat Jun 8 2019 20:21:23