• 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

56.76
/plugins/karate/KaratePlugin.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
 * KaratePlugin.cpp
17
 * The karate plugin for ola
18
 * Copyright (C) 2005 Simon Newton
19
 */
20

21
#include <errno.h>
22
#include <fcntl.h>
23
#include <stdio.h>
24
#include <stdlib.h>
25
#include <string.h>
26
#include <iostream>
27
#include <string>
28
#include <vector>
29

30
#include "ola/Logging.h"
31
#include "ola/io/IOUtils.h"
32
#include "olad/PluginAdaptor.h"
33
#include "olad/Preferences.h"
34
#include "plugins/karate/KarateDevice.h"
35
#include "plugins/karate/KaratePlugin.h"
36

37
namespace ola {
38
namespace plugin {
39
namespace karate {
40

41
using ola::PluginAdaptor;
42
using std::string;
43
using std::vector;
44

45
const char KaratePlugin::KARATE_DEVICE_PATH[] = "/dev/kldmx0";
46
const char KaratePlugin::KARATE_DEVICE_NAME[] = "KarateLight Device";
47
const char KaratePlugin::PLUGIN_NAME[] = "KarateLight";
48
const char KaratePlugin::PLUGIN_PREFIX[] = "karate";
49
const char KaratePlugin::DEVICE_KEY[] = "device";
50

51
/**
52
 * @brief Start the plugin
53
 */
54
bool KaratePlugin::StartHook() {
1✔
55
  vector<string> devices = m_preferences->GetMultipleValue(DEVICE_KEY);
1✔
56
  vector<string>::const_iterator iter = devices.begin();
1✔
57

58
  // start counting device ids from 0
59
  unsigned int device_id = 0;
1✔
60

61
  for (; iter != devices.end(); ++iter) {
2✔
62
    // first check if it's there
63
    int fd;
1✔
64
    if (ola::io::Open(*iter, O_WRONLY, &fd)) {
1✔
65
      close(fd);
×
66
      KarateDevice *device = new KarateDevice(
×
67
          this,
68
          KARATE_DEVICE_NAME,
69
          *iter,
×
70
          device_id++);
×
71
      if (device->Start()) {
×
72
        m_devices.push_back(device);
×
73
        m_plugin_adaptor->RegisterDevice(device);
×
74
      } else {
75
        OLA_WARN << "Failed to start KarateLight for " << *iter;
×
76
        delete device;
×
77
      }
78
    } else {
79
      OLA_WARN << "Could not open " << *iter << " " << strerror(errno);
1✔
80
    }
81
  }
82
  return true;
1✔
83
}
1✔
84

85

86
/**
87
 * @brief Stop the plugin
88
 * @return true on success, false on failure
89
 */
90
bool KaratePlugin::StopHook() {
1✔
91
  bool ret = true;
1✔
92
  DeviceList::iterator iter = m_devices.begin();
1✔
93
  for (; iter != m_devices.end(); ++iter) {
1✔
94
    m_plugin_adaptor->UnregisterDevice(*iter);
×
95
    ret &= (*iter)->Stop();
×
96
    delete *iter;
×
97
  }
98
  m_devices.clear();
1✔
99
  return ret;
1✔
100
}
101

102

103
/**
104
 * @brief Return the description for this plugin
105
 */
106
string KaratePlugin::Description() const {
×
107
    return
×
108
"KarateLight - Version 0.1\n"
×
109
"----------------------------\n"
110
"\n"
111
"The plugin creates devices with a single output port.\n"
112
"Info on the KarateLight Hardware can be found at http://karatelight.de\n"
113
"Unfortunately the site is in German only, but the maintainer will respond "
114
"to emails in English.\n\n"
115
"--- Config file : ola-karate.conf ---\n"
116
"\n"
117
"device = /dev/kldmx0\n"
118
"The path to the KarateLight device. Multiple entries are supported.\n";
×
119
}
120

121

122
/**
123
 * @brief Set default preferences.
124
 */
125
bool KaratePlugin::SetDefaultPreferences() {
1✔
126
  if (!m_preferences) {
1✔
127
    return false;
128
  }
129

130
  if (m_preferences->SetDefaultValue(DEVICE_KEY, StringValidator(),
1✔
131
                                     KARATE_DEVICE_PATH)) {
132
    m_preferences->Save();
1✔
133
  }
134

135
  // check if this saved correctly
136
  // we don't want to use it if null
137
  if (m_preferences->GetValue(DEVICE_KEY).empty()) {
1✔
138
    return false;
139
  }
140

141
  return true;
142
}
143
}  // namespace karate
144
}  // namespace plugin
145
}  // 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