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

mcallegari / qlcplus / 13633248611

03 Mar 2025 02:31PM UTC coverage: 31.871% (+0.4%) from 31.5%
13633248611

push

github

web-flow
actions: add chrpath to profile

14689 of 46089 relevant lines covered (31.87%)

26426.11 hits per line

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

98.59
/plugins/enttecwing/src/wing.cpp
1
/*
2
  Q Light Controller
3
  wing.cpp
4

5
  Copyright (c) Heikki Junnila
6

7
  Licensed under the Apache License, Version 2.0 (the "License");
8
  you may not use this file except in compliance with the License.
9
  You may obtain a copy of the License at
10

11
      http://www.apache.org/licenses/LICENSE-2.0.txt
12

13
  Unless required by applicable law or agreed to in writing, software
14
  distributed under the License is distributed on an "AS IS" BASIS,
15
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
  See the License for the specific language governing permissions and
17
  limitations under the License.
18
*/
19

20
#include <QHostAddress>
21
#include <QMessageBox>
22
#include <QByteArray>
23
#include <QString>
24
#include <QDebug>
25

26
#include "wing.h"
27

28
/** ENTTEC wings send data thru UDP port 3330 */
29
const int Wing::UDPPort = 3330;
30

31
/****************************************************************************
32
 * Initialization
33
 ****************************************************************************/
34

35
Wing::Wing(QObject* parent, const QHostAddress& address, const QByteArray& data)
6✔
36
    : QObject(parent)
6✔
37
{
38
    m_address = address;
6✔
39
    m_type = resolveType(data);
6✔
40
    m_firmware = resolveFirmware(data);
6✔
41
    m_page = WING_PAGE_MIN;
6✔
42
}
6✔
43

44
Wing::~Wing()
6✔
45
{
46
}
6✔
47

48
bool Wing::isOutputData(const QByteArray& data)
11✔
49
{
50
    /* Check, if there's enough bytes for the header */
51
    if (data.size() < WING_HEADER_SIZE)
11✔
52
        return false;
53

54
    QByteArray header(data.mid(WING_BYTE_HEADER, WING_HEADER_SIZE));
10✔
55
    return (header == WING_HEADER_OUTPUT);
56
}
10✔
57

58
QString Wing::infoText() const
3✔
59
{
60
    QString str;
61
    str  = QString("<B>%1</B>").arg(name());
3✔
62
    str += QString("<P>");
6✔
63
    str += tr("Firmware version %1").arg(int(m_firmware));
3✔
64
    str += QString("<BR>");
6✔
65
    str += tr("Device is operating correctly.");
3✔
66
    str += QString("</P>");
6✔
67
    return str;
3✔
68
}
×
69

70
/****************************************************************************
71
 * Wing data
72
 ****************************************************************************/
73

74
QHostAddress Wing::address() const
277✔
75
{
76
    return m_address;
277✔
77
}
78

79
Wing::Type Wing::type() const
2✔
80
{
81
    return m_type;
2✔
82
}
83

84
uchar Wing::firmware() const
4✔
85
{
86
    return m_firmware;
4✔
87
}
88

89
Wing::Type Wing::resolveType(const QByteArray& data)
11✔
90
{
91
    /* Check, if there's enough bytes for wing flags */
92
    if (data.size() < WING_BYTE_FLAGS)
11✔
93
    {
94
        qWarning() << Q_FUNC_INFO
6✔
95
                   << "Unable to determine wing type."
3✔
96
                   << "Expected at least" << WING_BYTE_FLAGS
3✔
97
                   << "bytes but got only" << data.size();
3✔
98
        return Unknown;
3✔
99
    }
100

101
    unsigned char flags = data[WING_BYTE_FLAGS];
8✔
102
    return Wing::Type(flags & WING_FLAGS_MASK_TYPE);
8✔
103
}
104

105
unsigned char Wing::resolveFirmware(const QByteArray& data)
10✔
106
{
107
    /* Check, if there's enough bytes for wing flags */
108
    if (data.size() < WING_BYTE_FIRMWARE)
10✔
109
    {
110
        qWarning() << Q_FUNC_INFO
6✔
111
                   << "Unable to determine firmware version."
3✔
112
                   << "Expected at least" << WING_BYTE_FIRMWARE
3✔
113
                   << "bytes but got only" << data.size();
3✔
114
        return 0;
3✔
115
    }
116

117
    return data[WING_BYTE_FIRMWARE];
7✔
118
}
119

120
/****************************************************************************
121
 * Page
122
 ****************************************************************************/
123

124
void Wing::nextPage()
295✔
125
{
126
    if (m_page == WING_PAGE_MAX)
295✔
127
        m_page = WING_PAGE_MIN;
2✔
128
    else
129
        m_page++;
293✔
130
}
295✔
131

132
void Wing::previousPage()
175✔
133
{
134
    if (m_page == WING_PAGE_MIN)
175✔
135
        m_page = WING_PAGE_MAX;
2✔
136
    else
137
        m_page--;
173✔
138
}
175✔
139

140
uchar Wing::page() const
2,754✔
141
{
142
    return m_page;
2,754✔
143
}
144

145

146
/****************************************************************************
147
 * Input data
148
 ****************************************************************************/
149

150
uchar Wing::cacheValue(int channel)
6,857✔
151
{
152
    if (channel >= m_values.size())
6,857✔
153
        return 0;
154
    else
155
        return m_values[channel];
13,712✔
156
}
157

158
void Wing::setCacheValue(int channel, uchar value)
134,257✔
159
{
160
    if (channel >= m_values.size())
134,257✔
161
        return;
162

163
    if (channel != WING_INVALID_CHANNEL && m_values[channel] != char(value))
134,256✔
164
    {
165
        m_values[channel] = char(value);
3,452✔
166
        emit valueChanged(channel, value);
3,452✔
167
    }
168
}
169

170
void Wing::feedBack(quint32 channel, uchar value)
1✔
171
{
172
    Q_UNUSED(channel);
173
    Q_UNUSED(value);
174
}
1✔
175

176
uchar Wing::toBCD(uchar number)
127✔
177
{
178
    uchar bcd = ((number / 10) & 0x0F) << 4;
127✔
179
    bcd |= (number % 10) & 0x0F;
127✔
180
    return bcd;
127✔
181
}
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