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

OpenLightingProject / ola / 16911433572

12 Aug 2025 02:08PM UTC coverage: 45.869% (-0.04%) from 45.909%
16911433572

Pull #1739

github

web-flow
Merge 02faeaa2d into 3566c28d9
Pull Request #1739: New web UI, store highest channel number used

7157 of 16316 branches covered (43.86%)

20915 of 45597 relevant lines covered (45.87%)

52.03 hits per line

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

81.94
/plugins/e131/E131Plugin.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
 * E131Plugin.cpp
17
 * The E1.31 plugin for ola
18
 * Copyright (C) 2007 Simon Newton
19
 */
20

21
#include <set>
22
#include <string>
23

24
#include "ola/Logging.h"
25
#include "ola/network/NetworkUtils.h"
26
#include "ola/StringUtils.h"
27
#include "ola/acn/CID.h"
28
#include "olad/PluginAdaptor.h"
29
#include "olad/Preferences.h"
30
#include "plugins/e131/E131Device.h"
31
#include "plugins/e131/E131Plugin.h"
32

33
namespace ola {
34
namespace plugin {
35
namespace e131 {
36

37
using ola::acn::CID;
38
using std::string;
39

40
const char E131Plugin::CID_KEY[] = "cid";
41
const unsigned int E131Plugin::DEFAULT_DSCP_VALUE = 0;
42
const char E131Plugin::DSCP_KEY[] = "dscp";
43
const char E131Plugin::DRAFT_DISCOVERY_KEY[] = "draft_discovery";
44
const char E131Plugin::IGNORE_PREVIEW_DATA_KEY[] = "ignore_preview";
45
const char E131Plugin::INPUT_PORT_COUNT_KEY[] = "input_ports";
46
const char E131Plugin::IP_KEY[] = "ip";
47
const char E131Plugin::OUTPUT_PORT_COUNT_KEY[] = "output_ports";
48
const char E131Plugin::PLUGIN_NAME[] = "E1.31 (sACN)";
49
const char E131Plugin::PLUGIN_PREFIX[] = "e131";
50
const char E131Plugin::PREPEND_HOSTNAME_KEY[] = "prepend_hostname";
51
const char E131Plugin::REVISION_0_2[] = "0.2";
52
const char E131Plugin::REVISION_0_46[] = "0.46";
53
const char E131Plugin::REVISION_KEY[] = "revision";
54
const unsigned int E131Plugin::DEFAULT_PORT_COUNT = 5;
55

56

57
/*
58
 * Start the plugin
59
 */
60
bool E131Plugin::StartHook() {
1✔
61
  CID cid = CID::FromString(m_preferences->GetValue(CID_KEY));
2✔
62
  string ip_addr = m_preferences->GetValue(IP_KEY);
1✔
63

64
  E131Device::E131DeviceOptions options;
1✔
65
  options.use_rev2 = (m_preferences->GetValue(REVISION_KEY) == REVISION_0_2);
1✔
66
  options.ignore_preview = m_preferences->GetValueAsBool(
1✔
67
      IGNORE_PREVIEW_DATA_KEY);
68
  options.enable_draft_discovery = m_preferences->GetValueAsBool(
1✔
69
      DRAFT_DISCOVERY_KEY);
70
  if (m_preferences->GetValueAsBool(PREPEND_HOSTNAME_KEY)) {
1✔
71
    std::ostringstream str;
1✔
72
    str << ola::network::Hostname() << "-" << m_plugin_adaptor->InstanceName();
3✔
73
    options.source_name = str.str();
1✔
74
  } else {
1✔
75
    options.source_name = m_plugin_adaptor->InstanceName();
×
76
  }
77

78
  unsigned int dscp;
1✔
79
  if (!StringToInt(m_preferences->GetValue(DSCP_KEY), &dscp)) {
1✔
80
    OLA_WARN << "Can't convert dscp value " <<
×
81
      m_preferences->GetValue(DSCP_KEY) << " to int";
×
82
    options.dscp = 0;
×
83
  } else {
84
    // shift 2 bits left
85
    options.dscp = dscp << 2;
1✔
86
  }
87

88
  if (!StringToInt(m_preferences->GetValue(INPUT_PORT_COUNT_KEY),
1✔
89
                   &options.input_ports)) {
90
    OLA_WARN << "Invalid value for input_ports";
×
91
  }
92

93
  if (!StringToInt(m_preferences->GetValue(OUTPUT_PORT_COUNT_KEY),
1✔
94
                   &options.output_ports)) {
95
    OLA_WARN << "Invalid value for output_ports";
×
96
  }
97

98
  m_device = new E131Device(this, cid, ip_addr, m_plugin_adaptor, options);
1✔
99

100
  if (!m_device->Start()) {
1✔
101
    delete m_device;
×
102
    return false;
×
103
  }
104

105
  m_plugin_adaptor->RegisterDevice(m_device);
1✔
106
  return true;
107
}
1✔
108

109

110
/*
111
 * Stop the plugin
112
 * @return true on success, false on failure
113
 */
114
bool E131Plugin::StopHook() {
1✔
115
  if (m_device) {
1✔
116
    m_plugin_adaptor->UnregisterDevice(m_device);
1✔
117
    bool ret = m_device->Stop();
1✔
118
    delete m_device;
1✔
119
    return ret;
1✔
120
  }
121
  return true;
122
}
123

124

125
/*
126
 * Return the description for this plugin
127
 */
128
string E131Plugin::Description() const {
×
129
    return
×
130
"E1.31 (Streaming DMX over ACN) Plugin\n"
×
131
"----------------------------\n"
132
"\n"
133
"This plugin creates a single device with a configurable number of input \n"
134
"and output ports.\n"
135
"\n"
136
"Each port can be assigned to a different E1.31 Universe.\n"
137
"\n"
138
"--- Config file : ola-e131.conf ---\n"
139
"\n"
140
"cid = 00010203-0405-0607-0809-0A0B0C0D0E0F\n"
141
"The CID to use for this device.\n"
142
"\n"
143
"dscp = [int]\n"
144
"The DSCP value to tag the packets with, range is 0 to 63.\n"
145
"\n"
146
"draft_discovery = [bool]\n"
147
"Enable the draft (2014) E1.31 discovery protocol.\n"
148
"\n"
149
"ignore_preview = [true|false]\n"
150
"Ignore preview data.\n"
151
"\n"
152
"input_ports = [int]\n"
153
"The number of input ports to create up to an arbitrary max of 512.\n"
154
"\n"
155
"ip = [a.b.c.d|<interface_name>]\n"
156
"The ip address or interface name to bind to. If not specified it will\n"
157
"use the first non-loopback interface.\n"
158
"\n"
159
"output_ports = [int]\n"
160
"The number of output ports to create up to an arbitrary max of 512.\n"
161
"\n"
162
"prepend_hostname = [true|false]\n"
163
"Prepend the hostname to the source name when sending packets.\n"
164
"\n"
165
"revision = [0.2|0.46]\n"
166
"Select which revision of the standard to use when sending data. 0.2 is the\n"
167
" standardized revision, 0.46 (default) is the ANSI standard version.\n"
168
"\n";
×
169
}
170

171

172
/*
173
 * Load the plugin prefs and default to sensible values
174
 *
175
 */
176
bool E131Plugin::SetDefaultPreferences() {
1✔
177
  if (!m_preferences)
1✔
178
    return false;
179

180
  bool save = false;
1✔
181

182
  CID cid = CID::FromString(m_preferences->GetValue(CID_KEY));
2✔
183
  if (cid.IsNil()) {
1✔
184
    cid = CID::Generate();
1✔
185
    m_preferences->SetValue(CID_KEY, cid.ToString());
2✔
186
    save = true;
1✔
187
  }
188

189
  save |= m_preferences->SetDefaultValue(
1✔
190
      DSCP_KEY,
191
      UIntValidator(0, 63),
1✔
192
      DEFAULT_DSCP_VALUE);
193

194
  save |= m_preferences->SetDefaultValue(
1✔
195
      DRAFT_DISCOVERY_KEY,
196
      BoolValidator(),
1✔
197
      false);
198

199
  save |= m_preferences->SetDefaultValue(
1✔
200
      IGNORE_PREVIEW_DATA_KEY,
201
      BoolValidator(),
1✔
202
      true);
203

204
  save |= m_preferences->SetDefaultValue(
1✔
205
      INPUT_PORT_COUNT_KEY,
206
      UIntValidator(0, 512),
1✔
207
      DEFAULT_PORT_COUNT);
208

209
  save |= m_preferences->SetDefaultValue(
1✔
210
      OUTPUT_PORT_COUNT_KEY,
211
      UIntValidator(0, 512),
1✔
212
      DEFAULT_PORT_COUNT);
213

214
  save |= m_preferences->SetDefaultValue(IP_KEY, StringValidator(true), "");
1✔
215

216
  save |= m_preferences->SetDefaultValue(
1✔
217
      PREPEND_HOSTNAME_KEY,
218
      BoolValidator(),
1✔
219
      true);
220

221
  std::set<string> revision_values;
1✔
222
  revision_values.insert(REVISION_0_2);
1✔
223
  revision_values.insert(REVISION_0_46);
1✔
224

225
  save |= m_preferences->SetDefaultValue(
2✔
226
      REVISION_KEY,
227
      SetValidator<string>(revision_values),
1✔
228
      REVISION_0_46);
229

230
  if (save) {
1✔
231
    m_preferences->Save();
1✔
232
  }
233

234
  // check if this saved correctly
235
  // we don't want to use it if null
236
  string revision = m_preferences->GetValue(REVISION_KEY);
1✔
237
  if (m_preferences->GetValue(CID_KEY).empty() ||
2✔
238
      (revision != REVISION_0_2 && revision != REVISION_0_46)) {
1✔
239
    return false;
×
240
  }
241

242
  return true;
243
}
1✔
244
}  // namespace e131
245
}  // namespace plugin
246
}  // 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

© 2026 Coveralls, Inc