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:
redPanther 2016-09-22 09:19:31 +02:00 committed by GitHub
parent f88cd3a230
commit b8f1ad50b9
12 changed files with 66 additions and 66 deletions

View File

@ -47,3 +47,15 @@ MyClass::MyClass()
{ {
} }
``` ```
- pointer declaration
```
bad:
int *foo;
int * fooFoo;
good:
int* foo;
```

View File

@ -16,16 +16,14 @@
#include "LedDeviceTpm2net.h" #include "LedDeviceTpm2net.h"
LedDeviceTpm2net::LedDeviceTpm2net(const Json::Value &deviceConfig) LedDeviceTpm2net::LedDeviceTpm2net(const Json::Value &deviceConfig)
: ProviderUdp(deviceConfig) : ProviderUdp()
{ {
setConfig(deviceConfig); setConfig(deviceConfig);
} }
bool LedDeviceTpm2net::setConfig(const Json::Value &deviceConfig) bool LedDeviceTpm2net::setConfig(const Json::Value &deviceConfig)
{ {
ProviderUdp::setConfig(deviceConfig); ProviderUdp::setConfig(deviceConfig,50200,104000);
_LatchTime_ns = deviceConfig.get("latchtime",104000).asInt();
_tpm2_max = deviceConfig.get("max-packet",170).asInt(); _tpm2_max = deviceConfig.get("max-packet",170).asInt();
return true; return true;
} }
@ -80,8 +78,3 @@ int LedDeviceTpm2net::write(const std::vector<ColorRgb> &ledValues)
return retVal; return retVal;
} }
int LedDeviceTpm2net::switchOff()
{
return write(std::vector<ColorRgb>(_ledCount, ColorRgb{0,0,0}));
}

View File

@ -31,7 +31,6 @@ public:
/// constructs leddevice /// constructs leddevice
static LedDevice* construct(const Json::Value &deviceConfig); static LedDevice* construct(const Json::Value &deviceConfig);
/// ///
/// Writes the led color values to the led-device /// Writes the led color values to the led-device
/// ///
@ -40,9 +39,6 @@ public:
/// ///
virtual int write(const std::vector<ColorRgb> &ledValues); virtual int write(const std::vector<ColorRgb> &ledValues);
/// Switch the leds off
virtual int switchOff();
private: private:
int _tpm2_max; int _tpm2_max;
int _tpm2ByteCount; int _tpm2ByteCount;

View File

@ -16,16 +16,14 @@
#include "LedDeviceUdpE131.h" #include "LedDeviceUdpE131.h"
LedDeviceUdpE131::LedDeviceUdpE131(const Json::Value &deviceConfig) LedDeviceUdpE131::LedDeviceUdpE131(const Json::Value &deviceConfig)
: ProviderUdp(deviceConfig) : ProviderUdp()
{ {
setConfig(deviceConfig); setConfig(deviceConfig);
} }
bool LedDeviceUdpE131::setConfig(const Json::Value &deviceConfig) bool LedDeviceUdpE131::setConfig(const Json::Value &deviceConfig)
{ {
ProviderUdp::setConfig(deviceConfig); ProviderUdp::setConfig(deviceConfig, 104000, 5568);
_LatchTime_ns = deviceConfig.get("latchtime",104000).asInt();
_e131_universe = deviceConfig.get("universe",1).asInt(); _e131_universe = deviceConfig.get("universe",1).asInt();
_e131_source_name = deviceConfig.get("source-name","hyperion on "+QHostInfo::localHostName().toStdString()).asString(); _e131_source_name = deviceConfig.get("source-name","hyperion on "+QHostInfo::localHostName().toStdString()).asString();
QString _json_cid = QString::fromStdString(deviceConfig.get("cid","").asString()); QString _json_cid = QString::fromStdString(deviceConfig.get("cid","").asString());
@ -129,7 +127,3 @@ int LedDeviceUdpE131::write(const std::vector<ColorRgb> &ledValues)
return retVal; return retVal;
} }
int LedDeviceUdpE131::switchOff()
{
return write(std::vector<ColorRgb>(_ledCount, ColorRgb{0,0,0}));
}

View File

@ -127,9 +127,6 @@ public:
/// ///
virtual int write(const std::vector<ColorRgb> &ledValues); virtual int write(const std::vector<ColorRgb> &ledValues);
/// Switch the leds off
virtual int switchOff();
private: private:
void prepare(const unsigned this_universe, const unsigned this_dmxChannelCount); void prepare(const unsigned this_universe, const unsigned this_dmxChannelCount);

View File

@ -12,17 +12,9 @@
#include "LedDeviceUdpRaw.h" #include "LedDeviceUdpRaw.h"
LedDeviceUdpRaw::LedDeviceUdpRaw(const Json::Value &deviceConfig) LedDeviceUdpRaw::LedDeviceUdpRaw(const Json::Value &deviceConfig)
: ProviderUdp(deviceConfig) : ProviderUdp()
{ {
setConfig(deviceConfig); ProviderUdp::setConfig(deviceConfig, 500000, 5568);
}
bool LedDeviceUdpRaw::setConfig(const Json::Value &deviceConfig)
{
ProviderUdp::setConfig(deviceConfig);
_LatchTime_ns = deviceConfig.get("latchtime",500000).asInt();
return true;
} }
LedDevice* LedDeviceUdpRaw::construct(const Json::Value &deviceConfig) LedDevice* LedDeviceUdpRaw::construct(const Json::Value &deviceConfig)
@ -39,8 +31,3 @@ int LedDeviceUdpRaw::write(const std::vector<ColorRgb> &ledValues)
return writeBytes(dataLen, dataPtr); return writeBytes(dataLen, dataPtr);
} }
int LedDeviceUdpRaw::switchOff()
{
return write(std::vector<ColorRgb>(_ledCount, ColorRgb{0,0,0}));
}

View File

@ -19,13 +19,6 @@ public:
/// ///
LedDeviceUdpRaw(const Json::Value &deviceConfig); 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 /// constructs leddevice
static LedDevice* construct(const Json::Value &deviceConfig); static LedDevice* construct(const Json::Value &deviceConfig);
@ -36,7 +29,4 @@ public:
/// @return Zero on succes else negative /// @return Zero on succes else negative
/// ///
virtual int write(const std::vector<ColorRgb> &ledValues); virtual int write(const std::vector<ColorRgb> &ledValues);
/// Switch the leds off
virtual int switchOff();
}; };

View File

@ -15,11 +15,11 @@
// Local Hyperion includes // Local Hyperion includes
#include "ProviderUdp.h" #include "ProviderUdp.h"
ProviderUdp::ProviderUdp(const Json::Value &deviceConfig) ProviderUdp::ProviderUdp()
: LedDevice() : LedDevice()
, _LatchTime_ns(-1) , _LatchTime_ns(-1)
, _port(0)
{ {
setConfig(deviceConfig);
_udpSocket = new QUdpSocket(); _udpSocket = new QUdpSocket();
} }
@ -28,16 +28,18 @@ ProviderUdp::~ProviderUdp()
_udpSocket->close(); _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()); Debug( _log, "Successfully parsed %s as an ip address.", deviceConfig["host"].asString().c_str());
} }
else else
{ {
Debug( _log, "Failed to parse %s as an ip address.", deviceConfig["host"].asString().c_str()); 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()) if (info.addresses().isEmpty())
{ {
Debug( _log, "Failed to parse %s as a hostname.", deviceConfig["host"].asString().c_str()); 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()); Debug( _log, "Successfully parsed %s as a hostname.", deviceConfig["host"].asString().c_str());
_address = info.addresses().first(); _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 ); Debug( _log, "UDP using %s:%d", _address.toString().toStdString().c_str() , _port );
_LatchTime_ns = deviceConfig.get("latchtime", defaultLatchTime).asInt();
return true; return true;
} }
@ -84,3 +94,9 @@ int ProviderUdp::writeBytes(const unsigned size, const uint8_t * data)
return retVal; return retVal;
} }
int ProviderUdp::switchOff()
{
return write(std::vector<ColorRgb>(_ledCount, ColorRgb{0,0,0}));
}

View File

@ -17,7 +17,7 @@ public:
/// ///
/// @param deviceConfig json device config /// @param deviceConfig json device config
/// ///
ProviderUdp(const Json::Value &deviceConfig); ProviderUdp();
/// ///
/// Destructor of the LedDevice; closes the output device if it is open /// Destructor of the LedDevice; closes the output device if it is open
@ -29,7 +29,7 @@ public:
/// ///
/// @param deviceConfig the json device config /// @param deviceConfig the json device config
/// @return true if success /// @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 /// Opens and configures the output device
@ -38,6 +38,9 @@ public:
/// ///
int open(); int open();
/// Switch the leds off
virtual int switchOff();
protected: protected:
/// ///
/// Writes the given bytes/bits to the SPI-device and sleeps the latch time to ensure that the /// Writes the given bytes/bits to the SPI-device and sleeps the latch time to ensure that the

View File

@ -11,6 +11,8 @@
"type": "integer", "type": "integer",
"title":"Port", "title":"Port",
"default": 5568, "default": 5568,
"minimum" : 0,
"maximum" : 65535,
"propertyOrder" : 2 "propertyOrder" : 2
}, },
"universe": { "universe": {

View File

@ -4,21 +4,29 @@
"properties":{ "properties":{
"host" : { "host" : {
"type": "string", "type": "string",
"title":"Target IP", "title":"Target IP/hostname",
"propertyOrder" : 1 "propertyOrder" : 1
}, },
"port": {
"type": "integer",
"title":"Target Port",
"minimum" : 0,
"maximum" : 65535,
"default" : 50200,
"propertyOrder" : 2
},
"latchtime": { "latchtime": {
"type": "integer", "type": "integer",
"title":"Latchtime", "title":"Latchtime",
"default": 104000, "default": 104000,
"propertyOrder" : 2 "propertyOrder" : 3
}, },
"max-packet": { "max-packet": {
"type": "integer", "type": "integer",
"title":"Max-packet", "title":"Max-packet",
"minimum" : 0, "minimum" : 0,
"default" : 170, "default" : 170,
"propertyOrder" : 3 "propertyOrder" : 4
} }
}, },
"additionalProperties": true "additionalProperties": true

View File

@ -11,6 +11,8 @@
"type": "integer", "type": "integer",
"title":"Port", "title":"Port",
"default": 5568, "default": 5568,
"minimum" : 0,
"maximum" : 65535,
"propertyOrder" : 2 "propertyOrder" : 2
} }
}, },