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_;
48 bool asynchronous_;
49 };
50
51 //
52 // Dictionary of Transceiver types Capabilities
53 //
54 typedef QMap<QString, Capabilities> Transceivers;
55
56 //
57 // various Transceiver parameters
58 //
59 enum DataBits { seven_data_bits = 7, eight_data_bits, default_data_bits };
60 Q_ENUM(DataBits)
61 enum StopBits { one_stop_bit = 1, two_stop_bits, default_stop_bits };
62 Q_ENUM(StopBits)
63 enum Handshake {
64 handshake_default,
65 handshake_none,
66 handshake_XonXoff,
67 handshake_hardware
68 };
69 Q_ENUM(Handshake)
70 enum PTTMethod {
71 PTT_method_VOX,
72 PTT_method_CAT,
73 PTT_method_DTR,
74 PTT_method_RTS
75 };
76 Q_ENUM(PTTMethod)
77 enum TXAudioSource { TX_audio_source_front, TX_audio_source_rear };
78 Q_ENUM(TXAudioSource)
79 enum SplitMode { split_mode_none, split_mode_rig, split_mode_emulate };
80 Q_ENUM(SplitMode)
81
82 TransceiverFactory();
83 ~TransceiverFactory();
84
85 static char const
86 *const basic_transceiver_name_; // dummy transceiver is basic model
87
88 //
89 // fetch all supported rigs as a list of name and model id
90 //
91 Transceivers const &supported_transceivers() const;
92
93 // supported model queries
94 Capabilities::PortType
95 CAT_port_type(QString const &name) const; // how to talk to CAT
96 bool has_CAT_PTT(QString const &name) const; // can be keyed via CAT
97 bool has_CAT_PTT_mic_data(
98 QString const &name) const; // Tx audio port is switchable via CAT
99 bool has_CAT_indirect_serial_PTT(QString const &name)
100 const; // Can PTT via CAT port use DTR or RTS
101 bool has_asynchronous_CAT(
102 QString const &name) const; // CAT asynchronous rather than polled
103
105 QString rig_name; // from supported_transceivers () key
106 QString serial_port; // serial port device name or empty
107 QString network_port; // hostname:port or empty
108 QString usb_port; // [vid[:pid[:vendor[:product]]]]
109 int baud;
110 DataBits data_bits;
111 StopBits stop_bits;
112 Handshake handshake;
113 bool force_dtr;
114 bool dtr_high; // to power interface
115 bool force_rts;
116 bool rts_high; // to power interface
117 PTTMethod ptt_type; // "CAT" | "DTR" | "RTS" | "VOX"
118 TXAudioSource audio_source; // some rigs allow audio routing
119 // to Mic/Data connector
120 SplitMode split_mode; // how to support split TX mode
121 QString ptt_port; // serial port device name or special
122 // value "CAT"
123 int poll_interval; // in seconds for interfaces that
124 // require polling for state changes
125
126 bool operator==(ParameterPack const &rhs) const {
127 return rhs.rig_name == rig_name && rhs.serial_port == serial_port &&
128 rhs.network_port == network_port &&
129 rhs.usb_port == usb_port && rhs.baud == baud &&
130 rhs.data_bits == data_bits && rhs.stop_bits == stop_bits &&
131 rhs.handshake == handshake && rhs.force_dtr == force_dtr &&
132 rhs.dtr_high == dtr_high && rhs.force_rts == force_rts &&
133 rhs.rts_high == rts_high && rhs.ptt_type == ptt_type &&
134 rhs.audio_source == audio_source &&
135 rhs.split_mode == split_mode && rhs.ptt_port == ptt_port &&
136 rhs.poll_interval == poll_interval;
137 }
138 };
139
140 // make a new Transceiver instance
141 //
142 // cat_port, cat_baud, cat_data_bits, cat_stop_bits, cat_handshake,
143 // cat_dtr_control, cat_rts_control are only relevant to interfaces
144 // that are served by Hamlib
145 //
146 // PTT port and to some extent ptt_type are independent of interface
147 // type
148 //
149 std::unique_ptr<Transceiver> create(ParameterPack const &,
150 QThread *target_thread = nullptr);
151
152 private:
153 Transceivers transceivers_;
154};
155
156inline bool operator!=(TransceiverFactory::ParameterPack const &lhs,
158 return !(lhs == rhs);
159}
160
161//
162// boilerplate routines to make enum types useable and debuggable in
163// Qt
164//
165#if !defined(QT_NO_DEBUG_STREAM)
166ENUM_QDEBUG_OPS_DECL(TransceiverFactory, DataBits);
167ENUM_QDEBUG_OPS_DECL(TransceiverFactory, StopBits);
168ENUM_QDEBUG_OPS_DECL(TransceiverFactory, Handshake);
169ENUM_QDEBUG_OPS_DECL(TransceiverFactory, PTTMethod);
170ENUM_QDEBUG_OPS_DECL(TransceiverFactory, TXAudioSource);
171ENUM_QDEBUG_OPS_DECL(TransceiverFactory, SplitMode);
172#endif
173
174ENUM_QDATASTREAM_OPS_DECL(TransceiverFactory, DataBits);
175ENUM_QDATASTREAM_OPS_DECL(TransceiverFactory, StopBits);
176ENUM_QDATASTREAM_OPS_DECL(TransceiverFactory, Handshake);
177ENUM_QDATASTREAM_OPS_DECL(TransceiverFactory, PTTMethod);
178ENUM_QDATASTREAM_OPS_DECL(TransceiverFactory, TXAudioSource);
179ENUM_QDATASTREAM_OPS_DECL(TransceiverFactory, SplitMode);
180
181ENUM_CONVERSION_OPS_DECL(TransceiverFactory, DataBits);
182ENUM_CONVERSION_OPS_DECL(TransceiverFactory, StopBits);
183ENUM_CONVERSION_OPS_DECL(TransceiverFactory, Handshake);
184ENUM_CONVERSION_OPS_DECL(TransceiverFactory, PTTMethod);
185ENUM_CONVERSION_OPS_DECL(TransceiverFactory, TXAudioSource);
186ENUM_CONVERSION_OPS_DECL(TransceiverFactory, SplitMode);
187
188#endif
Definition TransceiverFactory.h:19
Definition TransceiverFactory.h:104