JS8Call-Improved master
Loading...
Searching...
No Matches
HRDTransceiver.h
1#ifndef HRD_TRANSCEIVER_HPP__
2#define HRD_TRANSCEIVER_HPP__
3
4#include "PollingTransceiver.h"
5#include "TransceiverFactory.h"
6
7#include <QScopedPointer>
8#include <QString>
9#include <QStringList>
10
11#include <memory>
12#include <tuple>
13#include <vector>
14
15class QRegularExpression;
16class QTcpSocket;
17class QByteArray;
18
19//
20// Ham Radio Deluxe Transceiver Interface
21//
22// Implemented as a Transceiver decorator because we may want the PTT
23// services of another Transceiver type such as the HamlibTransceiver
24// which can be enabled by wrapping a HamlibTransceiver instantiated
25// as a "Hamlib Dummy" transceiver in the Transceiver factory method.
26//
27class HRDTransceiver final : public PollingTransceiver {
28 public:
29 static void register_transceivers(TransceiverFactory::Transceivers *,
30 int id);
31
32 // takes ownership of wrapped Transceiver
33 explicit HRDTransceiver(std::unique_ptr<TransceiverBase> wrapped,
34 QString const &server, bool use_for_ptt,
35 TransceiverFactory::TXAudioSource,
36 int poll_interval, QObject *parent = nullptr);
37
38 protected:
39 // Implement the TransceiverBase interface.
40 int do_start() override;
41 void do_stop() override;
42 void do_frequency(Frequency, MODE, bool no_ignore) override;
43 void do_tx_frequency(Frequency, MODE, bool no_ignore) override;
44 void do_mode(MODE) override;
45 void do_ptt(bool on) override;
46
47 // Implement the PollingTransceiver interface.
48 void poll() override;
49
50 private:
51 QString send_command(QString const &, bool no_debug = false,
52 bool prepend_context = true, bool recurse = false);
53 QByteArray read_reply(QString const &command);
54 void send_simple_command(QString const &, bool no_debug = false);
55 bool write_to_port(char const *, qint64 length);
56 int find_button(QRegularExpression const &) const;
57 int find_dropdown(QRegularExpression const &) const;
58 std::vector<int> find_dropdown_selection(int dropdown,
59 QRegularExpression const &) const;
60 int get_dropdown(int, bool no_debug = false);
61 void set_dropdown(int, int);
62 void set_button(int button_index, bool checked = true);
63 bool is_button_checked(int button_index, bool no_debug = false);
64
65 // This dictionary type maps Transceiver::MODE to a list of mode
66 // drop down selection indexes that equate to that mode. It is used
67 // to map internal MODE values to HRD drop down selections and vice
68 // versa.
69 using ModeMap = std::vector<std::tuple<MODE, std::vector<int>>>;
70
71 void map_modes(int dropdown, ModeMap *);
72 int lookup_mode(MODE, ModeMap const &) const;
73 MODE lookup_mode(int, ModeMap const &) const;
74 void set_data_mode(MODE);
75 MODE get_data_mode(MODE, bool no_debug = false);
76
77 // An alternate TransceiverBase instance that can be used to drive
78 // PTT if required.
79 std::unique_ptr<TransceiverBase> wrapped_; // may be null
80
81 bool use_for_ptt_; // Use HRD for PTT.
82 TransceiverFactory::TXAudioSource audio_source_; // Select rear/data
83 // audio if available
84
85 QString server_; // The TCP/IP addrress and port for
86 // the HRD server.
87
88 QTcpSocket *hrd_; // The TCP/IP client that links to the
89 // HRD server.
90
91 enum {
92 none,
93 v4,
94 v5
95 } protocol_; // The HRD protocol that has been
96 // detected.
97
98 using RadioMap = std::vector<std::tuple<unsigned, QString>>;
99
100 RadioMap radios_; // Dictionary of available radios.
101
102 unsigned current_radio_; // The current addressed radio.
103
104 unsigned vfo_count_; // How many VFOs are supported.
105
106 QStringList buttons_; // The buttons available to click.
107
108 QStringList dropdown_names_; // The names of drop down selectors
109 // available.
110
111 QMap<QString, QStringList> dropdowns_; // Dictionary of available
112 // drop down selections.
113
114 QStringList slider_names_; // The name of available sliders.
115
116 QMap<QString, QStringList> sliders_; // Dictionary of available
117 // slider ranges.
118
119 int vfo_A_button_; // The button we use to select VFO
120 // A. May be -1 if none available.
121
122 int vfo_B_button_; // Index of button we use to select
123 // VFO B. May be -1 if none available.
124
125 int vfo_toggle_button_; // Index of button we use to toggle
126 // the VFOs. Use this if VFO A and VFO
127 // B selection are not available.
128
129 int mode_A_dropdown_; // Index of the mode drop down for VFO
130 // A.
131
132 ModeMap mode_A_map_; // The map of modes available for VFO
133 // A.
134
135 int mode_B_dropdown_; // The drop down index for VFO B mode
136 // setting. May be -1 if independent
137 // VFO mode setting not available.
138
139 ModeMap mode_B_map_; // The map of modes for VFO B.
140
141 int data_mode_toggle_button_; // Button to toggle DATA mode
142 int data_mode_on_button_; // Button to enable DATA mode
143 int data_mode_off_button_; // Button to disable DATA mode
144 int data_mode_dropdown_; // Index of data mode drop down, may
145 // be -1 if no such drop down exists
146 std::vector<int>
147 data_mode_dropdown_selection_on_; // The drop down
148 // selection to turn on data mode.
149
150 std::vector<int> data_mode_dropdown_selection_off_; // The drop
151 // down selection to
152 // disable data mode.
153
154 int split_mode_button_; // Button to use to select split
155 // operation. May be -1 if no button
156 // is available.
157
158 int split_mode_dropdown_; // The drop down index that allows
159 // split mode to be turned on and
160 // off. May be -1 if no such drop down
161 // exists.
162
163 bool split_mode_dropdown_write_only_; // Some rigs cannot report
164 // split status.
165
166 std::vector<int> split_mode_dropdown_selection_on_; // The drop down
167 // selection to
168 // turn on
169 // split.
170
171 std::vector<int> split_mode_dropdown_selection_off_; // The drop
172 // down
173 // selection to
174 // disable
175 // split.
176
177 int split_off_button_; // The button to turn off split mode.
178
179 int tx_A_button_; // The button to transmit on VFO A.
180
181 int tx_B_button_; // The button to transmit on VFO B.
182
183 int rx_A_button_; // The button to receive on VFO A
184 // A. May be -1 if none available.
185
186 int rx_B_button_; // The button to receive on VFO B
187 // May be -1 if none available.
188
189 int receiver_dropdown_; // Select receiver
190
191 std::vector<int> rx_A_selection_;
192
193 std::vector<int> rx_B_selection_;
194
195 int ptt_button_; // The button to toggle PTT.
196 int alt_ptt_button_; // The alternative button to toggle
197 // PTT - used to select rear audio.
198
199 bool reversed_; // True if VFOs are reversed.
200};
201
202#endif