-
Notifications
You must be signed in to change notification settings - Fork 531
Expand file tree
/
Copy pathmorsedecoder.h
More file actions
257 lines (205 loc) · 8.35 KB
/
morsedecoder.h
File metadata and controls
257 lines (205 loc) · 8.35 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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2024 Edouard Griffiths, F4EXB <f4exb06@gmail.com> //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation as version 3 of the License, or //
// (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License V3 for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef INCLUDE_FEATURE_MORSEDECODER_H_
#define INCLUDE_FEATURE_MORSEDECODER_H_
#include <QHash>
#include <QNetworkRequest>
#include <QRecursiveMutex>
#include <QFile>
#include <QTextStream>
#include <QUdpSocket>
#include "feature/feature.h"
#include "util/message.h"
#include "availablechannelorfeaturehandler.h"
#include "dsp/scopevis.h"
#include "morsedecodersettings.h"
class WebAPIAdapterInterface;
class MorseDecoderWorker;
class QNetworkAccessManager;
class QNetworkReply;
class QThread;
class ObjectPipe;
namespace SWGSDRangel {
class SWGDeviceState;
}
class MorseDecoder : public Feature
{
Q_OBJECT
public:
class MsgConfigureMorseDecoder : public Message {
MESSAGE_CLASS_DECLARATION
public:
const MorseDecoderSettings& getSettings() const { return m_settings; }
const QList<QString>& getSettingsKeys() const { return m_settingsKeys; }
bool getForce() const { return m_force; }
static MsgConfigureMorseDecoder* create(const MorseDecoderSettings& settings, const QList<QString>& settingsKeys, bool force) {
return new MsgConfigureMorseDecoder(settings, settingsKeys, force);
}
private:
MorseDecoderSettings m_settings;
QList<QString> m_settingsKeys;
bool m_force;
MsgConfigureMorseDecoder(const MorseDecoderSettings& settings, const QList<QString>& settingsKeys, bool force) :
Message(),
m_settings(settings),
m_settingsKeys(settingsKeys),
m_force(force)
{ }
};
class MsgStartStop : public Message {
MESSAGE_CLASS_DECLARATION
public:
bool getStartStop() const { return m_startStop; }
static MsgStartStop* create(bool startStop) {
return new MsgStartStop(startStop);
}
protected:
bool m_startStop;
MsgStartStop(bool startStop) :
Message(),
m_startStop(startStop)
{ }
};
class MsgReportChannels : public Message {
MESSAGE_CLASS_DECLARATION
public:
AvailableChannelOrFeatureList& getAvailableChannels() { return m_availableChannels; }
const QStringList& getRenameFrom() const { return m_renameFrom; }
const QStringList& getRenameTo() const { return m_renameTo; }
static MsgReportChannels* create(const QStringList& renameFrom, const QStringList& renameTo) {
return new MsgReportChannels(renameFrom, renameTo);
}
private:
AvailableChannelOrFeatureList m_availableChannels;
QStringList m_renameFrom;
QStringList m_renameTo;
MsgReportChannels(const QStringList& renameFrom, const QStringList& renameTo) :
Message(),
m_renameFrom(renameFrom),
m_renameTo(renameTo)
{}
};
class MsgSelectChannel : public Message {
MESSAGE_CLASS_DECLARATION
public:
ChannelAPI *getChannel() { return m_channel; }
static MsgSelectChannel* create(ChannelAPI *channel) {
return new MsgSelectChannel(channel);
}
protected:
ChannelAPI *m_channel;
MsgSelectChannel(ChannelAPI *channel) :
Message(),
m_channel(channel)
{ }
};
class MsgReportSampleRate : public Message {
MESSAGE_CLASS_DECLARATION
public:
int getSampleRate() const { return m_sampleRate; }
static MsgReportSampleRate* create(int sampleRate) {
return new MsgReportSampleRate(sampleRate);
}
private:
int m_sampleRate;
MsgReportSampleRate(int sampleRate) :
Message(),
m_sampleRate(sampleRate)
{}
};
class MsgReportText : public Message {
MESSAGE_CLASS_DECLARATION
public:
QString getText() const { return m_text; }
static MsgReportText* create(const QString& text) {
return new MsgReportText(text);
}
float m_estimatedPitchHz;
float m_estimatedSpeedWPM;
float m_signalThreshold;
float m_costFunction;
private:
QString m_text;
MsgReportText(const QString& text) :
m_text(text)
{}
};
MorseDecoder(WebAPIAdapterInterface *webAPIAdapterInterface);
virtual ~MorseDecoder();
virtual void destroy() { delete this; }
virtual bool handleMessage(const Message& cmd);
virtual void getIdentifier(QString& id) const { id = objectName(); }
virtual QString getIdentifier() const { return objectName(); }
virtual void getTitle(QString& title) const { title = m_settings.m_title; }
virtual QByteArray serialize() const;
virtual bool deserialize(const QByteArray& data);
virtual int webapiRun(bool run,
SWGSDRangel::SWGDeviceState& response,
QString& errorMessage);
virtual int webapiSettingsGet(
SWGSDRangel::SWGFeatureSettings& response,
QString& errorMessage);
virtual int webapiSettingsPutPatch(
bool force,
const QStringList& featureSettingsKeys,
SWGSDRangel::SWGFeatureSettings& response,
QString& errorMessage);
virtual int webapiActionsPost(
const QStringList& featureActionsKeys,
SWGSDRangel::SWGFeatureActions& query,
QString& errorMessage);
static void webapiFormatFeatureSettings(
SWGSDRangel::SWGFeatureSettings& response,
const MorseDecoderSettings& settings);
static void webapiUpdateFeatureSettings(
MorseDecoderSettings& settings,
const QStringList& featureSettingsKeys,
SWGSDRangel::SWGFeatureSettings& response);
ScopeVis *getScopeVis() { return &m_scopeVis; }
void getAvailableChannelsReport();
static const char* const m_featureIdURI;
static const char* const m_featureId;
private:
QThread *m_thread;
QRecursiveMutex m_mutex;
bool m_running;
MorseDecoderWorker *m_worker;
MorseDecoderSettings m_settings;
ScopeVis m_scopeVis;
AvailableChannelOrFeatureList m_availableChannels;
AvailableChannelOrFeatureHandler m_availableChannelOrFeatureHandler;
ChannelAPI *m_selectedChannel;
ObjectPipe *m_dataPipe;
int m_sampleRate;
QFile m_logFile;
QTextStream m_logStream;
QUdpSocket m_udpSocket;
QNetworkAccessManager *m_networkManager;
QNetworkRequest m_networkRequest;
void start();
void stop();
void applySettings(const MorseDecoderSettings& settings, const QList<QString>& settingsKeys, bool force = false);
void notifyUpdate(const QStringList& renameFrom, const QStringList& renameTo);
void setChannel(ChannelAPI *selectedChannel);
void webapiReverseSendSettings(const QList<QString>& featureSettingsKeys, const MorseDecoderSettings& settings, bool force);
private slots:
void networkManagerFinished(QNetworkReply *reply);
void handleChannelMessageQueue(MessageQueue *messageQueues);
void channelsOrFeaturesChanged(const QStringList& renameFrom, const QStringList& renameTo);
void handleDataPipeToBeDeleted(int reason, QObject *object);
};
#endif // INCLUDE_FEATURE_MORSEDECODER_H_