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
uint8_t EIP_USINT
Definition: eip_types.h:36
void addLogicalClass(EIP_USINT class_id)
Definition: path.cpp:59
void addLogicalConnectionPoint(EIP_USINT connection_id)
Definition: path.cpp:74
virtual Writer & serialize(Writer &writer) const
Definition: path.h:137
bool pad_after_length_
Definition: path.h:170
uint8_t EIP_BYTE
Definition: eip_types.h:35
Definition: connection.h:41
Path(bool pad_after_length=false)
Definition: path.cpp:32
void addLogicalInstance(EIP_USINT instance_id)
Definition: path.cpp:64
void addSegment(EIP_USINT type, EIP_USINT data)
Definition: path.cpp:53
virtual size_t getLength() const
Definition: path.cpp:79
void addLogicalAttribute(EIP_USINT attribute_id)
Definition: path.cpp:69
vector< EIP_USINT > path_buf_
Definition: path.h:171


odva_ethernetip
Author(s): Kareem Shehata
autogenerated on Mon Jun 10 2019 14:00:16