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

Classes

class  CyclicDataBuilder
 Builds C_SDU payload from IO data objects with double-buffering. More...
 
struct  IOCRConfig
 IOCR configuration derived from AR setup: timing parameters and IO object mappings needed for cyclic data exchange. More...
 
struct  IODataObject
 Single IO data object within the C_SDU: one piece of process data mapped to a slot/subslot, with its IOPS (and optional IOCS) offset. More...
 
struct  RTFrame
 A single PROFINET Real-Time cyclic frame: Frame ID + C_SDU payload + cycle counter/status trailer. More...
 

Functions

template<typename SlotT >
std::pair< IOCRConfig, IOCRConfigBuildIocrConfigs (const std::vector< SlotT > &slots, std::uint16_t inputFrameId, std::uint16_t outputFrameId, std::uint16_t sendClockFactor=32, std::uint16_t reductionRatio=32, int watchdogFactor=3, std::uint16_t cSduLength=43)
 
Bytes BuildEthernetFrame (const MacAddress &dstMac, const MacAddress &srcMac, const RTFrame &rtFrame)
 Build a complete Ethernet frame carrying an RT frame.
 
std::optional< RTFrameParseEthernetFrame (const Bytes &data)
 Parse a complete Ethernet frame and extract its RT frame.
 

Variables

constexpr std::uint16_t ETHERTYPE_PROFINET = 0x8892
 EtherType used by PROFINET RT frames (0x8892).
 
constexpr std::uint16_t FRAME_ID_RT_CLASS_1_MIN = 0xC000
 Minimum frame ID in the RT_CLASS_1 range.
 
constexpr std::uint16_t FRAME_ID_RT_CLASS_1_MAX = 0xF7FF
 Maximum frame ID in the RT_CLASS_1 range.
 
constexpr std::uint16_t VLAN_TAG_RT = 0x8100C000
 802.1Q priority tag for cyclic RT frames per IEC 61158-6-10: TPID 0x8100, PCP 6, VID 0 (TCI 0xC000, matching the negotiated IOCRTagHeader). Devices validate the negotiated priority, and managed switches may drop untagged sub-64-byte RT frames as runts, so TX frames must carry the tag.
 
constexpr std::uint16_t FRAME_ID_ALARM_HIGH = 0xFC01
 Frame ID used for high-priority alarms.
 
constexpr std::uint16_t FRAME_ID_ALARM_LOW = 0xFE01
 Frame ID used for low-priority alarms.
 
constexpr std::uint16_t IOCR_TYPE_INPUT = 1
 IOCR direction: Device -> Controller.
 
constexpr std::uint16_t IOCR_TYPE_OUTPUT = 2
 IOCR direction: Controller -> Device.
 
constexpr std::uint8_t RT_CLASS_1 = 0x01
 Real-time class: software scheduled (250us-512ms).
 
constexpr std::uint8_t RT_CLASS_2 = 0x02
 Real-time class: hardware scheduled (reserved).
 
constexpr std::uint8_t RT_CLASS_3 = 0x03
 Real-time class: isochronous (IRT, hardware only).
 
constexpr std::uint8_t DATA_STATUS_STATE = 0x01
 DataStatus bit: provider state, 0=Backup, 1=Primary.
 
constexpr std::uint8_t DATA_STATUS_REDUNDANCY = 0x02
 DataStatus bit: redundancy state.
 
constexpr std::uint8_t DATA_STATUS_VALID = 0x04
 DataStatus bit: data validity, 0=Invalid, 1=Valid.
 
constexpr std::uint8_t DATA_STATUS_RESERVED = 0x08
 DataStatus bit: reserved.
 
constexpr std::uint8_t DATA_STATUS_PROVIDER_RUN = 0x10
 DataStatus bit: provider run state, 0=Stop, 1=Run.
 
constexpr std::uint8_t DATA_STATUS_STATION_OK = 0x20
 DataStatus bit: station health, 0=Problem, 1=OK.
 
constexpr std::uint8_t DATA_STATUS_IGNORE = 0x80
 DataStatus bit: 1=Ignore this frame.
 
constexpr std::uint8_t IOXS_GOOD = 0x80
 IOxS value: good, subslot level.
 
constexpr std::uint8_t IOXS_DATA_STATE_GOOD = 0x80
 IOxS value: DataState is bit 7 of an IOxS byte; the lower bits carry Instance and Extension, so a received IOxS must be masked rather than compared to IOXS_GOOD.
 
constexpr std::uint8_t IOXS_BAD = 0x00
 IOxS value: bad.
 
constexpr std::uint8_t IOXS_EXTENSION = 0x01
 IOxS value: extension bit set (another IOxS byte follows).
 

Function Documentation

◆ BuildEthernetFrame()

Bytes profinet::rt::BuildEthernetFrame ( const MacAddress dstMac,
const MacAddress srcMac,
const RTFrame rtFrame 
)

Build a complete Ethernet frame carrying an RT frame.

Parameters
dstMacDestination MAC address.
srcMacSource MAC address.
rtFrameRT frame to embed.
Returns
DstMac + SrcMac + EtherType(0x8892) + RtFrame.ToBytes().

Definition at line 212 of file rt.cpp.

References ETHERTYPE_PROFINET, profinet::LowByteMask, profinet::OneOctetShift, and profinet::rt::RTFrame::ToBytes().

Referenced by profinet::cyclic::CyclicController::SendOutputFrame().

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

◆ BuildIocrConfigs()

template<typename SlotT >
std::pair< IOCRConfig, IOCRConfig > profinet::rt::BuildIocrConfigs ( const std::vector< SlotT > &  slots,
std::uint16_t  inputFrameId,
std::uint16_t  outputFrameId,
std::uint16_t  sendClockFactor = 32,
std::uint16_t  reductionRatio = 32,
int  watchdogFactor = 3,
std::uint16_t  cSduLength = 43 
)

◆ ParseEthernetFrame()

std::optional< RTFrame > profinet::rt::ParseEthernetFrame ( const Bytes data)

Parse a complete Ethernet frame and extract its RT frame.

Parameters
dataComplete frame bytes, starting at the destination MAC.
Returns
The parsed RT frame, or std::nullopt if too short, not PROFINET EtherType, or malformed.

Definition at line 229 of file rt.cpp.

References ETHERTYPE_PROFINET, profinet::rt::RTFrame::FromBytes(), and profinet::OneOctetShift.

+ Here is the call graph for this function:

Variable Documentation

◆ DATA_STATUS_IGNORE

constexpr std::uint8_t profinet::rt::DATA_STATUS_IGNORE = 0x80
inlineconstexpr

DataStatus bit: 1=Ignore this frame.

Definition at line 85 of file rt.h.

◆ DATA_STATUS_PROVIDER_RUN

constexpr std::uint8_t profinet::rt::DATA_STATUS_PROVIDER_RUN = 0x10
inlineconstexpr

DataStatus bit: provider run state, 0=Stop, 1=Run.

Definition at line 81 of file rt.h.

Referenced by profinet::rt::RTFrame::IsRunning(), and profinet::cyclic::CyclicController::SendOutputFrame().

◆ DATA_STATUS_REDUNDANCY

constexpr std::uint8_t profinet::rt::DATA_STATUS_REDUNDANCY = 0x02
inlineconstexpr

DataStatus bit: redundancy state.

Definition at line 75 of file rt.h.

◆ DATA_STATUS_RESERVED

constexpr std::uint8_t profinet::rt::DATA_STATUS_RESERVED = 0x08
inlineconstexpr

DataStatus bit: reserved.

Definition at line 79 of file rt.h.

◆ DATA_STATUS_STATE

constexpr std::uint8_t profinet::rt::DATA_STATUS_STATE = 0x01
inlineconstexpr

DataStatus bit: provider state, 0=Backup, 1=Primary.

Definition at line 73 of file rt.h.

Referenced by profinet::rt::RTFrame::IsPrimary(), profinet::cyclic::CyclicController::SendOutputFrame(), and profinet::cyclic::CyclicController::SendStopFrames().

◆ DATA_STATUS_STATION_OK

constexpr std::uint8_t profinet::rt::DATA_STATUS_STATION_OK = 0x20
inlineconstexpr

DataStatus bit: station health, 0=Problem, 1=OK.

Definition at line 83 of file rt.h.

Referenced by profinet::rt::RTFrame::IsOk(), profinet::cyclic::CyclicController::SendOutputFrame(), and profinet::cyclic::CyclicController::SendStopFrames().

◆ DATA_STATUS_VALID

constexpr std::uint8_t profinet::rt::DATA_STATUS_VALID = 0x04
inlineconstexpr

DataStatus bit: data validity, 0=Invalid, 1=Valid.

Definition at line 77 of file rt.h.

Referenced by profinet::rt::RTFrame::IsValid(), profinet::cyclic::CyclicController::SendOutputFrame(), and profinet::cyclic::CyclicController::SendStopFrames().

◆ ETHERTYPE_PROFINET

constexpr std::uint16_t profinet::rt::ETHERTYPE_PROFINET = 0x8892
inlineconstexpr

EtherType used by PROFINET RT frames (0x8892).

Definition at line 34 of file rt.h.

Referenced by BuildEthernetFrame(), ParseEthernetFrame(), and profinet::cyclic::CyclicController::ProcessInputFrame().

◆ FRAME_ID_ALARM_HIGH

constexpr std::uint16_t profinet::rt::FRAME_ID_ALARM_HIGH = 0xFC01
inlineconstexpr

Frame ID used for high-priority alarms.

Definition at line 55 of file rt.h.

◆ FRAME_ID_ALARM_LOW

constexpr std::uint16_t profinet::rt::FRAME_ID_ALARM_LOW = 0xFE01
inlineconstexpr

Frame ID used for low-priority alarms.

Definition at line 57 of file rt.h.

◆ FRAME_ID_RT_CLASS_1_MAX

constexpr std::uint16_t profinet::rt::FRAME_ID_RT_CLASS_1_MAX = 0xF7FF
inlineconstexpr

Maximum frame ID in the RT_CLASS_1 range.

Definition at line 46 of file rt.h.

◆ FRAME_ID_RT_CLASS_1_MIN

constexpr std::uint16_t profinet::rt::FRAME_ID_RT_CLASS_1_MIN = 0xC000
inlineconstexpr

Minimum frame ID in the RT_CLASS_1 range.

Definition at line 44 of file rt.h.

◆ IOCR_TYPE_INPUT

constexpr std::uint16_t profinet::rt::IOCR_TYPE_INPUT = 1
inlineconstexpr

IOCR direction: Device -> Controller.

Definition at line 60 of file rt.h.

Referenced by BuildIocrConfigs(), and profinet::rt::IOCRConfig::IsInput().

◆ IOCR_TYPE_OUTPUT

constexpr std::uint16_t profinet::rt::IOCR_TYPE_OUTPUT = 2
inlineconstexpr

IOCR direction: Controller -> Device.

Definition at line 62 of file rt.h.

Referenced by BuildIocrConfigs(), and profinet::rt::IOCRConfig::IsOutput().

◆ IOXS_BAD

constexpr std::uint8_t profinet::rt::IOXS_BAD = 0x00
inlineconstexpr

IOxS value: bad.

Definition at line 95 of file rt.h.

Referenced by profinet::cyclic::CyclicController::HandleWatchdogTimeout().

◆ IOXS_DATA_STATE_GOOD

constexpr std::uint8_t profinet::rt::IOXS_DATA_STATE_GOOD = 0x80
inlineconstexpr

IOxS value: DataState is bit 7 of an IOxS byte; the lower bits carry Instance and Extension, so a received IOxS must be masked rather than compared to IOXS_GOOD.

Definition at line 93 of file rt.h.

Referenced by profinet::cyclic::CyclicController::LocalIsInputGood(), and profinet::cyclic::CyclicController::ProcessInputFrame().

◆ IOXS_EXTENSION

constexpr std::uint8_t profinet::rt::IOXS_EXTENSION = 0x01
inlineconstexpr

IOxS value: extension bit set (another IOxS byte follows).

Definition at line 97 of file rt.h.

◆ IOXS_GOOD

constexpr std::uint8_t profinet::rt::IOXS_GOOD = 0x80
inlineconstexpr

◆ RT_CLASS_1

constexpr std::uint8_t profinet::rt::RT_CLASS_1 = 0x01
inlineconstexpr

Real-time class: software scheduled (250us-512ms).

Definition at line 65 of file rt.h.

◆ RT_CLASS_2

constexpr std::uint8_t profinet::rt::RT_CLASS_2 = 0x02
inlineconstexpr

Real-time class: hardware scheduled (reserved).

Definition at line 67 of file rt.h.

◆ RT_CLASS_3

constexpr std::uint8_t profinet::rt::RT_CLASS_3 = 0x03
inlineconstexpr

Real-time class: isochronous (IRT, hardware only).

Definition at line 69 of file rt.h.

◆ VLAN_TAG_RT

constexpr std::uint16_t profinet::rt::VLAN_TAG_RT = 0x8100C000
inlineconstexpr

802.1Q priority tag for cyclic RT frames per IEC 61158-6-10: TPID 0x8100, PCP 6, VID 0 (TCI 0xC000, matching the negotiated IOCRTagHeader). Devices validate the negotiated priority, and managed switches may drop untagged sub-64-byte RT frames as runts, so TX frames must carry the tag.

Definition at line 52 of file rt.h.