mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
New builtin udp listener (#18)
* Fixed compile error when no grabbers are defined * Remove stupid avahi warning... * Started on the new integrated UDP listener to replace the python effect. Cloned boblight server and rename it to be UDP listener It compiles!, It starts! it seems to work as a second boblight protocol server... * moving from the exsting TCP to UDP. i can catch packets now.. need to consider ditching the connection handling * It kinda works right now. UDP packets are received, led data is sent and hyperion displays them. .... for a moment before going back to what it was doing * It works! looks like the default priority of 900 was fighting with something else that was also 900 commented out some udp packet debugging * oops, forgot to add the changes the the previous commit * resolving merge conflicts
This commit is contained in:
parent
065e65b8e0
commit
a23735d1ef
62
include/udplistener/UDPListener.h
Normal file
62
include/udplistener/UDPListener.h
Normal file
@ -0,0 +1,62 @@
|
||||
#pragma once
|
||||
|
||||
// system includes
|
||||
#include <cstdint>
|
||||
|
||||
// Qt includes
|
||||
#include <QUdpSocket>
|
||||
#include <QSet>
|
||||
|
||||
// Hyperion includes
|
||||
#include <hyperion/Hyperion.h>
|
||||
|
||||
class UDPClientConnection;
|
||||
|
||||
///
|
||||
/// This class creates a UDP server which accepts connections from boblight clients.
|
||||
///
|
||||
class UDPListener : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
///
|
||||
/// UDPListener constructor
|
||||
/// @param hyperion Hyperion instance
|
||||
/// @param port port number on which to start listening for connections
|
||||
///
|
||||
UDPListener(Hyperion * hyperion, const int priority, const int timeout, uint16_t port = 2801);
|
||||
~UDPListener();
|
||||
|
||||
///
|
||||
/// @return the port number on which this UDP listens for incoming connections
|
||||
///
|
||||
uint16_t getPort() const;
|
||||
|
||||
private slots:
|
||||
///
|
||||
/// Slot which is called when a client tries to create a new connection
|
||||
///
|
||||
void readPendingDatagrams();
|
||||
void processTheDatagram(const QByteArray * _datagram);
|
||||
|
||||
|
||||
private:
|
||||
/// Hyperion instance
|
||||
Hyperion * _hyperion;
|
||||
|
||||
/// The UDP server object
|
||||
QUdpSocket * _server;
|
||||
|
||||
/// List with open connections
|
||||
QSet<UDPClientConnection *> _openConnections;
|
||||
|
||||
/// hyperion priority
|
||||
int _priority;
|
||||
|
||||
/// hyperion priority
|
||||
int _timeout;
|
||||
|
||||
/// The latest led color data
|
||||
std::vector<ColorRgb> _ledColors;
|
||||
};
|
@ -9,6 +9,7 @@ add_subdirectory(jsonserver)
|
||||
add_subdirectory(protoserver)
|
||||
add_subdirectory(bonjour)
|
||||
add_subdirectory(boblightserver)
|
||||
add_subdirectory(udplistener)
|
||||
add_subdirectory(leddevice)
|
||||
add_subdirectory(utils)
|
||||
add_subdirectory(xbmcvideochecker)
|
||||
|
32
libsrc/udplistener/CMakeLists.txt
Normal file
32
libsrc/udplistener/CMakeLists.txt
Normal file
@ -0,0 +1,32 @@
|
||||
|
||||
# Define the current source locations
|
||||
set(CURRENT_HEADER_DIR ${CMAKE_SOURCE_DIR}/include/udplistener)
|
||||
set(CURRENT_SOURCE_DIR ${CMAKE_SOURCE_DIR}/libsrc/udplistener)
|
||||
|
||||
# Group the headers that go through the MOC compiler
|
||||
set(UDPListener_QT_HEADERS
|
||||
${CURRENT_HEADER_DIR}/UDPListener.h
|
||||
)
|
||||
|
||||
set(UDPListener_HEADERS
|
||||
)
|
||||
|
||||
set(UDPListener_SOURCES
|
||||
${CURRENT_SOURCE_DIR}/UDPListener.cpp
|
||||
)
|
||||
|
||||
qt5_wrap_cpp(UDPListener_HEADERS_MOC ${UDPListener_QT_HEADERS})
|
||||
|
||||
add_library(udplistener
|
||||
${UDPListener_HEADERS}
|
||||
${UDPListener_QT_HEADERS}
|
||||
${UDPListener_SOURCES}
|
||||
${UDPListener_HEADERS_MOC}
|
||||
)
|
||||
|
||||
qt5_use_modules(udplistener Widgets)
|
||||
|
||||
target_link_libraries(udplistener
|
||||
hyperion
|
||||
hyperion-utils
|
||||
${QT_LIBRARIES})
|
83
libsrc/udplistener/UDPListener.cpp
Normal file
83
libsrc/udplistener/UDPListener.cpp
Normal file
@ -0,0 +1,83 @@
|
||||
// system includes
|
||||
#include <stdexcept>
|
||||
|
||||
// project includes
|
||||
#include <udplistener/UDPListener.h>
|
||||
|
||||
// hyperion util includes
|
||||
#include "hyperion/ImageProcessorFactory.h"
|
||||
#include "hyperion/ImageProcessor.h"
|
||||
#include "utils/ColorRgb.h"
|
||||
#include "HyperionConfig.h"
|
||||
|
||||
UDPListener::UDPListener(Hyperion *hyperion, const int priority, const int timeout, uint16_t port) :
|
||||
QObject(),
|
||||
_hyperion(hyperion),
|
||||
_server(),
|
||||
_openConnections(),
|
||||
_priority(priority),
|
||||
_timeout(timeout),
|
||||
_ledColors(hyperion->getLedCount(), ColorRgb::BLACK)
|
||||
|
||||
{
|
||||
_server = new QUdpSocket(this);
|
||||
if (!_server->bind(QHostAddress::Any, port))
|
||||
{
|
||||
throw std::runtime_error("UDPLISTENER ERROR: server could not bind to port");
|
||||
}
|
||||
|
||||
// Set trigger for incoming connections
|
||||
connect(_server, SIGNAL(readyRead()), this, SLOT(readPendingDatagrams()));
|
||||
}
|
||||
|
||||
UDPListener::~UDPListener()
|
||||
{
|
||||
// clear the current channel
|
||||
_hyperion->clear(_priority);
|
||||
}
|
||||
|
||||
uint16_t UDPListener::getPort() const
|
||||
{
|
||||
return _server->localPort();
|
||||
}
|
||||
|
||||
|
||||
void UDPListener::readPendingDatagrams()
|
||||
{
|
||||
while (_server->hasPendingDatagrams()) {
|
||||
QByteArray datagram;
|
||||
datagram.resize(_server->pendingDatagramSize());
|
||||
QHostAddress sender;
|
||||
quint16 senderPort;
|
||||
|
||||
_server->readDatagram(datagram.data(), datagram.size(),
|
||||
&sender, &senderPort);
|
||||
|
||||
// std::cout << "UDPLISTENER INFO: new packet from " << std::endl;
|
||||
processTheDatagram(&datagram);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void UDPListener::processTheDatagram(const QByteArray * datagram)
|
||||
{
|
||||
// std::cout << "udp message: " << datagram->data() << std::endl;
|
||||
|
||||
int packlen = datagram->size()/3;
|
||||
int ledlen = _ledColors.size();
|
||||
// int maxled = std::min(datagram->size()/3, _ledColors.size());
|
||||
int maxled = std::min(packlen , ledlen);
|
||||
|
||||
for (int ledIndex=0; ledIndex < maxled; ledIndex++) {
|
||||
ColorRgb & rgb = _ledColors[ledIndex];
|
||||
rgb.red = datagram->at(ledIndex*3+0);
|
||||
rgb.green = datagram->at(ledIndex*3+1);
|
||||
rgb.blue = datagram->at(ledIndex*3+2);
|
||||
// printf("%02x%02x%02x%02x ", ledIndex, rgb.red, rgb.green, rgb.blue);
|
||||
}
|
||||
// printf ("\n");
|
||||
|
||||
_hyperion->setColors(_priority, _ledColors, _timeout, -1);
|
||||
|
||||
}
|
@ -9,6 +9,7 @@ target_link_libraries(hyperiond
|
||||
effectengine
|
||||
jsonserver
|
||||
boblightserver
|
||||
udplistener
|
||||
protoserver
|
||||
webconfig
|
||||
bonjour
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include <jsonserver/JsonServer.h>
|
||||
#include <protoserver/ProtoServer.h>
|
||||
#include <boblightserver/BoblightServer.h>
|
||||
#include <udplistener/UDPListener.h>
|
||||
|
||||
#include "hyperiond.h"
|
||||
|
||||
@ -28,6 +29,7 @@ HyperionDaemon::HyperionDaemon(std::string configFile, QObject *parent)
|
||||
, _jsonServer(nullptr)
|
||||
, _protoServer(nullptr)
|
||||
, _boblightServer(nullptr)
|
||||
, _udpListener(nullptr)
|
||||
, _v4l2Grabber(nullptr)
|
||||
, _dispmanx(nullptr)
|
||||
, _amlGrabber(nullptr)
|
||||
@ -51,6 +53,7 @@ HyperionDaemon::~HyperionDaemon()
|
||||
delete _jsonServer;
|
||||
delete _protoServer;
|
||||
delete _boblightServer;
|
||||
delete _udpListener;
|
||||
delete _webConfig;
|
||||
|
||||
}
|
||||
@ -217,6 +220,18 @@ void HyperionDaemon::startNetworkServices()
|
||||
Info(_log, "Boblight server created and started on port %d", _boblightServer->getPort());
|
||||
}
|
||||
|
||||
// Create UDP listener if configuration is present
|
||||
if (_config.isMember("udpListener"))
|
||||
{
|
||||
const Json::Value & udpListenerConfig = _config["udpListener"];
|
||||
_udpListener = new UDPListener(hyperion,
|
||||
udpListenerConfig.get("priority",890).asInt(),
|
||||
udpListenerConfig.get("timeout",10000).asInt(),
|
||||
udpListenerConfig["port"].asUInt()
|
||||
);
|
||||
Info(_log, "UDP listener created and started on port %d", _udpListener->getPort());
|
||||
}
|
||||
|
||||
// zeroconf
|
||||
const Json::Value & deviceConfig = _config["device"];
|
||||
const std::string deviceName = deviceConfig.get("name", "").asString();
|
||||
|
@ -39,6 +39,7 @@
|
||||
#include <protoserver/ProtoServer.h>
|
||||
#include <boblightserver/BoblightServer.h>
|
||||
#include <webconfig/WebConfig.h>
|
||||
#include <udplistener/UDPListener.h>
|
||||
|
||||
class HyperionDaemon : public QObject
|
||||
{
|
||||
@ -67,6 +68,7 @@ private:
|
||||
JsonServer* _jsonServer;
|
||||
ProtoServer* _protoServer;
|
||||
BoblightServer* _boblightServer;
|
||||
UDPListener* _udpListener;
|
||||
V4L2Wrapper* _v4l2Grabber;
|
||||
DispmanxWrapper* _dispmanx;
|
||||
AmlogicWrapper* _amlGrabber;
|
||||
|
Loading…
Reference in New Issue
Block a user