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

Classes

struct  BlockHeader
 PROFINET block header (6 bytes). More...
 
struct  ExpectedSubmodule
 Expected submodule within a slot. More...
 
struct  ExpectedSubmoduleAPI
 Expected submodules for a specific API/slot. More...
 
class  ExpectedSubmoduleBlockReq
 ExpectedSubmoduleBlockReq (0x0104) builder. More...
 
struct  ExpectedSubmoduleDataDescription
 Describes I/O data for a submodule (one direction: Input or Output). More...
 
struct  ExpectedSubmoduleSlot
 One slot with in an api submodule. More...
 
struct  InterfaceInfo
 Interface information from PDInterfaceDataReal (0x0240). More...
 
class  IODWriteMultipleBuilder
 Builder for IODWriteMultipleReq packets (index 0xE040). More...
 
struct  ModuleDiffBlock
 Parsed ModuleDiffBlock (0x8104). More...
 
struct  ModuleDiffModule
 Difference info for a single module (slot). More...
 
struct  ModuleDiffSubmodule
 Difference info for a single submodule. More...
 
struct  PDRealData
 Parsed PDRealData (0xF841) structure. More...
 
struct  PeerInfo
 LLDP peer information from PDPortDataReal. More...
 
struct  PortInfo
 Port information from PDPortDataReal (0x020F). More...
 
struct  PortStatistics
 Parsed PDPortStatistic (0x0251) counters. More...
 
struct  RealIdentificationData
 Parsed RealIdentificationData (0xF000/0x0013) structure. More...
 
struct  SlotInfo
 Slot/subslot discovered from a device. More...
 
struct  WriteMultipleResult
 Result of a single write within a WriteMultiple operation. More...
 

Enumerations

enum class  ModuleType : std::uint16_t { None = 0 , InputOnly = 1 , OutputOnly = 2 , InputAndOutput = 3 }
 

Functions

std::pair< BlockHeader, std::size_t > ParseBlockHeader (const Bytes &data, std::size_t offset=0)
 Parse a 6-byte PROFINET block header at an offset.
 
std::size_t Align4 (std::size_t offset)
 Round an offset up to the next 4-byte boundary.
 
std::tuple< std::uint32_t, std::uint16_t, std::uint16_t, std::size_t > ParseMultipleBlockHeader (const Bytes &data, std::size_t offset=0)
 Parse a MultipleBlockHeader (0x0400) body.
 
InterfaceInfo ParsePdInterfaceDataReal (const Bytes &data, std::size_t offset=0, std::size_t blockHeaderSize=blockHeaderLenght)
 Parse a PDInterfaceDataReal (0x0240) block body.
 
PortInfo ParsePdPortDataReal (const Bytes &data, std::size_t offset=0, std::uint16_t slot=0, std::uint16_t subslot=0)
 Parse a PDPortDataReal (0x020F) block body.
 
PDRealData ParsePdRealData (const Bytes &data)
 Parse a complete PDRealData (0xF841) response.
 
RealIdentificationData ParseRealIdentificationData (const Bytes &data)
 Parse a RealIdentificationData (0xF000 or 0x0013) response.
 
std::optional< PortStatisticsParsePortStatistics (const Bytes &data, std::size_t offset=0)
 Parse a PDPortStatistic (0x0251) block body.
 
ModuleDiffBlock ParseModuleDiffBlock (const Bytes &data)
 Parse a ModuleDiffBlock (0x8104) from raw bytes.
 
std::vector< WriteMultipleResultParseWriteMultipleResponse (const Bytes &data)
 Parse an IODWriteMultipleRes into individual per-write results.
 

Detailed Description

Provides structures used by AR establishment and parameterization, including AR, IOCR, AlarmCR, ExpectedSubmodule, control, read, and related PROFINET block types.

Data classes and parsing functions for PROFINET block structures, extracted from the Wireshark pn_io dissector. Block structures follow the standard format: BlockHeader (6 bytes: Type, Length, Version) + variable body depending on block type.

Enumeration Type Documentation

◆ ModuleType

enum class profinet::blocks::ModuleType : std::uint16_t
strong
Enumerator
None 
InputOnly 
OutputOnly 
InputAndOutput 

Definition at line 569 of file blocks.h.

Function Documentation

◆ Align4()

std::size_t profinet::blocks::Align4 ( std::size_t  offset)
inline

Round an offset up to the next 4-byte boundary.

Parameters
offsetOffset to align.
Returns
The aligned offset.

Definition at line 266 of file blocks.h.

Referenced by ParsePdInterfaceDataReal(), and ParsePdPortDataReal().

+ Here is the caller graph for this function:

◆ ParseBlockHeader()

std::pair< BlockHeader, std::size_t > profinet::blocks::ParseBlockHeader ( const Bytes data,
std::size_t  offset = 0 
)

Parse a 6-byte PROFINET block header at an offset.

Parameters
dataBuffer containing the header.
offsetByte offset within Data to start parsing at.
Returns
The parsed header and the offset immediately after it.

Throws std::invalid_argument if data is too short.

Definition at line 109 of file blocks.cpp.

References profinet::blockHeaderLenght, profinet::blocks::BlockHeader::blockLength, profinet::blocks::BlockHeader::blockType, profinet::wire::Reader::U16(), profinet::wire::Reader::U8(), profinet::blocks::BlockHeader::versionHigh, and profinet::blocks::BlockHeader::versionLow.

Referenced by ParsePdRealData(), and ParseRealIdentificationData().

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

◆ ParseModuleDiffBlock()

ModuleDiffBlock profinet::blocks::ParseModuleDiffBlock ( const Bytes data)

Parse a ModuleDiffBlock (0x8104) from raw bytes.

Parameters
dataBuffer containing the complete block, including its own 6-byte block header.
Returns
The parsed block.

Throws std::invalid_argument if the block type doesn't match 0x8104. Returns an empty ModuleDiffBlock (not an error) if data is merely too short to contain the header, matching blocks.py's lenient handling.

Definition at line 593 of file blocks.cpp.

References profinet::GetBlockTypeName(), profinet::ModuleDifference, profinet::wire::Reader::Remaining(), profinet::wire::Reader::Skip(), profinet::wire::Reader::U16(), and profinet::wire::Reader::U32().

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

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

◆ ParseMultipleBlockHeader()

std::tuple< std::uint32_t, std::uint16_t, std::uint16_t, std::size_t > profinet::blocks::ParseMultipleBlockHeader ( const Bytes data,
std::size_t  offset = 0 
)

Parse a MultipleBlockHeader (0x0400) body.

Parameters
dataBuffer containing the body.
offsetByte offset within Data to start parsing at.
Returns
(api, slot, subslot, offset immediately after the body).

Layout: 2 bytes padding + API(4) + SlotNr(2) + SubslotNr(2). Throws std::invalid_argument if data is too short.

Definition at line 125 of file blocks.cpp.

References profinet::wire::Reader::Skip(), profinet::wire::Reader::U16(), and profinet::wire::Reader::U32().

Referenced by ParsePdRealData().

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

◆ ParsePdInterfaceDataReal()

InterfaceInfo profinet::blocks::ParsePdInterfaceDataReal ( const Bytes data,
std::size_t  offset = 0,
std::size_t  blockHeaderSize = blockHeaderLenght 
)

Parse a PDInterfaceDataReal (0x0240) block body.

Parameters
dataBuffer containing the body.
offsetByte offset within Data to start parsing at.
blockHeaderSizeSize used for the alignment calculation (defaults to 6), matching blocks.py's align_from_block behavior.
Returns
The parsed interface information.

Throws std::invalid_argument if data is truncated.

Definition at line 140 of file blocks.cpp.

References Align4(), profinet::blocks::InterfaceInfo::chassisId, profinet::blocks::InterfaceInfo::gateway, profinet::blocks::InterfaceInfo::ipAddress, profinet::blocks::InterfaceInfo::macAddress, and profinet::blocks::InterfaceInfo::subnetMask.

Referenced by ParsePdRealData().

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

◆ ParsePdPortDataReal()

PortInfo profinet::blocks::ParsePdPortDataReal ( const Bytes data,
std::size_t  offset = 0,
std::uint16_t  slot = 0,
std::uint16_t  subslot = 0 
)

Parse a PDPortDataReal (0x020F) block body.

Parameters
dataBuffer containing the body.
offsetByte offset within Data to start parsing at.
slotFallback slot number, used only if not found in the data itself.
subslotFallback subslot number, used only if not found in the data itself.
Returns
The parsed port information.

Slot/Subslot are typically overridden by a Slot/Subslot pair found in the data itself, matching blocks.py.

Definition at line 191 of file blocks.cpp.

References Align4(), profinet::OneOctetShift, profinet::blocks::PortInfo::slot, profinet::ThreeOctetsShift, and profinet::TwoOctetsShift.

Referenced by ParsePdRealData().

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

◆ ParsePdRealData()

PDRealData profinet::blocks::ParsePdRealData ( const Bytes data)

Parse a complete PDRealData (0xF841) response.

Parameters
dataBuffer containing the complete response.
Returns
The parsed topology (interface + ports + slots).

A sequence of MultipleBlockHeader blocks, each describing a slot/subslot with nested sub-blocks (PDInterfaceDataReal, PDPortDataReal, etc).

Definition at line 313 of file blocks.cpp.

References profinet::blocks::SlotInfo::api, profinet::blockHeaderLenght, profinet::blocks::SlotInfo::blocks, profinet::blocks::BlockHeader::blockType, profinet::blocks::BlockHeader::BodyLength(), profinet::blocks::PDRealData::interface, profinet::MultipleHeader, ParseBlockHeader(), ParseMultipleBlockHeader(), ParsePdInterfaceDataReal(), ParsePdPortDataReal(), profinet::PortDataInterfaceDataReal, profinet::PortDataReal, profinet::blocks::PDRealData::ports, profinet::blocks::PDRealData::rawBlocks, profinet::blocks::SlotInfo::slot, profinet::blocks::PDRealData::slots, profinet::blocks::SlotInfo::subslot, and profinet::blocks::BlockHeader::TypeName().

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

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

◆ ParsePortStatistics()

std::optional< PortStatistics > profinet::blocks::ParsePortStatistics ( const Bytes data,
std::size_t  offset = 0 
)

Parse a PDPortStatistic (0x0251) block body.

Parameters
dataBuffer containing the body.
offsetByte offset within Data to start parsing at.
Returns
The parsed counters, or std::nullopt if data is too short (< 26 bytes at Offset).

Definition at line 514 of file blocks.cpp.

References profinet::blocks::PortStatistics::counterStatus, profinet::blocks::PortStatistics::inDiscards, profinet::blocks::PortStatistics::inErrors, profinet::blocks::PortStatistics::inOctets, profinet::blocks::PortStatistics::outDiscards, profinet::blocks::PortStatistics::outErrors, profinet::blocks::PortStatistics::outOctets, profinet::wire::Reader::U16(), and profinet::wire::Reader::U32().

+ Here is the call graph for this function:

◆ ParseRealIdentificationData()

RealIdentificationData profinet::blocks::ParseRealIdentificationData ( const Bytes data)

Parse a RealIdentificationData (0xF000 or 0x0013) response.

Parameters
dataBuffer containing the complete response.
Returns
The parsed slot/subslot structure.

Handles both version 1.0 (no API level) and version 1.1 (API-grouped) layouts.

Definition at line 407 of file blocks.cpp.

References profinet::blocks::BlockHeader::blockType, ParseBlockHeader(), profinet::RealIdentificationData, profinet::RealIdentificationDataApi, profinet::wire::Reader::Remaining(), profinet::blocks::RealIdentificationData::slots, profinet::wire::Reader::U16(), profinet::wire::Reader::U32(), profinet::blocks::RealIdentificationData::version, profinet::blocks::BlockHeader::versionHigh, and profinet::blocks::BlockHeader::versionLow.

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

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

◆ ParseWriteMultipleResponse()

std::vector< WriteMultipleResult > profinet::blocks::ParseWriteMultipleResponse ( const Bytes data)

Parse an IODWriteMultipleRes into individual per-write results.

Parameters
dataBuffer containing the complete response.
Returns
The per-write results.

Definition at line 740 of file blocks.cpp.

References profinet::OneOctetShift, profinet::wire::Reader::Skip(), profinet::ThreeOctetsShift, profinet::TwoOctetsShift, profinet::wire::Reader::U16(), profinet::wire::Reader::U32(), and profinet::uuidLenght.

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

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