rr_data.cpp
Go to the documentation of this file.
00001 
00026 #include <boost/shared_ptr.hpp>
00027 #include <boost/make_shared.hpp>
00028 
00029 #include "odva_ethernetip/rr_data.h"
00030 #include "odva_ethernetip/cpf_packet.h"
00031 #include "odva_ethernetip/cpf_item.h"
00032 
00033 using boost::shared_ptr;
00034 using boost::make_shared;
00035 
00036 namespace eip {
00037 
00038 Writer& RRData::serialize(Writer& writer) const
00039 {
00040   writer.write(interface_handle);
00041   writer.write(timeout);
00042   CPFPacket pkt;
00043   pkt.getItems().push_back(CPFItem());
00044   pkt.getItems().push_back(CPFItem(EIP_ITEM_UNCONNECTED_MESSAGE, getData()));
00045   pkt.serialize(writer);
00046   return writer;
00047 }
00048 
00049 Reader& RRData::deserialize(Reader& reader)
00050 {
00051   reader.read(interface_handle);
00052   reader.read(timeout);
00053   CPFPacket pkt;
00054   pkt.deserialize(reader);
00055 
00056   // check that CPF items are correct
00057   if (pkt.getItemCount() < 2)
00058   {
00059     throw std::logic_error("Not enough items in RR Data");
00060   }
00061   if (pkt.getItemCount() > 2)
00062   {
00063     std::cout << "Warning: more than 2 items in RR data response" << std::endl;
00064   }
00065   if (pkt.getItems().at(0).getItemType() != EIP_ITEM_NULL)
00066   {
00067     throw std::logic_error("Address other than null in RR Data");
00068   }
00069   if (pkt.getItems().at(0).getDataLength() != 0)
00070   {
00071     throw std::logic_error("Data length greater than zero in null address type");
00072   }
00073 
00074   if (pkt.getItems().at(1).getItemType() != EIP_ITEM_UNCONNECTED_MESSAGE)
00075   {
00076     throw std::logic_error("Unexpected data type in RR Data");
00077   }
00078 
00079   setData(pkt.getItems().at(1));
00080   return reader;
00081 }
00082 
00083 } // namespace eip


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