|
PROFINET IO Controller Stack 1.0.0
Modern C++ implementation of a PROFINET IO Controller stack
|
Implements PROFINET DCP discovery and device configuration operations. More...
#include "profinet/dcp.h"#include <algorithm>#include <cstdio>#include <cstring>#include <magic_enum.hpp>#include <map>#include <random>#include <thread>#include "profinet/exceptions.h"#include "profinet/protocol.h"#include "profinet/vendors.h"
Include dependency graph for dcp.cpp:Go to the source code of this file.
Namespaces | |
| namespace | profinet |
| namespace | profinet::dcp |
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::DeviceRoleName (DcpDeviceRole role) |
| Get the human-readable name of a DCP device role. | |
| std::string | profinet::dcp::GetSuboptionName (std::uint16_t option, std::uint8_t value) |
| std::string | profinet::dcp::GetBlockName (std::uint16_t option, std::uint8_t suboption) |
| Get the human-readable name for a (option, suboption) DCP block. | |
| std::string | profinet::dcp::GetBlockName (DcpOption option, std::uint8_t suboption) |
| Get the human-readable name for a (option, suboption) DCP block. | |
| std::string | profinet::dcp::GetBlockName (DcpOption option, DcpIpSuboption suboption) |
| Get the human-readable name for a (option, suboption) DCP block. | |
| std::string | profinet::dcp::GetBlockName (DcpOption option, DcpDeviceSuboption suboption) |
| Get the human-readable name for a (option, suboption) DCP block. | |
| std::string | profinet::dcp::GetBlockName (DcpOption option, DcpControlSuboption suboption) |
| Get the human-readable name for a (option, suboption) DCP block. | |
| std::string | profinet::dcp::GetBlockName (DcpOption option, DcpDhcpSuboption suboption) |
| Get the human-readable name for a (option, suboption) DCP block. | |
| std::string | profinet::dcp::GetBlockName (DcpOption option, DcpDeviceInitiativeSuboption suboption) |
| Get the human-readable name for a (option, suboption) DCP block. | |
| DcpBlockError | profinet::dcp::RecvSetResponse (IRawEthernetSocket &sock, const MacAddress &srcMac, int timeoutSec) |
| Receive and parse a DCP SET response, filtering out unrelated frames. | |
| DcpBlockError | profinet::dcp::ParseSetResponse (const Bytes &data) |
| Parses the raw byte response payload received from a SET operation. | |
| std::string | profinet::dcp::GetIPBlockInfoName (DcpIpBlockInfo info) |
| Get the human-readable name for an IP block info value. | |
| bool | profinet::dcp::HasConflict (DcpIpBlockInfo info) |
| Whether an address conflict was detected. | |
| bool | profinet::dcp::IsDhcp (DcpIpBlockInfo info) |
| Whether the address was assigned via DHCP. | |
| std::string | profinet::dcp::GetDcpBlockQualifierDescription (DcpBlockQualifier qualifier) |
| Get the human-readable description of a DCP block qualifier. | |
| std::string | profinet::dcp::GetResetQualifierName (std::uint16_t qualifier) |
| Get the human-readable name for a reset qualifier value. | |
| std::string | profinet::dcp::GetResetQualifierName (DcpResetQualifier qualifier) |
| Get the human-readable name for a reset qualifier value. | |
| std::string | profinet::dcp::GetDeviceInitiativeName (DcpDeviceInitiative value) |
| std::string | profinet::dcp::GetDcpResponseCodeName (DcpResponseCode value) |
| Get the human-readable name for a device-response value. | |
| std::string | profinet::dcp::GetDcpBlockErrorDescription (DcpBlockError error) |
| Get the human-readable name for a DCP SET block-level error code. | |
| const std::map< std::string, BlockKey > & | profinet::dcp::Params () |
| Table of supported parameter names, mapping to their (option, suboption). | |
| Bytes | profinet::dcp::BuildSetParamRequest (const MacAddress &dst, const MacAddress &src, const std::string ¶m, 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. | |
| std::optional< std::vector< std::uint8_t > > | profinet::dcp::GetParam (IRawEthernetSocket &sock, const MacAddress &src, const std::string &target, const std::string ¶m, int timeoutSec=DEFAULT_TIMEOUT) |
| Read a named parameter from a device. | |
| bool | profinet::dcp::SetParam (IRawEthernetSocket &sock, const MacAddress &src, const std::string &target, const std::string ¶m, const std::string &value, int timeoutSec=DEFAULT_TIMEOUT, bool permanent=false, int threadSleepMs=DEFAULT_THREAD_SLEEP_MS) |
| Write a named parameter to a device. | |
| bool | profinet::dcp::SetIp (IRawEthernetSocket &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, int threadSleepMs=DEFAULT_THREAD_SLEEP_MS) |
| Set a device's IP configuration via DCP. | |
| void | profinet::dcp::SendDiscover (IRawEthernetSocket &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 (IRawEthernetSocket &sock, const MacAddress &src, BlockKey blockType, const Bytes &value) |
| Send a DCP Identify request filtered to a specific (option, suboption). | |
| ResponseMap | profinet::dcp::ReadResponse (IRawEthernetSocket &sock, const MacAddress &myMac, double 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 (IRawEthernetSocket &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}, DcpDeviceRole deviceRole=DcpDeviceRole::IoDevice) |
| Send a DCP Hello multicast announcement (device self-announce after power-on). | |
| std::vector< DCPDeviceDescription > | profinet::dcp::ReceiveHello (IRawEthernetSocket &sock, const MacAddress &myMac, double timeoutSec=DEFAULT_HELLO_TIMEOUT, const std::function< void(const DCPDeviceDescription &)> &callback=nullptr) |
| Listen for DCP Hello announcements from other devices. | |
| bool | profinet::dcp::SignalDevice (IRawEthernetSocket &sock, const MacAddress &src, const std::string &target, int durationMs=FLASH_DURATION_MS, double timeoutSec=DEFAULT_TIMEOUT) |
| Flash a device's identification LEDs. | |
| bool | profinet::dcp::ResetToFactory (IRawEthernetSocket &sock, const MacAddress &src, const std::string &target, DcpResetMode mode=DcpResetMode::Communication, double timeoutSec=DEFAULT_TIMEOUT) |
| Reset a device to factory defaults. | |
Implements PROFINET DCP discovery and device configuration operations.
Implements the PROFINET Discovery and Configuration Protocol (DCP) functionality declared in dcp.h. The implementation provides construction, transmission, reception, parsing, and interpretation of DCP Ethernet frames for device discovery and configuration.
The implementation covers:
Transaction identifiers are generated for DCP requests, while received frames are validated and filtered by destination, EtherType, service type, and, where applicable, transaction identifier. Malformed or unrelated frames are ignored where appropriate so that discovery and response processing can continue until the configured timeout expires.
Definition in file dcp.cpp.