PROFINET IO Controller Stack 1.0.0
Modern C++ implementation of a PROFINET IO Controller stack
Loading...
Searching...
No Matches
virtual_pn_lab.h
Go to the documentation of this file.
1
3#pragma once
4
5#include <cstdint>
6#include <memory>
7#include <string>
8#include <vector>
9
10#include "profinet/gsdml.h"
11#include "profinet/rt.h"
15
16namespace profinet::sim
17{
18
22{
23 public:
25 VirtualProfinetLab() = default;
27
30
39 VirtualAumaValve& AddAumaValve(std::string name,
40 const gsdml::GSDMLDevice& gsdml,
41 MacAddress deviceMac,
42 rt::IOCRConfig inputIocr,
43 rt::IOCRConfig outputIocr,
45
47 VirtualPhoenixPlc& AddPhoenixPlc(std::string name,
48 const gsdml::GSDMLDevice& gsdml,
49 MacAddress controllerMac);
50
52 void Connect(asio::io_context& ioContext,
53 const std::string& plcName,
54 const std::string& valveName,
55 rt::IOCRConfig inputIocr,
56 rt::IOCRConfig outputIocr,
57 int maxConsecutiveTimeouts = cyclic::DEFAULT_MAX_CONSECUTIVE_TIMEOUTS);
58
60 void SetAumaScenario(const std::string& valveName, VirtualAumaScenario scenario);
61
63 [[nodiscard]] InMemoryEthernetBus& Bus() noexcept;
64
66 [[nodiscard]] VirtualAumaValve& Valve(const std::string& name);
67
69 [[nodiscard]] const VirtualAumaValve& Valve(const std::string& name) const;
70
72 [[nodiscard]] VirtualPhoenixPlc& Plc(const std::string& name);
73
75 [[nodiscard]] const VirtualPhoenixPlc& Plc(const std::string& name) const;
76
78 [[nodiscard]] std::vector<std::string> ValveNames() const;
79
81 [[nodiscard]] std::vector<std::string> PlcNames() const;
82
84 [[nodiscard]] std::string StatusReport() const;
85
87 void Stop();
88
89 private:
91 struct AumaEntry
92 {
93 std::string name;
94 std::unique_ptr<VirtualAumaValve> valve;
95 };
96 struct PlcEntry
97 {
98 std::string name;
99 std::unique_ptr<VirtualPhoenixPlc> plc;
100 };
101 std::vector<AumaEntry> valves;
102 std::vector<PlcEntry> plcs;
103
105 [[nodiscard]] bool IsMacInUse(const MacAddress& mac) const noexcept;
106};
107
108} // namespace profinet::sim
Small virtual Ethernet switch suitable for deterministic tests and demos.
AUMA SGx application model that behaves as a real RTC1 peer in memory.
Virtual Phoenix Contact AXC F 1252 controller hosting real CyclicController instances.
Owns one shared Ethernet bus plus any number of virtual PLCs and AUMA valves.
void SetAumaScenario(const std::string &valveName, VirtualAumaScenario scenario)
Set one valve scenario.
std::vector< AumaEntry > valves
std::vector< std::string > PlcNames() const
Return all PLC names.
VirtualPhoenixPlc & AddPhoenixPlc(std::string name, const gsdml::GSDMLDevice &gsdml, MacAddress controllerMac)
Add one Phoenix AXC F 1252 controller instance.
VirtualProfinetLab(const VirtualProfinetLab &)=delete
VirtualProfinetLab()=default
Create an empty virtual network.
VirtualProfinetLab & operator=(const VirtualProfinetLab &)=delete
std::string StatusReport() const
Render a compact multi-device status dashboard.
InMemoryEthernetBus & Bus() noexcept
Return the shared virtual bus.
VirtualPhoenixPlc & Plc(const std::string &name)
Find a PLC by name.
void Stop()
Stop all devices and controllers.
bool IsMacInUse(const MacAddress &mac) const noexcept
Determine whether a node MAC is already used by this lab.
VirtualAumaValve & Valve(const std::string &name)
Find a valve by name.
void Connect(asio::io_context &ioContext, const std::string &plcName, const std::string &valveName, rt::IOCRConfig inputIocr, rt::IOCRConfig outputIocr, int maxConsecutiveTimeouts=cyclic::DEFAULT_MAX_CONSECUTIVE_TIMEOUTS)
Connect a PLC to an AUMA valve.
VirtualAumaValve & AddAumaValve(std::string name, const gsdml::GSDMLDevice &gsdml, MacAddress deviceMac, rt::IOCRConfig inputIocr, rt::IOCRConfig outputIocr, VirtualAumaValveConfiguration config={})
Add one AUMA valve instance.
std::vector< std::string > ValveNames() const
Return all valve names.
Declares the GSDML parser and PROFINET device-description data model.
Thread-safe in-memory Layer-2 Ethernet switch for PROFINET simulation.
constexpr int DEFAULT_MAX_CONSECUTIVE_TIMEOUTS
Default number of consecutive watchdog timeouts before transitioning to Fault.
Definition cyclic.h:157
VirtualAumaScenario
Deterministic operating and communication scenarios for a virtual AUMA valve.
std::array< std::uint8_t, macAddressLength > MacAddress
A 6-byte Ethernet MAC address.
Definition util.h:48
Declares PROFINET RT_CLASS_1 cyclic frame and IOCR data structures.
Complete parsed GSDML device profile.
Definition gsdml.h:166
IOCR configuration derived from AR setup: timing parameters and IO object mappings needed for cyclic ...
Definition rt.h:137
Application-level signal mapping and motion settings for a virtual AUMA SGx.
std::unique_ptr< VirtualAumaValve > valve
std::unique_ptr< VirtualPhoenixPlc > plc
std::unique_ptr< asio::io_context > ioContext
Shared ASIO context.
Stateful in-memory AUMA SGx PROFINET IO device simulator.
In-memory Phoenix Contact AXC F 1252 PLC/controller simulator.