Merge remote-tracking branch 'redPanther/leddevice' into h801

This commit is contained in:
Rick van Hattem 2016-09-21 23:32:19 +02:00
commit 37130f9c9b
7 changed files with 31 additions and 10 deletions

View File

@ -24,7 +24,7 @@ LedDeviceTpm2net::LedDeviceTpm2net(const Json::Value &deviceConfig)
bool LedDeviceTpm2net::setConfig(const Json::Value &deviceConfig) bool LedDeviceTpm2net::setConfig(const Json::Value &deviceConfig)
{ {
ProviderUdp::setConfig(deviceConfig); ProviderUdp::setConfig(deviceConfig,50200);
_LatchTime_ns = deviceConfig.get("latchtime",104000).asInt(); _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;

View File

@ -19,7 +19,7 @@ LedDeviceUdpRaw::LedDeviceUdpRaw(const Json::Value &deviceConfig)
bool LedDeviceUdpRaw::setConfig(const Json::Value &deviceConfig) bool LedDeviceUdpRaw::setConfig(const Json::Value &deviceConfig)
{ {
ProviderUdp::setConfig(deviceConfig); ProviderUdp::setConfig(deviceConfig,5568);
_LatchTime_ns = deviceConfig.get("latchtime",500000).asInt(); _LatchTime_ns = deviceConfig.get("latchtime",500000).asInt();
return true; return true;

View File

@ -18,6 +18,7 @@
ProviderUdp::ProviderUdp(const Json::Value &deviceConfig) ProviderUdp::ProviderUdp(const Json::Value &deviceConfig)
: LedDevice() : LedDevice()
, _LatchTime_ns(-1) , _LatchTime_ns(-1)
, _port(0)
{ {
setConfig(deviceConfig); setConfig(deviceConfig);
_udpSocket = new QUdpSocket(); _udpSocket = new QUdpSocket();
@ -28,16 +29,18 @@ ProviderUdp::~ProviderUdp()
_udpSocket->close(); _udpSocket->close();
} }
bool ProviderUdp::setConfig(const Json::Value &deviceConfig) bool ProviderUdp::setConfig(const Json::Value &deviceConfig, 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,7 +49,13 @@ 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 );
return true; return true;

View File

@ -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 defaultPort=0, std::string defaultHost="127.0.0.1");
/// ///
/// Opens and configures the output device /// Opens and configures the output device

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
} }
}, },