JS8Call-Improved master
Loading...
Searching...
No Matches
TransceiverFactory.h
1#ifndef TRANSCEIVER_FACTORY_HPP__
2#define TRANSCEIVER_FACTORY_HPP__
3
4#include "JS8_Main/qt_helpers.h"
5#include "Transceiver.h"
6
7#include <QMap>
8#include <QObject>
9
10#include <memory>
11
12class QString;
13class QThread;
14class QDir;
15
16//
17// Transceiver Factory
18//
19class TransceiverFactory : public QObject {
20 Q_OBJECT
21 Q_ENUMS(DataBits StopBits Handshake PTTMethod TXAudioSource SplitMode)
22
23 public:
24 //
25 // Capabilities of a Transceiver that can be determined without
26 // actually instantiating one, these are for use in Configuration
27 // GUI behaviour determination
28 //
29 struct Capabilities {
30 enum PortType { none, serial, network, usb };
31
32 explicit Capabilities(int model_number = 0, PortType port_type = none,
33 bool has_CAT_PTT = false,
34 bool has_CAT_PTT_mic_data = false,
35 bool has_CAT_indirect_serial_PTT = false,
36 bool asynchronous = false)
37 : model_number_{model_number}, port_type_{port_type},
38 has_CAT_PTT_{has_CAT_PTT},
39 has_CAT_PTT_mic_data_{has_CAT_PTT_mic_data},
40 has_CAT_indirect_serial_PTT_{has_CAT_indirect_serial_PTT},
41 asynchronous_{asynchronous} {}
42
43 int model_number_;
44 PortType port_type_;
45 bool has_CAT_PTT_;
46 bool has_CAT_PTT_mic_data_;
47 bool has_CAT_indirect_serial_PTT_; // OmniRig controls RTS/DTR via COM
48 // interface
49 bool asynchronous_;
50 };
51
52 //
53 // Dictionary of Transceiver types Capabilities
54 //
55 typedef QMap<QString, Capabilities> Transceivers;
56
57 //
58 // various Transceiver parameters
59 //
60 enum DataBits { seven_data_bits = 7, eight_data_bits, default_data_bits };
61 Q_ENUM(DataBits)
62 enum StopBits { one_stop_bit = 1, two_stop_bits, default_stop_bits };
63 Q_ENUM(StopBits)
64 enum Handshake {
65 handshake_default,
66 handshake_none,
67 handshake_XonXoff,
68 handshake_hardware
69 };
70 Q_ENUM(Handshake)
71 enum PTTMethod {
72 PTT_method_VOX,
73 PTT_method_CAT,
74 PTT_method_DTR,
75 PTT_method_RTS
76 };
77 Q_ENUM(PTTMethod)
78 enum TXAudioSource { TX_audio_source_front, TX_audio_source_rear };
79 Q_ENUM(TXAudioSource)
80 enum SplitMode { split_mode_none, split_mode_rig, split_mode_emulate };
81 Q_ENUM(SplitMode)
82
83 TransceiverFactory();
84 ~TransceiverFactory();
85
86 static char const
87 *const basic_transceiver_name_; // dummy transceiver is basic model
88
89 //
90 // fetch all supported rigs as a list of name and model id
91 //
92 Transceivers const &supported_transceivers() const;
93
94 // supported model queries
95 Capabilities::PortType
96 CAT_port_type(QString const &name) const; // how to talk to CAT
97 bool has_CAT_PTT(QString const &name) const; // can be keyed via CAT
98 bool has_CAT_PTT_mic_data(
99 QString const &name) const; // Tx audio port is switchable via CAT
100 bool has_CAT_indirect_serial_PTT(QString const &name)
101 const; // Can PTT via CAT port use DTR or RTS (OmniRig for example)
102 bool has_asynchronous_CAT(
103 QString const &name) const; // CAT asynchronous rather than polled
104
106 QString rig_name; // from supported_transceivers () key
107 QString serial_port; // serial port device name or empty
108 QString network_port; // hostname:port or empty
109 QString usb_port; // [vid[:pid[:vendor[:product]]]]
110 int baud;
111 DataBits data_bits;
112 StopBits stop_bits;
113 Handshake handshake;
114 bool force_dtr;
115 bool dtr_high; // to power interface
116 bool force_rts;
117 bool rts_high; // to power interface
118 PTTMethod ptt_type; // "CAT" | "DTR" | "RTS" | "VOX"
119 TXAudioSource audio_source; // some rigs allow audio routing
120 // to Mic/Data connector
121 SplitMode split_mode; // how to support split TX mode
122 QString ptt_port; // serial port device name or special
123 // value "CAT"
124 int poll_interval; // in seconds for interfaces that
125 // require polling for state changes
126
127 bool operator==(ParameterPack const &rhs) const {
128 return rhs.rig_name == rig_name && rhs.serial_port == serial_port &&
129 rhs.network_port == network_port &&
130 rhs.usb_port == usb_port && rhs.baud == baud &&
131 rhs.data_bits == data_bits && rhs.stop_bits == stop_bits &&
132 rhs.handshake == handshake && rhs.force_dtr == force_dtr &&
133 rhs.dtr_high == dtr_high && rhs.force_rts == force_rts &&
134 rhs.rts_high == rts_high && rhs.ptt_type == ptt_type &&
135 rhs.audio_source == audio_source &&
136 rhs.split_mode == split_mode && rhs.ptt_port == ptt_port &&
137 rhs.poll_interval == poll_interval;
138 }
139 };
140
141 // make a new Transceiver instance
142 //
143 // cat_port, cat_baud, cat_data_bits, cat_stop_bits, cat_handshake,
144 // cat_dtr_control, cat_rts_control are only relevant to interfaces
145 // that are served by Hamlib
146 //
147 // PTT port and to some extent ptt_type are independent of interface
148 // type
149 //
150 std::unique_ptr<Transceiver> create(ParameterPack const &,
151 QThread *target_thread = nullptr);
152
153 private:
154 Transceivers transceivers_;
155};
156
157inline bool operator!=(TransceiverFactory::ParameterPack const &lhs,
159 return !(lhs == rhs);
160}
161
162//
163// boilerplate routines to make enum types useable and debuggable in
164// Qt
165//
166#if QT_VERSION < 0x050500
167Q_DECLARE_METATYPE(TransceiverFactory::DataBits);
168Q_DECLARE_METATYPE(TransceiverFactory::StopBits);
169Q_DECLARE_METATYPE(TransceiverFactory::Handshake);
170Q_DECLARE_METATYPE(TransceiverFactory::PTTMethod);
171Q_DECLARE_METATYPE(TransceiverFactory::TXAudioSource);
172Q_DECLARE_METATYPE(TransceiverFactory::SplitMode);
173#endif
174
175#if !defined(QT_NO_DEBUG_STREAM)
176ENUM_QDEBUG_OPS_DECL(TransceiverFactory, DataBits);
177ENUM_QDEBUG_OPS_DECL(TransceiverFactory, StopBits);
178ENUM_QDEBUG_OPS_DECL(TransceiverFactory, Handshake);
179ENUM_QDEBUG_OPS_DECL(TransceiverFactory, PTTMethod);
180ENUM_QDEBUG_OPS_DECL(TransceiverFactory, TXAudioSource);
181ENUM_QDEBUG_OPS_DECL(TransceiverFactory, SplitMode);
182#endif
183
184ENUM_QDATASTREAM_OPS_DECL(TransceiverFactory, DataBits);
185ENUM_QDATASTREAM_OPS_DECL(TransceiverFactory, StopBits);
186ENUM_QDATASTREAM_OPS_DECL(TransceiverFactory, Handshake);
187ENUM_QDATASTREAM_OPS_DECL(TransceiverFactory, PTTMethod);
188ENUM_QDATASTREAM_OPS_DECL(TransceiverFactory, TXAudioSource);
189ENUM_QDATASTREAM_OPS_DECL(TransceiverFactory, SplitMode);
190
191ENUM_CONVERSION_OPS_DECL(TransceiverFactory, DataBits);
192ENUM_CONVERSION_OPS_DECL(TransceiverFactory, StopBits);
193ENUM_CONVERSION_OPS_DECL(TransceiverFactory, Handshake);
194ENUM_CONVERSION_OPS_DECL(TransceiverFactory, PTTMethod);
195ENUM_CONVERSION_OPS_DECL(TransceiverFactory, TXAudioSource);
196ENUM_CONVERSION_OPS_DECL(TransceiverFactory, SplitMode);
197
198#endif
Definition TransceiverFactory.h:19
Definition TransceiverFactory.h:105