rr_data.cpp
Go to the documentation of this file.
1 
26 #include <boost/shared_ptr.hpp>
27 #include <boost/make_shared.hpp>
28 
32 
33 using boost::shared_ptr;
34 using boost::make_shared;
35 
36 namespace eip {
37 
38 Writer& RRData::serialize(Writer& writer) const
39 {
40  writer.write(interface_handle);
41  writer.write(timeout);
42  CPFPacket pkt;
43  pkt.getItems().push_back(CPFItem());
45  pkt.serialize(writer);
46  return writer;
47 }
48 
49 Reader& RRData::deserialize(Reader& reader)
50 {
51  reader.read(interface_handle);
52  reader.read(timeout);
53  CPFPacket pkt;
54  pkt.deserialize(reader);
55 
56  // check that CPF items are correct
57  if (pkt.getItemCount() < 2)
58  {
59  throw std::logic_error("Not enough items in RR Data");
60  }
61  if (pkt.getItemCount() > 2)
62  {
63  std::cout << "Warning: more than 2 items in RR data response" << std::endl;
64  }
65  if (pkt.getItems().at(0).getItemType() != EIP_ITEM_NULL)
66  {
67  throw std::logic_error("Address other than null in RR Data");
68  }
69  if (pkt.getItems().at(0).getDataLength() != 0)
70  {
71  throw std::logic_error("Data length greater than zero in null address type");
72  }
73 
74  if (pkt.getItems().at(1).getItemType() != EIP_ITEM_UNCONNECTED_MESSAGE)
75  {
76  throw std::logic_error("Unexpected data type in RR Data");
77  }
78 
79  setData(pkt.getItems().at(1));
80  return reader;
81 }
82 
83 } // namespace eip
virtual Reader & deserialize(Reader &reader, size_t length)
Definition: rr_data.h:88
virtual void setData(CPFItem &item)
Definition: rr_data.h:116
virtual Writer & serialize(Writer &writer) const
Definition: rr_data.cpp:38
EIP_UINT timeout
Definition: rr_data.h:56
virtual shared_ptr< Serializable > getData() const
Definition: rr_data.h:107
EIP_UDINT interface_handle
Definition: rr_data.h:55
virtual Reader & deserialize(Reader &reader, size_t length)
Definition: cpf_packet.h:89
Definition: connection.h:41
virtual Writer & serialize(Writer &writer) const
Definition: cpf_packet.cpp:46
vector< CPFItem > & getItems()
Definition: cpf_packet.h:66
EIP_UINT getItemCount() const
Definition: cpf_packet.h:57


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