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
This commit is contained in:
parent
f88cd3a230
commit
a86b3a2335
@ -24,7 +24,7 @@ LedDeviceTpm2net::LedDeviceTpm2net(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();
|
||||
_tpm2_max = deviceConfig.get("max-packet",170).asInt();
|
||||
return true;
|
||||
|
@ -19,7 +19,7 @@ LedDeviceUdpRaw::LedDeviceUdpRaw(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();
|
||||
|
||||
return true;
|
||||
|
@ -18,6 +18,7 @@
|
||||
ProviderUdp::ProviderUdp(const Json::Value &deviceConfig)
|
||||
: LedDevice()
|
||||
, _LatchTime_ns(-1)
|
||||
, _port(0)
|
||||
{
|
||||
setConfig(deviceConfig);
|
||||
_udpSocket = new QUdpSocket();
|
||||
@ -28,16 +29,18 @@ ProviderUdp::~ProviderUdp()
|
||||
_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());
|
||||
}
|
||||
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,7 +49,13 @@ 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 );
|
||||
|
||||
return true;
|
||||
|
@ -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 defaultPort=0, std::string defaultHost="127.0.0.1");
|
||||
|
||||
///
|
||||
/// Opens and configures the output device
|
||||
|
@ -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