SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
cwkeyer.h
Go to the documentation of this file.
1 // Copyright (C) 2016 F4EXB //
3 // written by Edouard Griffiths //
4 // //
5 // This program is free software; you can redistribute it and/or modify //
6 // it under the terms of the GNU General Public License as published by //
7 // the Free Software Foundation as version 3 of the License, or //
8 // (at your option) any later version. //
9 // //
10 // This program is distributed in the hope that it will be useful, //
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
13 // GNU General Public License V3 for more details. //
14 // //
15 // You should have received a copy of the GNU General Public License //
16 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
18 
19 #ifndef SDRBASE_DSP_CWKEYER_H_
20 #define SDRBASE_DSP_CWKEYER_H_
21 
22 #include <QObject>
23 #include <QMutex>
24 
25 #include "export.h"
26 #include "util/message.h"
27 #include "util/messagequeue.h"
28 #include "cwkeyersettings.h"
29 #include "SWGChannelSettings.h"
30 
35 {
36 public:
37  CWSmoother();
38  ~CWSmoother();
39 
40  void setNbFadeSamples(unsigned int nbFadeSamples);
41  bool getFadeSample(bool on, float& sample);
42 
43 private:
44  QMutex m_mutex;
45  unsigned int m_fadeInCounter;
46  unsigned int m_fadeOutCounter;
47  unsigned int m_nbFadeSamples;
50 };
51 
52 class SDRBASE_API CWKeyer : public QObject {
53  Q_OBJECT
54 
55 public:
58 
59  public:
60  const CWKeyerSettings& getSettings() const { return m_settings; }
61  bool getForce() const { return m_force; }
62 
63  static MsgConfigureCWKeyer* create(const CWKeyerSettings& settings, bool force)
64  {
65  return new MsgConfigureCWKeyer(settings, force);
66  }
67 
68  private:
70  bool m_force;
71 
72  MsgConfigureCWKeyer(const CWKeyerSettings& settings, bool force) :
73  Message(),
74  m_settings(settings),
75  m_force(force)
76  { }
77  };
78 
80  {
83  KeyDash
84  };
85 
87  {
95  TextStop
96  };
97 
98  CWKeyer();
99  ~CWKeyer();
100 
101  void resetToDefaults();
102  QByteArray serialize() const;
103  bool deserialize(const QByteArray& data);
104  MessageQueue *getInputMessageQueue() { return &m_inputMessageQueue; }
105 
106  void setSampleRate(int sampleRate);
107  const CWKeyerSettings& getSettings() const { return m_settings; }
108 
109  void reset() { m_keyIambicState = KeySilent; }
110 
111  CWSmoother& getCWSmoother() { return m_cwSmoother; }
112  int getSample();
113  bool eom();
114  void resetText() { m_textState = TextStart; }
115  void stopText() { m_textState = TextStop; }
116  void setKeyboardDots();
117  void setKeyboardDashes();
118  void setKeyboardSilence();
119 
120  static void webapiSettingsPutPatch(
121  const QStringList& channelSettingsKeys,
122  CWKeyerSettings& cwKeyerSettings,
123  SWGSDRangel::SWGCWKeyerSettings *apiCwKeyerSettings
124  );
125 
126  static void webapiFormatChannelSettings(
127  SWGSDRangel::SWGCWKeyerSettings *apiCwKeyerSettings,
128  const CWKeyerSettings& cwKeyerSettings
129  );
130 
131 private:
132  QMutex m_mutex;
141  bool m_key;
142  bool m_dot;
143  bool m_dash;
145  signed char m_asciiChar;
149 
150  static const signed char m_asciiToMorse[128][7];
151 
152  void applySettings(const CWKeyerSettings& settings, bool force = false);
153  bool handleMessage(const Message& cmd);
154  void nextStateIambic();
155  void nextStateText();
156 
157 private slots:
158  void handleInputMessages();
159 };
160 
161 #endif /* SDRBASE_DSP_CWKEYER_H_ */
CWTextState
Definition: cwkeyer.h:86
void resetText()
Definition: cwkeyer.h:114
MsgConfigureCWKeyer(const CWKeyerSettings &settings, bool force)
Definition: cwkeyer.h:72
bool m_dash
Definition: cwkeyer.h:143
signed char m_asciiChar
Definition: cwkeyer.h:145
static MsgConfigureCWKeyer * create(const CWKeyerSettings &settings, bool force)
Definition: cwkeyer.h:63
bool m_key
Definition: cwkeyer.h:141
bool m_elementSpace
Definition: cwkeyer.h:139
CWKeyerSettings m_settings
Definition: cwkeyer.h:69
int m_elementPointer
Definition: cwkeyer.h:137
MessageQueue * getInputMessageQueue()
Get the queue for asynchronous inbound communication.
Definition: cwkeyer.h:104
bool m_characterSpace
Definition: cwkeyer.h:140
QMutex m_mutex
Definition: cwkeyer.h:44
int m_samplePointer
Definition: cwkeyer.h:138
#define MESSAGE_CLASS_DECLARATION
Definition: message.h:43
CWSmoother & getCWSmoother()
Definition: cwkeyer.h:111
int m_dotLength
dot length in samples
Definition: cwkeyer.h:135
QMutex m_mutex
Definition: cwkeyer.h:132
bool m_elementOn
Definition: cwkeyer.h:144
float * m_fadeOutSamples
Definition: cwkeyer.h:49
CWTextState m_textState
Definition: cwkeyer.h:147
MessageQueue m_inputMessageQueue
Definition: cwkeyer.h:134
unsigned int m_nbFadeSamples
Definition: cwkeyer.h:47
CWKeyIambicState m_keyIambicState
Definition: cwkeyer.h:146
unsigned int m_fadeInCounter
Definition: cwkeyer.h:45
bool m_dot
Definition: cwkeyer.h:142
CWSmoother m_cwSmoother
Definition: cwkeyer.h:148
CWKeyIambicState
Definition: cwkeyer.h:79
CWKeyerSettings m_settings
Definition: cwkeyer.h:133
void reset()
Definition: cwkeyer.h:109
#define SDRBASE_API
Definition: export.h:40
const CWKeyerSettings & getSettings() const
Definition: cwkeyer.h:107
void stopText()
Definition: cwkeyer.h:115
unsigned int m_fadeOutCounter
Definition: cwkeyer.h:46
int m_textPointer
Definition: cwkeyer.h:136
const CWKeyerSettings & getSettings() const
Definition: cwkeyer.h:60
float * m_fadeInSamples
Definition: cwkeyer.h:48