path.cpp
Go to the documentation of this file.
1 
26 #include "odva_ethernetip/path.h"
27 
28 #include <boost/asio.hpp>
29 
30 namespace eip {
31 
32 Path::Path(bool pad_after_length) : pad_after_length_(pad_after_length)
33 {
34  path_buf_.reserve(6);
35 }
36 
37 Path::Path(EIP_USINT class_id, EIP_USINT instance_id, EIP_USINT attribute_id,
38  bool pad_after_length) : pad_after_length_(pad_after_length)
39 {
40  path_buf_.reserve(6);
41  addLogicalClass(class_id);
42  addLogicalInstance(instance_id);
43  addLogicalAttribute(attribute_id);
44 }
45 
46 Path::Path(EIP_USINT class_id, EIP_USINT instance_id) : pad_after_length_(false)
47 {
48  path_buf_.reserve(4);
49  addLogicalClass(class_id);
50  addLogicalInstance(instance_id);
51 }
52 
54 {
55  path_buf_.push_back(type);
56  path_buf_.push_back(data);
57 }
58 
60 {
61  addSegment(0x20, class_id);
62 }
63 
65 {
66  addSegment(0x24, instance_id);
67 }
68 
70 {
71  addSegment(0x30, attribute_id);
72 }
73 
75 {
76  addSegment(0x2C, connection_id);
77 }
78 
79 size_t Path::getLength() const
80 {
81  return sizeof(EIP_USINT) + path_buf_.size() * sizeof(EIP_USINT) + (pad_after_length_ ? 1 : 0);
82 }
83 
84 Writer& Path::serialize(Writer& writer, bool pad_after_length) const
85 {
86  EIP_USINT length = path_buf_.size() / 2;
87  writer.write(length);
88  if (pad_after_length)
89  {
90  EIP_BYTE reserved = 0;
91  writer.write(reserved);
92  }
93  writer.writeBuffer(boost::asio::buffer(path_buf_));
94  return writer;
95 }
96 
97 } // namespace eip
path.h
eip::serialization::Writer
Definition: writer.h:41
eip::Path::path_buf_
vector< EIP_USINT > path_buf_
Definition: path.h:171
eip
Definition: connection.h:41
EIP_BYTE
uint8_t EIP_BYTE
Definition: eip_types.h:35
eip::Path::addLogicalConnectionPoint
void addLogicalConnectionPoint(EIP_USINT connection_id)
Definition: path.cpp:74
eip::Path::addLogicalClass
void addLogicalClass(EIP_USINT class_id)
Definition: path.cpp:59
eip::serialization::Writer::write
void write(const T &v)
Definition: writer.h:50
EIP_USINT
uint8_t EIP_USINT
Definition: eip_types.h:36
eip::Path::pad_after_length_
bool pad_after_length_
Definition: path.h:170
eip::Path::addLogicalInstance
void addLogicalInstance(EIP_USINT instance_id)
Definition: path.cpp:64
eip::Path::Path
Path(bool pad_after_length=false)
Definition: path.cpp:32
eip::Path::addSegment
void addSegment(EIP_USINT type, EIP_USINT data)
Definition: path.cpp:53
eip::Path::getLength
virtual size_t getLength() const
Definition: path.cpp:79
eip::serialization::Writer::writeBuffer
virtual void writeBuffer(const_buffer b)=0
eip::Path::serialize
virtual Writer & serialize(Writer &writer) const
Definition: path.h:137
eip::Path::addLogicalAttribute
void addLogicalAttribute(EIP_USINT attribute_id)
Definition: path.cpp:69


odva_ethernetip
Author(s): Kareem Shehata
autogenerated on Wed Mar 2 2022 00:38:56