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

Builds C_SDU payload from IO data objects with double-buffering. More...

#include <rt.h>

+ Collaboration diagram for profinet::rt::CyclicDataBuilder:

Public Member Functions

 CyclicDataBuilder (IOCRConfig config)
 Construct a builder for the given IOCR configuration.
 
void SetData (int slot, int subslot, const Bytes &data)
 Write one object's data into the write buffer.
 
Bytes GetData (int slot, int subslot) const
 Read one object's data from the write buffer.
 
void SetIops (int slot, int subslot, std::uint8_t status=IOXS_GOOD)
 Set one object's IOPS (provider status) byte.
 
void SetIocs (int slot, int subslot, std::uint8_t status=IOXS_GOOD)
 Set one object's IOCS (consumer status) byte, if it has one.
 
void SetAllIops (std::uint8_t status=IOXS_GOOD)
 Set every object's IOPS byte to the same value.
 
void SetAllIocs (std::uint8_t status=IOXS_GOOD)
 Set every object's IOCS byte to the same value.
 
void Clear ()
 Zero the entire write buffer.
 
void Swap ()
 Promote the write buffer to the send buffer.
 
Bytes Build () const
 Get the current send buffer contents.
 
void Load (const Bytes &payload)
 Load received payload data into the write buffer.
 
const IOCRConfig & Config () const
 The IOCR configuration this builder was constructed with.
 

Private Attributes

IOCRConfig config
 IOCR configuration describing the objects this builder manages.
 
Bytes writeBuffer
 Buffer the application thread writes into.
 
Bytes sendBuffer
 Buffer the TX thread reads from (updated only by Swap()).
 
std::mutex writeLock
 Guards writeBuffer against concurrent access.
 
bool dirty = false
 Whether writeBuffer has changed since the last Swap().
 

Detailed Description

Builds C_SDU payload from IO data objects with double-buffering.

Two buffers give lock-free reads for the TX thread: the application thread writes via SetData()/SetIops()/SetIocs() into the write buffer; Swap() atomically promotes it to the send buffer that Build() reads from.

Definition at line 286 of file rt.h.

Constructor & Destructor Documentation

◆ CyclicDataBuilder()

profinet::rt::CyclicDataBuilder::CyclicDataBuilder ( IOCRConfig  config)
explicit

Construct a builder for the given IOCR configuration.

Parameters
configIOCR configuration describing the objects to build data for.

Definition at line 105 of file rt.cpp.

References profinet::rt::IOCRConfig::dataLength, and profinet::rt::IOCRConfig::objects.

Member Function Documentation

◆ Build()

Bytes profinet::rt::CyclicDataBuilder::Build ( ) const

Get the current send buffer contents.

Returns
A copy of the send buffer.

Lock-free: reads the send buffer, only updated by Swap().

Definition at line 228 of file rt.cpp.

References sendBuffer, and writeLock.

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

+ Here is the caller graph for this function:

◆ Clear()

void profinet::rt::CyclicDataBuilder::Clear ( )

Zero the entire write buffer.

Definition at line 211 of file rt.cpp.

References dirty, writeBuffer, and writeLock.

Referenced by TEST_F().

+ Here is the caller graph for this function:

◆ Config()

const IOCRConfig & profinet::rt::CyclicDataBuilder::Config ( ) const
inline

The IOCR configuration this builder was constructed with.

Returns
A const reference to the configuration.

Definition at line 346 of file rt.h.

References config.

Referenced by TEST_F().

+ Here is the caller graph for this function:

◆ GetData()

Bytes profinet::rt::CyclicDataBuilder::GetData ( int  slot,
int  subslot 
) const

Read one object's data from the write buffer.

Parameters
slotSlot number of the object.
subslotSubslot number of the object.
Returns
A copy of the object's current data.

Definition at line 133 of file rt.cpp.

References config, obj, profinet::rt::IOCRConfig::objects, writeBuffer, and writeLock.

Referenced by profinet::cyclic::CyclicController::GetOutputData(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().

+ Here is the caller graph for this function:

◆ Load()

void profinet::rt::CyclicDataBuilder::Load ( const Bytes &  payload)

Load received payload data into the write buffer.

Parameters
payloadReceived cyclic frame payload.

Definition at line 234 of file rt.cpp.

References dirty, payload, writeBuffer, and writeLock.

Referenced by profinet::TEST(), TEST_F(), and TEST_F().

+ Here is the caller graph for this function:

◆ SetAllIocs()

void profinet::rt::CyclicDataBuilder::SetAllIocs ( std::uint8_t  status = IOXS_GOOD)

Set every object's IOCS byte to the same value.

Parameters
statusNew IOCS value (defaults to IOXS_GOOD).

Definition at line 198 of file rt.cpp.

References config, dirty, obj, profinet::rt::IOCRConfig::objects, writeBuffer, and writeLock.

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

+ Here is the caller graph for this function:

◆ SetAllIops()

void profinet::rt::CyclicDataBuilder::SetAllIops ( std::uint8_t  status = IOXS_GOOD)

Set every object's IOPS byte to the same value.

Parameters
statusNew IOPS value (defaults to IOXS_GOOD).

Definition at line 185 of file rt.cpp.

References config, dirty, obj, profinet::rt::IOCRConfig::objects, writeBuffer, and writeLock.

Referenced by profinet::cyclic::CyclicController::CyclicController(), and TEST_F().

+ Here is the caller graph for this function:

◆ SetData()

void profinet::rt::CyclicDataBuilder::SetData ( int  slot,
int  subslot,
const Bytes &  data 
)

Write one object's data into the write buffer.

Parameters
slotSlot number of the object.
subslotSubslot number of the object.
dataNew data for the object (truncated to the object's configured length).

Thread-safe. Throws std::invalid_argument if slot/subslot unknown.

Definition at line 116 of file rt.cpp.

References config, dirty, obj, profinet::rt::IOCRConfig::objects, writeBuffer, and writeLock.

Referenced by profinet::cyclic::CyclicController::SetOutputData(), profinet::TEST(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().

+ Here is the caller graph for this function:

◆ SetIocs()

void profinet::rt::CyclicDataBuilder::SetIocs ( int  slot,
int  subslot,
std::uint8_t  status = IOXS_GOOD 
)

Set one object's IOCS (consumer status) byte, if it has one.

Parameters
slotSlot number of the object.
subslotSubslot number of the object.
statusNew IOCS value (defaults to IOXS_GOOD).

Definition at line 167 of file rt.cpp.

References config, dirty, obj, profinet::rt::IOCRConfig::objects, writeBuffer, and writeLock.

Referenced by TEST_F(), TEST_F(), and TEST_F().

+ Here is the caller graph for this function:

◆ SetIops()

void profinet::rt::CyclicDataBuilder::SetIops ( int  slot,
int  subslot,
std::uint8_t  status = IOXS_GOOD 
)

Set one object's IOPS (provider status) byte.

Parameters
slotSlot number of the object.
subslotSubslot number of the object.
statusNew IOPS value (defaults to IOXS_GOOD).

Skips IOCS-only objects (DataLength == 0), which have no IOPS byte.

Definition at line 149 of file rt.cpp.

References config, dirty, obj, profinet::rt::IOCRConfig::objects, writeBuffer, and writeLock.

Referenced by profinet::cyclic::CyclicController::SetOutputData(), TEST_F(), TEST_F(), and TEST_F().

+ Here is the caller graph for this function:

◆ Swap()

void profinet::rt::CyclicDataBuilder::Swap ( )

Promote the write buffer to the send buffer.

Call at the start of each cycle. Only copies if the write buffer has changed since the last swap.

Definition at line 218 of file rt.cpp.

References dirty, sendBuffer, writeBuffer, and writeLock.

Referenced by profinet::cyclic::CyclicController::SendStopFrames(), profinet::cyclic::CyclicController::Start(), profinet::TEST(), profinet::TEST(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and profinet::cyclic::CyclicController::TxCycle().

+ Here is the caller graph for this function:

Member Data Documentation

◆ config

IOCRConfig profinet::rt::CyclicDataBuilder::config
private

IOCR configuration describing the objects this builder manages.

Definition at line 353 of file rt.h.

Referenced by Config(), GetData(), SetAllIocs(), SetAllIops(), SetData(), SetIocs(), and SetIops().

◆ dirty

bool profinet::rt::CyclicDataBuilder::dirty = false
private

Whether writeBuffer has changed since the last Swap().

Definition at line 365 of file rt.h.

Referenced by Clear(), Load(), SetAllIocs(), SetAllIops(), SetData(), SetIocs(), SetIops(), and Swap().

◆ sendBuffer

Bytes profinet::rt::CyclicDataBuilder::sendBuffer
private

Buffer the TX thread reads from (updated only by Swap()).

Definition at line 359 of file rt.h.

Referenced by Build(), and Swap().

◆ writeBuffer

Bytes profinet::rt::CyclicDataBuilder::writeBuffer
private

Buffer the application thread writes into.

Definition at line 356 of file rt.h.

Referenced by Clear(), GetData(), Load(), SetAllIocs(), SetAllIops(), SetData(), SetIocs(), SetIops(), and Swap().

◆ writeLock

std::mutex profinet::rt::CyclicDataBuilder::writeLock
mutableprivate

Guards writeBuffer against concurrent access.

Definition at line 362 of file rt.h.

Referenced by Build(), Clear(), GetData(), Load(), SetAllIocs(), SetAllIops(), SetData(), SetIocs(), SetIops(), and Swap().


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