|
PROFINET IO Controller Stack 1.0.0
Modern C++ implementation of a PROFINET IO Controller stack
|
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(). | |
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.
|
explicit |
| Bytes profinet::rt::CyclicDataBuilder::Build | ( | ) | const |
Get the current send buffer contents.
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:| void profinet::rt::CyclicDataBuilder::Clear | ( | ) |
Zero the entire write buffer.
Definition at line 182 of file rt.cpp.
References dirty, writeBuffer, and writeLock.
|
inline |
| Bytes profinet::rt::CyclicDataBuilder::GetData | ( | int | slot, |
| int | subslot | ||
| ) | const |
Read one object's data from the write buffer.
| slot | Slot number of the object. |
| subslot | Subslot number of the object. |
Definition at line 107 of file rt.cpp.
References config, obj, profinet::rt::IOCRConfig::objects, writeBuffer, and writeLock.
| void profinet::rt::CyclicDataBuilder::Load | ( | const Bytes & | payload | ) |
| void profinet::rt::CyclicDataBuilder::SetAllIocs | ( | std::uint8_t | status = IOXS_GOOD | ) |
Set every object's IOCS byte to the same value.
| status | New 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:| void profinet::rt::CyclicDataBuilder::SetAllIops | ( | std::uint8_t | status = IOXS_GOOD | ) |
Set every object's IOPS byte to the same value.
| status | New 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:| void profinet::rt::CyclicDataBuilder::SetData | ( | int | slot, |
| int | subslot, | ||
| const Bytes & | data | ||
| ) |
Write one object's data into the write buffer.
| slot | Slot number of the object. |
| subslot | Subslot number of the object. |
| data | New 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:| 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.
| slot | Slot number of the object. |
| subslot | Subslot number of the object. |
| status | New 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.
| void profinet::rt::CyclicDataBuilder::SetIops | ( | int | slot, |
| int | subslot, | ||
| std::uint8_t | status = IOXS_GOOD |
||
| ) |
Set one object's IOPS (provider status) byte.
| slot | Slot number of the object. |
| subslot | Subslot number of the object. |
| status | New 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:| 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:
|
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().
|
private |
|
private |
|
private |
|
mutableprivate |