JS8Call-Improved master
Loading...
Searching...
No Matches
Transceiver.h
1#ifndef TRANSCEIVER_HPP__
2#define TRANSCEIVER_HPP__
3
4#include "JS8_Main/Radio.h"
5#include "JS8_Main/qt_helpers.h"
6
7#include <QObject>
8
9class QString;
10
11//
12// Abstract Transceiver Interface
13//
14// This is the minimal generic interface to a rig.
15//
16// Responsibilities
17//
18// Provides a Qt slot to set the frequency, mode and PTT of some
19// transceiver. This is a Qt slot so that it may be invoked across a
20// thread boundary.
21//
22// Provides a synchronisation Qt slot which should be implemented in
23// sub-classes in such a way that normal operation of the rig is not
24// disturbed. This is intended to be use to poll rig state
25// periodically and changing VFO to read the other VFO frequency or
26// mode for example should not be done since the operator may be
27// tuning the VFO at the time and would be surprised by an unprompted
28// VFO change.
29//
30// Provides a control interface using Qt slots to start and stop the
31// rig control and PTT connections.
32//
33// These are Qt slots rather than the constructor and destructor
34// because it is expected that the concrete Transceiver
35// implementations will run in a separate thread from where they are
36// constructed.
37//
38// Qt signals are defined to notify clients of asynchronous rig state
39// changes and failures. These can and are expected to cross thread
40// boundaries.
41//
42// A signal finished() is defined that concrete Transceiver
43// implementations must emit when they are ripe for destruction. This
44// is intended to be used by clients that move the Transceiver
45// instance to a thread and need to use QObject::deleteLater() to
46// safely dispose of the Transceiver instance. Implementations should
47// expect Qt slot calls after emitting finished, it is up to the
48// implementation whether these slot invocations are ignored.
49//
50class Transceiver : public QObject {
51 Q_OBJECT
52
53 public:
54 using Frequency = Radio::Frequency;
55
56 protected:
57 Transceiver(QObject *parent) : QObject{parent} {}
58
59 public:
60 virtual ~Transceiver() {}
61
62 enum MODE {
63 UNK,
64 CW,
65 CW_R,
66 USB,
67 LSB,
68 FSK,
69 FSK_R,
70 DIG_U,
71 DIG_L,
72 AM,
73 FM,
74 DIG_FM
75 };
76 Q_ENUM(MODE)
77
78 //
79 // Aggregation of all of the rig and PTT state accessible via this
80 // interface.
81 //
82 class TransceiverState {
83 public:
84 TransceiverState()
85 : online_{false}, rx_frequency_{0}, tx_frequency_{0}, mode_{UNK},
86 split_{Split::unknown}, ptt_{false} {}
87
88 bool online() const { return online_; }
89 Frequency frequency() const { return rx_frequency_; }
90 Frequency tx_frequency() const { return tx_frequency_; }
91 bool split() const { return Split::on == split_; }
92 MODE mode() const { return mode_; }
93 bool ptt() const { return ptt_; }
94
95 void online(bool state) { online_ = state; }
96 void frequency(Frequency f) { rx_frequency_ = f; }
97 void tx_frequency(Frequency f) { tx_frequency_ = f; }
98 void split(bool state) { split_ = state ? Split::on : Split::off; }
99 void mode(MODE m) { mode_ = m; }
100 void ptt(bool state) { ptt_ = state; }
101
102 private:
103 bool online_;
104 Frequency rx_frequency_;
105 Frequency tx_frequency_; // 0 means use Rx
106 MODE mode_;
107 enum class Split { unknown, off, on } split_;
108 bool ptt_;
109 // Don't forget to update the debug print and != operator if you
110 // add more members here
111
112 friend QDebug operator<<(QDebug, TransceiverState const &);
113 friend bool operator!=(TransceiverState const &,
114 TransceiverState const &);
115 };
116
117 //
118 // The following slots and signals are expected to all run in the
119 // same thread which is not necessarily the main GUI thread. It is
120 // up to the client of the Transceiver class to organise the
121 // allocation to a thread and the lifetime of the object instances.
122 //
123
124 // Apply state changes to the rig. The sequence_number parameter
125 // will be included in any status updates generated after this
126 // transaction is processed. The sequence number may be used to
127 // ignore any status updates until the results of this transaction
128 // have been processed thus avoiding any unwanted "ping-pong" due to
129 // signals crossing in transit.
130 Q_SLOT virtual void set(Transceiver::TransceiverState const &,
131 unsigned sequence_number) noexcept = 0;
132
133 // Connect and disconnect.
134 Q_SLOT virtual void start(unsigned sequence_number) noexcept = 0;
135 Q_SLOT virtual void stop() noexcept = 0;
136
137 //
138 // asynchronous status updates
139 //
140
141 // 0 - 1Hz
142 // 1 - 10Hz rounded
143 // -1 - 10Hz truncated
144 // 2 - 100Hz rounded
145 // -2 - 100Hz truncated
146 Q_SIGNAL void resolution(int);
147
148 // rig state changed
149 Q_SIGNAL void update(Transceiver::TransceiverState const &,
150 unsigned sequence_number) const;
151
152 // something went wrong - not recoverable, start new instance
153 Q_SIGNAL void failure(QString const &reason) const;
154
155 // Ready to be destroyed.
156 Q_SIGNAL void finished() const;
157};
158
159Q_DECLARE_METATYPE(Transceiver::TransceiverState);
160
161#if !defined(QT_NO_DEBUG_STREAM)
162ENUM_QDEBUG_OPS_DECL(Transceiver, MODE);
163
164QDebug operator<<(QDebug, Transceiver::TransceiverState const &);
165#endif
166
167ENUM_QDATASTREAM_OPS_DECL(Transceiver, MODE);
168ENUM_CONVERSION_OPS_DECL(Transceiver, MODE);
169
170bool operator!=(Transceiver::TransceiverState const &,
172bool operator==(Transceiver::TransceiverState const &,
174
175#endif
Definition Transceiver.h:82