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 IOCRConfigConfig () 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. This mirrors rt.py's CyclicDataBuilder exactly, substituting std::mutex for threading.Lock.

Definition at line 276 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 82 of file rt.cpp.

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

References sendBuffer.

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

+ Here is the caller graph for this function:

◆ Clear()

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

Zero the entire write buffer.

Definition at line 182 of file rt.cpp.

References dirty, writeBuffer, and writeLock.

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

References config.

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

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

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

References dirty, payload, writeBuffer, and writeLock.

◆ 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 169 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(), and profinet::cyclic::CyclicController::ProcessInputFrame().

+ 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 156 of file rt.cpp.

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

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

+ 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 89 of file rt.cpp.

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

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

+ 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 139 of file rt.cpp.

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

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

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

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

+ 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 189 of file rt.cpp.

References dirty, sendBuffer, writeBuffer, and writeLock.

Referenced by profinet::cyclic::CyclicController::SendStopFrames(), profinet::cyclic::CyclicController::Start(), 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 343 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 355 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 349 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 346 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 352 of file rt.h.

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


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