• 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

78.18
/plugins/dummy/DummyPlugin.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
 * DummyPlugin.cpp
17
 * The Dummy plugin for ola, contains a single dummy device
18
 * Copyright (C) 2005 Simon Newton
19
 */
20

21
#include <stdlib.h>
22
#include <stdio.h>
23
#include <string>
24

25
#include "ola/StringUtils.h"
26
#include "olad/PluginAdaptor.h"
27
#include "olad/Preferences.h"
28
#include "plugins/dummy/DummyDevice.h"
29
#include "plugins/dummy/DummyPort.h"
30
#include "plugins/dummy/DummyPlugin.h"
31

32
namespace ola {
33
namespace plugin {
34
namespace dummy {
35

36
using std::string;
37

38
const char DummyPlugin::ACK_TIMER_COUNT_KEY[] = "ack_timer_count";
39
const char DummyPlugin::ADVANCED_DIMMER_KEY[] = "advanced_dimmer_count";
40
const uint8_t DummyPlugin::DEFAULT_DEVICE_COUNT = 1;
41
// 0 for now, since the web UI doesn't handle it.
42
const uint8_t DummyPlugin::DEFAULT_ACK_TIMER_DEVICE_COUNT = 0;
43
const uint16_t DummyPlugin::DEFAULT_SUBDEVICE_COUNT = 4;
44
const char DummyPlugin::DEVICE_NAME[] = "Dummy Device";
45
const char DummyPlugin::DIMMER_COUNT_KEY[] = "dimmer_count";
46
const char DummyPlugin::DIMMER_SUBDEVICE_COUNT_KEY[] = "dimmer_subdevice_count";
47
const char DummyPlugin::DUMMY_DEVICE_COUNT_KEY[] = "dummy_device_count";
48
const char DummyPlugin::MOVING_LIGHT_COUNT_KEY[] = "moving_light_count";
49
const char DummyPlugin::NETWORK_COUNT_KEY[] = "network_device_count";
50
const char DummyPlugin::PLUGIN_NAME[] = "Dummy";
51
const char DummyPlugin::PLUGIN_PREFIX[] = "dummy";
52
const char DummyPlugin::SENSOR_COUNT_KEY[] = "sensor_device_count";
53

54
/*
55
 * Start the plugin
56
 *
57
 * Lets keep it simple, one device for this plugin.
58
 */
59
bool DummyPlugin::StartHook() {
1✔
60
  DummyPort::Options options;
1✔
61

62
  if (!StringToInt(m_preferences->GetValue(DUMMY_DEVICE_COUNT_KEY) ,
1✔
63
                   &options.number_of_dummy_responders)) {
64
    options.number_of_dummy_responders = DEFAULT_DEVICE_COUNT;
×
65
  }
66

67
  if (!StringToInt(m_preferences->GetValue(DIMMER_COUNT_KEY) ,
1✔
68
                   &options.number_of_dimmers)) {
69
    options.number_of_dimmers = DEFAULT_DEVICE_COUNT;
×
70
  }
71

72
  if (!StringToInt(m_preferences->GetValue(DIMMER_SUBDEVICE_COUNT_KEY) ,
1✔
73
                   &options.dimmer_sub_device_count)) {
74
    options.dimmer_sub_device_count = DEFAULT_SUBDEVICE_COUNT;
×
75
  }
76

77
  if (!StringToInt(m_preferences->GetValue(MOVING_LIGHT_COUNT_KEY) ,
1✔
78
                   &options.number_of_moving_lights)) {
79
    options.number_of_moving_lights = DEFAULT_DEVICE_COUNT;
×
80
  }
81

82
  if (!StringToInt(m_preferences->GetValue(ACK_TIMER_COUNT_KEY) ,
1✔
83
                   &options.number_of_ack_timer_responders)) {
84
    options.number_of_ack_timer_responders = DEFAULT_ACK_TIMER_DEVICE_COUNT;
×
85
  }
86

87
  if (!StringToInt(m_preferences->GetValue(ADVANCED_DIMMER_KEY) ,
1✔
88
                   &options.number_of_advanced_dimmers)) {
89
    options.number_of_advanced_dimmers = DEFAULT_DEVICE_COUNT;
×
90
  }
91

92
  if (!StringToInt(m_preferences->GetValue(SENSOR_COUNT_KEY) ,
1✔
93
                   &options.number_of_sensor_responders)) {
94
    options.number_of_sensor_responders = DEFAULT_DEVICE_COUNT;
×
95
  }
96

97
  if (!StringToInt(m_preferences->GetValue(NETWORK_COUNT_KEY) ,
1✔
98
                   &options.number_of_network_responders)) {
99
    options.number_of_network_responders = DEFAULT_DEVICE_COUNT;
×
100
  }
101

102
  std::auto_ptr<DummyDevice> device(
1✔
103
      new DummyDevice(this, DEVICE_NAME, options));
1✔
104
  if (!device->Start()) {
1✔
105
    return false;
106
  }
107
  m_device = device.release();
1✔
108
  m_plugin_adaptor->RegisterDevice(m_device);
1✔
109
  return true;
110
}
1✔
111

112

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

127

128
string DummyPlugin::Description() const {
×
129
  return
×
130
"Dummy Plugin\n"
×
131
"----------------------------\n"
132
"\n"
133
"The plugin creates a single device with one port. When used as an output\n"
134
"port it prints the first two bytes of dmx data to stdout.\n"
135
"\n"
136
"The Dummy plugin can also emulate a range of RDM devices. It supports the\n"
137
"following RDM device types:\n"
138
" * Dummy Device (original)\n"
139
" * Dimmer Rack, with a configurable number of sub-devices\n"
140
" * Moving Light\n"
141
" * Advanced Dimmer Rack, with E1.37-1 PIDs\n"
142
" * A device that responds with ack timers\n"
143
" * Sensor Device, with a number of sensors implemented\n"
144
" * Network Device, with E1.37-2 PIDs\n"
145
"\n"
146
"The number of each device is configurable.\n"
147
"\n"
148
"--- Config file : ola-dummy.conf ---\n"
149
"\n"
150
"ack_timer_count = 0\n"
151
"The number of ack timer responders to create.\n"
152
"\n"
153
"advanced_dimmer_count = 0\n"
154
"The number of E1.37-1 dimmer responders to create.\n"
155
"\n"
156
"dimmer_count = 1\n"
157
"The number of dimmer devices to create.\n"
158
"\n"
159
"dimmer_subdevice_count = 1\n"
160
"The number of sub-devices each dimmer device should have.\n"
161
"\n"
162
"dummy_device_count = 1\n"
163
"The number of dummy devices to create.\n"
164
"\n"
165
"moving_light_count = 1\n"
166
"The number of moving light devices to create.\n"
167
"\n"
168
"sensor_device_count = 1\n"
169
"The number of sensor-only devices to create.\n"
170
"\n"
171
"network_device_count = 1\n"
172
"The number of network E1.37-2 devices to create.\n"
173
"\n";
×
174
}
175

176

177
/**
178
 * Set the default preferences for the dummy plugin.
179
 */
180
bool DummyPlugin::SetDefaultPreferences() {
1✔
181
  if (!m_preferences) {
1✔
182
    return false;
183
  }
184

185
  bool save = false;
1✔
186

187
  save |= m_preferences->SetDefaultValue(DUMMY_DEVICE_COUNT_KEY,
1✔
188
                                         UIntValidator(0, 254),
1✔
189
                                         DEFAULT_DEVICE_COUNT);
190

191
  save |= m_preferences->SetDefaultValue(DIMMER_COUNT_KEY,
1✔
192
                                         UIntValidator(0, 254),
1✔
193
                                         DEFAULT_DEVICE_COUNT);
194

195
  save |= m_preferences->SetDefaultValue(DIMMER_SUBDEVICE_COUNT_KEY,
1✔
196
                                         UIntValidator(0, 255),
1✔
197
                                         DEFAULT_SUBDEVICE_COUNT);
198

199
  save |= m_preferences->SetDefaultValue(MOVING_LIGHT_COUNT_KEY,
1✔
200
                                         UIntValidator(0, 254),
1✔
201
                                         DEFAULT_DEVICE_COUNT);
202

203
  save |= m_preferences->SetDefaultValue(ACK_TIMER_COUNT_KEY,
1✔
204
                                         UIntValidator(0, 254),
1✔
205
                                         DEFAULT_ACK_TIMER_DEVICE_COUNT);
206

207
  save |= m_preferences->SetDefaultValue(ADVANCED_DIMMER_KEY,
1✔
208
                                         UIntValidator(0, 254),
1✔
209
                                         DEFAULT_DEVICE_COUNT);
210

211
  save |= m_preferences->SetDefaultValue(SENSOR_COUNT_KEY,
1✔
212
                                         UIntValidator(0, 254),
1✔
213
                                         DEFAULT_DEVICE_COUNT);
214

215
  save |= m_preferences->SetDefaultValue(NETWORK_COUNT_KEY,
1✔
216
                                         IntValidator(0, 254),
1✔
217
                                         DEFAULT_DEVICE_COUNT);
218

219
  if (save) {
1✔
220
    m_preferences->Save();
1✔
221
  }
222

223
  return true;
224
}
225
}  // namespace dummy
226
}  // namespace plugin
227
}  // 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