mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
add ability for default values in providerudp (#251)
* add ability for default values in providerudp * udp: move switchOff into baseclass * udp: more code cleanups
This commit is contained in:
parent
f88cd3a230
commit
b8f1ad50b9
@ -47,3 +47,15 @@ MyClass::MyClass()
|
||||
{
|
||||
}
|
||||
```
|
||||
|
||||
- pointer declaration
|
||||
|
||||
```
|
||||
bad:
|
||||
int *foo;
|
||||
int * fooFoo;
|
||||
|
||||
good:
|
||||
int* foo;
|
||||
```
|
||||
|
||||
|
@ -16,16 +16,14 @@
|
||||
#include "LedDeviceTpm2net.h"
|
||||
|
||||
LedDeviceTpm2net::LedDeviceTpm2net(const Json::Value &deviceConfig)
|
||||
: ProviderUdp(deviceConfig)
|
||||
|
||||
: ProviderUdp()
|
||||
{
|
||||
setConfig(deviceConfig);
|
||||
}
|
||||
|
||||
bool LedDeviceTpm2net::setConfig(const Json::Value &deviceConfig)
|
||||
{
|
||||
ProviderUdp::setConfig(deviceConfig);
|
||||
_LatchTime_ns = deviceConfig.get("latchtime",104000).asInt();
|
||||
ProviderUdp::setConfig(deviceConfig,50200,104000);
|
||||
_tpm2_max = deviceConfig.get("max-packet",170).asInt();
|
||||
return true;
|
||||
}
|
||||
@ -80,8 +78,3 @@ int LedDeviceTpm2net::write(const std::vector<ColorRgb> &ledValues)
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
int LedDeviceTpm2net::switchOff()
|
||||
{
|
||||
return write(std::vector<ColorRgb>(_ledCount, ColorRgb{0,0,0}));
|
||||
}
|
||||
|
@ -31,7 +31,6 @@ public:
|
||||
/// constructs leddevice
|
||||
static LedDevice* construct(const Json::Value &deviceConfig);
|
||||
|
||||
|
||||
///
|
||||
/// Writes the led color values to the led-device
|
||||
///
|
||||
@ -40,12 +39,9 @@ public:
|
||||
///
|
||||
virtual int write(const std::vector<ColorRgb> &ledValues);
|
||||
|
||||
/// Switch the leds off
|
||||
virtual int switchOff();
|
||||
|
||||
private:
|
||||
int _tpm2_max;
|
||||
int _tpm2ByteCount;
|
||||
int _tpm2TotalPackets;
|
||||
int _tpm2ThisPacket;
|
||||
int _tpm2ByteCount;
|
||||
int _tpm2TotalPackets;
|
||||
int _tpm2ThisPacket;
|
||||
};
|
||||
|
@ -16,16 +16,14 @@
|
||||
#include "LedDeviceUdpE131.h"
|
||||
|
||||
LedDeviceUdpE131::LedDeviceUdpE131(const Json::Value &deviceConfig)
|
||||
: ProviderUdp(deviceConfig)
|
||||
|
||||
: ProviderUdp()
|
||||
{
|
||||
setConfig(deviceConfig);
|
||||
}
|
||||
|
||||
bool LedDeviceUdpE131::setConfig(const Json::Value &deviceConfig)
|
||||
{
|
||||
ProviderUdp::setConfig(deviceConfig);
|
||||
_LatchTime_ns = deviceConfig.get("latchtime",104000).asInt();
|
||||
ProviderUdp::setConfig(deviceConfig, 104000, 5568);
|
||||
_e131_universe = deviceConfig.get("universe",1).asInt();
|
||||
_e131_source_name = deviceConfig.get("source-name","hyperion on "+QHostInfo::localHostName().toStdString()).asString();
|
||||
QString _json_cid = QString::fromStdString(deviceConfig.get("cid","").asString());
|
||||
@ -129,7 +127,3 @@ int LedDeviceUdpE131::write(const std::vector<ColorRgb> &ledValues)
|
||||
return retVal;
|
||||
}
|
||||
|
||||
int LedDeviceUdpE131::switchOff()
|
||||
{
|
||||
return write(std::vector<ColorRgb>(_ledCount, ColorRgb{0,0,0}));
|
||||
}
|
||||
|
@ -127,16 +127,13 @@ public:
|
||||
///
|
||||
virtual int write(const std::vector<ColorRgb> &ledValues);
|
||||
|
||||
/// Switch the leds off
|
||||
virtual int switchOff();
|
||||
|
||||
private:
|
||||
void prepare(const unsigned this_universe, const unsigned this_dmxChannelCount);
|
||||
|
||||
e131_packet_t e131_packet;
|
||||
uint8_t _e131_seq = 0;
|
||||
uint8_t _e131_universe = 1;
|
||||
uint8_t _acn_id[12] = {0x41, 0x53, 0x43, 0x2d, 0x45, 0x31, 0x2e, 0x31, 0x37, 0x00, 0x00, 0x00 };
|
||||
uint8_t _e131_seq = 0;
|
||||
uint8_t _e131_universe = 1;
|
||||
uint8_t _acn_id[12] = {0x41, 0x53, 0x43, 0x2d, 0x45, 0x31, 0x2e, 0x31, 0x37, 0x00, 0x00, 0x00 };
|
||||
std::string _e131_source_name;
|
||||
QUuid _e131_cid;
|
||||
};
|
||||
|
@ -12,17 +12,9 @@
|
||||
#include "LedDeviceUdpRaw.h"
|
||||
|
||||
LedDeviceUdpRaw::LedDeviceUdpRaw(const Json::Value &deviceConfig)
|
||||
: ProviderUdp(deviceConfig)
|
||||
: ProviderUdp()
|
||||
{
|
||||
setConfig(deviceConfig);
|
||||
}
|
||||
|
||||
bool LedDeviceUdpRaw::setConfig(const Json::Value &deviceConfig)
|
||||
{
|
||||
ProviderUdp::setConfig(deviceConfig);
|
||||
_LatchTime_ns = deviceConfig.get("latchtime",500000).asInt();
|
||||
|
||||
return true;
|
||||
ProviderUdp::setConfig(deviceConfig, 500000, 5568);
|
||||
}
|
||||
|
||||
LedDevice* LedDeviceUdpRaw::construct(const Json::Value &deviceConfig)
|
||||
@ -39,8 +31,3 @@ int LedDeviceUdpRaw::write(const std::vector<ColorRgb> &ledValues)
|
||||
|
||||
return writeBytes(dataLen, dataPtr);
|
||||
}
|
||||
|
||||
int LedDeviceUdpRaw::switchOff()
|
||||
{
|
||||
return write(std::vector<ColorRgb>(_ledCount, ColorRgb{0,0,0}));
|
||||
}
|
||||
|
@ -19,13 +19,6 @@ public:
|
||||
///
|
||||
LedDeviceUdpRaw(const Json::Value &deviceConfig);
|
||||
|
||||
///
|
||||
/// Sets configuration
|
||||
///
|
||||
/// @param deviceConfig the json device config
|
||||
/// @return true if success
|
||||
bool setConfig(const Json::Value &deviceConfig);
|
||||
|
||||
/// constructs leddevice
|
||||
static LedDevice* construct(const Json::Value &deviceConfig);
|
||||
|
||||
@ -36,7 +29,4 @@ public:
|
||||
/// @return Zero on succes else negative
|
||||
///
|
||||
virtual int write(const std::vector<ColorRgb> &ledValues);
|
||||
|
||||
/// Switch the leds off
|
||||
virtual int switchOff();
|
||||
};
|
||||
|
@ -15,11 +15,11 @@
|
||||
// Local Hyperion includes
|
||||
#include "ProviderUdp.h"
|
||||
|
||||
ProviderUdp::ProviderUdp(const Json::Value &deviceConfig)
|
||||
ProviderUdp::ProviderUdp()
|
||||
: LedDevice()
|
||||
, _LatchTime_ns(-1)
|
||||
, _port(0)
|
||||
{
|
||||
setConfig(deviceConfig);
|
||||
_udpSocket = new QUdpSocket();
|
||||
}
|
||||
|
||||
@ -28,16 +28,18 @@ ProviderUdp::~ProviderUdp()
|
||||
_udpSocket->close();
|
||||
}
|
||||
|
||||
bool ProviderUdp::setConfig(const Json::Value &deviceConfig)
|
||||
bool ProviderUdp::setConfig(const Json::Value &deviceConfig, int defaultLatchTime, int defaultPort, std::string defaultHost)
|
||||
{
|
||||
if (_address.setAddress( QString::fromStdString(deviceConfig["host"].asString()) ) )
|
||||
QString host = QString::fromStdString(deviceConfig.get("host",defaultHost).asString());
|
||||
|
||||
if (_address.setAddress(host) )
|
||||
{
|
||||
Debug( _log, "Successfully parsed %s as an ip address.", deviceConfig["host"].asString().c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug( _log, "Failed to parse %s as an ip address.", deviceConfig["host"].asString().c_str());
|
||||
QHostInfo info = QHostInfo::fromName( QString::fromStdString(deviceConfig["host"].asString()) );
|
||||
QHostInfo info = QHostInfo::fromName(host);
|
||||
if (info.addresses().isEmpty())
|
||||
{
|
||||
Debug( _log, "Failed to parse %s as a hostname.", deviceConfig["host"].asString().c_str());
|
||||
@ -46,9 +48,17 @@ bool ProviderUdp::setConfig(const Json::Value &deviceConfig)
|
||||
Debug( _log, "Successfully parsed %s as a hostname.", deviceConfig["host"].asString().c_str());
|
||||
_address = info.addresses().first();
|
||||
}
|
||||
_port = deviceConfig["port"].asUInt();
|
||||
|
||||
_port = deviceConfig.get("port", defaultPort).asUInt();
|
||||
if ( _port<=0 || _port > 65535)
|
||||
{
|
||||
throw std::runtime_error("invalid target port");
|
||||
}
|
||||
|
||||
Debug( _log, "UDP using %s:%d", _address.toString().toStdString().c_str() , _port );
|
||||
|
||||
_LatchTime_ns = deviceConfig.get("latchtime", defaultLatchTime).asInt();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -84,3 +94,9 @@ int ProviderUdp::writeBytes(const unsigned size, const uint8_t * data)
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
int ProviderUdp::switchOff()
|
||||
{
|
||||
return write(std::vector<ColorRgb>(_ledCount, ColorRgb{0,0,0}));
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,7 @@ public:
|
||||
///
|
||||
/// @param deviceConfig json device config
|
||||
///
|
||||
ProviderUdp(const Json::Value &deviceConfig);
|
||||
ProviderUdp();
|
||||
|
||||
///
|
||||
/// Destructor of the LedDevice; closes the output device if it is open
|
||||
@ -29,7 +29,7 @@ public:
|
||||
///
|
||||
/// @param deviceConfig the json device config
|
||||
/// @return true if success
|
||||
bool setConfig(const Json::Value &deviceConfig);
|
||||
bool setConfig(const Json::Value &deviceConfig, int defaultLatchTime=-1, int defaultPort=0, std::string defaultHost="127.0.0.1");
|
||||
|
||||
///
|
||||
/// Opens and configures the output device
|
||||
@ -38,6 +38,9 @@ public:
|
||||
///
|
||||
int open();
|
||||
|
||||
/// Switch the leds off
|
||||
virtual int switchOff();
|
||||
|
||||
protected:
|
||||
///
|
||||
/// Writes the given bytes/bits to the SPI-device and sleeps the latch time to ensure that the
|
||||
|
@ -11,6 +11,8 @@
|
||||
"type": "integer",
|
||||
"title":"Port",
|
||||
"default": 5568,
|
||||
"minimum" : 0,
|
||||
"maximum" : 65535,
|
||||
"propertyOrder" : 2
|
||||
},
|
||||
"universe": {
|
||||
|
@ -4,21 +4,29 @@
|
||||
"properties":{
|
||||
"host" : {
|
||||
"type": "string",
|
||||
"title":"Target IP",
|
||||
"title":"Target IP/hostname",
|
||||
"propertyOrder" : 1
|
||||
},
|
||||
"port": {
|
||||
"type": "integer",
|
||||
"title":"Target Port",
|
||||
"minimum" : 0,
|
||||
"maximum" : 65535,
|
||||
"default" : 50200,
|
||||
"propertyOrder" : 2
|
||||
},
|
||||
"latchtime": {
|
||||
"type": "integer",
|
||||
"title":"Latchtime",
|
||||
"default": 104000,
|
||||
"propertyOrder" : 2
|
||||
"propertyOrder" : 3
|
||||
},
|
||||
"max-packet": {
|
||||
"type": "integer",
|
||||
"title":"Max-packet",
|
||||
"minimum" : 0,
|
||||
"default" : 170,
|
||||
"propertyOrder" : 3
|
||||
"propertyOrder" : 4
|
||||
}
|
||||
},
|
||||
"additionalProperties": true
|
||||
|
@ -11,6 +11,8 @@
|
||||
"type": "integer",
|
||||
"title":"Port",
|
||||
"default": 5568,
|
||||
"minimum" : 0,
|
||||
"maximum" : 65535,
|
||||
"propertyOrder" : 2
|
||||
}
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user