20#include <netinet/in.h>
109 std::unique_ptr<IRawEthernetSocket> l2Socket =
nullptr);
140 void Start()
override;
144 void Stop()
override;
183 void SendUdpAck(
const Bytes& ackData,
const sockaddr_in& dstAddr)
const;
224 std::unique_ptr<IRawEthernetSocket>
l2Sock;
Interface for PROFINET alarm listeners.
Declares PROFINET alarm, diagnosis, maintenance, and USI payload types and parsers.
Background listener for PROFINET alarm notifications.
std::atomic< bool > running
Whether the listener thread should keep running.
void SendAck(const AlarmNotification &alarm, std::optional< MacAddress > srcMac)
Build and send an AlarmAck-PDU for a received notification.
friend class AlarmListenerCallbackTest
Test fixture for callback behavior tests.
AlarmEndpoint endpoint
Alarm endpoint configuration.
friend class AlarmListenerTests
Test fixture for AlarmListener unit tests.
void HandleUdpFrame()
Receive and process one UDP frame.
friend class AlarmListenerRtaTest
Test fixture for RTA transport regression tests.
AlarmListener(const AlarmListener &)=delete
Not copyable (owns a socket and background thread).
~AlarmListener() override
Stop (if running) and release resources.
std::optional< sockaddr_in > lastUdpSrc
Address of the most recently received UDP alarm, for replying.
void Stop() override
Stop the listener.
std::uint16_t recvSeqNum
Last received sequence number, for duplicate detection.
std::unique_ptr< IRawEthernetSocket > l2Sock
Raw Ethernet transport used for Layer 2 alarm reception.
MacAddress controllerMac
This host's MAC address.
std::uint16_t sendSeqNum
Sequence number for outgoing AlarmAck-PDUs.
void HandleLayer2Frame()
Receive and process one Layer 2 (RTA-PDU) frame.
bool IsRunning() const override
Whether the listener thread is currently running.
void SendUdpAck(const Bytes &ackData, const sockaddr_in &dstAddr) const
Send an AlarmAck-PDU over the UDP transport.
void ListenLoop()
Listener thread body: dispatches to the Layer 2 or UDP handler.
std::thread thread
Background thread receiving and processing alarms.
void RemoveCallback(std::function< void(const AlarmNotification &)> callback) override
Remove a registered callback.
void SendLayer2Ack(const Bytes &ackData, const MacAddress &dstMac, bool highPriority)
Send an AlarmAck-PDU over the Layer 2 transport.
std::vector< std::function< void(const AlarmNotification &)> > callbacks
Registered callbacks invoked for successfully parsed alarms.
void ProcessAlarm(const Bytes &payload, std::optional< bool > highPriority, std::optional< MacAddress > srcMac)
Parse an alarm payload and dispatch it to registered callbacks.
int udpFd
Socket file descriptor used for the UDP transport.
friend class AlarmListenerRtaIntegrationTest
Test fixture for multi-frame RTA integration tests.
void AddCallback(std::function< void(const AlarmNotification &)> callback) override
Register a callback for received alarms.
void Start() override
Start the background listener (socket + thread).
AlarmListener & operator=(const AlarmListener &)=delete
Not copyable (owns a socket and background thread).
std::mutex callbacksMutex
Protects concurrent access to callbacks.
Abstract interface for receiving PROFINET alarm notifications.
std::array< std::uint8_t, macAddressLength > MacAddress
A 6-byte Ethernet MAC address.
constexpr std::uint16_t ALARM_UDP_PORT
UDP port used for alarm transport when Transport == 1.
std::vector< std::uint8_t > Bytes
Generic byte buffer alias used throughout the library for raw wire data.
constexpr std::uint16_t FRAME_ID_ALARM_HIGH
Frame ID used for high-priority alarms.
constexpr std::uint16_t ETHERTYPE_PROFINET
EtherType used by PROFINET RTA frames (0x8892).
constexpr std::uint16_t FRAME_ID_ALARM_LOW
Frame ID used for low-priority alarms.
Alarm endpoint configuration.
int transport
Transport: 0 = Layer2 (RTA), 1 = UDP.
std::string interface
Network interface name to bind to, e.g. "eth0".
std::uint16_t controllerRef
Controller's local alarm reference (from AlarmCRBlockReq).
std::uint16_t deviceRef
Device's local alarm reference (from AlarmCRBlockRes).
MacAddress deviceMac
The device's MAC address.
Complete parsed AlarmNotification PDU: header fields + parsed items.
Declares Linux Ethernet, addressing, timing, and utility helpers used by the PROFINET stack.