2016-05-26 23:44:27 +02:00
|
|
|
// Local-Hyperion includes
|
|
|
|
#include "LedDeviceAtmoOrb.h"
|
2020-07-12 20:27:56 +02:00
|
|
|
#include <utils/QStringUtils.h>
|
2016-05-26 23:44:27 +02:00
|
|
|
|
|
|
|
// qt includes
|
2020-06-28 23:05:32 +02:00
|
|
|
#include <QUdpSocket>
|
2020-09-14 17:20:00 +02:00
|
|
|
#include <QNetworkInterface>
|
|
|
|
#include <QUrl>
|
|
|
|
#include <QHostInfo>
|
2020-06-28 23:05:32 +02:00
|
|
|
|
2020-09-14 17:20:00 +02:00
|
|
|
#include <chrono>
|
|
|
|
|
|
|
|
// Constants
|
|
|
|
namespace {
|
|
|
|
|
2021-03-19 22:52:04 +01:00
|
|
|
const bool verbose = false;
|
|
|
|
const bool verbose3 = false;
|
2020-09-14 17:20:00 +02:00
|
|
|
const QString MULTICAST_GROUP_DEFAULT_ADDRESS = "239.255.255.250";
|
|
|
|
const quint16 MULTICAST_GROUP_DEFAULT_PORT = 49692;
|
|
|
|
|
|
|
|
constexpr std::chrono::milliseconds DEFAULT_DISCOVERY_TIMEOUT{2000};
|
|
|
|
|
|
|
|
} //End of constants
|
2016-05-26 23:44:27 +02:00
|
|
|
|
2020-02-10 15:21:58 +01:00
|
|
|
LedDeviceAtmoOrb::LedDeviceAtmoOrb(const QJsonObject &deviceConfig)
|
2020-08-08 00:21:19 +02:00
|
|
|
: LedDevice(deviceConfig)
|
2020-02-10 15:21:58 +01:00
|
|
|
, _udpSocket (nullptr)
|
2020-09-14 17:20:00 +02:00
|
|
|
, _multicastGroup(MULTICAST_GROUP_DEFAULT_ADDRESS)
|
|
|
|
, _multiCastGroupPort (MULTICAST_GROUP_DEFAULT_PORT)
|
2020-06-28 23:05:32 +02:00
|
|
|
, _joinedMulticastgroup (false)
|
2020-02-10 15:21:58 +01:00
|
|
|
, _useOrbSmoothing (false)
|
|
|
|
, _skipSmoothingDiff (0)
|
2017-03-04 22:17:42 +01:00
|
|
|
{
|
2016-05-26 23:44:27 +02:00
|
|
|
}
|
|
|
|
|
2020-02-10 15:21:58 +01:00
|
|
|
LedDevice* LedDeviceAtmoOrb::construct(const QJsonObject &deviceConfig)
|
|
|
|
{
|
|
|
|
return new LedDeviceAtmoOrb(deviceConfig);
|
|
|
|
}
|
|
|
|
|
|
|
|
LedDeviceAtmoOrb::~LedDeviceAtmoOrb()
|
|
|
|
{
|
2020-08-08 00:21:19 +02:00
|
|
|
delete _udpSocket;
|
2020-02-10 15:21:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool LedDeviceAtmoOrb::init(const QJsonObject &deviceConfig)
|
|
|
|
{
|
2020-06-28 23:05:32 +02:00
|
|
|
bool isInitOK = false;
|
2020-02-10 15:21:58 +01:00
|
|
|
|
2020-06-28 23:05:32 +02:00
|
|
|
if ( LedDevice::init(deviceConfig) )
|
2020-02-10 15:21:58 +01:00
|
|
|
{
|
|
|
|
|
Media Foundation/V4L2 grabber ... (#1119)
* - New Media Foundation grabber
- JsonAPI available grabber fix
- commented json config removed
* Added libjpeg-turbo to dependencies
* Fix OSX build
Removed Azure Pipelines from build scripts
* Remove Platform from Dashboard
* Correct Grabber Namings
* Grabber UI improvements, generic JSONEditor Selection Update
* Active grabber fix
* Stop Framebuffer grabber on failure
* - Image format NV12 and I420 added
- Flip mode
- Scaling factor for MJPEG
- VSCode (compile before run)
- CI (push) dependency libjpeg-turbo added
* Refactor MediaFoundation (Part 1)
* Remove QDebug output
* Added image flipping ability to MF Grabber
* fix issue 1160
* -Reload MF Grabber only once per WebUI update
- Cleanup
* Improvements
* - Set 'Software Frame Decimation' begin to 0
- Removed grabber specific device name from Log
- Keep pixel format when switching resolution
- Display 'Flip mode' correct in Log
- BGR24 images always flipped
* Refactor MediaFoundation (Part 2)
* Refactor V4L2 grabber (part 1) (#62)
* Media Foundation grabber adapted to V4L2 change
* Enable Media Foundation grabber on windows
* Have fps as int, fix height typo
* Added video standards to JsonAPI output
* Error handling in source reader improved
* Fix "Frame to small" error
* Discovery VideoSources and Dynamically Update Editor
* Hide all element when no video grabber discovered, upate naming
* Do not show unsupported grabbers
* Copy Log to Clipboard
* Update Grabber schema and Defaults
* Update access levels and validate crop ranges
* Height and width in Qt grabber corrected
* Correct formatting
* Untabify
* Global component states across instances
* Components divided on the dashboard
* refactor
* Fix Merge-issues
* Database migration aligning with updated grabber model
* Align Grabber.js with new utility functions
* Allow editor-validation for enum-lists
* Handle "Show Explainations scenario" correctly
* Grabber - Ensure save is only possible on valid content
* Dashboard update + fix GlobalSignal connection
* Ensure default database is populated with current release
* Correct grabber4L2 access level
* Display Signal detection area in preview
* Write Hyperion version into default config on compiling.
* Create defaultconfig.json dynamically
* WebUI changes
* Correct grabber config look-ups
* Refactor i18n language loading
* Fix en.json
* Split global capture from instance capture config
* Update grabber default values
* Standalone grabber: Add --debug switch
* Enhance showInputOptionsForKey for multiple keys
* Add grabber instance link to system grabber config
* Only show signal detection area, if grabber is enabled
* Always show Active element on grabber page
* Remote control - Only display gabber status, if global grabber is enabled
* WebUI optimization (thx to @mkcologne)
Start Grabber only when global settings are enabled
Fixed an issue in the WebUI preview
* V4L2/MF changes
* Jsoneditor, Correct translation for default values
* Refactor LED-Device handling in UI and make element naming consistent
* MF Discovery extended
* Fix LGTM finding
* Support Grabber Bri, Hue, Sat and Con in UI, plus their defaults
* Concider Access level for item filtering
* Concider Access level for item filtering
* Revert "Concider Access level for item filtering"
This reverts commit 5b0ce3c0f2de67e0c43788190cfff45614706129.
* Disable fpsSoftwareDecimation for framegrabber, as not supported yet
* JSON-Editor- Add updated schema for validation on dynamic elements
* added V4L2 color IDs
* LGTM findings fix
* destroy SR callback only on exit
* Grabber.js - Hide elements not supported by platform
* Fixed freezing start effect
* Grabber UI - Hardware controls - Show current values and allow to reset to defaults
* Grabber - Discovery - Add current values to properties
* Small things
* Clean-up Effects and have ENDLESS consistently defined
* Fix on/off/on priority during startup, by initializing _prevVisComp in line with background priority
* Add missing translation mappings
* DirectX Grabber reactivated/ QT Grabber size decimation fixed
* typo in push-master workflow
* Use PreciseTimer for Grabber to ensure stable FPS timing
* Set default Screencapture rate consistently
* Fix libjpeg-turbo download
* Remove Zero character from file
* docker-compile Add PLATFORM parameter, only copy output file after successful compile
* Framebuffer, Dispmanx, OSX, AML Grabber discovery, various clean-up and consistencies across grabbers
* Fix merge problem - on docker-compile Add PLATFORM parameter, only copy output file after successful compile
* Fix definition
* OSXFRameGrabber - Revert cast
* Clean-ups nach Feedback
* Disable certain libraries when building armlogic via standard stretch image as developer
* Add CEC availability to ServerInfo to have it platform independent
* Grabber UI - Fix problem that crop values are not populated when refining editor rage
* Preserve value when updating json-editor range
* LEDVisualisation - Clear image when source changes
* Fix - Preserve value when updating json-editor range
* LEDVisualisation - Clear image when no component is active
* Allow to have password handled by Password-Manager (#1263)
* Update default signal detection area to green assuming rainbow grabber
* LED Visualisation - Handle empty priority update
* Fix yuv420 in v4l2 grabber
* V4L2-Grabber discovery - Only report grabbers with valid video input information
* Grabber - Update static variables to have them working in release build
* LED Visualisation - ClearImage when no priorities
* LED Visualisation - Fix Logo resizing issue
* LED Visualisation - Have nearly black background and negative logo
Co-authored-by: LordGrey <lordgrey.emmel@gmail.com>
Co-authored-by: LordGrey <48840279+Lord-Grey@users.noreply.github.com>
2021-07-14 20:48:33 +02:00
|
|
|
_multicastGroup = deviceConfig["host"].toString(MULTICAST_GROUP_DEFAULT_ADDRESS);
|
2020-09-14 17:20:00 +02:00
|
|
|
_multiCastGroupPort = static_cast<quint16>(deviceConfig["port"].toInt(MULTICAST_GROUP_DEFAULT_PORT));
|
2020-02-10 15:21:58 +01:00
|
|
|
_useOrbSmoothing = deviceConfig["useOrbSmoothing"].toBool(false);
|
|
|
|
_skipSmoothingDiff = deviceConfig["skipSmoothingDiff"].toInt(0);
|
2020-07-12 20:27:56 +02:00
|
|
|
QStringList orbIds = QStringUtils::split(deviceConfig["orbIds"].toString().simplified().remove(" "),",", QStringUtils::SplitBehavior::SkipEmptyParts);
|
2020-09-14 17:20:00 +02:00
|
|
|
|
|
|
|
Debug(_log, "DeviceType : %s", QSTRING_CSTR( this->getActiveDeviceType() ));
|
2020-11-14 17:58:56 +01:00
|
|
|
Debug(_log, "LedCount : %d", this->getLedCount());
|
2020-09-14 17:20:00 +02:00
|
|
|
Debug(_log, "ColorOrder : %s", QSTRING_CSTR( this->getColorOrder() ));
|
|
|
|
Debug(_log, "RefreshTime : %d", _refreshTimerInterval_ms);
|
|
|
|
Debug(_log, "LatchTime : %d", this->getLatchTime());
|
|
|
|
|
|
|
|
Debug(_log, "MulticastGroup : %s", QSTRING_CSTR(_multicastGroup));
|
|
|
|
Debug(_log, "MulticastGroupPort: %d", _multiCastGroupPort);
|
|
|
|
Debug(_log, "Orb ID list : %s", QSTRING_CSTR(deviceConfig["orbIds"].toString()));
|
|
|
|
Debug(_log, "Use Orb Smoothing : %d", _useOrbSmoothing);
|
|
|
|
Debug(_log, "Skip SmoothingDiff: %d", _skipSmoothingDiff);
|
|
|
|
|
2020-02-10 15:21:58 +01:00
|
|
|
_orbIds.clear();
|
|
|
|
|
2020-07-12 20:27:56 +02:00
|
|
|
for (auto & id_str : orbIds)
|
2020-02-10 15:21:58 +01:00
|
|
|
{
|
|
|
|
bool ok;
|
|
|
|
int id = id_str.toInt(&ok);
|
|
|
|
if (ok)
|
2020-06-28 23:05:32 +02:00
|
|
|
{
|
|
|
|
if ( id < 1 || id > 255 )
|
2020-07-12 20:27:56 +02:00
|
|
|
{
|
2020-06-28 23:05:32 +02:00
|
|
|
Warning(_log, "Skip orb id '%d'. IDs must be in range 1-255", id);
|
2020-07-12 20:27:56 +02:00
|
|
|
}
|
2020-06-28 23:05:32 +02:00
|
|
|
else
|
2020-07-12 20:27:56 +02:00
|
|
|
{
|
2020-06-28 23:05:32 +02:00
|
|
|
_orbIds.append(id);
|
2020-07-12 20:27:56 +02:00
|
|
|
}
|
2020-06-28 23:05:32 +02:00
|
|
|
}
|
2020-02-10 15:21:58 +01:00
|
|
|
else
|
2020-07-12 20:27:56 +02:00
|
|
|
{
|
2020-02-10 15:21:58 +01:00
|
|
|
Error(_log, "orb id '%s' is not a number", QSTRING_CSTR(id_str));
|
2020-07-12 20:27:56 +02:00
|
|
|
}
|
2020-02-10 15:21:58 +01:00
|
|
|
}
|
|
|
|
|
2020-11-14 17:58:56 +01:00
|
|
|
int numberOrbs = _orbIds.size();
|
|
|
|
int configuredLedCount = this->getLedCount();
|
2020-09-14 17:20:00 +02:00
|
|
|
|
2020-07-12 20:27:56 +02:00
|
|
|
if ( _orbIds.empty() )
|
2020-02-10 15:21:58 +01:00
|
|
|
{
|
|
|
|
this->setInError("No valid OrbIds found!");
|
|
|
|
isInitOK = false;
|
|
|
|
}
|
2020-06-28 23:05:32 +02:00
|
|
|
else
|
|
|
|
{
|
2020-09-14 17:20:00 +02:00
|
|
|
if ( numberOrbs < configuredLedCount )
|
|
|
|
{
|
|
|
|
QString errorReason = QString("Not enough Orbs [%1] for configured LEDs [%2] found!")
|
|
|
|
.arg(numberOrbs)
|
|
|
|
.arg(configuredLedCount);
|
|
|
|
this->setInError(errorReason);
|
|
|
|
isInitOK = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( numberOrbs > configuredLedCount )
|
|
|
|
{
|
2020-11-14 17:58:56 +01:00
|
|
|
Info(_log, "%s: More Orbs [%d] than configured LEDs [%d].", QSTRING_CSTR(this->getActiveDeviceType()), numberOrbs, configuredLedCount );
|
2020-09-14 17:20:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
isInitOK = true;
|
|
|
|
}
|
2020-06-28 23:05:32 +02:00
|
|
|
}
|
2020-02-10 15:21:58 +01:00
|
|
|
}
|
|
|
|
return isInitOK;
|
|
|
|
}
|
|
|
|
|
|
|
|
int LedDeviceAtmoOrb::open()
|
2016-08-23 20:07:12 +02:00
|
|
|
{
|
2020-02-10 15:21:58 +01:00
|
|
|
int retval = -1;
|
2020-07-12 20:27:56 +02:00
|
|
|
_isDeviceReady = false;
|
2020-02-10 15:21:58 +01:00
|
|
|
|
2020-09-14 17:20:00 +02:00
|
|
|
if ( _udpSocket == nullptr )
|
|
|
|
{
|
|
|
|
_udpSocket = new QUdpSocket();
|
|
|
|
}
|
|
|
|
|
2020-07-12 20:27:56 +02:00
|
|
|
// Try to bind the UDP-Socket
|
|
|
|
if ( _udpSocket != nullptr )
|
2016-08-23 20:07:12 +02:00
|
|
|
{
|
2020-09-14 17:20:00 +02:00
|
|
|
if ( _udpSocket->state() != QAbstractSocket::BoundState )
|
2020-07-12 20:27:56 +02:00
|
|
|
{
|
2020-09-14 17:20:00 +02:00
|
|
|
if ( !_udpSocket->bind(QHostAddress(QHostAddress::AnyIPv4), 0 ) )
|
2020-06-28 23:05:32 +02:00
|
|
|
{
|
2020-09-14 17:20:00 +02:00
|
|
|
QString errortext = QString ("Socket bind failed: (%1) %2, MulticastGroup: (%3)").arg(_udpSocket->error()).arg(_udpSocket->errorString(), _multicastGroup);
|
2020-06-28 23:05:32 +02:00
|
|
|
this->setInError( errortext );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-09-14 17:20:00 +02:00
|
|
|
_groupAddress = QHostAddress(_multicastGroup);
|
|
|
|
_joinedMulticastgroup = _udpSocket->joinMulticastGroup(_groupAddress);
|
|
|
|
if ( !_joinedMulticastgroup )
|
|
|
|
{
|
|
|
|
QString errortext = QString ("Joining Multicastgroup failed: (%1) %2, MulticastGroup: (%3)").arg(_udpSocket->error()).arg(_udpSocket->errorString(), _multicastGroup);
|
|
|
|
this->setInError( errortext );
|
|
|
|
}
|
2020-06-28 23:05:32 +02:00
|
|
|
}
|
2020-02-10 15:21:58 +01:00
|
|
|
}
|
2020-09-14 17:20:00 +02:00
|
|
|
|
|
|
|
if ( ! _isDeviceInError )
|
|
|
|
{
|
|
|
|
// Everything is OK, device is ready
|
|
|
|
_isDeviceReady = true;
|
|
|
|
retval = 0;
|
|
|
|
}
|
2020-06-28 23:05:32 +02:00
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2020-07-12 20:27:56 +02:00
|
|
|
int LedDeviceAtmoOrb::close()
|
2020-06-28 23:05:32 +02:00
|
|
|
{
|
2020-07-12 20:27:56 +02:00
|
|
|
int retval = 0;
|
|
|
|
_isDeviceReady = false;
|
2020-06-28 23:05:32 +02:00
|
|
|
|
|
|
|
if ( _udpSocket != nullptr )
|
|
|
|
{
|
2020-09-14 17:20:00 +02:00
|
|
|
if ( _udpSocket->state() == QAbstractSocket::BoundState )
|
|
|
|
{
|
|
|
|
_udpSocket->leaveMulticastGroup(_groupAddress);
|
|
|
|
}
|
|
|
|
|
2020-06-28 23:05:32 +02:00
|
|
|
// Test, if device requires closing
|
|
|
|
if ( _udpSocket->isOpen() )
|
2020-02-10 15:21:58 +01:00
|
|
|
{
|
2020-06-28 23:05:32 +02:00
|
|
|
Debug(_log,"Close UDP-device: %s", QSTRING_CSTR( this->getActiveDeviceType() ) );
|
|
|
|
_udpSocket->close();
|
|
|
|
// Everything is OK -> device is closed
|
2020-02-10 15:21:58 +01:00
|
|
|
}
|
2016-08-23 20:07:12 +02:00
|
|
|
}
|
2020-07-12 20:27:56 +02:00
|
|
|
return retval;
|
2016-08-23 20:07:12 +02:00
|
|
|
}
|
|
|
|
|
2016-08-14 10:46:44 +02:00
|
|
|
int LedDeviceAtmoOrb::write(const std::vector <ColorRgb> &ledValues)
|
|
|
|
{
|
2016-05-26 23:44:27 +02:00
|
|
|
// If not in multicast group return
|
2020-06-28 23:05:32 +02:00
|
|
|
if (!_joinedMulticastgroup)
|
2016-08-14 10:46:44 +02:00
|
|
|
{
|
2016-05-26 23:44:27 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Command options:
|
|
|
|
//
|
|
|
|
// 1 = force off
|
|
|
|
// 2 = use lamp smoothing and validate by Orb ID
|
|
|
|
// 4 = validate by Orb ID
|
|
|
|
|
2016-08-14 10:46:44 +02:00
|
|
|
// When setting _useOrbSmoothing = true it's recommended to disable Hyperion's own smoothing as it will conflict (double smoothing)
|
2016-05-26 23:44:27 +02:00
|
|
|
int commandType = 4;
|
2016-08-14 10:46:44 +02:00
|
|
|
if(_useOrbSmoothing)
|
2016-05-26 23:44:27 +02:00
|
|
|
{
|
|
|
|
commandType = 2;
|
|
|
|
}
|
|
|
|
|
2020-09-14 17:20:00 +02:00
|
|
|
ColorRgb color;
|
|
|
|
for (int idx = 0; idx < _orbIds.size(); idx++ )
|
2016-08-14 10:46:44 +02:00
|
|
|
{
|
2020-09-14 17:20:00 +02:00
|
|
|
if ( idx < static_cast<int>(ledValues.size()) )
|
|
|
|
{
|
|
|
|
color = ledValues[idx];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
color = ColorRgb::BLACK;
|
|
|
|
}
|
2016-05-26 23:44:27 +02:00
|
|
|
// Retrieve last send colors
|
|
|
|
int lastRed = lastColorRedMap[idx];
|
|
|
|
int lastGreen = lastColorGreenMap[idx];
|
|
|
|
int lastBlue = lastColorBlueMap[idx];
|
|
|
|
|
2016-08-14 10:46:44 +02:00
|
|
|
// If color difference is higher than _skipSmoothingDiff than we skip Orb smoothing (if enabled) and send it right away
|
|
|
|
if ((_skipSmoothingDiff != 0 && _useOrbSmoothing) && (abs(color.red - lastRed) >= _skipSmoothingDiff || abs(color.blue - lastBlue) >= _skipSmoothingDiff ||
|
|
|
|
abs(color.green - lastGreen) >= _skipSmoothingDiff))
|
2016-05-26 23:44:27 +02:00
|
|
|
{
|
|
|
|
// Skip Orb smoothing when using (command type 4)
|
2020-09-14 17:20:00 +02:00
|
|
|
commandType = 4;
|
2016-05-26 23:44:27 +02:00
|
|
|
}
|
|
|
|
|
2020-09-14 17:20:00 +02:00
|
|
|
// Send color
|
|
|
|
setColor(_orbIds[idx], color, commandType);
|
|
|
|
|
2016-05-26 23:44:27 +02:00
|
|
|
// Store last colors send for light id
|
2016-08-14 10:46:44 +02:00
|
|
|
lastColorRedMap[idx] = color.red;
|
2016-05-26 23:44:27 +02:00
|
|
|
lastColorGreenMap[idx] = color.green;
|
2016-08-14 10:46:44 +02:00
|
|
|
lastColorBlueMap[idx] = color.blue;
|
2016-05-26 23:44:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-02-10 15:21:58 +01:00
|
|
|
void LedDeviceAtmoOrb::setColor(int orbId, const ColorRgb &color, int commandType)
|
2016-08-14 10:46:44 +02:00
|
|
|
{
|
2016-05-26 23:44:27 +02:00
|
|
|
QByteArray bytes;
|
2020-07-12 20:27:56 +02:00
|
|
|
|
|
|
|
// 5 bytes command-header + 3 bytes color information
|
|
|
|
bytes.resize(5 + 3);
|
2016-05-26 23:44:27 +02:00
|
|
|
bytes.fill('\0');
|
|
|
|
|
|
|
|
// Command identifier: C0FFEE
|
2020-06-28 23:05:32 +02:00
|
|
|
bytes[0] = static_cast<char>(0xC0);
|
|
|
|
bytes[1] = static_cast<char>(0xFF);
|
|
|
|
bytes[2] = static_cast<char>(0xEE);
|
2016-05-26 23:44:27 +02:00
|
|
|
|
|
|
|
// Command type
|
2020-06-28 23:05:32 +02:00
|
|
|
bytes[3] = static_cast<char>(commandType);
|
2016-05-26 23:44:27 +02:00
|
|
|
|
|
|
|
// Orb ID
|
2020-06-28 23:05:32 +02:00
|
|
|
bytes[4] = static_cast<char>(orbId);
|
2016-05-26 23:44:27 +02:00
|
|
|
|
|
|
|
// RED / GREEN / BLUE
|
2020-06-28 23:05:32 +02:00
|
|
|
bytes[5] = static_cast<char>(color.red);
|
|
|
|
bytes[6] = static_cast<char>(color.green);
|
|
|
|
bytes[7] = static_cast<char>(color.blue);
|
|
|
|
|
2016-05-26 23:44:27 +02:00
|
|
|
sendCommand(bytes);
|
|
|
|
}
|
|
|
|
|
2016-08-14 10:46:44 +02:00
|
|
|
void LedDeviceAtmoOrb::sendCommand(const QByteArray &bytes)
|
|
|
|
{
|
2021-03-19 22:52:04 +01:00
|
|
|
DebugIf(verbose3, _log, "command: [%s] -> %s:%u", QSTRING_CSTR( QString(bytes.toHex())), QSTRING_CSTR(_groupAddress.toString()), _multiCastGroupPort );
|
2020-08-08 00:21:19 +02:00
|
|
|
_udpSocket->writeDatagram(bytes.data(), bytes.size(), _groupAddress, _multiCastGroupPort);
|
2016-05-26 23:44:27 +02:00
|
|
|
}
|
2020-09-14 17:20:00 +02:00
|
|
|
|
2020-11-14 17:58:56 +01:00
|
|
|
QJsonObject LedDeviceAtmoOrb::discover(const QJsonObject& params)
|
2020-09-14 17:20:00 +02:00
|
|
|
{
|
2021-03-19 22:52:04 +01:00
|
|
|
DebugIf(verbose, _log, "params: [%s]", QString(QJsonDocument(params).toJson(QJsonDocument::Compact)).toUtf8().constData());
|
2020-11-14 17:58:56 +01:00
|
|
|
|
2020-09-14 17:20:00 +02:00
|
|
|
QJsonObject devicesDiscovered;
|
|
|
|
devicesDiscovered.insert("ledDeviceType", _activeDeviceType );
|
|
|
|
|
|
|
|
QJsonArray deviceList;
|
|
|
|
|
2020-11-14 17:58:56 +01:00
|
|
|
_multicastGroup = params["multiCastGroup"].toString(MULTICAST_GROUP_DEFAULT_ADDRESS);
|
|
|
|
_multiCastGroupPort = static_cast<quint16>(params["multiCastPort"].toInt(MULTICAST_GROUP_DEFAULT_PORT));
|
|
|
|
|
2020-09-14 17:20:00 +02:00
|
|
|
if ( open() == 0 )
|
|
|
|
{
|
2020-11-14 17:58:56 +01:00
|
|
|
Debug ( _log, "Send discovery requests to all AtmoOrbs listening to %s:%d", QSTRING_CSTR(_multicastGroup),_multiCastGroupPort );
|
2020-09-14 17:20:00 +02:00
|
|
|
setColor(0, ColorRgb::BLACK, 8);
|
|
|
|
|
|
|
|
if ( _udpSocket->waitForReadyRead(DEFAULT_DISCOVERY_TIMEOUT.count()) )
|
|
|
|
{
|
|
|
|
while (_udpSocket->waitForReadyRead(500))
|
|
|
|
{
|
|
|
|
QByteArray datagram;
|
|
|
|
|
|
|
|
while (_udpSocket->hasPendingDatagrams())
|
|
|
|
{
|
|
|
|
datagram.resize(_udpSocket->pendingDatagramSize());
|
|
|
|
QHostAddress senderIP;
|
|
|
|
quint16 senderPort;
|
|
|
|
|
|
|
|
_udpSocket->readDatagram(datagram.data(), datagram.size(), &senderIP, &senderPort);
|
|
|
|
|
|
|
|
if ( datagram.size() == 1 )
|
|
|
|
{
|
|
|
|
unsigned char orbId = datagram[0];
|
|
|
|
if ( orbId > 0 )
|
|
|
|
{
|
|
|
|
Debug(_log, "Orb ID (%d) discovered at [%s]", orbId, QSTRING_CSTR(senderIP.toString()));
|
|
|
|
_services.insert(orbId, senderIP);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
|
|
|
|
QMap<int, QHostAddress>::iterator i;
|
|
|
|
for (i = _services.begin(); i != _services.end(); ++i)
|
|
|
|
{
|
|
|
|
QJsonObject obj;
|
|
|
|
|
|
|
|
obj.insert("id", i.key());
|
|
|
|
obj.insert("ip", i.value().toString());
|
|
|
|
|
|
|
|
QHostInfo hostInfo = QHostInfo::fromName(i.value().toString());
|
|
|
|
if (hostInfo.error() == QHostInfo::NoError )
|
|
|
|
{
|
|
|
|
QString hostname = hostInfo.hostName();
|
|
|
|
//Seems that for Windows no local domain name is resolved
|
|
|
|
if (!hostInfo.localDomainName().isEmpty() )
|
|
|
|
{
|
|
|
|
obj.insert("hostname", hostname.remove("."+hostInfo.localDomainName()));
|
|
|
|
obj.insert("domain", hostInfo.localDomainName());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int domainPos = hostname.indexOf('.');
|
|
|
|
obj.insert("hostname", hostname.left(domainPos));
|
|
|
|
obj.insert("domain", hostname.mid(domainPos+1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
deviceList << obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
devicesDiscovered.insert("devices", deviceList);
|
2021-03-19 22:52:04 +01:00
|
|
|
DebugIf(verbose, _log, "devicesDiscovered: [%s]", QString(QJsonDocument(devicesDiscovered).toJson(QJsonDocument::Compact)).toUtf8().constData() );
|
2020-09-14 17:20:00 +02:00
|
|
|
|
|
|
|
return devicesDiscovered;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LedDeviceAtmoOrb::identify(const QJsonObject& params)
|
|
|
|
{
|
2021-03-19 22:52:04 +01:00
|
|
|
DebugIf(verbose, _log, "params: [%s]", QString(QJsonDocument(params).toJson(QJsonDocument::Compact)).toUtf8().constData());
|
2020-09-14 17:20:00 +02:00
|
|
|
|
|
|
|
int orbId = 0;
|
|
|
|
if ( params["id"].isString() )
|
|
|
|
{
|
|
|
|
orbId = params["id"].toString().toInt();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
orbId = params["id"].toInt();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( orbId >0 && orbId < 256 )
|
|
|
|
{
|
|
|
|
Debug (_log, "Orb ID [%d]", orbId);
|
|
|
|
if ( open() == 0 )
|
|
|
|
{
|
|
|
|
setColor(orbId, ColorRgb::BLACK, 9);
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Warning(_log, "Identification of Orb with ID='%d' skipped. ID must be in range 1-255", orbId);
|
|
|
|
}
|
|
|
|
}
|