diff --git a/CODING_STYLE.md b/CODING_STYLE.md index 1a5d5f07..5b711f6e 100644 --- a/CODING_STYLE.md +++ b/CODING_STYLE.md @@ -47,3 +47,15 @@ MyClass::MyClass() { } ``` + +- pointer declaration + +``` +bad: +int *foo; +int * fooFoo; + +good: +int* foo; +``` + diff --git a/libsrc/leddevice/LedDeviceTpm2net.cpp b/libsrc/leddevice/LedDeviceTpm2net.cpp index 29c7a47b..9f38be58 100644 --- a/libsrc/leddevice/LedDeviceTpm2net.cpp +++ b/libsrc/leddevice/LedDeviceTpm2net.cpp @@ -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 &ledValues) return retVal; } - -int LedDeviceTpm2net::switchOff() -{ - return write(std::vector(_ledCount, ColorRgb{0,0,0})); -} diff --git a/libsrc/leddevice/LedDeviceTpm2net.h b/libsrc/leddevice/LedDeviceTpm2net.h index 2a6e7a76..f3ced7ca 100644 --- a/libsrc/leddevice/LedDeviceTpm2net.h +++ b/libsrc/leddevice/LedDeviceTpm2net.h @@ -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 &ledValues); - /// Switch the leds off - virtual int switchOff(); - private: int _tpm2_max; - int _tpm2ByteCount; - int _tpm2TotalPackets; - int _tpm2ThisPacket; + int _tpm2ByteCount; + int _tpm2TotalPackets; + int _tpm2ThisPacket; }; diff --git a/libsrc/leddevice/LedDeviceUdpE131.cpp b/libsrc/leddevice/LedDeviceUdpE131.cpp index 1e93b732..ac6e7588 100644 --- a/libsrc/leddevice/LedDeviceUdpE131.cpp +++ b/libsrc/leddevice/LedDeviceUdpE131.cpp @@ -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 &ledValues) return retVal; } -int LedDeviceUdpE131::switchOff() -{ - return write(std::vector(_ledCount, ColorRgb{0,0,0})); -} diff --git a/libsrc/leddevice/LedDeviceUdpE131.h b/libsrc/leddevice/LedDeviceUdpE131.h index 5fc62bff..fb26aa8a 100644 --- a/libsrc/leddevice/LedDeviceUdpE131.h +++ b/libsrc/leddevice/LedDeviceUdpE131.h @@ -127,16 +127,13 @@ public: /// virtual int write(const std::vector &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; }; diff --git a/libsrc/leddevice/LedDeviceUdpRaw.cpp b/libsrc/leddevice/LedDeviceUdpRaw.cpp index 81cf892f..82c60a36 100644 --- a/libsrc/leddevice/LedDeviceUdpRaw.cpp +++ b/libsrc/leddevice/LedDeviceUdpRaw.cpp @@ -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 &ledValues) return writeBytes(dataLen, dataPtr); } - -int LedDeviceUdpRaw::switchOff() -{ - return write(std::vector(_ledCount, ColorRgb{0,0,0})); -} diff --git a/libsrc/leddevice/LedDeviceUdpRaw.h b/libsrc/leddevice/LedDeviceUdpRaw.h index 980c414c..ff75b29c 100644 --- a/libsrc/leddevice/LedDeviceUdpRaw.h +++ b/libsrc/leddevice/LedDeviceUdpRaw.h @@ -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 &ledValues); - - /// Switch the leds off - virtual int switchOff(); }; diff --git a/libsrc/leddevice/ProviderUdp.cpp b/libsrc/leddevice/ProviderUdp.cpp index 03ac61f0..caadf2e2 100644 --- a/libsrc/leddevice/ProviderUdp.cpp +++ b/libsrc/leddevice/ProviderUdp.cpp @@ -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(_ledCount, ColorRgb{0,0,0})); +} + diff --git a/libsrc/leddevice/ProviderUdp.h b/libsrc/leddevice/ProviderUdp.h index b5f9ec37..0ef35734 100644 --- a/libsrc/leddevice/ProviderUdp.h +++ b/libsrc/leddevice/ProviderUdp.h @@ -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 diff --git a/libsrc/leddevice/schemas/schema-e131.json b/libsrc/leddevice/schemas/schema-e131.json index ef14834e..85e97e4c 100644 --- a/libsrc/leddevice/schemas/schema-e131.json +++ b/libsrc/leddevice/schemas/schema-e131.json @@ -11,6 +11,8 @@ "type": "integer", "title":"Port", "default": 5568, + "minimum" : 0, + "maximum" : 65535, "propertyOrder" : 2 }, "universe": { diff --git a/libsrc/leddevice/schemas/schema-tpm2net.json b/libsrc/leddevice/schemas/schema-tpm2net.json index f9a01219..535beef3 100644 --- a/libsrc/leddevice/schemas/schema-tpm2net.json +++ b/libsrc/leddevice/schemas/schema-tpm2net.json @@ -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 diff --git a/libsrc/leddevice/schemas/schema-udpraw.json b/libsrc/leddevice/schemas/schema-udpraw.json index a9da54ef..f8115b42 100644 --- a/libsrc/leddevice/schemas/schema-udpraw.json +++ b/libsrc/leddevice/schemas/schema-udpraw.json @@ -11,6 +11,8 @@ "type": "integer", "title":"Port", "default": 5568, + "minimum" : 0, + "maximum" : 65535, "propertyOrder" : 2 } },