PROFINET IO Controller Stack 1.0.0
Modern C++ implementation of a PROFINET IO Controller stack
Loading...
Searching...
No Matches
dcp.h
Go to the documentation of this file.
1
31
32#pragma once
33
34#include <chrono>
35#include <cstdint>
36#include <functional>
37#include <map>
38#include <optional>
39#include <string>
40#include <utility>
41#include <vector>
42
44#include "profinet/protocol.h"
45#include "profinet/util.h"
46
48{
49// NOLINTBEGIN(readability-identifier-naming)
50// =============================================================================
51// Constants
52// =============================================================================
53
55inline const std::string DCP_MULTICAST_MAC = "01:0e:cf:00:00:00";
57inline const std::string DCP_HELLO_MULTICAST_MAC = "01:0e:cf:00:00:01";
58
60inline constexpr std::uint16_t DCP_IDENTIFY_REQUEST_FRAME_ID = 0xFEFE;
62inline constexpr std::uint16_t DCP_IDENTIFY_RESPONSE_FRAME_ID = 0xFEFF;
64inline constexpr std::uint16_t DCP_GET_SET_FRAME_ID = 0xFEFD;
66inline constexpr std::uint16_t DCP_HELLO_FRAME_ID = 0xFEFC;
67
69inline constexpr std::uint8_t DCP_SERVICE_ID_GET = 0x03;
71inline constexpr std::uint8_t DCP_SERVICE_ID_SET = 0x04;
73inline constexpr std::uint8_t DCP_SERVICE_ID_IDENTIFY = 0x05;
75inline constexpr std::uint8_t DCP_SERVICE_ID_HELLO = 0x06;
76
78inline constexpr std::uint8_t DCP_SERVICE_TYPE_REQUEST = 0x00;
80inline constexpr std::uint8_t DCP_SERVICE_TYPE_RESPONSE_SUCCESS = 0x01;
82inline constexpr std::uint8_t DCP_SERVICE_TYPE_RESPONSE_UNSUPPORTED = 0x05;
83
85inline constexpr std::size_t DCP_MAX_NAME_LENGTH = 240;
86
88inline constexpr std::uint8_t DCP_OPTION_IP = 0x01;
90inline constexpr std::uint8_t DCP_OPTION_DEVICE = 0x02;
92inline constexpr std::uint8_t DCP_OPTION_DHCP = 0x03;
94inline constexpr std::uint8_t DCP_OPTION_RESERVED = 0x04;
96inline constexpr std::uint8_t DCP_OPTION_CONTROL = 0x05;
98inline constexpr std::uint8_t DCP_OPTION_DEVICE_INITIATIVE = 0x06;
100inline constexpr std::uint8_t DCP_OPTION_NME = 0x07;
102inline constexpr std::uint8_t DCP_OPTION_ALL = 0xFF;
103
105inline constexpr std::uint8_t DCP_SUBOPTION_IP_MAC = 0x01;
107inline constexpr std::uint8_t DCP_SUBOPTION_IP_PARAMETER = 0x02;
109inline constexpr std::uint8_t DCP_SUBOPTION_IP_FULL_SUITE = 0x03;
110
112inline constexpr std::uint8_t DCP_SUBOPTION_DEVICE_TYPE = 0x01;
114inline constexpr std::uint8_t DCP_SUBOPTION_DEVICE_NAME = 0x02;
116inline constexpr std::uint8_t DCP_SUBOPTION_DEVICE_ID = 0x03;
118inline constexpr std::uint8_t DCP_SUBOPTION_DEVICE_ROLE = 0x04;
120inline constexpr std::uint8_t DCP_SUBOPTION_DEVICE_OPTIONS = 0x05;
122inline constexpr std::uint8_t DCP_SUBOPTION_DEVICE_ALIAS = 0x06;
124inline constexpr std::uint8_t DCP_SUBOPTION_DEVICE_INSTANCE = 0x07;
126inline constexpr std::uint8_t DCP_SUBOPTION_DEVICE_OEM_ID = 0x08;
128inline constexpr std::uint8_t DCP_SUBOPTION_DEVICE_RSI = 0x0A;
129
131inline constexpr std::uint8_t DCP_SUBOPTION_CONTROL_START = 0x01;
133inline constexpr std::uint8_t DCP_SUBOPTION_CONTROL_STOP = 0x02;
135inline constexpr std::uint8_t DCP_SUBOPTION_CONTROL_SIGNAL = 0x03;
137inline constexpr std::uint8_t DCP_SUBOPTION_CONTROL_RESPONSE = 0x04;
139inline constexpr std::uint8_t DCP_SUBOPTION_CONTROL_RESET_FACTORY = 0x05;
141inline constexpr std::uint8_t DCP_SUBOPTION_CONTROL_RESET_TO_FACTORY = 0x06;
142
144inline constexpr std::uint8_t DCP_SUBOPTION_DHCP_HOSTNAME = 0x0C;
146inline constexpr std::uint8_t DCP_SUBOPTION_DHCP_VENDOR_SPEC = 0x2B;
148inline constexpr std::uint8_t DCP_SUBOPTION_DHCP_SERVER_ID = 0x36;
150inline constexpr std::uint8_t DCP_SUBOPTION_DHCP_PARAM_REQ = 0x37;
152inline constexpr std::uint8_t DCP_SUBOPTION_DHCP_CLASS_ID = 0x3C;
154inline constexpr std::uint8_t DCP_SUBOPTION_DHCP_CLIENT_ID = 0x3D;
156inline constexpr std::uint8_t DCP_SUBOPTION_DHCP_FQDN = 0x51;
158inline constexpr std::uint8_t DCP_SUBOPTION_DHCP_UUID = 0x61;
160inline constexpr std::uint8_t DCP_SUBOPTION_DHCP_CONTROL = 0xFF;
161
163inline constexpr std::uint8_t DCP_SUBOPTION_DEVICE_INITIATIVE = 0x01;
164
166inline constexpr std::uint8_t DEVICE_ROLE_IO_DEVICE = 0x01;
168inline constexpr std::uint8_t DEVICE_ROLE_IO_CONTROLLER = 0x02;
170inline constexpr std::uint8_t DEVICE_ROLE_IO_MULTIDEVICE = 0x04;
172inline constexpr std::uint8_t DEVICE_ROLE_PN_SUPERVISOR = 0x08;
173
175inline constexpr std::uint16_t RESET_MODE_COMMUNICATION = 0x0002;
177inline constexpr std::uint16_t RESET_MODE_APPLICATION = 0x0004;
179inline constexpr std::uint16_t RESET_MODE_ENGINEERING = 0x0008;
181inline constexpr std::uint16_t RESET_MODE_ALL_DATA = 0x0010;
183inline constexpr std::uint16_t RESET_MODE_DEVICE = 0x0020;
185inline constexpr std::uint16_t RESET_MODE_FACTORY = 0x0040;
186
188inline constexpr std::uint16_t DEFAULT_TIMEOUT = 5;
190inline constexpr std::uint16_t DEFAULT_RESPONSE_TIMEOUT = 20;
192inline constexpr std::uint16_t DEFAULT_HELLO_TIMEOUT = 10;
194inline constexpr std::uint16_t DEFAULT_RESPONSE_DELAY_FACTOR = 0x0080; // 128
196inline constexpr std::uint16_t FLASH_DURATION_MS = 3000;
197
198// NOLINTEND(readability-identifier-naming)
199//
203std::vector<std::string> DecodeDeviceRole(std::uint8_t roleByte);
204
209std::string GetBlockName(std::uint8_t option, std::uint8_t suboption);
210
214std::uint8_t ParseSetResponse(const Bytes& data);
215
223std::uint8_t RecvSetResponse(const IRawEthernetSocket& sock, const MacAddress& srcMac, int timeoutSec);
224
227{
228 // NOLINTBEGIN(readability-identifier-naming)
230 static constexpr std::uint16_t IP_NOT_SET = 0x0000;
231
233 static constexpr std::uint16_t IP_SET = 0x0001;
234
236 static constexpr std::uint16_t IP_SET_BY_DHCP = 0x0002;
237
239 static constexpr std::uint16_t IP_NOT_SET_CONFLICT = 0x0080;
240
242 static constexpr std::uint16_t IP_SET_CONFLICT = 0x0081;
243
245 static constexpr std::uint16_t IP_SET_BY_DHCP_CONFLICT = 0x0082;
246
248 static constexpr std::uint16_t IP_CONFLICT_BIT = 0x0080;
249 // NOLINTEND(readability-identifier-naming)
250 //
254 static std::string GetName(std::uint16_t info);
255
259 static bool HasConflict(std::uint16_t info)
260 {
261 return (info & IP_CONFLICT_BIT) != 0;
262 }
263
267 static bool IsDhcp(std::uint16_t info)
268 {
269 return (info & 0x0002) != 0;
270 }
271};
272
275{
276 // NOLINTBEGIN(readability-identifier-naming)
278 static constexpr std::uint16_t TEMPORARY = 0x0000;
279
281 static constexpr std::uint16_t PERMANENT = 0x0001;
282 // NOLINTEND(readability-identifier-naming)
286 static std::string GetName(std::uint16_t qualifier);
287};
288
291{
292 // NOLINTBEGIN(readability-identifier-naming)
294 static constexpr std::uint16_t RESET_APPLICATION_DATA = 0x0002;
295
297 static constexpr std::uint16_t RESET_COMMUNICATION_PARAM = 0x0004;
298
300 static constexpr std::uint16_t RESET_ENGINEERING_PARAM = 0x0006;
301
303 static constexpr std::uint16_t RESET_ALL_STORED_DATA = 0x0008;
304
306 static constexpr std::uint16_t RESET_TO_FACTORY = 0x0010;
307
309 static constexpr std::uint16_t RESET_AND_RESTORE = 0x0012;
310 // NOLINTEND(readability-identifier-naming)
314 static std::string GetName(std::uint16_t qualifier);
315};
316
319{
320 // NOLINTBEGIN(readability-identifier-naming)
322 static constexpr std::uint16_t NO_HELLO = 0x0000;
323
325 static constexpr std::uint16_t ISSUE_HELLO = 0x0001;
326 // NOLINTEND(readability-identifier-naming)
330 static std::string GetName(std::uint16_t value);
331};
332
335{
336 // NOLINTBEGIN(readability-identifier-naming)
338 static constexpr std::uint8_t NO_ERROR = 0x00;
339
341 static constexpr std::uint8_t OPTION_NOT_SUPPORTED = 0x01;
342
344 static constexpr std::uint8_t SUBOPTION_NOT_SUPPORTED = 0x02;
345
347 static constexpr std::uint8_t SUBOPTION_NOT_SET = 0x03;
348
350 static constexpr std::uint8_t RESOURCE_ERROR = 0x04;
351
353 static constexpr std::uint8_t SET_NOT_POSSIBLE = 0x05;
354
356 static constexpr std::uint8_t IN_OPERATION_SET_NOT_POSSIBLE = 0x06;
357 // NOLINTEND(readability-identifier-naming)
361 static std::string GetName(std::uint8_t code);
362};
363
364// NOLINTBEGIN(readability-identifier-naming)
366inline constexpr std::uint8_t DCP_BLOCK_ERROR_OK = 0x00;
368inline constexpr std::uint8_t DCP_BLOCK_ERROR_OPTION_UNSUPPORTED = 0x01;
370inline constexpr std::uint8_t DCP_BLOCK_ERROR_SUBOPTION_UNSUPPORTED = 0x02;
372inline constexpr std::uint8_t DCP_BLOCK_ERROR_SUBOPTION_NOT_SET = 0x03;
374inline constexpr std::uint8_t DCP_BLOCK_ERROR_RESOURCE = 0x04;
376inline constexpr std::uint8_t DCP_BLOCK_ERROR_SET_NOT_POSSIBLE = 0x05;
378inline constexpr std::uint8_t DCP_BLOCK_ERROR_IN_OPERATION = 0x06;
379// NOLINTEND(readability-identifier-naming)
380
384std::string DcpBlockErrorName(std::uint8_t code);
385
388{
390 std::uint8_t suboption = 0;
391
393 std::string suboptionName;
394
396 std::vector<std::uint8_t> rawData;
397
399 std::optional<std::string> hostname;
400
402 std::optional<std::vector<std::uint8_t>> clientId;
403
405 std::optional<std::vector<std::uint8_t>> vendorSpecific;
406
408 std::optional<std::string> fqdn;
409
411 std::optional<std::string> uuid;
412
417 static DCPDHCPBlock Parse(std::uint8_t suboption, const std::vector<std::uint8_t>& data);
418};
419
421using BlockKey = std::pair<std::uint8_t, std::uint8_t>;
422
426{
427 public:
431 DCPDeviceDescription(const MacAddress& mac, const std::map<BlockKey, std::vector<std::uint8_t>>& blocks);
432
434 std::string mac;
435
437 std::string deviceType;
438
440 std::string name;
441
443 std::string ip = "0.0.0.0";
444
446 std::string netmask = "0.0.0.0";
447
449 std::string gateway = "0.0.0.0";
450
452 std::uint16_t ipBlockInfo = 0;
453
455 bool ipConflict = false;
456
458 bool ipSetByDhcp = false;
459
461 std::uint8_t vendorHigh = 0;
462
464 std::uint8_t vendorLow = 0;
465
467 std::uint8_t deviceHigh = 0;
468
470 std::uint8_t deviceLow = 0;
471
473 std::uint8_t deviceRole = 0;
474
476 std::vector<std::string> deviceRoles;
477
479 std::pair<std::uint8_t, std::uint8_t> deviceInstance{0, 0};
480
482 std::string aliasName;
483
485 std::vector<BlockKey> supportedOptions;
486
488 std::vector<DCPDHCPBlock> dhcpBlocks;
489
491 std::uint16_t deviceInitiative = 0;
492
494 bool issuesHello = false;
495
497 std::map<BlockKey, std::vector<std::uint8_t>> rawBlocks;
498
501 [[nodiscard]] std::uint16_t VendorId() const
502 {
503 return static_cast<std::uint16_t>((vendorHigh << OneOctetShift) | vendorLow);
504 }
505
508 [[nodiscard]] std::uint16_t DeviceId() const
509 {
510 return static_cast<std::uint16_t>((deviceHigh << OneOctetShift) | deviceLow);
511 }
512
515 [[nodiscard]] std::string VendorName() const;
516
519 [[nodiscard]] std::string ToString() const;
520};
521
522// =============================================================================
523// DCP Operations
524// =============================================================================
550 const MacAddress& src,
551 const std::string& param,
552 const std::string& value,
553 bool permanent);
554
569[[nodiscard]] Bytes BuildDcpSignalRequest(const MacAddress& dst, const MacAddress& src);
570
573const std::map<std::string, BlockKey>& Params();
574
583std::optional<std::vector<std::uint8_t>> GetParam(const EthernetSocket& sock, const MacAddress& src,
584 const std::string& target, const std::string& param,
585 int timeoutSec = DEFAULT_TIMEOUT);
586
600bool SetParam(const EthernetSocket& sock, const MacAddress& src, const std::string& target,
601 const std::string& param, const std::string& value, int timeoutSec = DEFAULT_TIMEOUT, bool permanent = false);
602
613bool SetIp(const EthernetSocket& sock, const MacAddress& src, const std::string& target,
614 const std::string& ip, const std::string& netmask, const std::string& gateway,
615 bool permanent = false, int timeoutSec = DEFAULT_TIMEOUT);
616
621void SendDiscover(const EthernetSocket& sock, const MacAddress& src, std::uint16_t responseDelay = DEFAULT_RESPONSE_DELAY_FACTOR);
622
628void SendRequest(const EthernetSocket& sock, const MacAddress& src, BlockKey blockType,
629 const std::vector<std::uint8_t>& value);
630
632using ResponseMap = std::map<MacAddress, std::map<BlockKey, std::vector<std::uint8_t>>>;
633
641ResponseMap ReadResponse(const EthernetSocket& sock, const MacAddress& myMac, int timeoutSec = DEFAULT_RESPONSE_TIMEOUT,
642 bool once = false, std::optional<std::uint32_t> expectedXid = std::nullopt);
643
653void SendHello(const EthernetSocket& sock, const MacAddress& src, const std::string& stationName,
654 const std::string& ip = "0.0.0.0", const std::string& netmask = "0.0.0.0",
655 const std::string& gateway = "0.0.0.0", std::pair<std::uint16_t, std::uint16_t> deviceId = {0, 0},
656 std::uint8_t deviceRole = DEVICE_ROLE_IO_DEVICE);
657
664std::vector<DCPDeviceDescription> ReceiveHello(
665 const EthernetSocket& sock, const MacAddress& myMac, int timeoutSec = DEFAULT_HELLO_TIMEOUT,
666 const std::function<void(const DCPDeviceDescription&)>& callback = nullptr);
667
676bool SignalDevice(const EthernetSocket& sock, const MacAddress& src, const std::string& target,
677 int durationMs = FLASH_DURATION_MS, int timeoutSec = DEFAULT_TIMEOUT);
678
687bool ResetToFactory(const EthernetSocket& sock, const MacAddress& src, const std::string& target,
688 std::uint16_t mode = RESET_MODE_COMMUNICATION, int timeoutSec = DEFAULT_TIMEOUT);
689
690} // namespace profinet::dcp
Abstraction for sending and receiving raw Ethernet frames.
A minimal RAII wrapper around a Linux AF_PACKET raw socket bound to an interface.
Definition util.h:196
Abstract interface for raw Ethernet frame transport.
Parsed PROFINET device information from a DCP response.
Definition dcp.h:426
std::pair< std::uint8_t, std::uint8_t > deviceInstance
Device instance (high, low) pair.
Definition dcp.h:479
bool ipConflict
Whether an IP address conflict was detected.
Definition dcp.h:455
std::uint8_t vendorLow
Low byte of the PROFINET vendor ID.
Definition dcp.h:464
std::string netmask
IPv4 subnet mask, or "0.0.0.0" if unset.
Definition dcp.h:446
std::string ToString() const
Multi-line human-readable summary of this device.
Definition dcp.cpp:626
std::uint16_t ipBlockInfo
Raw IP block info flags (see IPBlockInfo).
Definition dcp.h:452
std::string name
Station name.
Definition dcp.h:440
std::uint8_t vendorHigh
High byte of the PROFINET vendor ID.
Definition dcp.h:461
std::uint8_t deviceLow
Low byte of the PROFINET device ID.
Definition dcp.h:470
std::uint16_t VendorId() const
Combine VendorHigh/VendorLow into a 16-bit vendor ID.
Definition dcp.h:501
std::uint8_t deviceRole
Raw device role bitmask.
Definition dcp.h:473
std::string gateway
IPv4 default gateway, or "0.0.0.0" if unset.
Definition dcp.h:449
std::uint16_t DeviceId() const
Combine DeviceHigh/DeviceLow into a 16-bit device ID.
Definition dcp.h:508
std::string aliasName
Device alias name, if set.
Definition dcp.h:482
std::map< BlockKey, std::vector< std::uint8_t > > rawBlocks
Any parsed blocks not covered by the named fields above.
Definition dcp.h:497
std::uint16_t deviceInitiative
Raw device-initiative value (see DeviceInitiative).
Definition dcp.h:491
std::vector< BlockKey > supportedOptions
List of (option, suboption) blocks the device supports.
Definition dcp.h:485
bool issuesHello
Whether the device issues a DCP-Hello after power-on.
Definition dcp.h:494
std::uint8_t deviceHigh
High byte of the PROFINET device ID.
Definition dcp.h:467
std::string VendorName() const
Look up the vendor name for this device's vendor ID.
Definition dcp.cpp:621
std::string mac
Device's MAC address, formatted as a string.
Definition dcp.h:434
std::string ip
IPv4 address, or "0.0.0.0" if unset.
Definition dcp.h:443
bool ipSetByDhcp
Whether the IP address was assigned via DHCP.
Definition dcp.h:458
std::vector< DCPDHCPBlock > dhcpBlocks
Parsed DHCP blocks from the response, if any.
Definition dcp.h:488
std::vector< std::string > deviceRoles
Decoded device role names (see DecodeDeviceRole()).
Definition dcp.h:476
std::string deviceType
Device type string (e.g. model name).
Definition dcp.h:437
bool ResetToFactory(const EthernetSocket &sock, const MacAddress &src, const std::string &target, std::uint16_t mode=RESET_MODE_COMMUNICATION, int timeoutSec=DEFAULT_TIMEOUT)
Reset a device to factory defaults.
Definition dcp.cpp:1328
constexpr std::uint8_t DCP_SUBOPTION_DEVICE_TYPE
DCP suboption (Device): device type string.
Definition dcp.h:112
void SendRequest(const EthernetSocket &sock, const MacAddress &src, BlockKey blockType, const std::vector< std::uint8_t > &value)
Send a DCP Identify request filtered to a specific (option, suboption).
Definition dcp.cpp:1025
constexpr std::uint8_t DCP_SUBOPTION_DEVICE_RSI
DCP suboption (Device): RSI (reverse status indication).
Definition dcp.h:128
constexpr std::uint8_t DCP_SUBOPTION_CONTROL_SIGNAL
DCP suboption (Control): signal (flash LEDs).
Definition dcp.h:135
constexpr std::uint8_t DCP_SUBOPTION_IP_PARAMETER
DCP suboption (IP): IP/netmask/gateway parameter.
Definition dcp.h:107
constexpr std::uint16_t RESET_MODE_COMMUNICATION
Reset mode bit: reset communication parameters.
Definition dcp.h:175
constexpr std::uint8_t DEVICE_ROLE_IO_MULTIDEVICE
Device role bit: IO-Multidevice.
Definition dcp.h:170
constexpr std::uint8_t DCP_SERVICE_TYPE_REQUEST
DCP service type: REQUEST.
Definition dcp.h:78
Bytes BuildSetParamRequest(const MacAddress &dst, const MacAddress &src, const std::string &param, const std::string &value, bool permanent)
Build a serialized DCP SET request for a named parameter.
Definition dcp.cpp:756
constexpr std::uint8_t DCP_SUBOPTION_DHCP_CLIENT_ID
DCP suboption (DHCP): client identifier option.
Definition dcp.h:154
bool SetParam(const EthernetSocket &sock, const MacAddress &src, const std::string &target, const std::string &param, const std::string &value, int timeoutSec=DEFAULT_TIMEOUT, bool permanent=false)
Write a named parameter to a device.
Definition dcp.cpp:922
constexpr std::uint16_t DCP_HELLO_FRAME_ID
Frame ID for DCP Hello announcements.
Definition dcp.h:66
constexpr std::uint8_t DCP_SUBOPTION_DHCP_PARAM_REQ
DCP suboption (DHCP): parameter request list.
Definition dcp.h:150
Bytes BuildDcpSignalRequest(const MacAddress &dst, const MacAddress &src)
Build a serialized DCP Signal request.
Definition dcp.cpp:812
constexpr std::uint8_t DCP_SUBOPTION_DEVICE_INSTANCE
DCP suboption (Device): device instance.
Definition dcp.h:124
constexpr std::uint8_t DCP_OPTION_DEVICE
DCP option: device identification.
Definition dcp.h:90
const std::map< std::string, BlockKey > & Params()
Table of supported parameter names, mapping to their (option, suboption).
Definition dcp.cpp:480
std::string GetBlockName(std::uint8_t option, std::uint8_t suboption)
Get the human-readable name for a (option, suboption) DCP block.
Definition dcp.cpp:163
constexpr std::uint8_t DCP_SUBOPTION_DEVICE_ROLE
DCP suboption (Device): device role bitmask.
Definition dcp.h:118
constexpr std::uint8_t DCP_BLOCK_ERROR_SET_NOT_POSSIBLE
DCP SET block-level result: set not possible locally.
Definition dcp.h:376
constexpr std::uint16_t DCP_GET_SET_FRAME_ID
Frame ID for DCP Get/Set requests and responses.
Definition dcp.h:64
constexpr std::uint8_t DCP_BLOCK_ERROR_OPTION_UNSUPPORTED
DCP SET block-level result: option not supported.
Definition dcp.h:368
constexpr std::uint8_t DCP_SERVICE_ID_IDENTIFY
DCP service ID: IDENTIFY.
Definition dcp.h:73
constexpr std::uint16_t DEFAULT_RESPONSE_DELAY_FACTOR
Default dcp response delay factor.
Definition dcp.h:194
constexpr std::uint16_t RESET_MODE_DEVICE
Reset mode bit: reset device.
Definition dcp.h:183
constexpr std::uint8_t DCP_SERVICE_ID_HELLO
DCP service ID: HELLO.
Definition dcp.h:75
constexpr std::uint8_t DCP_BLOCK_ERROR_SUBOPTION_UNSUPPORTED
DCP SET block-level result: suboption not supported.
Definition dcp.h:370
constexpr std::uint16_t RESET_MODE_ALL_DATA
Reset mode bit: reset all stored data.
Definition dcp.h:181
constexpr std::uint8_t DCP_SUBOPTION_IP_MAC
DCP suboption (IP): MAC address.
Definition dcp.h:105
constexpr std::uint16_t FLASH_DURATION_MS
Default flash duration of the leds.
Definition dcp.h:196
constexpr std::uint8_t DCP_SUBOPTION_DEVICE_INITIATIVE
DCP suboption (DeviceInitiative): the only suboption.
Definition dcp.h:163
constexpr std::uint16_t DEFAULT_HELLO_TIMEOUT
Default HELLO timeout.
Definition dcp.h:192
constexpr std::uint8_t DCP_SUBOPTION_DHCP_UUID
DCP suboption (DHCP): client UUID option.
Definition dcp.h:158
constexpr std::uint8_t DCP_SUBOPTION_DEVICE_OPTIONS
DCP suboption (Device): supported options list.
Definition dcp.h:120
std::pair< std::uint8_t, std::uint8_t > BlockKey
(option, suboption) key identifying a DCP block.
Definition dcp.h:421
constexpr std::uint8_t DCP_SUBOPTION_DEVICE_ALIAS
DCP suboption (Device): alias name.
Definition dcp.h:122
constexpr std::uint8_t DCP_SUBOPTION_DEVICE_ID
DCP suboption (Device): vendor/device ID.
Definition dcp.h:116
constexpr std::uint16_t DCP_IDENTIFY_REQUEST_FRAME_ID
Frame ID for DCP Identify requests.
Definition dcp.h:60
constexpr std::uint16_t DEFAULT_TIMEOUT
Default timeout.
Definition dcp.h:188
constexpr std::uint8_t DCP_SERVICE_ID_GET
DCP service ID: GET.
Definition dcp.h:69
constexpr std::uint8_t DCP_SUBOPTION_DHCP_CONTROL
DCP suboption (DHCP): DHCP control.
Definition dcp.h:160
constexpr std::uint8_t DCP_SUBOPTION_CONTROL_STOP
DCP suboption (Control): stop.
Definition dcp.h:133
constexpr std::uint8_t DCP_SUBOPTION_DHCP_VENDOR_SPEC
DCP suboption (DHCP): vendor-specific option.
Definition dcp.h:146
std::optional< std::vector< std::uint8_t > > GetParam(const EthernetSocket &sock, const MacAddress &src, const std::string &target, const std::string &param, int timeoutSec=DEFAULT_TIMEOUT)
Read a named parameter from a device.
Definition dcp.cpp:880
constexpr std::uint8_t DCP_SUBOPTION_CONTROL_RESET_FACTORY
DCP suboption (Control): factory reset.
Definition dcp.h:139
void SendDiscover(const EthernetSocket &sock, const MacAddress &src, std::uint16_t responseDelay=DEFAULT_RESPONSE_DELAY_FACTOR)
Send a DCP Identify multicast request to discover all devices on the segment.
Definition dcp.cpp:1003
const std::string DCP_MULTICAST_MAC
DCP Identify/Get/Set multicast destination MAC.
Definition dcp.h:55
constexpr std::uint8_t DCP_SUBOPTION_IP_FULL_SUITE
DCP suboption (IP): full IP suite.
Definition dcp.h:109
constexpr std::uint8_t DCP_SUBOPTION_DHCP_FQDN
DCP suboption (DHCP): fully qualified domain name option.
Definition dcp.h:156
constexpr std::uint8_t DEVICE_ROLE_IO_DEVICE
Device role bit: IO-Device.
Definition dcp.h:166
const std::string DCP_HELLO_MULTICAST_MAC
DCP Hello multicast destination MAC.
Definition dcp.h:57
ResponseMap ReadResponse(const EthernetSocket &sock, const MacAddress &myMac, int timeoutSec=DEFAULT_RESPONSE_TIMEOUT, bool once=false, std::optional< std::uint32_t > expectedXid=std::nullopt)
Read and parse DCP Identify responses.
Definition dcp.cpp:1048
constexpr std::uint8_t DCP_SUBOPTION_DHCP_SERVER_ID
DCP suboption (DHCP): server identifier option.
Definition dcp.h:148
std::string DcpBlockErrorName(std::uint8_t code)
Get the human-readable name for a DCP SET block-level error code.
Definition dcp.cpp:430
std::vector< std::string > DecodeDeviceRole(std::uint8_t roleByte)
Decode a device role bitmask into a list of role names.
Definition dcp.cpp:146
constexpr std::uint8_t DCP_OPTION_IP
DCP option: IP configuration.
Definition dcp.h:88
std::uint8_t RecvSetResponse(const IRawEthernetSocket &sock, const MacAddress &srcMac, int timeoutSec)
Receive and parse a DCP SET response, filtering out unrelated frames.
Definition dcp.cpp:195
constexpr std::uint8_t DEVICE_ROLE_IO_CONTROLLER
Device role bit: IO-Controller.
Definition dcp.h:168
bool SetIp(const EthernetSocket &sock, const MacAddress &src, const std::string &target, const std::string &ip, const std::string &netmask, const std::string &gateway, bool permanent=false, int timeoutSec=DEFAULT_TIMEOUT)
Set a device's IP configuration via DCP.
Definition dcp.cpp:950
constexpr std::uint8_t DCP_SUBOPTION_DHCP_HOSTNAME
DCP suboption (DHCP): hostname option.
Definition dcp.h:144
constexpr std::uint8_t DCP_SUBOPTION_DHCP_CLASS_ID
DCP suboption (DHCP): class identifier option.
Definition dcp.h:152
constexpr std::uint8_t DCP_SUBOPTION_CONTROL_RESPONSE
DCP suboption (Control): response.
Definition dcp.h:137
constexpr std::uint8_t DCP_BLOCK_ERROR_IN_OPERATION
DCP SET block-level result: set not possible, device in operation.
Definition dcp.h:378
std::map< MacAddress, std::map< BlockKey, std::vector< std::uint8_t > > > ResponseMap
Result of ReadResponse(): MAC address -> parsed (option,suboption) -> payload blocks.
Definition dcp.h:632
constexpr std::uint8_t DCP_SUBOPTION_DEVICE_NAME
DCP suboption (Device): station name.
Definition dcp.h:114
constexpr std::uint8_t DCP_SUBOPTION_DEVICE_OEM_ID
DCP suboption (Device): OEM vendor/device ID.
Definition dcp.h:126
constexpr std::uint16_t RESET_MODE_FACTORY
Reset mode bit: reset to factory defaults.
Definition dcp.h:185
constexpr std::uint8_t DCP_BLOCK_ERROR_OK
DCP SET block-level result: OK.
Definition dcp.h:366
constexpr std::uint8_t DCP_SUBOPTION_CONTROL_START
DCP suboption (Control): start.
Definition dcp.h:131
constexpr std::uint16_t RESET_MODE_APPLICATION
Reset mode bit: reset application data.
Definition dcp.h:177
bool SignalDevice(const EthernetSocket &sock, const MacAddress &src, const std::string &target, int durationMs=FLASH_DURATION_MS, int timeoutSec=DEFAULT_TIMEOUT)
Flash a device's identification LEDs.
Definition dcp.cpp:1307
constexpr std::uint8_t DCP_SUBOPTION_CONTROL_RESET_TO_FACTORY
DCP suboption (Control): reset to factory.
Definition dcp.h:141
constexpr std::uint8_t DCP_OPTION_NME
DCP option: Network Management (NME).
Definition dcp.h:100
constexpr std::uint8_t DCP_BLOCK_ERROR_SUBOPTION_NOT_SET
DCP SET block-level result: suboption not set.
Definition dcp.h:372
constexpr std::uint8_t DCP_OPTION_CONTROL
DCP option: control (start/stop/signal/reset).
Definition dcp.h:96
constexpr std::uint8_t DCP_OPTION_DHCP
DCP option: DHCP.
Definition dcp.h:92
constexpr std::uint8_t DCP_SERVICE_ID_SET
DCP service ID: SET.
Definition dcp.h:71
constexpr std::uint16_t DEFAULT_RESPONSE_TIMEOUT
Default response timeout. How long to keep listening for responses.
Definition dcp.h:190
constexpr std::uint16_t RESET_MODE_ENGINEERING
Reset mode bit: reset engineering parameters.
Definition dcp.h:179
constexpr std::uint8_t DEVICE_ROLE_PN_SUPERVISOR
Device role bit: PN-Supervisor.
Definition dcp.h:172
constexpr std::uint8_t DCP_BLOCK_ERROR_RESOURCE
DCP SET block-level result: resource error.
Definition dcp.h:374
constexpr std::uint8_t DCP_OPTION_ALL
DCP option wildcard: all options.
Definition dcp.h:102
void SendHello(const EthernetSocket &sock, const MacAddress &src, const std::string &stationName, const std::string &ip="0.0.0.0", const std::string &netmask="0.0.0.0", const std::string &gateway="0.0.0.0", std::pair< std::uint16_t, std::uint16_t > deviceId={0, 0}, std::uint8_t deviceRole=DEVICE_ROLE_IO_DEVICE)
Send a DCP Hello multicast announcement (device self-announce after power-on).
Definition dcp.cpp:1135
constexpr std::uint8_t DCP_SERVICE_TYPE_RESPONSE_SUCCESS
DCP service type: RESPONSE (success).
Definition dcp.h:80
constexpr std::uint8_t DCP_OPTION_DEVICE_INITIATIVE
DCP option: device-initiative (Hello) configuration.
Definition dcp.h:98
std::vector< DCPDeviceDescription > ReceiveHello(const EthernetSocket &sock, const MacAddress &myMac, int timeoutSec=DEFAULT_HELLO_TIMEOUT, const std::function< void(const DCPDeviceDescription &)> &callback=nullptr)
Listen for DCP Hello announcements from other devices.
Definition dcp.cpp:1214
constexpr std::uint8_t DCP_OPTION_RESERVED
DCP option: reserved.
Definition dcp.h:94
std::uint8_t ParseSetResponse(const Bytes &data)
Parses the raw byte response payload received from a SET operation.
Definition dcp.cpp:258
constexpr std::uint8_t DCP_SERVICE_TYPE_RESPONSE_UNSUPPORTED
DCP service type: RESPONSE (service unsupported).
Definition dcp.h:82
constexpr std::size_t DCP_MAX_NAME_LENGTH
Maximum allowed length in bytes for a station name.
Definition dcp.h:85
constexpr std::uint16_t DCP_IDENTIFY_RESPONSE_FRAME_ID
Frame ID for DCP Identify responses.
Definition dcp.h:62
std::array< std::uint8_t, macAddressLength > MacAddress
A 6-byte Ethernet MAC address.
Definition util.h:67
static constexpr int OneOctetShift
The bit-shift distance required to move data across a single octet.
Definition util.h:50
std::vector< std::uint8_t > Bytes
Generic byte buffer alias used throughout the library for raw wire data.
Definition protocol.h:52
PROFINET protocol wire-format structures and serialization helpers.
Block qualifier: whether a Set operation is temporary or permanent.
Definition dcp.h:275
static constexpr std::uint16_t PERMANENT
Change is persisted permanently.
Definition dcp.h:281
static constexpr std::uint16_t TEMPORARY
Change applies until the next power cycle only.
Definition dcp.h:278
static std::string GetName(std::uint16_t qualifier)
Get the human-readable name for a qualifier value.
Definition dcp.cpp:359
Parsed DHCP block from a DCP response.
Definition dcp.h:388
std::uint8_t suboption
DHCP suboption code.
Definition dcp.h:390
std::optional< std::string > fqdn
Decoded fully qualified domain name, if this is an FQDN suboption.
Definition dcp.h:408
std::vector< std::uint8_t > rawData
Raw, undecoded block payload.
Definition dcp.h:396
std::optional< std::vector< std::uint8_t > > vendorSpecific
Decoded vendor-specific data, if this is a VendorSpec suboption.
Definition dcp.h:405
static DCPDHCPBlock Parse(std::uint8_t suboption, const std::vector< std::uint8_t > &data)
Parse a DHCP suboption's payload into a DCPDHCPBlock.
Definition dcp.cpp:440
std::optional< std::string > hostname
Decoded hostname, if this is a Hostname suboption.
Definition dcp.h:399
std::string suboptionName
Human-readable name of the suboption.
Definition dcp.h:393
std::optional< std::vector< std::uint8_t > > clientId
Decoded client ID, if this is a ClientID suboption.
Definition dcp.h:402
std::optional< std::string > uuid
Decoded UUID string, if this is a UUID suboption.
Definition dcp.h:411
DCP GET/SET response codes.
Definition dcp.h:335
static constexpr std::uint8_t RESOURCE_ERROR
A resource error occurred.
Definition dcp.h:350
static constexpr std::uint8_t SET_NOT_POSSIBLE
The SET operation is not currently possible.
Definition dcp.h:353
static constexpr std::uint8_t SUBOPTION_NOT_SUPPORTED
The requested suboption is not supported or has no data set.
Definition dcp.h:344
static constexpr std::uint8_t NO_ERROR
No error.
Definition dcp.h:338
static constexpr std::uint8_t OPTION_NOT_SUPPORTED
The requested option is not supported.
Definition dcp.h:341
static std::string GetName(std::uint8_t code)
Get the human-readable name for a response code.
Definition dcp.cpp:407
static constexpr std::uint8_t SUBOPTION_NOT_SET
The requested suboption is not set.
Definition dcp.h:347
static constexpr std::uint8_t IN_OPERATION_SET_NOT_POSSIBLE
The SET operation is not possible while the device is in operation.
Definition dcp.h:356
Device-initiative (Hello-after-power-on) setting values.
Definition dcp.h:319
static constexpr std::uint16_t ISSUE_HELLO
Device sends DCP-Hello after power-on.
Definition dcp.h:325
static std::string GetName(std::uint16_t value)
Get the human-readable name for a device-initiative value.
Definition dcp.cpp:394
static constexpr std::uint16_t NO_HELLO
Device does not send DCP-Hello after power-on.
Definition dcp.h:322
IP block status flags (IEC 61158-6-10 IPBlockInfo).
Definition dcp.h:227
static constexpr std::uint16_t IP_SET_BY_DHCP
IP address set via DHCP.
Definition dcp.h:236
static constexpr std::uint16_t IP_NOT_SET_CONFLICT
IP address not set, address conflict detected.
Definition dcp.h:239
static constexpr std::uint16_t IP_NOT_SET
IP address not set.
Definition dcp.h:230
static bool HasConflict(std::uint16_t info)
Whether an address conflict was detected.
Definition dcp.h:259
static constexpr std::uint16_t IP_SET_CONFLICT
IP address set (statically), address conflict detected.
Definition dcp.h:242
static constexpr std::uint16_t IP_CONFLICT_BIT
IP conflict bit value.
Definition dcp.h:248
static std::string GetName(std::uint16_t info)
Get the human-readable name for an IP block info value.
Definition dcp.cpp:338
static bool IsDhcp(std::uint16_t info)
Whether the address was assigned via DHCP.
Definition dcp.h:267
static constexpr std::uint16_t IP_SET_BY_DHCP_CONFLICT
IP address set via DHCP, address conflict detected.
Definition dcp.h:245
static constexpr std::uint16_t IP_SET
IP address set (statically).
Definition dcp.h:233
Reset qualifier values for ResetToFactory().
Definition dcp.h:291
static constexpr std::uint16_t RESET_AND_RESTORE
Reset and restore from backup.
Definition dcp.h:309
static constexpr std::uint16_t RESET_APPLICATION_DATA
Reset application data.
Definition dcp.h:294
static constexpr std::uint16_t RESET_TO_FACTORY
Reset to factory defaults.
Definition dcp.h:306
static constexpr std::uint16_t RESET_COMMUNICATION_PARAM
Reset communication parameters.
Definition dcp.h:297
static constexpr std::uint16_t RESET_ENGINEERING_PARAM
Reset engineering parameters.
Definition dcp.h:300
static std::string GetName(std::uint16_t qualifier)
Get the human-readable name for a reset qualifier value.
Definition dcp.cpp:364
static constexpr std::uint16_t RESET_ALL_STORED_DATA
Reset all stored data.
Definition dcp.h:303
Declares Linux Ethernet, addressing, timing, and utility helpers used by the PROFINET stack.