mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
LED Device Features, Fixes and Refactoring (Resubmit PR855) (#875)
* Refactor LedDevices - Initial version * Small renamings * Add WLED as own device * Lpd8806 Remove open() method * remove dependency on Qt 5.10 * Lpd8806 Remove open() method * Update WS281x * Update WS2812SPI * Add writeBlack for WLED powerOff * WLED remove extra bracket * Allow different Nanoleaf panel numbering sequence (Feature req.#827) * build(deps): bump websocket-extensions from 0.1.3 to 0.1.4 in /docs (#826) * Bumps [websocket-extensions](https://github.com/faye/websocket-extensions-node) from 0.1.3 to 0.1.4. - [Release notes](https://github.com/faye/websocket-extensions-node/releases) - [Changelog](https://github.com/faye/websocket-extensions-node/blob/master/CHANGELOG.md) - [Commits](https://github.com/faye/websocket-extensions-node/compare/0.1.3...0.1.4) * Fix typos * Nanoleaf clean-up * Yeelight support, generalize wizard elements * Update Yeelight to handle quota in music mode * Yeelight extend rage for extraTimeDarkness for testing * Clean-up - Add commentary, Remove development debug statements * Fix brightnessSwitchOffOnMinimum typo and default value * Yeelight support restoreOriginalState, additional Fixes * WLED - Remove UDP-Port, as it is not configurable * Fix merging issue * Remove QHostAddress::operator=(const QString&)' is deprecated * Windows compile errors and (Qt 5.15 deprecation) warnings * Fix order includes * LedDeviceFile Support Qt5.7 and greater * Windows compatibility and other Fixes * Fix Qt Version compatability * Rs232 - Resolve portname from unix /dev/ style, fix DMX sub-type support * Disable WLED Wizard Button (until Wizard is available) * Yeelight updates * Add wrong log-type as per #505 * Fixes and Clean-up after clang-tidy report * Fix udpe131 not enabled for generated CID * Change timer into dynamic for Qt Thread-Affinity * Hue clean-up and diyHue workaround * Updates after review feedback by m-seker * Add "chrono" includes
This commit is contained in:
@@ -94,7 +94,7 @@ signals:
|
||||
void callbackMessage(QJsonObject);
|
||||
|
||||
///
|
||||
/// Signal emits whenever a jsonmessage should be forwarded
|
||||
/// Signal emits whenever a JSON-message should be forwarded
|
||||
///
|
||||
void forwardJsonMessage(QJsonObject);
|
||||
|
||||
@@ -247,7 +247,7 @@ private:
|
||||
///
|
||||
void handleLoggingCommand(const QJsonObject &message, const QString &command, const int tan);
|
||||
|
||||
/// Handle an incoming JSON Proccessing message
|
||||
/// Handle an incoming JSON Processing message
|
||||
///
|
||||
/// @param message the incoming message
|
||||
///
|
||||
@@ -271,6 +271,12 @@ private:
|
||||
///
|
||||
void handleInstanceCommand(const QJsonObject &message, const QString &command, const int tan);
|
||||
|
||||
/// Handle an incoming JSON Led Device message
|
||||
///
|
||||
/// @param message the incoming message
|
||||
///
|
||||
void handleLedDeviceCommand(const QJsonObject &message, const QString &command, const int tan);
|
||||
|
||||
///
|
||||
/// Handle an incoming JSON message of unknown type
|
||||
///
|
||||
|
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
#ifndef LEDEVICE_H
|
||||
#define LEDEVICE_H
|
||||
|
||||
// qt includes
|
||||
#include <QObject>
|
||||
@@ -28,204 +29,397 @@ typedef LedDevice* ( *LedDeviceCreateFuncType ) ( const QJsonObject& );
|
||||
typedef std::map<QString,LedDeviceCreateFuncType> LedDeviceRegistry;
|
||||
|
||||
///
|
||||
/// Interface (pure virtual base class) for LedDevices.
|
||||
/// @brief Interface (pure virtual base class) for LED-devices.
|
||||
///
|
||||
class LedDevice : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
LedDevice(const QJsonObject& config = QJsonObject(), QObject* parent = nullptr);
|
||||
|
||||
///
|
||||
/// @brief Constructs LED-device
|
||||
///
|
||||
/// @param deviceConfig Device's configuration as JSON-Object
|
||||
/// @param parent QT parent
|
||||
///
|
||||
LedDevice(const QJsonObject& deviceConfig = QJsonObject(), QObject* parent = nullptr);
|
||||
|
||||
///
|
||||
/// @brief Destructor of the LED-device
|
||||
///
|
||||
~LedDevice() override;
|
||||
|
||||
///
|
||||
/// @brief Get color order of device
|
||||
/// @brief Get color order of device.
|
||||
///
|
||||
/// @return The color order
|
||||
///
|
||||
const QString & getColorOrder() const { return _colorOrder; }
|
||||
|
||||
///
|
||||
/// @brief Set the current active ledDevice type
|
||||
/// @brief Set the current active LED-device type.
|
||||
///
|
||||
/// @param deviceType Device's type
|
||||
///
|
||||
void setActiveDeviceType(const QString& deviceType);
|
||||
|
||||
///
|
||||
/// @brief Get the current active ledDevice type
|
||||
/// @brief Get the current active LED-device type.
|
||||
///
|
||||
const QString & getActiveDeviceType() const { return _activeDeviceType; }
|
||||
|
||||
///
|
||||
/// @brief Set the number of LEDs supported by the device.
|
||||
///
|
||||
/// @param[in] ledCount Number of device LEDs
|
||||
///
|
||||
void setLedCount(unsigned int ledCount);
|
||||
|
||||
///
|
||||
/// @brief Get the number of LEDs supported by the device.
|
||||
///
|
||||
/// @return Number of device's LEDs
|
||||
///
|
||||
unsigned int getLedCount() const { return _ledCount; }
|
||||
|
||||
bool enabled() const { return _enabled; }
|
||||
///
|
||||
/// @brief Check, if the device is enabled.
|
||||
///
|
||||
/// @return True, if enabled
|
||||
///
|
||||
bool isEnabled() const { return _isEnabled; }
|
||||
|
||||
///
|
||||
/// @brief Set a device's latch time.
|
||||
///
|
||||
/// Latch time is the time-frame a device requires until the next update can be processed.
|
||||
/// During that time-frame any updates done via updateLeds are skipped.
|
||||
///
|
||||
/// @param[in] latchTime_ms Latch time in milliseconds
|
||||
///
|
||||
void setLatchTime(int latchTime_ms);
|
||||
|
||||
///
|
||||
/// @brief Get the currently defined LatchTime.
|
||||
///
|
||||
/// @return Latch time in milliseconds
|
||||
///
|
||||
int getLatchTime() const { return _latchTime_ms; }
|
||||
void setLatchTime( int latchTime_ms );
|
||||
|
||||
///
|
||||
/// Check, if device is ready to be used
|
||||
/// i.e. initialisation and configuration were successfull
|
||||
/// @brief Discover devices of this type available (for configuration).
|
||||
/// @note Mainly used for network devices. Allows to find devices, e.g. via ssdp, mDNS or cloud ways.
|
||||
///
|
||||
/// @return True if device is ready
|
||||
/// @return A JSON structure holding a list of devices found
|
||||
///
|
||||
bool isReady() const { return _deviceReady; }
|
||||
virtual QJsonObject discover();
|
||||
|
||||
///
|
||||
/// Check, if device is in error state
|
||||
/// @brief Discover first device of this type available (for configuration).
|
||||
/// @note Mainly used for network devices. Allows to find devices, e.g. via ssdp, mDNS or cloud ways.
|
||||
///
|
||||
/// @return True if device is in error
|
||||
/// @return A string of the device found
|
||||
///
|
||||
bool isInError() const { return _deviceInError; }
|
||||
virtual QString discoverFirst();
|
||||
|
||||
inline bool componentState() const { return enabled(); }
|
||||
|
||||
/// Prints the RGB-Color values to stdout.
|
||||
///
|
||||
/// @param[in] ledValues The RGB-color per led
|
||||
/// @brief Get the device's properties
|
||||
///
|
||||
static void printLedValues (const std::vector<ColorRgb>& ledValues );
|
||||
/// Used in context of a set of devices of the same type.
|
||||
///
|
||||
/// @param[in] params Parameters to address device
|
||||
/// @return A JSON structure holding the device's properties
|
||||
///
|
||||
virtual QJsonObject getProperties(const QJsonObject& params);
|
||||
|
||||
///
|
||||
/// @brief Send an update to the device to identify it.
|
||||
///
|
||||
/// Used in context of a set of devices of the same type.
|
||||
///
|
||||
/// @param[in] params Parameters to address device
|
||||
///
|
||||
virtual void identify(const QJsonObject& params) {}
|
||||
|
||||
///
|
||||
/// @brief Check, if device is properly initialised
|
||||
///
|
||||
/// i.e. initialisation and configuration were successful.
|
||||
///
|
||||
/// @return True, if device is initialised
|
||||
///
|
||||
bool isInitialised() const { return _isDeviceInitialised; }
|
||||
|
||||
///
|
||||
/// @brief Check, if device is ready to be used.
|
||||
///
|
||||
/// i.e. initialisation and opening were successful.
|
||||
///
|
||||
/// @return True, if device is ready
|
||||
///
|
||||
bool isReady() const { return _isDeviceReady; }
|
||||
|
||||
///
|
||||
/// @brief Check, if device is in error state.
|
||||
///
|
||||
/// @return True, if device is in error
|
||||
///
|
||||
bool isInError() const { return _isDeviceInError; }
|
||||
|
||||
///
|
||||
/// @brief Get the LED-Device component's state.
|
||||
///
|
||||
/// @return True, if enabled
|
||||
///
|
||||
inline bool componentState() const { return isEnabled(); }
|
||||
|
||||
///
|
||||
/// @brief Prints the color values to stdout.
|
||||
///
|
||||
/// @param[in] ledValues The color per led
|
||||
///
|
||||
static void printLedValues(const std::vector<ColorRgb>& ledValues);
|
||||
|
||||
public slots:
|
||||
///
|
||||
/// Is called on thread start, all construction tasks and init should run here
|
||||
///
|
||||
virtual void start() { _deviceReady = (open() == 0); }
|
||||
|
||||
///
|
||||
/// Update the RGB-Color values to the leds.
|
||||
/// Handles refreshing of leds.
|
||||
/// @brief Is called on thread start, all construction tasks and init should run here.
|
||||
///
|
||||
/// @param[in] ledValues The RGB-color per led
|
||||
virtual void start();
|
||||
|
||||
///
|
||||
/// @brief Stops the device.
|
||||
///
|
||||
/// Includes switching-off the device and stopping refreshes.
|
||||
///
|
||||
virtual void stop();
|
||||
|
||||
///
|
||||
/// @brief Update the color values of the device's LEDs.
|
||||
///
|
||||
/// Handles refreshing of LEDs.
|
||||
///
|
||||
/// @param[in] ledValues The color per LED
|
||||
/// @return Zero on success else negative (i.e. device is not ready)
|
||||
///
|
||||
virtual int updateLeds(const std::vector<ColorRgb>& ledValues);
|
||||
|
||||
///
|
||||
/// Closes the output device.
|
||||
/// Includes switching-off the device and stopping refreshes
|
||||
/// @brief Enables/disables the device for output.
|
||||
///
|
||||
virtual void close();
|
||||
|
||||
/// If the device is not ready, it will not be enabled.
|
||||
///
|
||||
/// Enables/disables the device for output.
|
||||
/// If the device is not ready, it will not be enabled
|
||||
/// @param[in] enable The new state of the device
|
||||
///
|
||||
/// @param enable The new state of the device
|
||||
///
|
||||
void setEnable(bool enable); ///
|
||||
void setEnable(bool enable);
|
||||
|
||||
signals:
|
||||
///
|
||||
/// Emits whenever the led device switches between on/off
|
||||
/// @param newState The new state of the device
|
||||
/// @brief Emits whenever the LED-Device switches between on/off.
|
||||
///
|
||||
/// @param[in] newState The new state of the device
|
||||
///
|
||||
void enableStateChanged(bool newState);
|
||||
|
||||
protected:
|
||||
|
||||
///
|
||||
/// Initialise a device's configuration
|
||||
/// @brief Initialise the device's configuration.
|
||||
///
|
||||
/// @param deviceConfig the json device config
|
||||
/// @return True if success
|
||||
/// @param[in] deviceConfig the JSON device configuration
|
||||
/// @return True, if success
|
||||
///
|
||||
virtual bool init(const QJsonObject &deviceConfig);
|
||||
|
||||
///
|
||||
/// Opens and initiatialises the output device
|
||||
/// @brief Opens the output device.
|
||||
///
|
||||
/// @return Zero on succes (i.e. device is ready and enabled) else negative
|
||||
/// @return Zero, on success (i.e. device is ready), else negative
|
||||
///
|
||||
virtual int open();
|
||||
|
||||
///
|
||||
/// Writes the RGB-Color values to the leds.
|
||||
/// @brief Closes the output device.
|
||||
///
|
||||
/// @param[in] ledValues The RGB-color per led
|
||||
/// @return Zero on success (i.e. device is closed), else negative
|
||||
///
|
||||
/// @return Zero on success else negative
|
||||
virtual int close();
|
||||
|
||||
///
|
||||
/// @brief Writes the RGB-Color values to the LEDs.
|
||||
///
|
||||
/// @param[in] ledValues The RGB-color per LED
|
||||
/// @return Zero on success, else negative
|
||||
///
|
||||
virtual int write(const std::vector<ColorRgb>& ledValues) = 0;
|
||||
|
||||
///
|
||||
/// Writes "BLACK" to the output stream
|
||||
/// @brief Writes "BLACK" to the output stream,
|
||||
/// even if the device is not in enabled state (allowing to have a defined state during device power-off).
|
||||
/// @note: latch-time is considered between each write
|
||||
///
|
||||
/// @param[in] numberOfWrites Write Black given number of times
|
||||
/// @return Zero on success else negative
|
||||
///
|
||||
virtual int writeBlack();
|
||||
virtual int writeBlack(int numberOfBlack=1);
|
||||
|
||||
// Helper to pipe device config from constructor to start()
|
||||
///
|
||||
/// @brief Switch the LEDs on.
|
||||
///
|
||||
/// Takes care that the device is opened and powered-on.
|
||||
/// Depending on the configuration, the device may store its current state for later restore.
|
||||
/// @see powerOn, storeState
|
||||
///
|
||||
/// @return True, if success
|
||||
///
|
||||
virtual bool switchOn();
|
||||
|
||||
///
|
||||
/// @brief Switch the LEDs off.
|
||||
///
|
||||
/// Takes care that the LEDs and device are switched-off and device is closed.
|
||||
/// Depending on the configuration, the device may be powered-off or restored to its previous state.
|
||||
/// @see powerOff, restoreState
|
||||
///
|
||||
/// @return True, if success
|
||||
///
|
||||
virtual bool switchOff();
|
||||
|
||||
///
|
||||
/// @brief Power-/turn on the LED-device.
|
||||
///
|
||||
/// Powers-/Turns on the LED hardware, if supported.
|
||||
///
|
||||
/// @return True, if success
|
||||
///
|
||||
virtual bool powerOn();
|
||||
|
||||
///
|
||||
/// @brief Power-/turn off the LED-device.
|
||||
///
|
||||
/// Depending on the device's capability, the device is powered-/turned off or
|
||||
/// an off state is simulated by writing "Black to LED" (default).
|
||||
///
|
||||
/// @return True, if success
|
||||
///
|
||||
virtual bool powerOff();
|
||||
|
||||
///
|
||||
/// @brief Store the device's original state.
|
||||
///
|
||||
/// Save the device's state before hyperion color streaming starts allowing to restore state during switchOff().
|
||||
///
|
||||
/// @return True, if success
|
||||
///
|
||||
virtual bool storeState();
|
||||
|
||||
///
|
||||
/// @brief Restore the device's original state.
|
||||
///
|
||||
/// Restore the device's state as before hyperion color streaming started.
|
||||
/// This includes the on/off state of the device.
|
||||
///
|
||||
/// @return True, if success
|
||||
///
|
||||
virtual bool restoreState();
|
||||
|
||||
///
|
||||
/// @brief Converts an uint8_t array to hex string.
|
||||
///
|
||||
/// @param data uint8_t array
|
||||
/// @param size of the array
|
||||
/// @param number Number of array items to be converted.
|
||||
/// @return array as string of hex values
|
||||
QString uint8_t_to_hex_string(const uint8_t * data, const qint64 size, qint64 number = -1) const;
|
||||
|
||||
/// Current device's type
|
||||
QString _activeDeviceType;
|
||||
|
||||
/// Helper to pipe device configuration from constructor to start()
|
||||
QJsonObject _devConfig;
|
||||
|
||||
/// The common Logger instance for all LedDevices
|
||||
/// The common Logger instance for all LED-devices
|
||||
Logger * _log;
|
||||
|
||||
/// The buffer containing the packed RGB values
|
||||
std::vector<uint8_t> _ledBuffer;
|
||||
|
||||
bool _deviceReady;
|
||||
bool _deviceInError;
|
||||
/// Timer object which makes sure that LED data is written at a minimum rate
|
||||
/// e.g. some devices will switch off when they do not receive data at least every 15 seconds
|
||||
QTimer* _refreshTimer;
|
||||
|
||||
QString _activeDeviceType;
|
||||
// Device configuration parameters
|
||||
|
||||
/// Number of hardware LEDs supported by device.
|
||||
unsigned int _ledCount;
|
||||
unsigned int _ledRGBCount;
|
||||
unsigned int _ledRGBWCount;
|
||||
|
||||
/// Timer object which makes sure that led data is written at a minimum rate
|
||||
/// e.g. Adalight device will switch off when it does not receive data at least every 15 seconds
|
||||
QTimer* _refresh_timer;
|
||||
int _refresh_timer_interval;
|
||||
/// Refresh interval in milliseconds
|
||||
int _refreshTimerInterval_ms;
|
||||
|
||||
/// Time a device requires mandatorily between two writes (in milliseconds)
|
||||
int _latchTime_ms;
|
||||
|
||||
/// Does the device allow restoring the original state?
|
||||
bool _isRestoreOrigState;
|
||||
|
||||
/// Device, lights state before streaming via hyperion
|
||||
QJsonObject _orignalStateValues;
|
||||
|
||||
// Device states
|
||||
/// Is the device enabled?
|
||||
bool _isEnabled;
|
||||
|
||||
/// Is the device initialised?
|
||||
bool _isDeviceInitialised;
|
||||
|
||||
/// Is the device ready for processing?
|
||||
bool _isDeviceReady;
|
||||
|
||||
/// Is the device in error state and stopped?
|
||||
bool _isDeviceInError;
|
||||
|
||||
/// Is the device in the switchOff process?
|
||||
bool _isInSwitchOff;
|
||||
|
||||
/// Timestamp of last write
|
||||
QDateTime _lastWriteTime;
|
||||
|
||||
/// Time a device requires mandatorily between two writes
|
||||
int _latchTime_ms;
|
||||
|
||||
protected slots:
|
||||
|
||||
/// Write the last data to the leds again
|
||||
///
|
||||
/// @brief Write the last data to the LEDs again.
|
||||
///
|
||||
/// @return Zero on success else negative
|
||||
///
|
||||
int rewriteLeds();
|
||||
int rewriteLEDs();
|
||||
|
||||
/// Switch the leds off
|
||||
/// Writes "Black to LED" or may switch-off the LED hardware, if supported
|
||||
///
|
||||
virtual int switchOff();
|
||||
|
||||
/// Switch the leds on
|
||||
/// May switch-on the LED hardware, if supported
|
||||
/// @brief Set device in error state
|
||||
///
|
||||
virtual int switchOn();
|
||||
|
||||
/// Set device in error state
|
||||
/// @param[in] errorMsg The error message to be logged
|
||||
///
|
||||
/// @param errorMsg The error message to be logged
|
||||
///
|
||||
virtual void setInError( const QString& errorMsg);
|
||||
virtual void setInError( const QString& errorMsg);
|
||||
|
||||
private:
|
||||
|
||||
/// Start new refresh cycle
|
||||
///
|
||||
/// @brief Start a new refresh cycle
|
||||
void startRefreshTimer();
|
||||
|
||||
/// Stop refresh cycle
|
||||
///
|
||||
/// @brief Stop refresh cycle
|
||||
void stopRefreshTimer();
|
||||
|
||||
/// Is last write refreshing enabled?
|
||||
bool _isRefreshEnabled;
|
||||
|
||||
bool _componentRegistered;
|
||||
bool _enabled;
|
||||
bool _refresh_enabled;
|
||||
/// Order of Colors supported by the device
|
||||
/// "RGB", "BGR", "RBG", "BRG", "GBR", "GRB"
|
||||
QString _colorOrder;
|
||||
|
||||
/// Last LED values written
|
||||
std::vector<ColorRgb> _last_ledValues;
|
||||
std::vector<ColorRgb> _lastLedValues;
|
||||
};
|
||||
|
||||
#endif // LEDEVICE_H
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#ifndef LEDEVICEFACTORY_H
|
||||
#define LEDEVICEFACTORY_H
|
||||
|
||||
#pragma once
|
||||
|
||||
// Leddevice includes
|
||||
// LedDevice includes
|
||||
#include <leddevice/LedDevice.h>
|
||||
|
||||
///
|
||||
@@ -17,7 +17,9 @@ public:
|
||||
/// @param deviceConfig The configuration of the led-device
|
||||
///
|
||||
/// @return The constructed LedDevice or nullptr if configuration is invalid. The ownership of
|
||||
/// the constructed LedDevice is tranferred to the caller
|
||||
/// the constructed LedDevice is transferred to the caller
|
||||
///
|
||||
static LedDevice * construct(const QJsonObject & deviceConfig);
|
||||
};
|
||||
|
||||
#endif // LEDEVICEFACTORY_H
|
||||
|
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
#ifndef LEDEVICEWRAPPER_H
|
||||
#define LEDEVICEWRAPPER_H
|
||||
|
||||
// util
|
||||
#include <utils/Logger.h>
|
||||
@@ -21,8 +22,8 @@ public:
|
||||
explicit LedDeviceWrapper(Hyperion* hyperion);
|
||||
~LedDeviceWrapper() override;
|
||||
///
|
||||
/// @brief Contructs a new LedDevice, moves to thread and starts
|
||||
/// @param config With the given config
|
||||
/// @brief Constructs a new LedDevice, moves to thread and starts
|
||||
/// @param config With the given configuration
|
||||
///
|
||||
void createLedDevice(const QJsonObject& config);
|
||||
|
||||
@@ -33,19 +34,19 @@ public:
|
||||
static const QJsonObject getLedDeviceSchemas();
|
||||
|
||||
///
|
||||
/// @brief add all device constrcutors to the map
|
||||
/// @brief add all device constructors to the map
|
||||
///
|
||||
static int addToDeviceMap(QString name, LedDeviceCreateFuncType funcPtr);
|
||||
|
||||
///
|
||||
/// @brief Return all available device contructors
|
||||
/// @return device constrcutors
|
||||
/// @brief Return all available device constructors
|
||||
/// @return device constructors
|
||||
///
|
||||
static const LedDeviceRegistry& getDeviceMap();
|
||||
|
||||
///
|
||||
/// @brief Get the current latchtime of the ledDevice
|
||||
/// @ return latchtime in ms
|
||||
/// @brief Get the current latch time of the ledDevice
|
||||
/// @ return latch time in ms
|
||||
///
|
||||
int getLatchTime();
|
||||
|
||||
@@ -57,7 +58,7 @@ public:
|
||||
///
|
||||
/// @brief Return the last enable state
|
||||
///
|
||||
const bool & enabled() { return _enabled; }
|
||||
bool enabled();
|
||||
|
||||
///
|
||||
/// @brief Get the current colorOrder from device
|
||||
@@ -65,14 +66,14 @@ public:
|
||||
const QString & getColorOrder();
|
||||
|
||||
///
|
||||
/// @brief Get the number of Leds from device
|
||||
/// @brief Get the number of LEDs from device
|
||||
///
|
||||
unsigned int getLedCount() const;
|
||||
|
||||
public slots:
|
||||
///
|
||||
/// @brief Handle new component state request
|
||||
/// @apram component The comp from enum
|
||||
/// @param component The comp from enum
|
||||
/// @param state The new state
|
||||
///
|
||||
void handleComponentState(const hyperion::Components component, const bool state);
|
||||
@@ -100,7 +101,7 @@ private slots:
|
||||
|
||||
|
||||
protected:
|
||||
/// contains all available led device constrcutors
|
||||
/// contains all available led device constructors
|
||||
static LedDeviceRegistry _ledDeviceMap;
|
||||
|
||||
private:
|
||||
@@ -117,3 +118,5 @@ private:
|
||||
// the enable state
|
||||
bool _enabled;
|
||||
};
|
||||
|
||||
#endif // LEDEVICEWRAPPER_H
|
||||
|
@@ -1,7 +1,12 @@
|
||||
#pragma once
|
||||
#ifndef SSDPDISCOVER_H
|
||||
#define SSDPDISCOVER_H
|
||||
|
||||
#include <utils/Logger.h>
|
||||
#include <QHostAddress>
|
||||
#include <QUrl>
|
||||
#include <QRegularExpression>
|
||||
|
||||
#include <chrono>
|
||||
|
||||
class QUdpSocket;
|
||||
|
||||
@@ -11,6 +16,23 @@ enum class searchType{
|
||||
STY_JSONSERVER
|
||||
};
|
||||
|
||||
struct SSDPService {
|
||||
QString cacheControl;
|
||||
QUrl location;
|
||||
QString server;
|
||||
QString searchTarget;
|
||||
QString uniqueServiceName;
|
||||
QMap <QString,QString> otherHeaders;
|
||||
};
|
||||
|
||||
// Default values
|
||||
static const char DEFAULT_SEARCH_ADDRESS[] = "239.255.255.250";
|
||||
static const int DEFAULT_SEARCH_PORT = 1900;
|
||||
static const char DEFAULT_FILTER[] = ".*";
|
||||
static const char DEFAULT_FILTER_HEADER[] = "ST";
|
||||
|
||||
constexpr std::chrono::milliseconds DEFAULT_SSDP_TIMEOUT{5000}; // timeout in ms
|
||||
|
||||
///
|
||||
/// @brief Search for SSDP sessions, used by stand-alone capture binaries
|
||||
///
|
||||
@@ -37,6 +59,120 @@ public:
|
||||
///
|
||||
const QString getFirstService(const searchType &type = searchType::STY_WEBSERVER,const QString &st = "urn:hyperion-project.org:device:basic:1", const int &timeout_ms = 3000);
|
||||
|
||||
///
|
||||
/// @brief Discover services via ssdp.
|
||||
///
|
||||
/// Records meeting the search target and filter criteria ( setSearchFilter() ) are stored in a map using the given element as a key.
|
||||
///
|
||||
/// The search result can be accessed via getServicesDiscoveredJson() or getServicesDiscovered()
|
||||
///
|
||||
/// Usage sample:
|
||||
/// @code
|
||||
///
|
||||
/// SSDPDiscover discover;
|
||||
///
|
||||
/// discover.skipDuplicateKeys(true);
|
||||
/// QString searchTargetFilter = "(.*)IpBridge(.*)";
|
||||
/// discover.setSearchFilter(searchTargetFilter, "SERVER");
|
||||
/// QString searchTarget = "upnp:rootdevice";
|
||||
///
|
||||
/// if ( discover.discoverServices(searchTarget) > 0 )
|
||||
/// deviceList = discover.getServicesDiscoveredJson();
|
||||
///
|
||||
///@endcode
|
||||
///
|
||||
/// @param[in] searchTarget The ssdp discovery search target (ST)
|
||||
/// @param[in] key Element used as key for the result map
|
||||
///
|
||||
/// @return Number of service records found (meeting the search & filter criteria)
|
||||
///
|
||||
int discoverServices(const QString &searchTarget="ssdp:all", const QString &key="LOCATION");
|
||||
|
||||
///
|
||||
/// @brief Get services discovered during discoverServices()
|
||||
///
|
||||
/// @return Map of discovered services
|
||||
///
|
||||
const QMap<QString, SSDPService> getServicesDiscovered () { return _services; }
|
||||
|
||||
///
|
||||
/// @brief Get services discovered during discoverServices().
|
||||
///
|
||||
/// Hostname and domain are resolved from IP-address and stored in extra elements
|
||||
///
|
||||
/// Sample result:
|
||||
/// @code
|
||||
///
|
||||
/// [{
|
||||
/// "cache-control": "max-age=100",
|
||||
/// "domain": "fritz.box",
|
||||
/// "hostname": "ubuntu1910",
|
||||
/// "id": "http://192.168.2.152:8081/description.xml",
|
||||
/// "ip": "192.168.2.152",
|
||||
/// "location": "http://192.168.2.152:8081/description.xml",
|
||||
/// "other": { "ext": "", "host": "239.255.255.250:1900", "hue-bridgeid": "000C29FFFED8D52D"},
|
||||
/// "port": 8081,
|
||||
/// "server": "Linux/3.14.0 UPnP/1.0 IpBridge/1.19.0",
|
||||
/// "st": "upnp:rootdevice",
|
||||
/// "usn": "uuid:2f402f80-da50-11e1-9b23-000c29d8d52d::upnp:rootdevice"
|
||||
/// }]
|
||||
///
|
||||
///@endcode
|
||||
///
|
||||
/// @return Discovered services as JSON-document
|
||||
///
|
||||
QJsonArray getServicesDiscoveredJson();
|
||||
|
||||
///
|
||||
/// @brief Set the ssdp discovery address (HOST)
|
||||
///
|
||||
/// @param[in] IP-address used during discovery
|
||||
///
|
||||
void setAddress ( const QString &address) { _ssdpAddr = QHostAddress(address); }
|
||||
|
||||
///
|
||||
/// @brief Set the ssdp discovery port (HOST)
|
||||
///
|
||||
/// @param[in] port used during discovery
|
||||
///
|
||||
void setPort ( quint16 port) { _ssdpPort = port; }
|
||||
|
||||
///
|
||||
/// @brief Set the ssdp discovery max wait time (MX)
|
||||
///
|
||||
/// @param[in] maxWaitResponseTime
|
||||
///
|
||||
void setMaxWaitResponseTime ( int maxWaitResponseTime) { _ssdpMaxWaitResponseTime = maxWaitResponseTime; }
|
||||
|
||||
///
|
||||
/// @brief Set the ssdp discovery search target (ST)
|
||||
///
|
||||
/// @param[in] searchTarget
|
||||
///
|
||||
void setSearchTarget ( const QString &searchTarget) { _searchTarget = searchTarget; }
|
||||
|
||||
///
|
||||
/// @brief Set the ssdp discovery search target filter
|
||||
///
|
||||
/// @param[in] filter as regular expression
|
||||
/// @param[in] filterHeader Header element the filter is applied to
|
||||
///
|
||||
/// @return True, if valid regular expression
|
||||
///
|
||||
bool setSearchFilter ( const QString &filter=DEFAULT_FILTER, const QString &filterHeader="ST");
|
||||
|
||||
///
|
||||
/// @brief Set the ssdp discovery search target and filter to default values
|
||||
///
|
||||
void clearSearchFilter () { _filter=DEFAULT_FILTER; _filterHeader="ST"; }
|
||||
|
||||
///
|
||||
/// @brief Skip duplicate records with the same key-value
|
||||
///
|
||||
/// @param[in] skip True: skip records with duplicate key-values, False: Allow duplicate key-values
|
||||
///
|
||||
void skipDuplicateKeys( bool skip ) { _skipDupKeys = skip; }
|
||||
|
||||
signals:
|
||||
///
|
||||
/// @brief Emits whenever a new service has been found, search started with searchForService()
|
||||
@@ -60,6 +196,21 @@ private:
|
||||
|
||||
Logger* _log;
|
||||
QUdpSocket* _udpSocket;
|
||||
QString _searchTarget;
|
||||
QHostAddress _ssdpAddr;
|
||||
quint16 _ssdpPort;
|
||||
|
||||
int _ssdpMaxWaitResponseTime;
|
||||
int _ssdpTimeout;
|
||||
|
||||
QMap<QString, SSDPService> _services;
|
||||
|
||||
QStringList _usnList;
|
||||
QString _searchTarget;
|
||||
|
||||
QString _filter;
|
||||
QString _filterHeader;
|
||||
QRegularExpression _regExFilter;
|
||||
bool _skipDupKeys;
|
||||
};
|
||||
|
||||
#endif // SSDPDISCOVER_H
|
||||
|
42
include/utils/QStringUtils.h
Normal file
42
include/utils/QStringUtils.h
Normal file
@@ -0,0 +1,42 @@
|
||||
#ifndef QSTRINGUTILS_H
|
||||
#define QSTRINGUTILS_H
|
||||
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
|
||||
namespace QStringUtils {
|
||||
|
||||
enum class SplitBehavior {
|
||||
KeepEmptyParts,
|
||||
SkipEmptyParts,
|
||||
};
|
||||
|
||||
inline QStringList split (const QString &string, const QString &sep, SplitBehavior behavior = SplitBehavior::KeepEmptyParts, Qt::CaseSensitivity cs = Qt::CaseSensitive)
|
||||
{
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
|
||||
return behavior == SplitBehavior::SkipEmptyParts ? string.split(sep, Qt::SkipEmptyParts , cs) : string.split(sep, Qt::KeepEmptyParts , cs);
|
||||
#else
|
||||
return behavior == SplitBehavior::SkipEmptyParts ? string.split(sep, QString::SkipEmptyParts , cs) : string.split(sep, QString::KeepEmptyParts , cs);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline QStringList split (const QString &string, QChar sep, SplitBehavior behavior = SplitBehavior::KeepEmptyParts, Qt::CaseSensitivity cs = Qt::CaseSensitive)
|
||||
{
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
|
||||
return behavior == SplitBehavior::SkipEmptyParts ? string.split(sep, Qt::SkipEmptyParts , cs) : string.split(sep, Qt::KeepEmptyParts , cs);
|
||||
#else
|
||||
return behavior == SplitBehavior::SkipEmptyParts ? string.split(sep, QString::SkipEmptyParts , cs) : string.split(sep, QString::KeepEmptyParts , cs);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline QStringList split (const QString &string, const QRegExp &rx, SplitBehavior behavior = SplitBehavior::KeepEmptyParts)
|
||||
{
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
|
||||
return behavior == SplitBehavior::SkipEmptyParts ? string.split(rx, Qt::SkipEmptyParts) : string.split(rx, Qt::KeepEmptyParts);
|
||||
#else
|
||||
return behavior == SplitBehavior::SkipEmptyParts ? string.split(rx, QString::SkipEmptyParts) : string.split(rx, QString::KeepEmptyParts);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#endif // QSTRINGUTILS_H
|
Reference in New Issue
Block a user