session.h
Go to the documentation of this file.
1 
26 #ifndef ODVA_ETHERNETIP_SESSION_H
27 #define ODVA_ETHERNETIP_SESSION_H
28 
29 #include <string>
30 #include <gtest/gtest_prod.h>
31 #include <boost/shared_ptr.hpp>
32 #include <boost/make_shared.hpp>
33 #include <boost/asio.hpp>
34 
42 #include "odva_ethernetip/path.h"
44 
45 using std::string;
46 using boost::shared_ptr;
47 using boost::make_shared;
48 
49 namespace eip {
50 
51 using serialization::Serializable;
52 using serialization::SerializablePrimitive;
53 using socket::Socket;
54 
55 #define DEFAULT_VENDOR_ID 0x1234
56 #define DEFAULT_SERIAL_NUM 0x6789
57 
61 class Session
62 {
63 public:
64 
72  Session(shared_ptr<Socket> socket, shared_ptr<Socket> io_socket,
73  EIP_UINT vendor_id = DEFAULT_VENDOR_ID, EIP_UDINT serial_num = DEFAULT_SERIAL_NUM);
74 
75  virtual ~Session();
76 
83  void open(string hostname, string port = "44818", string io_port = "2222");
84 
88  void close();
89 
95  {
96  return session_id_;
97  }
98 
106  void getSingleAttributeSerializable(EIP_USINT class_id, EIP_USINT instance_id,
107  EIP_USINT attribute_id, Serializable& result);
108 
116  template <typename T>
117  T getSingleAttribute(EIP_USINT class_id, EIP_USINT instance_id, EIP_USINT attribute_id, T v)
118  {
119  SerializablePrimitive<T> data;
120  getSingleAttributeSerializable(class_id, instance_id, attribute_id, data);
121  return data.data;
122  }
123 
131  void setSingleAttributeSerializable(EIP_USINT class_id, EIP_USINT instance_id,
132  EIP_USINT attribute_id, shared_ptr<Serializable> data);
133 
141  template <typename T>
142  void setSingleAttribute(EIP_USINT class_id, EIP_USINT instance_id,
143  EIP_USINT attribute_id, T v)
144  {
145  shared_ptr< SerializablePrimitive<T> > data =
146  make_shared< SerializablePrimitive<T> > (v);
147  setSingleAttributeSerializable(class_id, instance_id, attribute_id, data);
148  }
149 
155  int createConnection(const EIP_CONNECTION_INFO_T& o_to_t,
156  const EIP_CONNECTION_INFO_T& t_to_o);
157 
162  void closeConnection(size_t n);
163 
168  inline EIP_UINT getVendorID() const
169  {
170  return my_vendor_id_;
171  }
172 
177  inline EIP_UDINT getSerialNum() const
178  {
179  return my_serial_num_;
180  }
181 
187  const Connection& getConnection(size_t n)
188  {
189  return connections_[n];
190  }
191 
199 
204  void sendIOPacket(CPFPacket& pkt);
205 
206 private:
207  FRIEND_TEST(SessionTest, test_create_connection);
208 
209  shared_ptr<Socket> socket_;
210  shared_ptr<Socket> io_socket_;
213 
218 
219  vector<Connection> connections_;
220 
226  void check_packet(EncapPacket& pkt, EIP_UINT exp_cmd);
227 
235 
245  RRDataResponse sendRRDataCommand(EIP_USINT service, const Path& path,
246  shared_ptr<Serializable> data);
247 };
248 
249 } // namespace eip
250 
251 #endif // ODVA_ETHERNETIP_SESSION_H
uint8_t EIP_USINT
Definition: eip_types.h:36
EIP_BYTE recv_buffer_[4 *1024]
Definition: session.h:212
EIP_UDINT session_id_
Definition: session.h:211
shared_ptr< Socket > io_socket_
Definition: session.h:210
virtual ~Session()
Definition: session.cpp:67
CPFPacket receiveIOPacket()
Definition: session.cpp:342
RRDataResponse sendRRDataCommand(EIP_USINT service, const Path &path, shared_ptr< Serializable > data)
Definition: session.cpp:247
EIP_UDINT getSessionID()
Definition: session.h:94
#define DEFAULT_SERIAL_NUM
Definition: session.h:56
void closeConnection(size_t n)
Definition: session.cpp:327
void open(string hostname, string port="44818", string io_port="2222")
Definition: session.cpp:82
void check_packet(EncapPacket &pkt, EIP_UINT exp_cmd)
Definition: session.cpp:194
void sendIOPacket(CPFPacket &pkt)
Definition: session.cpp:361
void close()
Definition: session.cpp:155
FRIEND_TEST(SessionTest, test_create_connection)
EIP_UDINT next_connection_id_
Definition: session.h:217
uint8_t EIP_BYTE
Definition: eip_types.h:35
Definition: path.h:50
Definition: connection.h:41
vector< Connection > connections_
Definition: session.h:219
void setSingleAttributeSerializable(EIP_USINT class_id, EIP_USINT instance_id, EIP_USINT attribute_id, shared_ptr< Serializable > data)
Definition: session.cpp:240
int createConnection(const EIP_CONNECTION_INFO_T &o_to_t, const EIP_CONNECTION_INFO_T &t_to_o)
Definition: session.cpp:303
uint16_t EIP_UINT
Definition: eip_types.h:39
void setSingleAttribute(EIP_USINT class_id, EIP_USINT instance_id, EIP_USINT attribute_id, T v)
Definition: session.h:142
const Connection & getConnection(size_t n)
Definition: session.h:187
EIP_UINT next_connection_sn_
Definition: session.h:216
EIP_UDINT my_serial_num_
Definition: session.h:215
uint32_t EIP_UDINT
Definition: eip_types.h:42
EIP_UINT my_vendor_id_
Definition: session.h:214
Session(shared_ptr< Socket > socket, shared_ptr< Socket > io_socket, EIP_UINT vendor_id=DEFAULT_VENDOR_ID, EIP_UDINT serial_num=DEFAULT_SERIAL_NUM)
Definition: session.cpp:52
T getSingleAttribute(EIP_USINT class_id, EIP_USINT instance_id, EIP_USINT attribute_id, T v)
Definition: session.h:117
EIP_UINT getVendorID() const
Definition: session.h:168
#define DEFAULT_VENDOR_ID
Definition: session.h:55
void getSingleAttributeSerializable(EIP_USINT class_id, EIP_USINT instance_id, EIP_USINT attribute_id, Serializable &result)
Definition: session.cpp:230
EIP_UDINT getSerialNum() const
Definition: session.h:177
EncapPacket sendCommand(EncapPacket &req)
Definition: session.cpp:171
shared_ptr< Socket > socket_
Definition: session.h:209


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