initial import of sACN Node platform driver for Qt
This commit is contained in:
parent
603080b9f3
commit
2c74470b16
|
@ -0,0 +1,23 @@
|
|||
cmake_minimum_required(VERSION 3.14)
|
||||
|
||||
project(QsACNNode LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||
set(CMAKE_AUTOUIC ON)
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_AUTORCC ON)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
find_package(QT NAMES Qt6 Qt5 COMPONENTS Network REQUIRED)
|
||||
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Network REQUIRED)
|
||||
|
||||
add_library(${PROJECT_NAME} STATIC
|
||||
qsacnnode_global.h
|
||||
qsacnnode.cpp
|
||||
qsacnnode.h
|
||||
)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} PUBLIC Qt${QT_VERSION_MAJOR}::Network ESTA)
|
||||
|
||||
target_compile_definitions(${PROJECT_NAME} PUBLIC QT_LIBRARY)
|
|
@ -0,0 +1,67 @@
|
|||
#include "qsacnnode.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QNetworkDatagram>
|
||||
|
||||
namespace SACN {
|
||||
|
||||
QSacnNode::QSacnNode(UUID::uuid cid)
|
||||
: Node(cid)
|
||||
{
|
||||
bind(QHostAddress::AnyIPv4, ACN_SDT_MULTICAST_PORT);
|
||||
|
||||
connect(this, &QUdpSocket::readyRead,
|
||||
this, &QSacnNode::UdpStreamHandler);
|
||||
|
||||
onDiscovered(std::bind(&QSacnNode::emitFound, this,
|
||||
std::placeholders::_1));
|
||||
}
|
||||
|
||||
|
||||
void QSacnNode::subscribe(const uint16_t num)
|
||||
{
|
||||
if (universe(num)) // already subscribed
|
||||
return;
|
||||
qDebug() << "Subscribing to universe " << QString::number(num);
|
||||
Receiver::subscribe(num);
|
||||
joinMulticastGroup(IPv4MulticastAddress(num));
|
||||
}
|
||||
|
||||
|
||||
void QSacnNode::unsubscribe(const uint16_t num)
|
||||
{
|
||||
if (!universe(num)) // not subscribed
|
||||
return;
|
||||
qDebug() << "Unsubscribing from universe " << QString::number(num);
|
||||
leaveMulticastGroup(IPv4MulticastAddress(num));
|
||||
Receiver::unsubscribe(num);
|
||||
}
|
||||
|
||||
|
||||
void QSacnNode::UdpStreamHandler()
|
||||
{
|
||||
while (hasPendingDatagrams()) {
|
||||
qDebug() << "processing UDP datagram...";
|
||||
QNetworkDatagram datagram = receiveDatagram();
|
||||
// Expecting IANA registered Session Data Transport traffic
|
||||
if (datagram.destinationPort() != ACN_SDT_MULTICAST_PORT)
|
||||
return;
|
||||
|
||||
// wrap a PDU io stream around the QNetworkDatagram data buffer
|
||||
PDU::Stream stream(new PDU::pdu_stream(
|
||||
(uint8_t*)datagram.data().constData(),
|
||||
datagram.data().length()));
|
||||
Appliance::UdpStreamHandler(stream);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// wrap callback to Qt signal
|
||||
void QSacnNode::emitFound(
|
||||
std::shared_ptr<EXTENDED::DISCOVERY::DiscoveredUniverse> univ)
|
||||
{
|
||||
qDebug() << "found universe " << QString::number(univ->universe());
|
||||
emit foundUniverse(univ);
|
||||
}
|
||||
|
||||
} // SACN
|
|
@ -0,0 +1,48 @@
|
|||
#ifndef QSACNNODE_H
|
||||
#define QSACNNODE_H
|
||||
|
||||
#include "qsacnnode_global.h"
|
||||
#include "../../sacn/node.h"
|
||||
|
||||
#include <QHostAddress>
|
||||
#include <QUdpSocket>
|
||||
|
||||
|
||||
namespace SACN {
|
||||
// 9.3.1 Allocation of IPv4 Multicast Addresses
|
||||
// Multicast addresses are from the IPv4 Local Scope.
|
||||
inline QHostAddress IPv4MulticastAddress(uint16_t universe) {
|
||||
quint32 address = 239 << 24 | 255 << 16 | universe;
|
||||
return QHostAddress(address);
|
||||
};
|
||||
|
||||
|
||||
// 9.3.2 Allocation of IPv6 Multicast Addresses
|
||||
inline QHostAddress IPv6MulticastAddress(uint16_t universe) {
|
||||
quint8 address [] = {255, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 131, 0,
|
||||
(quint8)(universe >> 8), (quint8)(universe & 0xff)};
|
||||
return QHostAddress(address);
|
||||
};
|
||||
|
||||
|
||||
class QT_EXPORT QSacnNode
|
||||
: public QUdpSocket
|
||||
, public Node
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QSacnNode(UUID::uuid = UUID::uuid());
|
||||
virtual void subscribe(const uint16_t universe = 1);
|
||||
virtual void unsubscribe(const uint16_t);
|
||||
|
||||
signals:
|
||||
void foundUniverse(std::shared_ptr<EXTENDED::DISCOVERY::DiscoveredUniverse>);
|
||||
|
||||
private:
|
||||
void UdpStreamHandler();
|
||||
void emitFound(std::shared_ptr<EXTENDED::DISCOVERY::DiscoveredUniverse>);
|
||||
};
|
||||
|
||||
} // namespace SACN
|
||||
#endif // QSACNNODE_H
|
|
@ -0,0 +1,12 @@
|
|||
#ifndef QT_GLOBAL_H
|
||||
#define QT_GLOBAL_H
|
||||
|
||||
#include <QtCore/qglobal.h>
|
||||
|
||||
#if defined(QT_LIBRARY)
|
||||
# define QT_EXPORT Q_DECL_EXPORT
|
||||
#else
|
||||
# define QT_EXPORT Q_DECL_IMPORT
|
||||
#endif
|
||||
|
||||
#endif // QT_GLOBAL_H
|
Loading…
Reference in New Issue