• 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

42.59
/plugins/milinst/MilInstPlugin.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
 * MilInstPlugin.cpp
17
 * The Milford Instruments plugin for ola
18
 * Copyright (C) 2013 Peter Newman
19
 */
20

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

24
#include "ola/Logging.h"
25
#include "olad/PluginAdaptor.h"
26
#include "olad/Preferences.h"
27
#include "plugins/milinst/MilInstDevice.h"
28
#include "plugins/milinst/MilInstPlugin.h"
29

30
namespace ola {
31
namespace plugin {
32
namespace milinst {
33

34
using ola::io::ConnectedDescriptor;
35
using std::string;
36
using std::vector;
37

38
// Blank default path, so we don't start using a serial port without being asked
39
const char MilInstPlugin::MILINST_DEVICE_PATH[] = "";
40
const char MilInstPlugin::PLUGIN_NAME[] = "Milford Instruments";
41
const char MilInstPlugin::PLUGIN_PREFIX[] = "milinst";
42
const char MilInstPlugin::DEVICE_KEY[] = "device";
43

44
/*
45
 * Start the plugin
46
 */
47
bool MilInstPlugin::StartHook() {
1✔
48
  vector<string> device_names;
1✔
49
  vector<string>::iterator it;
1✔
50
  MilInstDevice *device;
1✔
51

52
  // fetch device listing
53
  device_names = m_preferences->GetMultipleValue(DEVICE_KEY);
2✔
54

55
  for (it = device_names.begin(); it != device_names.end(); ++it) {
2✔
56
    if (it->empty()) {
1✔
57
      OLA_DEBUG << "No path configured for device, please set one in "
1✔
58
          "ola-milinst.conf";
×
59
      continue;
1✔
60
    }
61

62
    device = new MilInstDevice(this, m_preferences, *it);
×
63
    OLA_DEBUG << "Adding device " << *it;
×
64

65
    if (!device->Start()) {
×
66
      delete device;
×
67
      continue;
×
68
    }
69

70
    OLA_DEBUG << "Started device " << *it;
×
71

72
    m_plugin_adaptor->AddReadDescriptor(device->GetSocket());
×
73
    m_plugin_adaptor->RegisterDevice(device);
×
74
    m_devices.push_back(device);
×
75
  }
76
  return true;
1✔
77
}
1✔
78

79

80
/*
81
 * Stop the plugin
82
 * @return true on success, false on failure
83
 */
84
bool MilInstPlugin::StopHook() {
1✔
85
  vector<MilInstDevice*>::iterator iter;
1✔
86
  for (iter = m_devices.begin(); iter != m_devices.end(); ++iter) {
1✔
87
    m_plugin_adaptor->RemoveReadDescriptor((*iter)->GetSocket());
×
88
    DeleteDevice(*iter);
×
89
  }
90
  m_devices.clear();
1✔
91
  return true;
1✔
92
}
93

94

95
/*
96
 * Return the description for this plugin
97
 */
98
string MilInstPlugin::Description() const {
×
99
    return
×
100
"Milford Instruments Plugin\n"
×
101
"----------------------------\n"
102
"\n"
103
"This plugin creates devices with one output port. It currently supports the "
104
"1-463 DMX Protocol Converter and 1-553 512 Channel Serial to DMX "
105
"Transmitter.\n"
106
"\n"
107
"--- Config file : ola-milinst.conf ---\n"
108
"\n"
109
"device = /dev/ttyS0\n"
110
"The device to use as a path for the serial port. Multiple devices are "
111
"supported.\n"
112
"--- Per Device Settings ---\n"
113
"<device>-type = [1-463 | 1-553]\n"
114
"The type of interface.\n"
115
"\n"
116
"--- 1-553 Specific Per Device Settings ---\n"
117
"<device>-baudrate = [9600 | 19200]\n"
118
"The baudrate to connect at.\n"
119
"\n"
120
"<device>-channels = [128 | 256 | 512]\n"
121
"The number of channels to send.\n"
122
"\n";
×
123
}
124

125

126
/*
127
 * Called when the file descriptor is closed.
128
 */
129
int MilInstPlugin::SocketClosed(ConnectedDescriptor *socket) {
×
130
  vector<MilInstDevice*>::iterator iter;
×
131

132
  for (iter = m_devices.begin(); iter != m_devices.end(); ++iter) {
×
133
    if ((*iter)->GetSocket() == socket) {
×
134
      break;
135
    }
136
  }
137

138
  if (iter == m_devices.end()) {
×
139
    OLA_WARN << "unknown fd";
×
140
    return -1;
×
141
  }
142

143
  DeleteDevice(*iter);
×
144
  m_devices.erase(iter);
×
145
  return 0;
×
146
}
147

148

149
/*
150
 * load the plugin prefs and default to sensible values
151
 *
152
 */
153
bool MilInstPlugin::SetDefaultPreferences() {
1✔
154
  if (!m_preferences) {
1✔
155
    return false;
156
  }
157

158
  bool save = false;
1✔
159

160
  save |= m_preferences->SetDefaultValue(DEVICE_KEY, StringValidator(),
1✔
161
                                         MILINST_DEVICE_PATH);
162

163
  if (save) {
1✔
164
    m_preferences->Save();
1✔
165
  }
166

167
  // Just check key exists, as we've set it to ""
168
  if (!m_preferences->HasKey(DEVICE_KEY)) {
1✔
169
    return false;
170
  }
171
  return true;
172
}
173

174

175
/*
176
 * Cleanup a single device
177
 */
178
void MilInstPlugin::DeleteDevice(MilInstDevice *device) {
×
179
  m_plugin_adaptor->UnregisterDevice(device);
×
180
  device->Stop();
×
181
  delete device;
×
182
}
×
183
}  // namespace milinst
184
}  // namespace plugin
185
}  // 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