209std::string
GetBlockName(std::uint8_t option, std::uint8_t suboption);
233 static constexpr std::uint16_t
IP_SET = 0x0001;
254 static std::string
GetName(std::uint16_t info);
269 return (info & 0x0002) != 0;
286 static std::string
GetName(std::uint16_t qualifier);
314 static std::string
GetName(std::uint16_t qualifier);
330 static std::string
GetName(std::uint16_t value);
361 static std::string
GetName(std::uint8_t code);
408 std::optional<std::string>
fqdn;
411 std::optional<std::string>
uuid;
421using BlockKey = std::pair<std::uint8_t, std::uint8_t>;
443 std::string
ip =
"0.0.0.0";
497 std::map<BlockKey, std::vector<std::uint8_t>>
rawBlocks;
519 [[nodiscard]] std::string
ToString()
const;
551 const std::string& param,
552 const std::string& value,
573const std::map<std::string, BlockKey>&
Params();
584 const std::string& target,
const std::string& param,
601 const std::string& param,
const std::string& value,
int timeoutSec =
DEFAULT_TIMEOUT,
bool permanent =
false);
614 const std::string& ip,
const std::string& netmask,
const std::string& gateway,
629 const std::vector<std::uint8_t>& value);
632using ResponseMap = std::map<MacAddress, std::map<BlockKey, std::vector<std::uint8_t>>>;
642 bool once =
false, std::optional<std::uint32_t> expectedXid = std::nullopt);
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},
666 const std::function<
void(
const DCPDeviceDescription&)>& callback =
nullptr);
Abstraction for sending and receiving raw Ethernet frames.
A minimal RAII wrapper around a Linux AF_PACKET raw socket bound to an interface.
Abstract interface for raw Ethernet frame transport.
Parsed PROFINET device information from a DCP response.
std::pair< std::uint8_t, std::uint8_t > deviceInstance
Device instance (high, low) pair.
bool ipConflict
Whether an IP address conflict was detected.
std::uint8_t vendorLow
Low byte of the PROFINET vendor ID.
std::string netmask
IPv4 subnet mask, or "0.0.0.0" if unset.
std::string ToString() const
Multi-line human-readable summary of this device.
std::uint16_t ipBlockInfo
Raw IP block info flags (see IPBlockInfo).
std::string name
Station name.
std::uint8_t vendorHigh
High byte of the PROFINET vendor ID.
std::uint8_t deviceLow
Low byte of the PROFINET device ID.
std::uint16_t VendorId() const
Combine VendorHigh/VendorLow into a 16-bit vendor ID.
std::uint8_t deviceRole
Raw device role bitmask.
std::string gateway
IPv4 default gateway, or "0.0.0.0" if unset.
std::uint16_t DeviceId() const
Combine DeviceHigh/DeviceLow into a 16-bit device ID.
std::string aliasName
Device alias name, if set.
std::map< BlockKey, std::vector< std::uint8_t > > rawBlocks
Any parsed blocks not covered by the named fields above.
std::uint16_t deviceInitiative
Raw device-initiative value (see DeviceInitiative).
std::vector< BlockKey > supportedOptions
List of (option, suboption) blocks the device supports.
bool issuesHello
Whether the device issues a DCP-Hello after power-on.
std::uint8_t deviceHigh
High byte of the PROFINET device ID.
std::string VendorName() const
Look up the vendor name for this device's vendor ID.
std::string mac
Device's MAC address, formatted as a string.
std::string ip
IPv4 address, or "0.0.0.0" if unset.
bool ipSetByDhcp
Whether the IP address was assigned via DHCP.
std::vector< DCPDHCPBlock > dhcpBlocks
Parsed DHCP blocks from the response, if any.
std::vector< std::string > deviceRoles
Decoded device role names (see DecodeDeviceRole()).
std::string deviceType
Device type string (e.g. model name).
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.
constexpr std::uint8_t DCP_SUBOPTION_DEVICE_TYPE
DCP suboption (Device): device type string.
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).
constexpr std::uint8_t DCP_SUBOPTION_DEVICE_RSI
DCP suboption (Device): RSI (reverse status indication).
constexpr std::uint8_t DCP_SUBOPTION_CONTROL_SIGNAL
DCP suboption (Control): signal (flash LEDs).
constexpr std::uint8_t DCP_SUBOPTION_IP_PARAMETER
DCP suboption (IP): IP/netmask/gateway parameter.
constexpr std::uint16_t RESET_MODE_COMMUNICATION
Reset mode bit: reset communication parameters.
constexpr std::uint8_t DEVICE_ROLE_IO_MULTIDEVICE
Device role bit: IO-Multidevice.
constexpr std::uint8_t DCP_SERVICE_TYPE_REQUEST
DCP service type: REQUEST.
Bytes 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.
constexpr std::uint8_t DCP_SUBOPTION_DHCP_CLIENT_ID
DCP suboption (DHCP): client identifier option.
bool SetParam(const EthernetSocket &sock, const MacAddress &src, const std::string &target, const std::string ¶m, const std::string &value, int timeoutSec=DEFAULT_TIMEOUT, bool permanent=false)
Write a named parameter to a device.
constexpr std::uint16_t DCP_HELLO_FRAME_ID
Frame ID for DCP Hello announcements.
constexpr std::uint8_t DCP_SUBOPTION_DHCP_PARAM_REQ
DCP suboption (DHCP): parameter request list.
Bytes BuildDcpSignalRequest(const MacAddress &dst, const MacAddress &src)
Build a serialized DCP Signal request.
constexpr std::uint8_t DCP_SUBOPTION_DEVICE_INSTANCE
DCP suboption (Device): device instance.
constexpr std::uint8_t DCP_OPTION_DEVICE
DCP option: device identification.
const std::map< std::string, BlockKey > & Params()
Table of supported parameter names, mapping to their (option, suboption).
std::string GetBlockName(std::uint8_t option, std::uint8_t suboption)
Get the human-readable name for a (option, suboption) DCP block.
constexpr std::uint8_t DCP_SUBOPTION_DEVICE_ROLE
DCP suboption (Device): device role bitmask.
constexpr std::uint8_t DCP_BLOCK_ERROR_SET_NOT_POSSIBLE
DCP SET block-level result: set not possible locally.
constexpr std::uint16_t DCP_GET_SET_FRAME_ID
Frame ID for DCP Get/Set requests and responses.
constexpr std::uint8_t DCP_BLOCK_ERROR_OPTION_UNSUPPORTED
DCP SET block-level result: option not supported.
constexpr std::uint8_t DCP_SERVICE_ID_IDENTIFY
DCP service ID: IDENTIFY.
constexpr std::uint16_t DEFAULT_RESPONSE_DELAY_FACTOR
Default dcp response delay factor.
constexpr std::uint16_t RESET_MODE_DEVICE
Reset mode bit: reset device.
constexpr std::uint8_t DCP_SERVICE_ID_HELLO
DCP service ID: HELLO.
constexpr std::uint8_t DCP_BLOCK_ERROR_SUBOPTION_UNSUPPORTED
DCP SET block-level result: suboption not supported.
constexpr std::uint16_t RESET_MODE_ALL_DATA
Reset mode bit: reset all stored data.
constexpr std::uint8_t DCP_SUBOPTION_IP_MAC
DCP suboption (IP): MAC address.
constexpr std::uint16_t FLASH_DURATION_MS
Default flash duration of the leds.
constexpr std::uint8_t DCP_SUBOPTION_DEVICE_INITIATIVE
DCP suboption (DeviceInitiative): the only suboption.
constexpr std::uint16_t DEFAULT_HELLO_TIMEOUT
Default HELLO timeout.
constexpr std::uint8_t DCP_SUBOPTION_DHCP_UUID
DCP suboption (DHCP): client UUID option.
constexpr std::uint8_t DCP_SUBOPTION_DEVICE_OPTIONS
DCP suboption (Device): supported options list.
std::pair< std::uint8_t, std::uint8_t > BlockKey
(option, suboption) key identifying a DCP block.
constexpr std::uint8_t DCP_SUBOPTION_DEVICE_ALIAS
DCP suboption (Device): alias name.
constexpr std::uint8_t DCP_SUBOPTION_DEVICE_ID
DCP suboption (Device): vendor/device ID.
constexpr std::uint16_t DCP_IDENTIFY_REQUEST_FRAME_ID
Frame ID for DCP Identify requests.
constexpr std::uint16_t DEFAULT_TIMEOUT
Default timeout.
constexpr std::uint8_t DCP_SERVICE_ID_GET
DCP service ID: GET.
constexpr std::uint8_t DCP_SUBOPTION_DHCP_CONTROL
DCP suboption (DHCP): DHCP control.
constexpr std::uint8_t DCP_SUBOPTION_CONTROL_STOP
DCP suboption (Control): stop.
constexpr std::uint8_t DCP_SUBOPTION_DHCP_VENDOR_SPEC
DCP suboption (DHCP): vendor-specific option.
std::optional< std::vector< std::uint8_t > > GetParam(const EthernetSocket &sock, const MacAddress &src, const std::string &target, const std::string ¶m, int timeoutSec=DEFAULT_TIMEOUT)
Read a named parameter from a device.
constexpr std::uint8_t DCP_SUBOPTION_CONTROL_RESET_FACTORY
DCP suboption (Control): factory reset.
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.
const std::string DCP_MULTICAST_MAC
DCP Identify/Get/Set multicast destination MAC.
constexpr std::uint8_t DCP_SUBOPTION_IP_FULL_SUITE
DCP suboption (IP): full IP suite.
constexpr std::uint8_t DCP_SUBOPTION_DHCP_FQDN
DCP suboption (DHCP): fully qualified domain name option.
constexpr std::uint8_t DEVICE_ROLE_IO_DEVICE
Device role bit: IO-Device.
const std::string DCP_HELLO_MULTICAST_MAC
DCP Hello multicast destination MAC.
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.
constexpr std::uint8_t DCP_SUBOPTION_DHCP_SERVER_ID
DCP suboption (DHCP): server identifier option.
std::string DcpBlockErrorName(std::uint8_t code)
Get the human-readable name for a DCP SET block-level error code.
std::vector< std::string > DecodeDeviceRole(std::uint8_t roleByte)
Decode a device role bitmask into a list of role names.
constexpr std::uint8_t DCP_OPTION_IP
DCP option: IP configuration.
std::uint8_t RecvSetResponse(const IRawEthernetSocket &sock, const MacAddress &srcMac, int timeoutSec)
Receive and parse a DCP SET response, filtering out unrelated frames.
constexpr std::uint8_t DEVICE_ROLE_IO_CONTROLLER
Device role bit: IO-Controller.
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.
constexpr std::uint8_t DCP_SUBOPTION_DHCP_HOSTNAME
DCP suboption (DHCP): hostname option.
constexpr std::uint8_t DCP_SUBOPTION_DHCP_CLASS_ID
DCP suboption (DHCP): class identifier option.
constexpr std::uint8_t DCP_SUBOPTION_CONTROL_RESPONSE
DCP suboption (Control): response.
constexpr std::uint8_t DCP_BLOCK_ERROR_IN_OPERATION
DCP SET block-level result: set not possible, device in operation.
std::map< MacAddress, std::map< BlockKey, std::vector< std::uint8_t > > > ResponseMap
Result of ReadResponse(): MAC address -> parsed (option,suboption) -> payload blocks.
constexpr std::uint8_t DCP_SUBOPTION_DEVICE_NAME
DCP suboption (Device): station name.
constexpr std::uint8_t DCP_SUBOPTION_DEVICE_OEM_ID
DCP suboption (Device): OEM vendor/device ID.
constexpr std::uint16_t RESET_MODE_FACTORY
Reset mode bit: reset to factory defaults.
constexpr std::uint8_t DCP_BLOCK_ERROR_OK
DCP SET block-level result: OK.
constexpr std::uint8_t DCP_SUBOPTION_CONTROL_START
DCP suboption (Control): start.
constexpr std::uint16_t RESET_MODE_APPLICATION
Reset mode bit: reset application data.
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.
constexpr std::uint8_t DCP_SUBOPTION_CONTROL_RESET_TO_FACTORY
DCP suboption (Control): reset to factory.
constexpr std::uint8_t DCP_OPTION_NME
DCP option: Network Management (NME).
constexpr std::uint8_t DCP_BLOCK_ERROR_SUBOPTION_NOT_SET
DCP SET block-level result: suboption not set.
constexpr std::uint8_t DCP_OPTION_CONTROL
DCP option: control (start/stop/signal/reset).
constexpr std::uint8_t DCP_OPTION_DHCP
DCP option: DHCP.
constexpr std::uint8_t DCP_SERVICE_ID_SET
DCP service ID: SET.
constexpr std::uint16_t DEFAULT_RESPONSE_TIMEOUT
Default response timeout. How long to keep listening for responses.
constexpr std::uint16_t RESET_MODE_ENGINEERING
Reset mode bit: reset engineering parameters.
constexpr std::uint8_t DEVICE_ROLE_PN_SUPERVISOR
Device role bit: PN-Supervisor.
constexpr std::uint8_t DCP_BLOCK_ERROR_RESOURCE
DCP SET block-level result: resource error.
constexpr std::uint8_t DCP_OPTION_ALL
DCP option wildcard: all options.
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).
constexpr std::uint8_t DCP_SERVICE_TYPE_RESPONSE_SUCCESS
DCP service type: RESPONSE (success).
constexpr std::uint8_t DCP_OPTION_DEVICE_INITIATIVE
DCP option: device-initiative (Hello) configuration.
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.
constexpr std::uint8_t DCP_OPTION_RESERVED
DCP option: reserved.
std::uint8_t ParseSetResponse(const Bytes &data)
Parses the raw byte response payload received from a SET operation.
constexpr std::uint8_t DCP_SERVICE_TYPE_RESPONSE_UNSUPPORTED
DCP service type: RESPONSE (service unsupported).
constexpr std::size_t DCP_MAX_NAME_LENGTH
Maximum allowed length in bytes for a station name.
constexpr std::uint16_t DCP_IDENTIFY_RESPONSE_FRAME_ID
Frame ID for DCP Identify responses.
std::array< std::uint8_t, macAddressLength > MacAddress
A 6-byte Ethernet MAC address.
static constexpr int OneOctetShift
The bit-shift distance required to move data across a single octet.
std::vector< std::uint8_t > Bytes
Generic byte buffer alias used throughout the library for raw wire data.
PROFINET protocol wire-format structures and serialization helpers.
Block qualifier: whether a Set operation is temporary or permanent.
static constexpr std::uint16_t PERMANENT
Change is persisted permanently.
static constexpr std::uint16_t TEMPORARY
Change applies until the next power cycle only.
static std::string GetName(std::uint16_t qualifier)
Get the human-readable name for a qualifier value.
Parsed DHCP block from a DCP response.
std::uint8_t suboption
DHCP suboption code.
std::optional< std::string > fqdn
Decoded fully qualified domain name, if this is an FQDN suboption.
std::vector< std::uint8_t > rawData
Raw, undecoded block payload.
std::optional< std::vector< std::uint8_t > > vendorSpecific
Decoded vendor-specific data, if this is a VendorSpec suboption.
static DCPDHCPBlock Parse(std::uint8_t suboption, const std::vector< std::uint8_t > &data)
Parse a DHCP suboption's payload into a DCPDHCPBlock.
std::optional< std::string > hostname
Decoded hostname, if this is a Hostname suboption.
std::string suboptionName
Human-readable name of the suboption.
std::optional< std::vector< std::uint8_t > > clientId
Decoded client ID, if this is a ClientID suboption.
std::optional< std::string > uuid
Decoded UUID string, if this is a UUID suboption.
DCP GET/SET response codes.
static constexpr std::uint8_t RESOURCE_ERROR
A resource error occurred.
static constexpr std::uint8_t SET_NOT_POSSIBLE
The SET operation is not currently possible.
static constexpr std::uint8_t SUBOPTION_NOT_SUPPORTED
The requested suboption is not supported or has no data set.
static constexpr std::uint8_t NO_ERROR
No error.
static constexpr std::uint8_t OPTION_NOT_SUPPORTED
The requested option is not supported.
static std::string GetName(std::uint8_t code)
Get the human-readable name for a response code.
static constexpr std::uint8_t SUBOPTION_NOT_SET
The requested suboption is not set.
static constexpr std::uint8_t IN_OPERATION_SET_NOT_POSSIBLE
The SET operation is not possible while the device is in operation.
Device-initiative (Hello-after-power-on) setting values.
static constexpr std::uint16_t ISSUE_HELLO
Device sends DCP-Hello after power-on.
static std::string GetName(std::uint16_t value)
Get the human-readable name for a device-initiative value.
static constexpr std::uint16_t NO_HELLO
Device does not send DCP-Hello after power-on.
IP block status flags (IEC 61158-6-10 IPBlockInfo).
static constexpr std::uint16_t IP_SET_BY_DHCP
IP address set via DHCP.
static constexpr std::uint16_t IP_NOT_SET_CONFLICT
IP address not set, address conflict detected.
static constexpr std::uint16_t IP_NOT_SET
IP address not set.
static bool HasConflict(std::uint16_t info)
Whether an address conflict was detected.
static constexpr std::uint16_t IP_SET_CONFLICT
IP address set (statically), address conflict detected.
static constexpr std::uint16_t IP_CONFLICT_BIT
IP conflict bit value.
static std::string GetName(std::uint16_t info)
Get the human-readable name for an IP block info value.
static bool IsDhcp(std::uint16_t info)
Whether the address was assigned via DHCP.
static constexpr std::uint16_t IP_SET_BY_DHCP_CONFLICT
IP address set via DHCP, address conflict detected.
static constexpr std::uint16_t IP_SET
IP address set (statically).
Reset qualifier values for ResetToFactory().
static constexpr std::uint16_t RESET_AND_RESTORE
Reset and restore from backup.
static constexpr std::uint16_t RESET_APPLICATION_DATA
Reset application data.
static constexpr std::uint16_t RESET_TO_FACTORY
Reset to factory defaults.
static constexpr std::uint16_t RESET_COMMUNICATION_PARAM
Reset communication parameters.
static constexpr std::uint16_t RESET_ENGINEERING_PARAM
Reset engineering parameters.
static std::string GetName(std::uint16_t qualifier)
Get the human-readable name for a reset qualifier value.
static constexpr std::uint16_t RESET_ALL_STORED_DATA
Reset all stored data.
Declares Linux Ethernet, addressing, timing, and utility helpers used by the PROFINET stack.