This repository was archived by the owner on Feb 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathComtradeAnalogChannel.cpp
More file actions
200 lines (166 loc) · 4.59 KB
/
Copy pathComtradeAnalogChannel.cpp
File metadata and controls
200 lines (166 loc) · 4.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#include "ComtradeAnalogChannel.h"
#include <QtCore/QDebug>
#define ANALOG_LINE_TOKENS 13
ComtradeAnalogChannel::ComtradeAnalogChannel(QObject *parent)
: ComtradeChannel(parent)
, m_valueScaling(ScalingIdentifier::Invalid)
, m_multiplier(0)
, m_offset(0)
, m_channelSkewus(0)
, m_primaryRatio(0)
, m_secondaryRatio(0)
, m_minValue(0)
, m_maxValue(0)
{
}
ComtradeAnalogChannel::~ComtradeAnalogChannel()
{
}
QString ComtradeAnalogChannel::unit() const
{
return m_unit;
}
double ComtradeAnalogChannel::multiplier() const
{
return m_multiplier;
}
double ComtradeAnalogChannel::offset() const
{
return m_offset;
}
double ComtradeAnalogChannel::channelSkewus() const
{
return m_channelSkewus;
}
int ComtradeAnalogChannel::minValue() const
{
return m_minValue;
}
int ComtradeAnalogChannel::maxValue() const
{
return m_maxValue;
}
double ComtradeAnalogChannel::primaryRatio() const
{
return m_primaryRatio;
}
double ComtradeAnalogChannel::secondaryRatio() const
{
return m_secondaryRatio;
}
ComtradeAnalogChannel::ScalingIdentifier ComtradeAnalogChannel::valueScaling() const
{
return m_valueScaling;
}
void ComtradeAnalogChannel::setUnit(const QString &unit)
{
m_unit = unit;
}
void ComtradeAnalogChannel::setMultiplier(double multiplier)
{
m_multiplier = multiplier;
}
void ComtradeAnalogChannel::setOffset(double offset)
{
m_offset = offset;
}
void ComtradeAnalogChannel::setChannelSkewus(double channelSkewus)
{
m_channelSkewus = channelSkewus;
}
void ComtradeAnalogChannel::setMinValue(int minValue)
{
m_minValue = minValue;
}
void ComtradeAnalogChannel::setMaxValue(int maxValue)
{
m_maxValue = maxValue;
}
void ComtradeAnalogChannel::setPrimaryRatio(double primaryRatio)
{
m_primaryRatio = primaryRatio;
}
void ComtradeAnalogChannel::setSecondaryRatio(double secondaryRatio)
{
m_secondaryRatio = secondaryRatio;
}
void ComtradeAnalogChannel::setValueScaling(ScalingIdentifier scaling)
{
m_valueScaling = scaling;
}
ComtradeAnalogChannel *ComtradeAnalogChannel::fromCfgLine(const QByteArray &line, QObject *parent)
{
QList<QByteArray> tokens = line.trimmed().split(',');
if (tokens.count() != ANALOG_LINE_TOKENS) {
qWarning() << "Invalid analog channel cfg: " << line;
return nullptr;
}
bool ok;
int index = tokens.value(0).toInt(&ok);
if (!ok) {
qWarning() << "Invalid channel index: " << tokens.value(0);
return nullptr;
}
// Non-critical fields
QString id = QString::fromLatin1(tokens.value(1));
QString phase = QString::fromLatin1(tokens.value(2));
QString ccbm = QString::fromLatin1(tokens.value(3));
QString unit = QString::fromLatin1(tokens.value(4));
double multiplier = tokens.value(5).toDouble(&ok);
if (!ok) {
qWarning() << "Invalid multiplier: " << tokens.value(5);
return nullptr;
}
double offset = tokens.value(6).toDouble(&ok);
if (!ok) {
qWarning() << "Invalid offset: " << tokens.value(6);
return nullptr;
}
// Non critical
double channelSkewus = tokens.value(7).toDouble(&ok);
int minValue = tokens.value(8).toInt(&ok);
if (!ok) {
qWarning() << "Invalid minValue: " << tokens.value(8);
return nullptr;
}
int maxValue = tokens.value(9).toInt(&ok);
if (!ok) {
qWarning() << "Invalid maxValue: " << tokens.value(9);
return nullptr;
}
double primaryRatio = tokens.value(10).toDouble(&ok);
if (!ok) {
qWarning() << "Invalid primaryRatio: " << tokens.value(10);
return nullptr;
}
double secondaryRatio = tokens.value(11).toDouble(&ok);
if (!ok) {
qWarning() << "Invalid secondaryRatio: " << tokens.value(11);
return nullptr;
}
ScalingIdentifier scaling;
QByteArray scalingToken = tokens.value(12).toLower();
if (scalingToken == "p") {
scaling = ScalingIdentifier::Primary;
} else if (scalingToken == "s") {
scaling = ScalingIdentifier::Secondary;
} else {
qWarning() << "Invalid scaling identifier: " << tokens.value(12);
return nullptr;
}
ComtradeAnalogChannel *ret = new ComtradeAnalogChannel(parent);
ret->setIndex(index);
ret->setId(id);
ret->setPhase(phase);
ret->setCCBM(ccbm);
ret->setUnit(unit);
ret->setMultiplier(multiplier);
ret->setOffset(offset);
ret->setChannelSkewus(channelSkewus);
ret->setMinValue(minValue);
ret->setMaxValue(maxValue);
ret->setPrimaryRatio(primaryRatio);
ret->setSecondaryRatio(secondaryRatio);
ret->setValueScaling(scaling);
return ret;
}