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