PROFINET IO Controller Stack 1.0.0
Modern C++ implementation of a PROFINET IO Controller stack
Loading...
Searching...
No Matches
profinet::rpc Namespace Reference

Classes

struct  AllIM
 All I&M records a device supports, read in one call. More...
 
struct  BlockHeaderView
 Generic block header (type + length) used to scan response blocks. More...
 
struct  ConnectResult
 Result of a successful RPCCon::Connect() that also established cyclic IO. More...
 
struct  EPMEndpoint
 One RPC endpoint advertised by a device's Endpoint Mapper. More...
 
struct  IndexProbeResult
 Result of probing one index in EnumerateIndices(). More...
 
struct  IOCRSetup
 Configuration for establishing cyclic IO alongside an AR. More...
 
struct  IOSlot
 One slot/subslot's expected module configuration and IO data sizes. More...
 
class  IRPCCon
 Abstract interface for a PROFINET RPC connection. More...
 
class  IRpcTransport
 
class  RPCCon
 Connection to a PROFINET IO-Device: establishes an AR (Application Relationship) and performs acyclic read/write and CONTROL operations. More...
 
struct  RPCConOptions
 Configuration options for an RPC connection. More...
 
class  RpcTransport
 Synchronous UDP transport used by PROFINET DCE/RPC. More...
 
struct  WriteItem
 A single write operation for WriteMultiple(). More...
 

Functions

BlockHeaderView PeekBlockHeader (const Bytes &data, std::size_t offset)
 
std::string UuidBytesToString (const std::array< std::uint8_t, uuidLenght > &data)
 Format a 16-byte DCE/RPC UUID as a canonical string.
 
std::array< std::uint8_t, uuidLenghtStringToUuidBytes (const std::string &uuidStr)
 Parse a canonical UUID string into 16 raw DCE/RPC UUID bytes.
 
std::vector< EPMEndpointEpmLookup (asio::io_context &ioContext, const std::string &ip, std::uint16_t port=RPC_PORT, double timeoutSec=DEFAULT_TIMEOUT, std::optional< std::string > interfaceFilter=std::nullopt)
 Query a device's Endpoint Mapper for available RPC endpoints.
 
dcp::DCPDeviceDescription GetStationInfo (const EthernetSocket &sock, const MacAddress &src, const std::string &name, int timeoutSec=static_cast< int >(DEFAULT_TIMEOUT *2))
 Resolve a device by PROFINET station name via DCP.
 

Variables

constexpr std::uint16_t RPC_PORT = 0x8894
 PROFINET IO RPC port (34964).
 
constexpr std::uint16_t RPC_BIND_PORT = 0x8895
 PROFINET IO RPC bind port (34965).
 
const std::string UUID_NULL = "00000000-0000-0000-0000-000000000000"
 Null (all-zero) DCE/RPC UUID string.
 
const std::string UUID_EPM_V4 = "e1af8308-5d1f-11c9-91a4-08002b14a0fa"
 Endpoint Mapper interface UUID.
 
const std::string UUID_PNIO_DEVICE = "dea00001-6c97-11d1-8271-00a02442df7d"
 PROFINET IO-Device interface UUID.
 
const std::string UUID_PNIO_CONTROLLER = "dea00002-6c97-11d1-8271-00a02442df7d"
 PROFINET IO-Controller interface UUID.
 
constexpr std::uint32_t PNIO_DEVICE_INTERFACE_VERSION = 1
 Interface version used for the PNIO device interface.
 
constexpr std::uint32_t EPM_LOOKUP = 0x02
 EPM operation: Lookup.
 
constexpr std::uint32_t EPM_INQUIRY_ALL = 0x00
 EPM inquiry type: all interfaces.
 
constexpr std::uint32_t EPM_INQUIRY_INTERFACE = 0x01
 EPM inquiry type: specific interface.
 
constexpr double DEFAULT_TIMEOUT = 5.0
 Default RPC response timeout in seconds.
 
constexpr double CONNECTION_TIMEOUT = 10.0
 Maximum idle time in seconds before an AR is considered to need re-connection.
 
constexpr std::uint16_t BLOCK_IOD_CONTROL_PRM_END_REQ = 0x0110
 Block type: IODControlReqPrmEnd.
 
constexpr std::uint16_t BLOCK_IOD_CONTROL_APP_READY_REQ = 0x0112
 Block type: IODControlReqAppReady.
 
constexpr std::uint16_t BLOCK_IOD_CONTROL_APP_READY_RES = 0x8112
 Block type: IODControlResAppReady.
 
constexpr std::uint16_t BLOCK_IOD_CONTROL_RT_CLASS_3_REQ = 0x0117
 Block type: IODControlReqRTClass3.
 
constexpr std::uint16_t BLOCK_PRM_BEGIN_REQ = 0x0118
 Block type: PrmBeginReq.
 
constexpr std::uint16_t BLOCK_RELEASE_REQ = 0x0114
 Block type: IODReleaseReq.
 
constexpr std::uint16_t CONTROL_CMD_PRM_END = 0x0001
 Control command bit: PrmEnd.
 
constexpr std::uint16_t CONTROL_CMD_APP_READY = 0x0002
 Control command bit: ApplicationReady.
 
constexpr std::uint16_t CONTROL_CMD_RELEASE = 0x0004
 Control command bit: Release.
 
constexpr std::uint16_t CONTROL_CMD_DONE = 0x0008
 Control command bit: Done.
 
constexpr std::uint16_t CONTROL_CMD_READY_FOR_COMPANION = 0x0010
 Control command bit: ReadyForCompanion.
 
constexpr std::uint16_t CONTROL_CMD_READY_FOR_RT_CLASS_3 = 0x0020
 Control command bit: ReadyForRTClass3.
 
constexpr std::uint16_t CONTROL_CMD_PRM_BEGIN = 0x0040
 Control command bit: PrmBegin.
 
constexpr std::uint8_t VERSION_HIGH = 0x01
 Version high.
 
constexpr std::uint8_t VERSION_LOW = 0x00
 Version low.
 

Function Documentation

◆ EpmLookup()

std::vector< EPMEndpoint > profinet::rpc::EpmLookup ( asio::io_context &  ioContext,
const std::string &  ip,
std::uint16_t  port = RPC_PORT,
double  timeoutSec = DEFAULT_TIMEOUT,
std::optional< std::string >  interfaceFilter = std::nullopt 
)

Query a device's Endpoint Mapper for available RPC endpoints.

Parameters
ioContextAsio execution context.
ipIPv4 address of the device to query.
portUDP port of the device's Endpoint Mapper (defaults to RPC_PORT).
timeoutSecHow long to wait for a response.
interfaceFilterIf set, only endpoints for this interface UUID are requested.
Returns
The device's advertised endpoints, or an empty vector on timeout or malformed response (matches rpc.py's epm_lookup(), which logs and returns [] rather than raising).

Definition at line 389 of file rpc.cpp.

References EPM_INQUIRY_ALL, EPM_INQUIRY_INTERFACE, EPM_LOOKUP, profinet::PNRPCHeader::kFixedSize, profinet::LowByteMask, profinet::OneOctetShift, profinet::rpc::RpcTransport::Open(), profinet::PNRPCHeader::REQUEST, profinet::rpc::RpcTransport::SendReceive(), StringToUuidBytes(), UUID_EPM_V4, UuidBytesToString(), and profinet::uuidLenght.

Referenced by profinet::device::ProfinetDevice::GetInfo().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetStationInfo()

dcp::DCPDeviceDescription profinet::rpc::GetStationInfo ( const EthernetSocket sock,
const MacAddress src,
const std::string &  name,
int  timeoutSec = static_cast<int>(DEFAULT_TIMEOUT * 2) 
)

Resolve a device by PROFINET station name via DCP.

Parameters
sockBound Ethernet socket to send/receive on.
srcSource MAC address to send from.
nameStation name to resolve.
timeoutSecHow long to wait for each discovery attempt.
Returns
The resolved device's DCP description.

Falls back from a filtered Identify request to a broadcast discover + name filter. Throws DCPDeviceNotFoundError if no matching device responds.

Definition at line 588 of file rpc.cpp.

References profinet::dcp::DCPDeviceDescription::name, profinet::PNDCPBlock::NAME_OF_STATION, profinet::dcp::ReadResponse(), profinet::dcp::SendDiscover(), and profinet::dcp::SendRequest().

Referenced by profinet::device::ProfinetDevice::Discover().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ PeekBlockHeader()

BlockHeaderView profinet::rpc::PeekBlockHeader ( const Bytes data,
std::size_t  offset 
)
inline

Definition at line 53 of file rpc.h.

References profinet::rpc::BlockHeaderView::blockType, and profinet::OneOctetShift.

Referenced by profinet::rpc::RPCCon::ParseAlarmCrResponse(), and profinet::rpc::RPCCon::ParseIocrResponse().

+ Here is the caller graph for this function:

◆ StringToUuidBytes()

std::array< std::uint8_t, uuidLenght > profinet::rpc::StringToUuidBytes ( const std::string &  uuidStr)

Parse a canonical UUID string into 16 raw DCE/RPC UUID bytes.

Parameters
uuidStrString in "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" form.
Returns
The 16 raw UUID bytes (mixed-endian DCE/RPC format).

Throws std::invalid_argument on malformed input.

Definition at line 159 of file rpc.cpp.

References profinet::LowByteMask, profinet::OneOctetShift, profinet::ThreeOctetsShift, and profinet::TwoOctetsShift.

Referenced by EpmLookup().

+ Here is the caller graph for this function:

◆ UuidBytesToString()

std::string profinet::rpc::UuidBytesToString ( const std::array< std::uint8_t, uuidLenght > &  data)

Format a 16-byte DCE/RPC UUID as a canonical string.

Parameters
dataThe 16 raw UUID bytes (mixed-endian DCE/RPC format).
Returns
String in "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" form.

Definition at line 122 of file rpc.cpp.

References profinet::OneOctetShift, profinet::ThreeOctetsShift, profinet::ToHex(), and profinet::TwoOctetsShift.

Referenced by EpmLookup().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ BLOCK_IOD_CONTROL_APP_READY_REQ

constexpr std::uint16_t profinet::rpc::BLOCK_IOD_CONTROL_APP_READY_REQ = 0x0112
inlineconstexpr

Block type: IODControlReqAppReady.

Definition at line 60 of file rpcTypes.h.

Referenced by profinet::rpc::RPCCon::ApplicationReady().

◆ BLOCK_IOD_CONTROL_APP_READY_RES

constexpr std::uint16_t profinet::rpc::BLOCK_IOD_CONTROL_APP_READY_RES = 0x8112
inlineconstexpr

Block type: IODControlResAppReady.

Definition at line 62 of file rpcTypes.h.

◆ BLOCK_IOD_CONTROL_PRM_END_REQ

constexpr std::uint16_t profinet::rpc::BLOCK_IOD_CONTROL_PRM_END_REQ = 0x0110
inlineconstexpr

Block type: IODControlReqPrmEnd.

Definition at line 58 of file rpcTypes.h.

◆ BLOCK_IOD_CONTROL_RT_CLASS_3_REQ

constexpr std::uint16_t profinet::rpc::BLOCK_IOD_CONTROL_RT_CLASS_3_REQ = 0x0117
inlineconstexpr

Block type: IODControlReqRTClass3.

Definition at line 64 of file rpcTypes.h.

◆ BLOCK_PRM_BEGIN_REQ

constexpr std::uint16_t profinet::rpc::BLOCK_PRM_BEGIN_REQ = 0x0118
inlineconstexpr

Block type: PrmBeginReq.

Definition at line 66 of file rpcTypes.h.

◆ BLOCK_RELEASE_REQ

constexpr std::uint16_t profinet::rpc::BLOCK_RELEASE_REQ = 0x0114
inlineconstexpr

Block type: IODReleaseReq.

Definition at line 68 of file rpcTypes.h.

◆ CONNECTION_TIMEOUT

constexpr double profinet::rpc::CONNECTION_TIMEOUT = 10.0
inlineconstexpr

Maximum idle time in seconds before an AR is considered to need re-connection.

Definition at line 53 of file rpcTypes.h.

Referenced by profinet::rpc::RPCCon::CheckTimeout().

◆ CONTROL_CMD_APP_READY

constexpr std::uint16_t profinet::rpc::CONTROL_CMD_APP_READY = 0x0002
inlineconstexpr

Control command bit: ApplicationReady.

Definition at line 73 of file rpcTypes.h.

◆ CONTROL_CMD_DONE

constexpr std::uint16_t profinet::rpc::CONTROL_CMD_DONE = 0x0008
inlineconstexpr

Control command bit: Done.

Definition at line 77 of file rpcTypes.h.

◆ CONTROL_CMD_PRM_BEGIN

constexpr std::uint16_t profinet::rpc::CONTROL_CMD_PRM_BEGIN = 0x0040
inlineconstexpr

Control command bit: PrmBegin.

Definition at line 83 of file rpcTypes.h.

◆ CONTROL_CMD_PRM_END

constexpr std::uint16_t profinet::rpc::CONTROL_CMD_PRM_END = 0x0001
inlineconstexpr

Control command bit: PrmEnd.

Definition at line 71 of file rpcTypes.h.

◆ CONTROL_CMD_READY_FOR_COMPANION

constexpr std::uint16_t profinet::rpc::CONTROL_CMD_READY_FOR_COMPANION = 0x0010
inlineconstexpr

Control command bit: ReadyForCompanion.

Definition at line 79 of file rpcTypes.h.

◆ CONTROL_CMD_READY_FOR_RT_CLASS_3

constexpr std::uint16_t profinet::rpc::CONTROL_CMD_READY_FOR_RT_CLASS_3 = 0x0020
inlineconstexpr

Control command bit: ReadyForRTClass3.

Definition at line 81 of file rpcTypes.h.

◆ CONTROL_CMD_RELEASE

constexpr std::uint16_t profinet::rpc::CONTROL_CMD_RELEASE = 0x0004
inlineconstexpr

Control command bit: Release.

Definition at line 75 of file rpcTypes.h.

◆ DEFAULT_TIMEOUT

constexpr double profinet::rpc::DEFAULT_TIMEOUT = 5.0
inlineconstexpr

Default RPC response timeout in seconds.

Definition at line 51 of file rpcTypes.h.

◆ EPM_INQUIRY_ALL

constexpr std::uint32_t profinet::rpc::EPM_INQUIRY_ALL = 0x00
inlineconstexpr

EPM inquiry type: all interfaces.

Definition at line 46 of file rpcTypes.h.

Referenced by EpmLookup().

◆ EPM_INQUIRY_INTERFACE

constexpr std::uint32_t profinet::rpc::EPM_INQUIRY_INTERFACE = 0x01
inlineconstexpr

EPM inquiry type: specific interface.

Definition at line 48 of file rpcTypes.h.

Referenced by EpmLookup().

◆ EPM_LOOKUP

constexpr std::uint32_t profinet::rpc::EPM_LOOKUP = 0x02
inlineconstexpr

EPM operation: Lookup.

Definition at line 44 of file rpcTypes.h.

Referenced by EpmLookup().

◆ PNIO_DEVICE_INTERFACE_VERSION

constexpr std::uint32_t profinet::rpc::PNIO_DEVICE_INTERFACE_VERSION = 1
inlineconstexpr

Interface version used for the PNIO device interface.

Definition at line 41 of file rpcTypes.h.

◆ RPC_BIND_PORT

constexpr std::uint16_t profinet::rpc::RPC_BIND_PORT = 0x8895
inlineconstexpr

PROFINET IO RPC bind port (34965).

Definition at line 29 of file rpcTypes.h.

◆ RPC_PORT

constexpr std::uint16_t profinet::rpc::RPC_PORT = 0x8894
inlineconstexpr

PROFINET IO RPC port (34964).

Definition at line 27 of file rpcTypes.h.

◆ UUID_EPM_V4

const std::string profinet::rpc::UUID_EPM_V4 = "e1af8308-5d1f-11c9-91a4-08002b14a0fa"
inline

Endpoint Mapper interface UUID.

Definition at line 34 of file rpcTypes.h.

Referenced by EpmLookup(), and profinet::rpc::EPMEndpoint::InterfaceName().

◆ UUID_NULL

const std::string profinet::rpc::UUID_NULL = "00000000-0000-0000-0000-000000000000"
inline

Null (all-zero) DCE/RPC UUID string.

Definition at line 32 of file rpcTypes.h.

◆ UUID_PNIO_CONTROLLER

const std::string profinet::rpc::UUID_PNIO_CONTROLLER = "dea00002-6c97-11d1-8271-00a02442df7d"
inline

PROFINET IO-Controller interface UUID.

Definition at line 38 of file rpcTypes.h.

Referenced by profinet::rpc::EPMEndpoint::InterfaceName().

◆ UUID_PNIO_DEVICE

const std::string profinet::rpc::UUID_PNIO_DEVICE = "dea00001-6c97-11d1-8271-00a02442df7d"
inline

PROFINET IO-Device interface UUID.

Definition at line 36 of file rpcTypes.h.

Referenced by profinet::rpc::EPMEndpoint::InterfaceName().

◆ VERSION_HIGH

constexpr std::uint8_t profinet::rpc::VERSION_HIGH = 0x01
inlineconstexpr

◆ VERSION_LOW

constexpr std::uint8_t profinet::rpc::VERSION_LOW = 0x00
inlineconstexpr