Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
DaAwesomeP committed Jun 22, 2023
2 parents 53dc65e + e12b0a6 commit b214cd3
Show file tree
Hide file tree
Showing 12 changed files with 525 additions and 103 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ olad/ola-output.conf
olad/testdata/ola-output.conf
plugins/artnet/artnet_loadtest
plugins/artnet/artnet_loadtest.exe
plugins/kinet/kinet
plugins/kinet/kinet.exe
plugins/*/*PluginDescription.h
protoc/ola_protoc
protoc/ola_protoc.exe
Expand Down
165 changes: 141 additions & 24 deletions plugins/kinet/KiNetDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*/

#include <memory>
#include <set>
#include <sstream>
#include <string>
#include <vector>

Expand All @@ -30,6 +32,7 @@
#include "ola/network/NetworkUtils.h"
#include "olad/PluginAdaptor.h"
#include "olad/Port.h"
#include "olad/Preferences.h"
#include "plugins/kinet/KiNetDevice.h"
#include "plugins/kinet/KiNetPort.h"

Expand All @@ -39,58 +42,172 @@ namespace kinet {

using ola::network::IPV4Address;
using std::auto_ptr;
using std::ostringstream;
using std::set;
using std::string;
using std::vector;

const char KiNetDevice::KINET_DEVICE_NAME[] = "KiNET";
const char KiNetDevice::DMXOUT_MODE[] = "dmxout";
const char KiNetDevice::PORTOUT_MODE[] = "portout";

/*
* Create a new KiNet Device
*/
KiNetDevice::KiNetDevice(
AbstractPlugin *owner,
const vector<ola::network::IPV4Address> &power_supplies,
PluginAdaptor *plugin_adaptor)
: Device(owner, "KiNet Device"),
m_power_supplies(power_supplies),
m_node(NULL),
m_plugin_adaptor(plugin_adaptor) {
const ola::network::IPV4Address &power_supply,
PluginAdaptor *plugin_adaptor,
KiNetNode *node,
Preferences *preferences)
: Device(owner, KINET_DEVICE_NAME),
m_power_supply(power_supply),
m_plugin_adaptor(plugin_adaptor),
m_node(node),
m_preferences(preferences) {
// set up some per-device default configuration if not already set
SetDefaults();
}


string KiNetDevice::DeviceId() const {
return m_power_supply.ToString();
}


string KiNetDevice::ModeKey(const ola::network::IPV4Address &power_supply) {
return power_supply.ToString() + "-mode";
}


string KiNetDevice::ModeKey() const {
return ModeKey(m_power_supply);
}


void KiNetDevice::SetDefaults() {
if (!m_preferences) {
return;
}

bool save = false;

// Set device options
set<string> valid_modes;
valid_modes.insert(DMXOUT_MODE);
valid_modes.insert(PORTOUT_MODE);
save |= m_preferences->SetDefaultValue(ModeKey(),
SetValidator<string>(valid_modes),
DMXOUT_MODE);

if (save) {
m_preferences->Save();
}
}

const char KiNetPortOutDevice::KINET_PORT_OUT_DEVICE_NAME[] =
"KiNET Port Out Mode";

/*
* Create a new KiNET Port Out Device
*/
KiNetPortOutDevice::KiNetPortOutDevice(
AbstractPlugin *owner,
const ola::network::IPV4Address &power_supply,
PluginAdaptor *plugin_adaptor,
KiNetNode *node,
Preferences *preferences)
: KiNetDevice(owner,
power_supply,
plugin_adaptor,
node,
preferences) {
// set up some Port Out specific per-device default configuration if not
// already set
SetDefaults();
}


/*
* Start this device
* @return true on success, false on failure
*/
bool KiNetDevice::StartHook() {
m_node = new KiNetNode(m_plugin_adaptor);
bool KiNetPortOutDevice::StartHook() {
ostringstream str;
str << KINET_PORT_OUT_DEVICE_NAME << " [Power Supply "
<< m_power_supply.ToString() << "]";
SetName(str.str());

if (!m_node->Start()) {
delete m_node;
m_node = NULL;
return false;
uint8_t port_count;
if (!StringToInt(m_preferences->GetValue(PortCountKey()), &port_count)) {
port_count = KINET_PORTOUT_MAX_PORT_COUNT;
} else if ((port_count < 1) || (port_count > KINET_PORTOUT_MAX_PORT_COUNT)) {
OLA_WARN << "Invalid port count value for " << PortCountKey();
}

vector<IPV4Address>::const_iterator iter = m_power_supplies.begin();
unsigned int port_id = 0;
for (; iter != m_power_supplies.end(); ++iter) {
AddPort(new KiNetOutputPort(this, *iter, m_node, port_id++));
for (uint8_t i = 1; i <= port_count; i++) {
AddPort(new KiNetPortOutOutputPort(this, m_power_supply, m_node, i));
}
return true;
}


/**
* Stop this device. This is called before the ports are deleted
string KiNetPortOutDevice::PortCountKey() const {
return m_power_supply.ToString() + "-ports";
}


void KiNetPortOutDevice::SetDefaults() {
// Set port out specific device options
if (!m_preferences) {
return;
}

bool save = false;

save |= m_preferences->SetDefaultValue(
PortCountKey(),
UIntValidator(1, KINET_PORTOUT_MAX_PORT_COUNT),
KINET_PORTOUT_MAX_PORT_COUNT);

if (save) {
m_preferences->Save();
}
}


const char KiNetDmxOutDevice::KINET_DMX_OUT_DEVICE_NAME[] =
"KiNET DMX Out Mode";

/*
* Create a new KiNET DMX Out Device
*/
void KiNetDevice::PrePortStop() {
m_node->Stop();
KiNetDmxOutDevice::KiNetDmxOutDevice(
AbstractPlugin *owner,
const ola::network::IPV4Address &power_supply,
PluginAdaptor *plugin_adaptor,
KiNetNode *node,
Preferences *preferences)
: KiNetDevice(owner,
power_supply,
plugin_adaptor,
node,
preferences) {
}


/*
* Stop this device
* Start this device
* @return true on success, false on failure
*/
void KiNetDevice::PostPortStop() {
delete m_node;
m_node = NULL;
bool KiNetDmxOutDevice::StartHook() {
ostringstream str;
str << KINET_DMX_OUT_DEVICE_NAME << " [Power Supply "
<< m_power_supply.ToString() << "]";
SetName(str.str());

AddPort(new KiNetDmxOutOutputPort(this, m_power_supply, m_node));
return true;
}
} // namespace kinet
} // namespace plugin
Expand Down
66 changes: 52 additions & 14 deletions plugins/kinet/KiNetDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,64 @@ namespace kinet {

class KiNetDevice: public ola::Device {
public:
KiNetDevice(AbstractPlugin *owner,
const std::vector<ola::network::IPV4Address> &power_supplies,
class PluginAdaptor *plugin_adaptor);
KiNetDevice(AbstractPlugin *owner,
const ola::network::IPV4Address &power_supply,
class PluginAdaptor *plugin_adaptor,
class KiNetNode *node,
class Preferences *preferences);

// Only one KiNet device
std::string DeviceId() const { return "1"; }
std::string DeviceId() const;
static std::string ModeKey(const ola::network::IPV4Address &power_supply);
std::string ModeKey() const;
void SetDefaults();

// We can stream the same universe to multiple IPs
// TODO(Peter): Remove this when we have a device per IP
bool AllowMultiPortPatching() const { return true; }
// We can stream the same universe to multiple IPs or ports on an IP
bool AllowMultiPortPatching() const { return true; }

static const char DMXOUT_MODE[];
static const char PORTOUT_MODE[];

protected:
const ola::network::IPV4Address m_power_supply;
class PluginAdaptor *m_plugin_adaptor;
class KiNetNode *m_node;
class Preferences *m_preferences;

private:
static const char KINET_DEVICE_NAME[];
};

class KiNetPortOutDevice: public KiNetDevice {
public:
KiNetPortOutDevice(AbstractPlugin *owner,
const ola::network::IPV4Address &power_supply,
class PluginAdaptor *plugin_adaptor,
class KiNetNode *node,
class Preferences *preferences);

std::string PortCountKey() const;
void SetDefaults();

protected:
bool StartHook();

private:
static const char KINET_PORT_OUT_DEVICE_NAME[];
};

class KiNetDmxOutDevice: public KiNetDevice {
public:
KiNetDmxOutDevice(AbstractPlugin *owner,
const ola::network::IPV4Address &power_supply,
class PluginAdaptor *plugin_adaptor,
class KiNetNode *node,
class Preferences *preferences);

protected:
bool StartHook();
void PrePortStop();
void PostPortStop();
bool StartHook();

private:
const std::vector<ola::network::IPV4Address> m_power_supplies;
class KiNetNode *m_node;
class PluginAdaptor *m_plugin_adaptor;
static const char KINET_DMX_OUT_DEVICE_NAME[];
};
} // namespace kinet
} // namespace plugin
Expand Down
Loading

0 comments on commit b214cd3

Please sign in to comment.