PROFINET IO Controller Stack 1.0.0
Modern C++ implementation of a PROFINET IO Controller stack
Loading...
Searching...
No Matches
dcp.h File Reference

PROFINET DCP discovery and device configuration interface. More...

#include <chrono>
#include <cstdint>
#include <functional>
#include <map>
#include <optional>
#include <string>
#include <utility>
#include <vector>
#include "profinet/IRawEthernetSocket.h"
#include "profinet/protocol.h"
#include "profinet/util.h"
+ Include dependency graph for dcp.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  profinet::dcp::IPBlockInfo
 IP block status flags (IEC 61158-6-10 IPBlockInfo). More...
 
struct  profinet::dcp::BlockQualifier
 Block qualifier: whether a Set operation is temporary or permanent. More...
 
struct  profinet::dcp::ResetQualifier
 Reset qualifier values for ResetToFactory(). More...
 
struct  profinet::dcp::DeviceInitiative
 Device-initiative (Hello-after-power-on) setting values. More...
 
struct  profinet::dcp::DCPResponseCode
 DCP GET/SET response codes. More...
 
struct  profinet::dcp::DCPDHCPBlock
 Parsed DHCP block from a DCP response. More...
 
class  profinet::dcp::DCPDeviceDescription
 Parsed PROFINET device information from a DCP response. More...
 

Namespaces

namespace  profinet
 
namespace  profinet::dcp
 

Typedefs

using profinet::dcp::BlockKey = std::pair< std::uint8_t, std::uint8_t >
 (option, suboption) key identifying a DCP block.
 
using profinet::dcp::ResponseMap = std::map< MacAddress, std::map< BlockKey, std::vector< std::uint8_t > > >
 Result of ReadResponse(): MAC address -> parsed (option,suboption) -> payload blocks.
 

Functions

std::vector< std::string > profinet::dcp::DecodeDeviceRole (std::uint8_t roleByte)
 Decode a device role bitmask into a list of role names.
 
std::string profinet::dcp::GetBlockName (std::uint8_t option, std::uint8_t suboption)
 Get the human-readable name for a (option, suboption) DCP block.
 
std::uint8_t profinet::dcp::ParseSetResponse (const Bytes &data)
 Parses the raw byte response payload received from a SET operation.
 
std::uint8_t profinet::dcp::RecvSetResponse (const IRawEthernetSocket &sock, const MacAddress &srcMac, int timeoutSec)
 Receive and parse a DCP SET response, filtering out unrelated frames.
 
std::string profinet::dcp::DcpBlockErrorName (std::uint8_t code)
 Get the human-readable name for a DCP SET block-level error code.
 
Bytes profinet::dcp::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.
 
Bytes profinet::dcp::BuildDcpSignalRequest (const MacAddress &dst, const MacAddress &src)
 Build a serialized DCP Signal request.
 
const std::map< std::string, BlockKey > & profinet::dcp::Params ()
 Table of supported parameter names, mapping to their (option, suboption).
 
std::optional< std::vector< std::uint8_t > > profinet::dcp::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.
 
bool profinet::dcp::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.
 
bool profinet::dcp::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.
 
void profinet::dcp::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.
 
void profinet::dcp::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).
 
ResponseMap profinet::dcp::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.
 
void profinet::dcp::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).
 
std::vector< DCPDeviceDescriptionprofinet::dcp::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.
 
bool profinet::dcp::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.
 
bool profinet::dcp::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.
 

Variables

const std::string profinet::dcp::DCP_MULTICAST_MAC = "01:0e:cf:00:00:00"
 DCP Identify/Get/Set multicast destination MAC.
 
const std::string profinet::dcp::DCP_HELLO_MULTICAST_MAC = "01:0e:cf:00:00:01"
 DCP Hello multicast destination MAC.
 
constexpr std::uint16_t profinet::dcp::DCP_IDENTIFY_REQUEST_FRAME_ID = 0xFEFE
 Frame ID for DCP Identify requests.
 
constexpr std::uint16_t profinet::dcp::DCP_IDENTIFY_RESPONSE_FRAME_ID = 0xFEFF
 Frame ID for DCP Identify responses.
 
constexpr std::uint16_t profinet::dcp::DCP_GET_SET_FRAME_ID = 0xFEFD
 Frame ID for DCP Get/Set requests and responses.
 
constexpr std::uint16_t profinet::dcp::DCP_HELLO_FRAME_ID = 0xFEFC
 Frame ID for DCP Hello announcements.
 
constexpr std::uint8_t profinet::dcp::DCP_SERVICE_ID_GET = 0x03
 DCP service ID: GET.
 
constexpr std::uint8_t profinet::dcp::DCP_SERVICE_ID_SET = 0x04
 DCP service ID: SET.
 
constexpr std::uint8_t profinet::dcp::DCP_SERVICE_ID_IDENTIFY = 0x05
 DCP service ID: IDENTIFY.
 
constexpr std::uint8_t profinet::dcp::DCP_SERVICE_ID_HELLO = 0x06
 DCP service ID: HELLO.
 
constexpr std::uint8_t profinet::dcp::DCP_SERVICE_TYPE_REQUEST = 0x00
 DCP service type: REQUEST.
 
constexpr std::uint8_t profinet::dcp::DCP_SERVICE_TYPE_RESPONSE_SUCCESS = 0x01
 DCP service type: RESPONSE (success).
 
constexpr std::uint8_t profinet::dcp::DCP_SERVICE_TYPE_RESPONSE_UNSUPPORTED = 0x05
 DCP service type: RESPONSE (service unsupported).
 
constexpr std::size_t profinet::dcp::DCP_MAX_NAME_LENGTH = 240
 Maximum allowed length in bytes for a station name.
 
constexpr std::uint8_t profinet::dcp::DCP_OPTION_IP = 0x01
 DCP option: IP configuration.
 
constexpr std::uint8_t profinet::dcp::DCP_OPTION_DEVICE = 0x02
 DCP option: device identification.
 
constexpr std::uint8_t profinet::dcp::DCP_OPTION_DHCP = 0x03
 DCP option: DHCP.
 
constexpr std::uint8_t profinet::dcp::DCP_OPTION_RESERVED = 0x04
 DCP option: reserved.
 
constexpr std::uint8_t profinet::dcp::DCP_OPTION_CONTROL = 0x05
 DCP option: control (start/stop/signal/reset).
 
constexpr std::uint8_t profinet::dcp::DCP_OPTION_DEVICE_INITIATIVE = 0x06
 DCP option: device-initiative (Hello) configuration.
 
constexpr std::uint8_t profinet::dcp::DCP_OPTION_NME = 0x07
 DCP option: Network Management (NME).
 
constexpr std::uint8_t profinet::dcp::DCP_OPTION_ALL = 0xFF
 DCP option wildcard: all options.
 
constexpr std::uint8_t profinet::dcp::DCP_SUBOPTION_IP_MAC = 0x01
 DCP suboption (IP): MAC address.
 
constexpr std::uint8_t profinet::dcp::DCP_SUBOPTION_IP_PARAMETER = 0x02
 DCP suboption (IP): IP/netmask/gateway parameter.
 
constexpr std::uint8_t profinet::dcp::DCP_SUBOPTION_IP_FULL_SUITE = 0x03
 DCP suboption (IP): full IP suite.
 
constexpr std::uint8_t profinet::dcp::DCP_SUBOPTION_DEVICE_TYPE = 0x01
 DCP suboption (Device): device type string.
 
constexpr std::uint8_t profinet::dcp::DCP_SUBOPTION_DEVICE_NAME = 0x02
 DCP suboption (Device): station name.
 
constexpr std::uint8_t profinet::dcp::DCP_SUBOPTION_DEVICE_ID = 0x03
 DCP suboption (Device): vendor/device ID.
 
constexpr std::uint8_t profinet::dcp::DCP_SUBOPTION_DEVICE_ROLE = 0x04
 DCP suboption (Device): device role bitmask.
 
constexpr std::uint8_t profinet::dcp::DCP_SUBOPTION_DEVICE_OPTIONS = 0x05
 DCP suboption (Device): supported options list.
 
constexpr std::uint8_t profinet::dcp::DCP_SUBOPTION_DEVICE_ALIAS = 0x06
 DCP suboption (Device): alias name.
 
constexpr std::uint8_t profinet::dcp::DCP_SUBOPTION_DEVICE_INSTANCE = 0x07
 DCP suboption (Device): device instance.
 
constexpr std::uint8_t profinet::dcp::DCP_SUBOPTION_DEVICE_OEM_ID = 0x08
 DCP suboption (Device): OEM vendor/device ID.
 
constexpr std::uint8_t profinet::dcp::DCP_SUBOPTION_DEVICE_RSI = 0x0A
 DCP suboption (Device): RSI (reverse status indication).
 
constexpr std::uint8_t profinet::dcp::DCP_SUBOPTION_CONTROL_START = 0x01
 DCP suboption (Control): start.
 
constexpr std::uint8_t profinet::dcp::DCP_SUBOPTION_CONTROL_STOP = 0x02
 DCP suboption (Control): stop.
 
constexpr std::uint8_t profinet::dcp::DCP_SUBOPTION_CONTROL_SIGNAL = 0x03
 DCP suboption (Control): signal (flash LEDs).
 
constexpr std::uint8_t profinet::dcp::DCP_SUBOPTION_CONTROL_RESPONSE = 0x04
 DCP suboption (Control): response.
 
constexpr std::uint8_t profinet::dcp::DCP_SUBOPTION_CONTROL_RESET_FACTORY = 0x05
 DCP suboption (Control): factory reset.
 
constexpr std::uint8_t profinet::dcp::DCP_SUBOPTION_CONTROL_RESET_TO_FACTORY = 0x06
 DCP suboption (Control): reset to factory.
 
constexpr std::uint8_t profinet::dcp::DCP_SUBOPTION_DHCP_HOSTNAME = 0x0C
 DCP suboption (DHCP): hostname option.
 
constexpr std::uint8_t profinet::dcp::DCP_SUBOPTION_DHCP_VENDOR_SPEC = 0x2B
 DCP suboption (DHCP): vendor-specific option.
 
constexpr std::uint8_t profinet::dcp::DCP_SUBOPTION_DHCP_SERVER_ID = 0x36
 DCP suboption (DHCP): server identifier option.
 
constexpr std::uint8_t profinet::dcp::DCP_SUBOPTION_DHCP_PARAM_REQ = 0x37
 DCP suboption (DHCP): parameter request list.
 
constexpr std::uint8_t profinet::dcp::DCP_SUBOPTION_DHCP_CLASS_ID = 0x3C
 DCP suboption (DHCP): class identifier option.
 
constexpr std::uint8_t profinet::dcp::DCP_SUBOPTION_DHCP_CLIENT_ID = 0x3D
 DCP suboption (DHCP): client identifier option.
 
constexpr std::uint8_t profinet::dcp::DCP_SUBOPTION_DHCP_FQDN = 0x51
 DCP suboption (DHCP): fully qualified domain name option.
 
constexpr std::uint8_t profinet::dcp::DCP_SUBOPTION_DHCP_UUID = 0x61
 DCP suboption (DHCP): client UUID option.
 
constexpr std::uint8_t profinet::dcp::DCP_SUBOPTION_DHCP_CONTROL = 0xFF
 DCP suboption (DHCP): DHCP control.
 
constexpr std::uint8_t profinet::dcp::DCP_SUBOPTION_DEVICE_INITIATIVE = 0x01
 DCP suboption (DeviceInitiative): the only suboption.
 
constexpr std::uint8_t profinet::dcp::DEVICE_ROLE_IO_DEVICE = 0x01
 Device role bit: IO-Device.
 
constexpr std::uint8_t profinet::dcp::DEVICE_ROLE_IO_CONTROLLER = 0x02
 Device role bit: IO-Controller.
 
constexpr std::uint8_t profinet::dcp::DEVICE_ROLE_IO_MULTIDEVICE = 0x04
 Device role bit: IO-Multidevice.
 
constexpr std::uint8_t profinet::dcp::DEVICE_ROLE_PN_SUPERVISOR = 0x08
 Device role bit: PN-Supervisor.
 
constexpr std::uint16_t profinet::dcp::RESET_MODE_COMMUNICATION = 0x0002
 Reset mode bit: reset communication parameters.
 
constexpr std::uint16_t profinet::dcp::RESET_MODE_APPLICATION = 0x0004
 Reset mode bit: reset application data.
 
constexpr std::uint16_t profinet::dcp::RESET_MODE_ENGINEERING = 0x0008
 Reset mode bit: reset engineering parameters.
 
constexpr std::uint16_t profinet::dcp::RESET_MODE_ALL_DATA = 0x0010
 Reset mode bit: reset all stored data.
 
constexpr std::uint16_t profinet::dcp::RESET_MODE_DEVICE = 0x0020
 Reset mode bit: reset device.
 
constexpr std::uint16_t profinet::dcp::RESET_MODE_FACTORY = 0x0040
 Reset mode bit: reset to factory defaults.
 
constexpr std::uint16_t profinet::dcp::DEFAULT_TIMEOUT = 5
 Default timeout.
 
constexpr std::uint16_t profinet::dcp::DEFAULT_RESPONSE_TIMEOUT = 20
 Default response timeout. How long to keep listening for responses.
 
constexpr std::uint16_t profinet::dcp::DEFAULT_HELLO_TIMEOUT = 10
 Default HELLO timeout.
 
constexpr std::uint16_t profinet::dcp::DEFAULT_RESPONSE_DELAY_FACTOR = 0x0080
 Default dcp response delay factor.
 
constexpr std::uint16_t profinet::dcp::FLASH_DURATION_MS = 3000
 Default flash duration of the leds.
 
constexpr std::uint8_t profinet::dcp::DCP_BLOCK_ERROR_OK = 0x00
 DCP SET block-level result: OK.
 
constexpr std::uint8_t profinet::dcp::DCP_BLOCK_ERROR_OPTION_UNSUPPORTED = 0x01
 DCP SET block-level result: option not supported.
 
constexpr std::uint8_t profinet::dcp::DCP_BLOCK_ERROR_SUBOPTION_UNSUPPORTED = 0x02
 DCP SET block-level result: suboption not supported.
 
constexpr std::uint8_t profinet::dcp::DCP_BLOCK_ERROR_SUBOPTION_NOT_SET = 0x03
 DCP SET block-level result: suboption not set.
 
constexpr std::uint8_t profinet::dcp::DCP_BLOCK_ERROR_RESOURCE = 0x04
 DCP SET block-level result: resource error.
 
constexpr std::uint8_t profinet::dcp::DCP_BLOCK_ERROR_SET_NOT_POSSIBLE = 0x05
 DCP SET block-level result: set not possible locally.
 
constexpr std::uint8_t profinet::dcp::DCP_BLOCK_ERROR_IN_OPERATION = 0x06
 DCP SET block-level result: set not possible, device in operation.
 

Detailed Description

PROFINET DCP discovery and device configuration interface.

Defines the data structures, constants, and operations required for PROFINET Discovery and Configuration Protocol (DCP) communication.

The interface provides support for:

  • DCP Identify, GET, SET, and Hello services.
  • Station-name and IP-address configuration.
  • Device identification through the flashing device LED.
  • Factory-reset operations.
  • Parsing DCP response blocks and error codes.
  • Decoding device roles, IP status, reset qualifiers, and device initiative information.
  • Parsing DHCP-related DCP suboptions.
  • Representing discovered devices through DCPDeviceDescription.
  • Constructing DCP request frames and processing received responses.
  • Handling both VLAN-tagged and untagged PROFINET Ethernet frames.

DCPDeviceDescription stores the network and identification information obtained during discovery, including MAC address, station name, IP configuration, vendor and device identifiers, device role, supported DCP options, DHCP information, and device-initiative settings.

The interface operates directly on raw Ethernet frames and uses the PROFINET DCP wire-format definitions provided by protocol.h. Operations are designed to tolerate unrelated or malformed received frames where appropriate, allowing discovery and response processing to continue until the configured timeout expires.

Definition in file dcp.h.