• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

OpenLightingProject / ola / 5329180527

21 Jun 2023 01:46AM UTC coverage: 45.027% (-0.1%) from 45.16%
5329180527

push

github

web-flow
Merge pull request #1787 from peternewman/kinet-port-out

Add Kinet portout support, closes #1544

7602 of 17641 branches covered (43.09%)

146 of 146 new or added lines in 6 files covered. (100.0%)

21411 of 47551 relevant lines covered (45.03%)

55.79 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/plugins/kinet/KiNetDevice.cpp
1
/*
2
 * This program is free software; you can redistribute it and/or modify
3
 * it under the terms of the GNU General Public License as published by
4
 * the Free Software Foundation; either version 2 of the License, or
5
 * (at your option) any later version.
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU Library General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15
 *
16
 * KiNetDevice.cpp
17
 * A KiNet Device.
18
 * Copyright (C) 2013 Simon Newton
19
 */
20

21
#include <memory>
22
#include <set>
23
#include <sstream>
24
#include <string>
25
#include <vector>
26

27
#include "ola/Callback.h"
28
#include "ola/Logging.h"
29
#include "ola/StringUtils.h"
30
#include "ola/network/IPV4Address.h"
31
#include "ola/network/InterfacePicker.h"
32
#include "ola/network/NetworkUtils.h"
33
#include "olad/PluginAdaptor.h"
34
#include "olad/Port.h"
35
#include "olad/Preferences.h"
36
#include "plugins/kinet/KiNetDevice.h"
37
#include "plugins/kinet/KiNetPort.h"
38

39
namespace ola {
40
namespace plugin {
41
namespace kinet {
42

43
using ola::network::IPV4Address;
44
using std::auto_ptr;
45
using std::ostringstream;
46
using std::set;
47
using std::string;
48
using std::vector;
49

50
const char KiNetDevice::KINET_DEVICE_NAME[] = "KiNET";
51
const char KiNetDevice::DMXOUT_MODE[] = "dmxout";
52
const char KiNetDevice::PORTOUT_MODE[] = "portout";
53

54
/*
55
 * Create a new KiNet Device
56
 */
57
KiNetDevice::KiNetDevice(
×
58
    AbstractPlugin *owner,
59
    const ola::network::IPV4Address &power_supply,
60
    PluginAdaptor *plugin_adaptor,
61
    KiNetNode *node,
62
    Preferences *preferences)
×
63
    : Device(owner, KINET_DEVICE_NAME),
64
      m_power_supply(power_supply),
×
65
      m_plugin_adaptor(plugin_adaptor),
×
66
      m_node(node),
×
67
      m_preferences(preferences) {
×
68
  // set up some per-device default configuration if not already set
69
  SetDefaults();
×
70
}
×
71

72

73
string KiNetDevice::DeviceId() const {
×
74
  return m_power_supply.ToString();
×
75
}
76

77

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

82

83
string KiNetDevice::ModeKey() const {
×
84
  return ModeKey(m_power_supply);
×
85
}
86

87

88
void KiNetDevice::SetDefaults() {
×
89
  if (!m_preferences) {
×
90
    return;
×
91
  }
92

93
  bool save = false;
×
94

95
  // Set device options
96
  set<string> valid_modes;
×
97
  valid_modes.insert(DMXOUT_MODE);
×
98
  valid_modes.insert(PORTOUT_MODE);
×
99
  save |= m_preferences->SetDefaultValue(ModeKey(),
×
100
                                         SetValidator<string>(valid_modes),
×
101
                                         DMXOUT_MODE);
102

103
  if (save) {
×
104
    m_preferences->Save();
×
105
  }
106
}
×
107

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

111
/*
112
 * Create a new KiNET Port Out Device
113
 */
114
KiNetPortOutDevice::KiNetPortOutDevice(
×
115
    AbstractPlugin *owner,
116
    const ola::network::IPV4Address &power_supply,
117
    PluginAdaptor *plugin_adaptor,
118
    KiNetNode *node,
119
    Preferences *preferences)
×
120
    : KiNetDevice(owner,
121
                  power_supply,
122
                  plugin_adaptor,
123
                  node,
124
                  preferences) {
×
125
  // set up some Port Out specific per-device default configuration if not
126
  // already set
127
  SetDefaults();
×
128
}
×
129

130

131
/*
132
 * Start this device
133
 * @return true on success, false on failure
134
 */
135
bool KiNetPortOutDevice::StartHook() {
×
136
  ostringstream str;
×
137
  str << KINET_PORT_OUT_DEVICE_NAME << " [Power Supply "
×
138
      << m_power_supply.ToString() << "]";
×
139
  SetName(str.str());
×
140

141
  uint8_t port_count;
×
142
  if (!StringToInt(m_preferences->GetValue(PortCountKey()), &port_count)) {
×
143
    port_count = KINET_PORTOUT_MAX_PORT_COUNT;
×
144
  } else if ((port_count < 1) || (port_count > KINET_PORTOUT_MAX_PORT_COUNT)) {
×
145
    OLA_WARN << "Invalid port count value for " << PortCountKey();
×
146
  }
147

148
  for (uint8_t i = 1; i <= port_count; i++) {
×
149
    AddPort(new KiNetPortOutOutputPort(this, m_power_supply, m_node, i));
×
150
  }
151
  return true;
×
152
}
×
153

154

155
string KiNetPortOutDevice::PortCountKey() const {
×
156
  return m_power_supply.ToString() + "-ports";
×
157
}
158

159

160
void KiNetPortOutDevice::SetDefaults() {
×
161
  // Set port out specific device options
162
  if (!m_preferences) {
×
163
    return;
164
  }
165

166
  bool save = false;
×
167

168
  save |= m_preferences->SetDefaultValue(
×
169
      PortCountKey(),
×
170
      UIntValidator(1, KINET_PORTOUT_MAX_PORT_COUNT),
×
171
      KINET_PORTOUT_MAX_PORT_COUNT);
172

173
  if (save) {
×
174
    m_preferences->Save();
×
175
  }
176
}
177

178

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

182
/*
183
 * Create a new KiNET DMX Out Device
184
 */
185
KiNetDmxOutDevice::KiNetDmxOutDevice(
×
186
    AbstractPlugin *owner,
187
    const ola::network::IPV4Address &power_supply,
188
    PluginAdaptor *plugin_adaptor,
189
    KiNetNode *node,
190
    Preferences *preferences)
×
191
    : KiNetDevice(owner,
192
                  power_supply,
193
                  plugin_adaptor,
194
                  node,
195
                  preferences) {
×
196
}
×
197

198

199
/*
200
 * Start this device
201
 * @return true on success, false on failure
202
 */
203
bool KiNetDmxOutDevice::StartHook() {
×
204
  ostringstream str;
×
205
  str << KINET_DMX_OUT_DEVICE_NAME << " [Power Supply "
×
206
      << m_power_supply.ToString() << "]";
×
207
  SetName(str.str());
×
208

209
  AddPort(new KiNetDmxOutOutputPort(this, m_power_supply, m_node));
×
210
  return true;
×
211
}
×
212
}  // namespace kinet
213
}  // namespace plugin
214
}  // namespace ola
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc