PROFINET IO Controller Stack 1.0.0
Modern C++ implementation of a PROFINET IO Controller stack
Loading...
Searching...
No Matches
rpcTypes.h
Go to the documentation of this file.
1
11#pragma once
12
13#include <cstdint>
14#include <optional>
15#include <string>
16#include <vector>
17
18#include "profinet/blocks.h"
19#include "profinet/dcp.h"
20namespace profinet::rpc
21{
22// =============================================================================
23// Constants
24// =============================================================================
25// NOLINTBEGIN(readability-identifier-naming)
27inline constexpr std::uint16_t RPC_PORT = 0x8894;
29inline constexpr std::uint16_t RPC_BIND_PORT = 0x8895;
30
32inline const std::string UUID_NULL = "00000000-0000-0000-0000-000000000000";
34inline const std::string UUID_EPM_V4 = "e1af8308-5d1f-11c9-91a4-08002b14a0fa";
36inline const std::string UUID_PNIO_DEVICE = "dea00001-6c97-11d1-8271-00a02442df7d";
38inline const std::string UUID_PNIO_CONTROLLER = "dea00002-6c97-11d1-8271-00a02442df7d";
39
41inline constexpr std::uint32_t PNIO_DEVICE_INTERFACE_VERSION = 1;
42
44inline constexpr std::uint32_t EPM_LOOKUP = 0x02;
46inline constexpr std::uint32_t EPM_INQUIRY_ALL = 0x00;
48inline constexpr std::uint32_t EPM_INQUIRY_INTERFACE = 0x01;
49
51inline constexpr double DEFAULT_TIMEOUT = 5.0;
53inline constexpr double CONNECTION_TIMEOUT = 10.0;
54
55// CONTROL block types / commands (subset of indices.h's catalog needed
56// directly by RPCCon).
58inline constexpr std::uint16_t BLOCK_IOD_CONTROL_PRM_END_REQ = 0x0110;
60inline constexpr std::uint16_t BLOCK_IOD_CONTROL_APP_READY_REQ = 0x0112;
62inline constexpr std::uint16_t BLOCK_IOD_CONTROL_APP_READY_RES = 0x8112;
64inline constexpr std::uint16_t BLOCK_IOD_CONTROL_RT_CLASS_3_REQ = 0x0117;
66inline constexpr std::uint16_t BLOCK_PRM_BEGIN_REQ = 0x0118;
68inline constexpr std::uint16_t BLOCK_RELEASE_REQ = 0x0114;
69
71inline constexpr std::uint16_t CONTROL_CMD_PRM_END = 0x0001;
73inline constexpr std::uint16_t CONTROL_CMD_APP_READY = 0x0002;
75inline constexpr std::uint16_t CONTROL_CMD_RELEASE = 0x0004;
77inline constexpr std::uint16_t CONTROL_CMD_DONE = 0x0008;
79inline constexpr std::uint16_t CONTROL_CMD_READY_FOR_COMPANION = 0x0010;
81inline constexpr std::uint16_t CONTROL_CMD_READY_FOR_RT_CLASS_3 = 0x0020;
83inline constexpr std::uint16_t CONTROL_CMD_PRM_BEGIN = 0x0040;
84// NOLINTEND(readability-identifier-naming)
85// =============================================================================
86// IOCR (cyclic IO) configuration
87// =============================================================================
88
90struct IOSlot
91{
93 std::uint16_t slot = 0;
94
96 std::uint16_t subslot = 0;
97
99 std::uint16_t inputLength = 0;
100
102 std::uint16_t outputLength = 0;
103
105 std::uint32_t moduleIdent = 0;
106
108 std::uint32_t submoduleIdent = 0;
109
110 bool includeInInputIocr = false;
112
114 bool inputIoData = false;
116 bool outputIoData = false;
117 bool inputIocs = false;
118 bool outputIocs = false;
119
125 bool operator==(const IOSlot&) const = default;
126};
127
134{
136 std::vector<IOSlot> slots;
137
139 std::uint16_t sendClockFactor = 32;
140
142 std::uint16_t reductionRatio = 32;
143
145 std::uint16_t watchdogFactor = 6;
146
148 std::uint16_t dataHoldFactor = 6;
149
150 std::size_t dataLength = 43;
151
154 [[nodiscard]] std::uint32_t CycleTimeUs() const
155 {
156 return static_cast<std::uint32_t>(reductionRatio) * sendClockFactor * 125 / 4;
157 }
158
161 [[nodiscard]] double CycleTimeMs() const
162 {
163 return CycleTimeUs() / 1000.0;
164 }
165
168 [[nodiscard]] std::vector<std::string> Validate() const;
169
175 bool operator==(const IOCRSetup&) const = default;
176};
177
180{
182 std::array<std::uint8_t, uuidLenght> arUuid{};
183
185 std::uint16_t sessionKey = 0;
186
188 std::uint16_t inputFrameId = 0;
189
191 std::uint16_t outputFrameId = 0;
192
195
198 [[nodiscard]] bool HasCyclic() const
199 {
200 return inputFrameId != 0 || outputFrameId != 0;
201 }
202};
203
204// =============================================================================
205// RPCCon - PROFINET DCE/RPC connection to an IO-Device
206// =============================================================================
209{
211 std::uint16_t slot = 0;
213 std::uint16_t subslot = 0;
215 std::uint16_t index = 0;
219 std::uint32_t api = 0;
220};
221
226struct AllIM
227{
229 std::optional<PNInM0> im0;
231 std::optional<PNInM1> im1;
233 std::optional<PNInM2> im2;
235 std::optional<PNInM3> im3;
237 std::optional<PNInM4> im4;
239 std::optional<PNInM5> im5;
241 std::optional<PNInM6> im6;
243 std::optional<PNInM7> im7;
245 std::optional<PNInM8> im8;
247 std::optional<PNInM9> im9;
249 std::optional<PNInM10> im10;
251 std::optional<PNInM11> im11;
253 std::optional<PNInM12> im12;
255 std::optional<PNInM13> im13;
257 std::optional<PNInM14> im14;
259 std::optional<PNInM15> im15;
260
266 bool operator==(const AllIM&) const = default;
267};
270{
272 std::string status;
274 std::string name;
276 std::size_t size = 0;
278 std::string error;
280 std::uint8_t errorCode1 = 0;
282 std::uint8_t errorCode2 = 0;
283};
284
292{
295
297 std::uint16_t rpcPort = RPC_PORT;
298};
299} // namespace profinet::rpc
Declares PROFINET IO connection-management block structures and wire serialization.
PROFINET DCP discovery and device configuration interface.
constexpr std::uint16_t BLOCK_IOD_CONTROL_APP_READY_REQ
Block type: IODControlReqAppReady.
Definition rpcTypes.h:60
constexpr std::uint16_t CONTROL_CMD_DONE
Control command bit: Done.
Definition rpcTypes.h:77
constexpr std::uint16_t BLOCK_PRM_BEGIN_REQ
Block type: PrmBeginReq.
Definition rpcTypes.h:66
constexpr std::uint16_t CONTROL_CMD_PRM_BEGIN
Control command bit: PrmBegin.
Definition rpcTypes.h:83
const std::string UUID_PNIO_CONTROLLER
PROFINET IO-Controller interface UUID.
Definition rpcTypes.h:38
const std::string UUID_EPM_V4
Endpoint Mapper interface UUID.
Definition rpcTypes.h:34
constexpr double DEFAULT_TIMEOUT
Default RPC response timeout in seconds.
Definition rpcTypes.h:51
constexpr std::uint16_t BLOCK_IOD_CONTROL_RT_CLASS_3_REQ
Block type: IODControlReqRTClass3.
Definition rpcTypes.h:64
constexpr std::uint32_t PNIO_DEVICE_INTERFACE_VERSION
Interface version used for the PNIO device interface.
Definition rpcTypes.h:41
constexpr std::uint16_t BLOCK_IOD_CONTROL_PRM_END_REQ
Block type: IODControlReqPrmEnd.
Definition rpcTypes.h:58
constexpr std::uint16_t RPC_PORT
PROFINET IO RPC port (34964).
Definition rpcTypes.h:27
constexpr std::uint16_t BLOCK_RELEASE_REQ
Block type: IODReleaseReq.
Definition rpcTypes.h:68
constexpr std::uint16_t CONTROL_CMD_RELEASE
Control command bit: Release.
Definition rpcTypes.h:75
constexpr std::uint16_t CONTROL_CMD_READY_FOR_COMPANION
Control command bit: ReadyForCompanion.
Definition rpcTypes.h:79
constexpr std::uint16_t CONTROL_CMD_PRM_END
Control command bit: PrmEnd.
Definition rpcTypes.h:71
const std::string UUID_NULL
Null (all-zero) DCE/RPC UUID string.
Definition rpcTypes.h:32
constexpr std::uint16_t RPC_BIND_PORT
PROFINET IO RPC bind port (34965).
Definition rpcTypes.h:29
constexpr std::uint32_t EPM_INQUIRY_ALL
EPM inquiry type: all interfaces.
Definition rpcTypes.h:46
const std::string UUID_PNIO_DEVICE
PROFINET IO-Device interface UUID.
Definition rpcTypes.h:36
constexpr double CONNECTION_TIMEOUT
Maximum idle time in seconds before an AR is considered to need re-connection.
Definition rpcTypes.h:53
constexpr std::uint16_t CONTROL_CMD_APP_READY
Control command bit: ApplicationReady.
Definition rpcTypes.h:73
constexpr std::uint32_t EPM_INQUIRY_INTERFACE
EPM inquiry type: specific interface.
Definition rpcTypes.h:48
constexpr std::uint16_t CONTROL_CMD_READY_FOR_RT_CLASS_3
Control command bit: ReadyForRTClass3.
Definition rpcTypes.h:81
constexpr std::uint16_t BLOCK_IOD_CONTROL_APP_READY_RES
Block type: IODControlResAppReady.
Definition rpcTypes.h:62
constexpr std::uint32_t EPM_LOOKUP
EPM operation: Lookup.
Definition rpcTypes.h:44
std::vector< std::uint8_t > Bytes
Generic byte buffer alias used throughout the library for raw wire data.
Definition protocol.h:52
All I&M records a device supports, read in one call.
Definition rpcTypes.h:227
std::optional< PNInM7 > im7
I&M7 (reserved), if supported.
Definition rpcTypes.h:243
std::optional< PNInM15 > im15
I&M15 (reserved), if supported.
Definition rpcTypes.h:259
std::optional< PNInM9 > im9
I&M9 (reserved), if supported.
Definition rpcTypes.h:247
std::optional< PNInM14 > im14
I&M14 (reserved), if supported.
Definition rpcTypes.h:257
std::optional< PNInM1 > im1
I&M1 (tag function/location), if supported.
Definition rpcTypes.h:231
std::optional< PNInM5 > im5
I&M5 (free-text annotation), if supported.
Definition rpcTypes.h:239
std::optional< PNInM10 > im10
I&M10 (reserved), if supported.
Definition rpcTypes.h:249
std::optional< PNInM3 > im3
I&M3 (free-text descriptor), if supported.
Definition rpcTypes.h:235
std::optional< PNInM6 > im6
I&M6 (reserved), if supported.
Definition rpcTypes.h:241
std::optional< PNInM13 > im13
I&M13 (reserved), if supported.
Definition rpcTypes.h:255
std::optional< PNInM11 > im11
I&M11 (reserved), if supported.
Definition rpcTypes.h:251
bool operator==(const AllIM &) const =default
Compares two AllIM for equality.
std::optional< PNInM2 > im2
I&M2 (installation date), if supported.
Definition rpcTypes.h:233
std::optional< PNInM12 > im12
I&M12 (reserved), if supported.
Definition rpcTypes.h:253
std::optional< PNInM4 > im4
I&M4 (PROFIsafe signature), if supported.
Definition rpcTypes.h:237
std::optional< PNInM0 > im0
I&M0 (mandatory identification data).
Definition rpcTypes.h:229
std::optional< PNInM8 > im8
I&M8 (reserved), if supported.
Definition rpcTypes.h:245
Result of a successful RPCCon::Connect() that also established cyclic IO.
Definition rpcTypes.h:180
std::array< std::uint8_t, uuidLenght > arUuid
AR UUID assigned to this connection.
Definition rpcTypes.h:182
bool HasCyclic() const
Whether cyclic IO was actually established.
Definition rpcTypes.h:198
int deviceAlarmRef
Device's local alarm reference, if an AlarmCR was also established.
Definition rpcTypes.h:194
std::uint16_t outputFrameId
Frame ID assigned to the output (controller -> device) IOCR.
Definition rpcTypes.h:191
std::uint16_t sessionKey
Session key for this connection.
Definition rpcTypes.h:185
std::uint16_t inputFrameId
Frame ID assigned to the input (device -> controller) IOCR.
Definition rpcTypes.h:188
Configuration for establishing cyclic IO alongside an AR.
Definition rpcTypes.h:134
std::uint16_t watchdogFactor
Watchdog factor (missed-frame tolerance before a timeout fault).
Definition rpcTypes.h:145
std::uint16_t dataHoldFactor
Data hold factor (how long to keep the last good frame's data).
Definition rpcTypes.h:148
std::vector< IOSlot > slots
Slots to include in the cyclic data frames.
Definition rpcTypes.h:136
bool operator==(const IOCRSetup &) const =default
Compares two IOCR configurations for equality.
std::vector< std::string > Validate() const
Sanity-check this configuration.
Definition rpc.cpp:625
double CycleTimeMs() const
Compute the cycle time in milliseconds.
Definition rpcTypes.h:161
std::uint16_t reductionRatio
Reduction ratio relative to the send clock.
Definition rpcTypes.h:142
std::uint16_t sendClockFactor
Send clock base factor (31.25us units).
Definition rpcTypes.h:139
std::uint32_t CycleTimeUs() const
Compute the cycle time in microseconds from SendClockFactor/ReductionRatio.
Definition rpcTypes.h:154
One slot/subslot's expected module configuration and IO data sizes.
Definition rpcTypes.h:91
bool operator==(const IOSlot &) const =default
Compares two IO slot configurations for equality.
std::uint16_t inputLength
Expected input data length in bytes (0 if no input data).
Definition rpcTypes.h:99
std::uint16_t slot
Slot number.
Definition rpcTypes.h:93
std::uint16_t outputLength
Expected output data length in bytes (0 if no output data).
Definition rpcTypes.h:102
bool outputIoData
IODataObject for Output CR.
Definition rpcTypes.h:116
bool inputIoData
IODataObject for Input CR.
Definition rpcTypes.h:114
std::uint32_t moduleIdent
Expected module ident number.
Definition rpcTypes.h:105
std::uint32_t submoduleIdent
Expected submodule ident number.
Definition rpcTypes.h:108
std::uint16_t subslot
Subslot number.
Definition rpcTypes.h:96
Result of probing one index in EnumerateIndices().
Definition rpcTypes.h:270
std::uint8_t errorCode1
PNIOError ErrorCode1, if the error was a PNIOError.
Definition rpcTypes.h:280
std::string name
Human-readable name of the index.
Definition rpcTypes.h:274
std::size_t size
Payload size in bytes; valid when Status == "readable".
Definition rpcTypes.h:276
std::uint8_t errorCode2
PNIOError ErrorCode2, if the error was a PNIOError.
Definition rpcTypes.h:282
std::string error
Error message; valid when Status == "error".
Definition rpcTypes.h:278
std::string status
Probe outcome: "readable", "empty", or "error".
Definition rpcTypes.h:272
Configuration options for an RPC connection.
Definition rpcTypes.h:292
double timeoutSec
Timeout in seconds for RPC operations.
Definition rpcTypes.h:294
std::uint16_t rpcPort
UDP port used for RPC communication.
Definition rpcTypes.h:297
A single write operation for WriteMultiple().
Definition rpcTypes.h:209
std::uint16_t slot
Slot number.
Definition rpcTypes.h:211
Bytes data
Record data to write.
Definition rpcTypes.h:217
std::uint32_t api
API number.
Definition rpcTypes.h:219
std::uint16_t subslot
Subslot number.
Definition rpcTypes.h:213
std::uint16_t index
Record data index to write.
Definition rpcTypes.h:215