Go to the documentation of this file.00001
00026 #include "odva_ethernetip/connection.h"
00027
00028 #include <boost/make_shared.hpp>
00029 #include <iostream>
00030
00031 using std::cout;
00032 using std::endl;
00033 using boost::shared_ptr;
00034 using boost::make_shared;
00035
00036 namespace eip {
00037
00038 Connection::Connection(const EIP_CONNECTION_INFO_T& o_to_t, const EIP_CONNECTION_INFO_T& t_to_o)
00039 {
00040 o_to_t_rpi = o_to_t.rpi;
00041 t_to_o_rpi = t_to_o.rpi;
00042 o_to_t_buffer_size = o_to_t.buffer_size;
00043 t_to_o_buffer_size = t_to_o.buffer_size;
00044 timeout_tick_size = 6;
00045 timeout_ticks = 80;
00046 timeout_multiplyer = 0;
00047 o_to_t_api = 0;
00048 t_to_o_api = 0;
00049 setConnectionPoints(o_to_t.assembly_id, t_to_o.assembly_id);
00050 }
00051
00052 void Connection::setConnectionPoints(EIP_USINT origin, EIP_USINT target)
00053 {
00054 path_.reset();
00055 path_.addLogicalClass(0x04);
00056 path_.addLogicalInstance(1);
00057 path_.addLogicalConnectionPoint(origin);
00058 path_.addLogicalConnectionPoint(target);
00059 }
00060
00061 shared_ptr<ForwardOpenRequest> Connection::createForwardOpenRequest()
00062 {
00063 shared_ptr<ForwardOpenRequest> req = make_shared<ForwardOpenRequest> ();
00064
00065 req->originator_vendor_id = originator_vendor_id;
00066 req->originator_sn = originator_sn;
00067 req->connection_sn = connection_sn;
00068
00069 req->o_to_t_connection_id = o_to_t_connection_id;
00070 req->t_to_o_connection_id = t_to_o_connection_id;
00071
00072 req->timeout_tick_size = timeout_tick_size;
00073 req->timeout_ticks = timeout_ticks;
00074 req->timeout_multiplyer = timeout_multiplyer;
00075
00076 req->o_to_t_rpi = o_to_t_rpi;
00077 req->t_to_o_rpi = t_to_o_rpi;
00078 req->conn_type = 1;
00079
00080
00081 req->setOriginToTargetParams(o_to_t_buffer_size, false, CONN_PRIORITY_SCHEDULED, CONN_TYPE_P2P, false);
00082 req->setTargetToOriginParams(t_to_o_buffer_size, true, CONN_PRIORITY_SCHEDULED, CONN_TYPE_P2P, false);
00083
00084 req->getPath() = path_;
00085 return req;
00086 }
00087
00088 shared_ptr<ForwardCloseRequest> Connection::createForwardCloseRequest()
00089 {
00090 shared_ptr<ForwardCloseRequest> req = make_shared<ForwardCloseRequest> ();
00091
00092 req->originator_vendor_id = originator_vendor_id;
00093 req->originator_sn = originator_sn;
00094 req->connection_sn = connection_sn;
00095
00096 req->timeout_tick_size = timeout_tick_size;
00097 req->timeout_ticks = timeout_ticks;
00098
00099
00100
00101 req->getPath() = Path(0x02, 0x01);
00102 return req;
00103 }
00104
00105 bool Connection::verifyForwardOpenResult(const ForwardOpenSuccess& result)
00106 {
00107 if (result.connection_sn != connection_sn
00108 || result.originator_vendor_id != originator_vendor_id
00109 || result.originator_sn != originator_sn)
00110 {
00111 return false;
00112 }
00113 if (result.o_to_t_connection_id != o_to_t_connection_id)
00114 {
00115 cout << "Replacing our o_to_t connection ID (" << o_to_t_connection_id
00116 << ") with connection ID provided by target ("
00117 << result.o_to_t_connection_id << ")" << endl;
00118 o_to_t_connection_id = result.o_to_t_connection_id;
00119 }
00120 if (result.t_to_o_connection_id != t_to_o_connection_id)
00121 {
00122 cout << "Replacing our t_to_o connection ID (" << t_to_o_connection_id
00123 << ") with connection ID provided by target ("
00124 << result.t_to_o_connection_id << ")" << endl;
00125 t_to_o_connection_id = result.t_to_o_connection_id;
00126 }
00127 o_to_t_api = result.o_to_t_api;
00128 t_to_o_api = result.t_to_o_api;
00129 return true;
00130 }
00131
00132 bool Connection::verifyForwardCloseResult(const ForwardCloseSuccess& result)
00133 {
00134
00135
00136
00137 printf("Connection SN: 0x%08X vs 0x%08X\n", connection_sn, result.connection_sn);
00138 return (result.connection_sn == connection_sn
00139 && result.originator_vendor_id == originator_vendor_id
00140 && result.originator_sn == originator_sn);
00141 }
00142
00143 }