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...
 
class  RtFrameTest
 Test fixture for RT Ethernet frame serialization. More...
 

Functions

template<typename SlotT >
std::pair< IOCRConfig, IOCRConfig > 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=40)
 
Bytes BuildEthernetFrame (const MacAddress &dstMac, const MacAddress &srcMac, const RTFrame &rtFrame)
 Build a complete Ethernet frame carrying an RT frame.
 
std::optional< RTFrame > ParseEthernetFrame (const Bytes &data)
 Parse a complete Ethernet frame and extract its RT frame.
 
 TEST_F (RtFrameTest, DISABLED_TaggedEthernetFrameRoundTrips)
 
 TEST_F (RtFrameTest, UntaggedEthernetFrameParses)
 
 TEST_F (RtFrameTest, NonProfinetEtherTypeIsRejected)
 

Variables

constexpr std::uint16_t ETHERTYPE_PROFINET = 0x8892
 EtherType used by PROFINET RT frames (0x8892).
 
constexpr std::uint16_t ETHERTYPE_VLAN = 0x8100
 EtherType used by VLAN frames, 802.1Q VLAN TPID (0x8100).
 
constexpr std::uint16_t ETHERTYPE_VLAN_AD = 0x88A8
 EtherType used by VLAN frames, 802.1ad VLAN TPID (0x88A8).
 
constexpr std::uint16_t ETHERTYPE_VLAN_LEGACY = 0x9100
 EtherType used by VLAN frames, 802.1Q double-tagging legacy VLAN TPID (0x9100).
 
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 242 of file rt.cpp.

References ETHERTYPE_PROFINET, profinet::wire::PutBigEndian(), and profinet::rt::RTFrame::ToBytes().

Referenced by profinet::sim::VirtualAumaValve::SendInputFrame(), profinet::cyclic::CyclicController::SendOutputFrame(), profinet::TEST(), profinet::TEST(), profinet::sim::TEST(), profinet::sim::TEST(), profinet::sim::TEST(), profinet::sim::TEST(), profinet::sim::TEST(), profinet::sim::TEST(), profinet::sim::TEST(), profinet::sim::TEST(), TEST_F(), and TEST_F().

+ 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 = 40 
)

◆ 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 261 of file rt.cpp.

References ETHERTYPE_PROFINET, ETHERTYPE_VLAN, profinet::rt::RTFrame::FromBytes(), profinet::wire::Reader::Skip(), profinet::wire::Reader::SkipTo(), and profinet::wire::Reader::U16().

Referenced by profinet::sim::VirtualAumaValve::ProcessOutputFrame(), profinet::CyclicCaptureTests::TEST(), profinet::sim::TEST(), profinet::sim::TEST(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().

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

◆ TEST_F() [1/3]

profinet::rt::TEST_F ( RtFrameTest  ,
DISABLED_TaggedEthernetFrameRoundTrips   
)
Test:
Verify that a priority-tagged RT Ethernet frame round-trips.

Definition at line 48 of file test_rtFrame.cpp.

References BuildEthernetFrame(), frame, and ParseEthernetFrame().

+ Here is the call graph for this function:

◆ TEST_F() [2/3]

profinet::rt::TEST_F ( RtFrameTest  ,
NonProfinetEtherTypeIsRejected   
)
Test:
Verify that an Ethernet frame with a non-PROFINET EtherType is rejected.

Definition at line 115 of file test_rtFrame.cpp.

References ParseEthernetFrame().

+ Here is the call graph for this function:

◆ TEST_F() [3/3]

profinet::rt::TEST_F ( RtFrameTest  ,
UntaggedEthernetFrameParses   
)
Test:
Verify that untagged RT Ethernet frames remain supported.

Definition at line 83 of file test_rtFrame.cpp.

References frame, and ParseEthernetFrame().

+ 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 91 of file rt.h.

◆ DATA_STATUS_PROVIDER_RUN

◆ DATA_STATUS_REDUNDANCY

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

DataStatus bit: redundancy state.

Definition at line 81 of file rt.h.

◆ DATA_STATUS_RESERVED

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

DataStatus bit: reserved.

Definition at line 85 of file rt.h.

◆ DATA_STATUS_STATE

◆ DATA_STATUS_STATION_OK

◆ DATA_STATUS_VALID

◆ ETHERTYPE_PROFINET

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

◆ ETHERTYPE_VLAN

constexpr std::uint16_t profinet::rt::ETHERTYPE_VLAN = 0x8100
inlineconstexpr

EtherType used by VLAN frames, 802.1Q VLAN TPID (0x8100).

Definition at line 36 of file rt.h.

Referenced by ParseEthernetFrame(), and profinet::SkipVlanTags().

◆ ETHERTYPE_VLAN_AD

constexpr std::uint16_t profinet::rt::ETHERTYPE_VLAN_AD = 0x88A8
inlineconstexpr

EtherType used by VLAN frames, 802.1ad VLAN TPID (0x88A8).

Definition at line 38 of file rt.h.

Referenced by profinet::SkipVlanTags().

◆ ETHERTYPE_VLAN_LEGACY

constexpr std::uint16_t profinet::rt::ETHERTYPE_VLAN_LEGACY = 0x9100
inlineconstexpr

EtherType used by VLAN frames, 802.1Q double-tagging legacy VLAN TPID (0x9100).

Definition at line 40 of file rt.h.

Referenced by profinet::SkipVlanTags().

◆ 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 61 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 63 of file rt.h.

Referenced by profinet::sim::TEST().

◆ 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 52 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 50 of file rt.h.

◆ IOCR_TYPE_INPUT

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

◆ IOCR_TYPE_OUTPUT

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

◆ IOXS_BAD

◆ 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 99 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 103 of file rt.h.

◆ IOXS_GOOD

◆ RT_CLASS_1

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

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

Definition at line 71 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 73 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 75 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 58 of file rt.h.