Public Member Functions | Private Member Functions | Private Attributes | List of all members
eip::Session Class Reference

#include <session.h>

Public Member Functions

void close ()
 
void closeConnection (size_t n)
 
int createConnection (const EIP_CONNECTION_INFO_T &o_to_t, const EIP_CONNECTION_INFO_T &t_to_o)
 
const ConnectiongetConnection (size_t n)
 
EIP_UDINT getSerialNum () const
 
EIP_UDINT getSessionID ()
 
template<typename T >
getSingleAttribute (EIP_USINT class_id, EIP_USINT instance_id, EIP_USINT attribute_id, T v)
 
void getSingleAttributeSerializable (EIP_USINT class_id, EIP_USINT instance_id, EIP_USINT attribute_id, Serializable &result)
 
EIP_UINT getVendorID () const
 
void open (string hostname, string port="44818", string io_port="2222")
 
CPFPacket receiveIOPacket ()
 
void sendIOPacket (CPFPacket &pkt)
 
 Session (shared_ptr< Socket > socket, shared_ptr< Socket > io_socket, EIP_UINT vendor_id=DEFAULT_VENDOR_ID, EIP_UDINT serial_num=DEFAULT_SERIAL_NUM)
 
template<typename T >
void setSingleAttribute (EIP_USINT class_id, EIP_USINT instance_id, EIP_USINT attribute_id, T v)
 
void setSingleAttributeSerializable (EIP_USINT class_id, EIP_USINT instance_id, EIP_USINT attribute_id, shared_ptr< Serializable > data)
 
virtual ~Session ()
 

Private Member Functions

void check_packet (EncapPacket &pkt, EIP_UINT exp_cmd)
 
 FRIEND_TEST (SessionTest, test_create_connection)
 
EncapPacket sendCommand (EncapPacket &req)
 
RRDataResponse sendRRDataCommand (EIP_USINT service, const Path &path, shared_ptr< Serializable > data)
 

Private Attributes

vector< Connectionconnections_
 
shared_ptr< Socket > io_socket_
 
EIP_UDINT my_serial_num_
 
EIP_UINT my_vendor_id_
 
EIP_UDINT next_connection_id_
 
EIP_UINT next_connection_sn_
 
EIP_BYTE recv_buffer_ [4 *1024]
 
EIP_UDINT session_id_
 
shared_ptr< Socket > socket_
 

Detailed Description

Class to handle creating and managing Ethernet/IP Sessions

Definition at line 61 of file session.h.

Constructor & Destructor Documentation

eip::Session::Session ( shared_ptr< Socket >  socket,
shared_ptr< Socket >  io_socket,
EIP_UINT  vendor_id = DEFAULT_VENDOR_ID,
EIP_UDINT  serial_num = DEFAULT_SERIAL_NUM 
)

Construct a session to use the given sockets

Parameters
socketControl socket, usually a TCP socket
io_socketIO Socket, usually a UDP socket directed at the same host
vendor_idMy vendor ID number to be used if different than the default
serial_numMy serial number to use when setting up connections

Definition at line 52 of file session.cpp.

eip::Session::~Session ( )
virtual

Definition at line 67 of file session.cpp.

Member Function Documentation

void eip::Session::check_packet ( EncapPacket pkt,
EIP_UINT  exp_cmd 
)
private

Helper to check a returned encapsulation packet based on an expected command. Note that there are some warnings given that do not produce an exception

Exceptions
std::logic_errorif problems are found with the response

Definition at line 194 of file session.cpp.

void eip::Session::close ( )

Close the session by unregistering the session and then closing the port

Definition at line 155 of file session.cpp.

void eip::Session::closeConnection ( size_t  n)

Close the given connection number

Parameters
nConnection number to close

Definition at line 327 of file session.cpp.

int eip::Session::createConnection ( const EIP_CONNECTION_INFO_T o_to_t,
const EIP_CONNECTION_INFO_T t_to_o 
)

Create an Ethernet/IP Connection for sending implicit messages

Parameters
o_to_tOrigin to target connection info
t_to_oTarget to origin connection info

Definition at line 303 of file session.cpp.

eip::Session::FRIEND_TEST ( SessionTest  ,
test_create_connection   
)
private
const Connection& eip::Session::getConnection ( size_t  n)
inline

Accessor for connection info

Parameters
nConnection number to access
Returns
Connection details

Definition at line 187 of file session.h.

EIP_UDINT eip::Session::getSerialNum ( ) const
inline

Accessor for serial number that will be used for this session

Returns
Serial number that will be sent to the target with any requests

Definition at line 177 of file session.h.

EIP_UDINT eip::Session::getSessionID ( )
inline

Get the ID number assigned to this session by the target

Returns
session ID number

Definition at line 94 of file session.h.

template<typename T >
T eip::Session::getSingleAttribute ( EIP_USINT  class_id,
EIP_USINT  instance_id,
EIP_USINT  attribute_id,
v 
)
inline

Shortcut to get a single attribute as a primitive type

Parameters
class_idClass ID for the path to get
instance_idInstance ID number for the path to get
attribute_idAttribute ID number for the path to get
Returns
Attribute value from target

Definition at line 117 of file session.h.

void eip::Session::getSingleAttributeSerializable ( EIP_USINT  class_id,
EIP_USINT  instance_id,
EIP_USINT  attribute_id,
Serializable &  result 
)

Get a single attribute from the given class / instance / attribute path

Parameters
class_idClass ID for the path to get
instance_idInstance ID number for the path to get
attribute_idAttribute ID number for the path to get
resultSerializable that will accept the result

Definition at line 230 of file session.cpp.

EIP_UINT eip::Session::getVendorID ( ) const
inline

Accessor for the Vendor ID to be used for this session

Returns
Vendor ID that will be sent to the target with any requests

Definition at line 168 of file session.h.

void eip::Session::open ( string  hostname,
string  port = "44818",
string  io_port = "2222" 
)

Open the session by opening the port and requesting a session.

Parameters
hostnamehostname of the target
portport to use if other than the standard
Exceptions
std::runtime_erroron problem opening the connection

Definition at line 82 of file session.cpp.

CPFPacket eip::Session::receiveIOPacket ( )

Receive the next packet from the IO socket. This is a hack. I'd really much prefer to have the Session receive and do callback through the connection object, but there's no time for that now.

Parameters
CPFPacketthe received packet

Definition at line 342 of file session.cpp.

EncapPacket eip::Session::sendCommand ( EncapPacket req)
private

Helper to send a command to the target as encapsulation packet and get the response, also as an encapsulation packet

Parameters
reqEncapsulation packet to send
Returns
Encapsulation packet received in response

Definition at line 171 of file session.cpp.

void eip::Session::sendIOPacket ( CPFPacket pkt)

Send an IO packet. Yet another hack. Should really keep track of sequence numbers and things inside of the session, but again no time for that.

Definition at line 361 of file session.cpp.

RRDataResponse eip::Session::sendRRDataCommand ( EIP_USINT  service,
const Path path,
shared_ptr< Serializable >  data 
)
private

Helper to send an RR Data command to the target

Parameters
serviceService code to send
class_idClass ID for the path
instance_idInstance ID number for the path
attribute_idAttribute ID number for the path
dataData to include. If null, then no data sent
Returns
RR Data Response

Definition at line 247 of file session.cpp.

template<typename T >
void eip::Session::setSingleAttribute ( EIP_USINT  class_id,
EIP_USINT  instance_id,
EIP_USINT  attribute_id,
v 
)
inline

Shortcut to set a single attribute from a primitive type

Parameters
class_idClass ID for the path to get
instance_idInstance ID number for the path to get
attribute_idAttribute ID number for the path to get
vValue to set attribute to

Definition at line 142 of file session.h.

void eip::Session::setSingleAttributeSerializable ( EIP_USINT  class_id,
EIP_USINT  instance_id,
EIP_USINT  attribute_id,
shared_ptr< Serializable >  data 
)

Set a single attribute from the given class / instance / attribute path

Parameters
class_idClass ID for the path to get
instance_idInstance ID number for the path to get
attribute_idAttribute ID number for the path to get
dataData to set the attribute to

Definition at line 240 of file session.cpp.

Member Data Documentation

vector<Connection> eip::Session::connections_
private

Definition at line 219 of file session.h.

shared_ptr<Socket> eip::Session::io_socket_
private

Definition at line 210 of file session.h.

EIP_UDINT eip::Session::my_serial_num_
private

Definition at line 215 of file session.h.

EIP_UINT eip::Session::my_vendor_id_
private

Definition at line 214 of file session.h.

EIP_UDINT eip::Session::next_connection_id_
private

Definition at line 217 of file session.h.

EIP_UINT eip::Session::next_connection_sn_
private

Definition at line 216 of file session.h.

EIP_BYTE eip::Session::recv_buffer_[4 *1024]
private

Definition at line 212 of file session.h.

EIP_UDINT eip::Session::session_id_
private

Definition at line 211 of file session.h.

shared_ptr<Socket> eip::Session::socket_
private

Definition at line 209 of file session.h.


The documentation for this class was generated from the following files:


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