1 /*
2 * Hamlib Kenwood backend - main header
3 * Copyright (c) 2000-2011 by Stephane Fillod
4 * Copyright (C) 2009,2010 Alessandro Zummo <a.zummo@towertech.it>
5 * Copyright (C) 2009,2010,2011,2012,2013 by Nate Bargmann, n0nb@n0nb.us
6 *
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 *
22 */
23
24 #ifndef _KENWOOD_H
25 #define _KENWOOD_H 1
26
27 #include <string.h>
28 #include "token.h"
29 #include "misc.h"
30
31 #define BACKEND_VER "20210911"
32
33 #define EOM_KEN ';'
34 #define EOM_TH '\r'
35
36 #define KENWOOD_MODE_TABLE_MAX 24
37 #define KENWOOD_MAX_BUF_LEN 128 /* max answer len, arbitrary */
38
39
40 /* Tokens for Parameters common to multiple rigs.
41 * Use token # >= 1 or <= 100. Defined here so they will be
42 * available in Kenwood name space.
43 */
44 #define TOK_VOICE TOKEN_BACKEND(1)
45 #define TOK_FINE TOKEN_BACKEND(2)
46 #define TOK_XIT TOKEN_BACKEND(3)
47 #define TOK_RIT TOKEN_BACKEND(4)
48 #define TOK_NO_ID TOKEN_BACKEND(5)
49
50 #define TOK_FUNC_FILTER_WIDTH_DATA TOKEN_BACKEND(6) // Data communications mode that affects SL/SH/FW commands
51
52 /* Token structure assigned to .cfgparams in rig_caps */
53 extern struct confparams kenwood_cfg_params[];
54
55
56 /*
57 * modes in use by the "MD" command
58 */
59 #define MD_NONE '0'
60 #define MD_LSB '1'
61 #define MD_USB '2'
62 #define MD_CW '3'
63 #define MD_FM '4'
64 #define MD_AM '5'
65 #define MD_FSK '6'
66 #define MD_CWR '7'
67 #define MD_FSKR '9'
68
69 /* S-meter calibration tables */
70 /* This one for the TS590 no doubt applies elsewhere */
71 #define TS590_SM_CAL { 10, \
72 { \
73 { 0, -54 }, \
74 { 3, -48 }, \
75 { 6, -36 }, \
76 { 9, -24 }, \
77 { 12, -12 }, \
78 { 15, 0 }, \
79 { 20, 20 }, \
80 { 25, 40 }, \
81 { 30, 60 }, \
82 } }
83
84 #define RIG_IS_HPSDR (rig->caps->rig_model == RIG_MODEL_HPSDR)
85 #define RIG_IS_K2 (rig->caps->rig_model == RIG_MODEL_K2)
86 #define RIG_IS_K3 (rig->caps->rig_model == RIG_MODEL_K3)
87 #define RIG_IS_K3S (rig->caps->rig_model == RIG_MODEL_K3S)
88 #define RIG_IS_KX2 (rig->caps->rig_model == RIG_MODEL_KX2)
89 #define RIG_IS_KX3 (rig->caps->rig_model == RIG_MODEL_KX3)
90 #define RIG_IS_THD7A (rig->caps->rig_model == RIG_MODEL_THD7A)
91 #define RIG_IS_THD74 (rig->caps->rig_model == RIG_MODEL_THD74)
92 #define RIG_IS_TS2000 (rig->caps->rig_model == RIG_MODEL_TS2000)
93 #define RIG_IS_TS50 (rig->caps->rig_model == RIG_MODEL_TS50)
94 #define RIG_IS_TS450S (rig->caps->rig_model == RIG_MODEL_TS450S)
95 #define RIG_IS_TS480 (rig->caps->rig_model == RIG_MODEL_TS480)
96 #define RIG_IS_TS590S (rig->caps->rig_model == RIG_MODEL_TS590S)
97 #define RIG_IS_TS590SG (rig->caps->rig_model == RIG_MODEL_TS590SG)
98 #define RIG_IS_TS690S (rig->caps->rig_model == RIG_MODEL_TS690S)
99 #define RIG_IS_TS790 (rig->caps->rig_model == RIG_MODEL_TS790)
100 #define RIG_IS_TS850 (rig->caps->rig_model == RIG_MODEL_TS850)
101 #define RIG_IS_TS890S (rig->caps->rig_model == RIG_MODEL_TS890S)
102 #define RIG_IS_TS940 (rig->caps->rig_model == RIG_MODEL_TS940)
103 #define RIG_IS_TS950SDX (rig->caps->rig_model == RIG_MODEL_TS950SDX)
104 #define RIG_IS_TS950S (rig->caps->rig_model == RIG_MODEL_TS950S)
105 #define RIG_IS_TS990S (rig->caps->rig_model == RIG_MODEL_TS990S)
106 #define RIG_IS_XG3 (rig->caps->rig_model == RIG_MODEL_XG3)
107 #define RIG_IS_PT8000A (rig->caps->rig_model == RIG_MODEL_PT8000A)
108 #define RIG_IS_POWERSDR (rig->caps->rig_model == RIG_MODEL_POWERSDR)
109 #define RIG_IS_MALACHITE (rig->caps->rig_model == RIG_MODEL_MALACHITE)
110
111 struct kenwood_filter_width
112 {
113 rmode_t modes;
114 int value;
115 pbwidth_t width_hz;
116 };
117
118 struct kenwood_slope_filter
119 {
120 rmode_t modes;
121 int data_mode_filter;
122 int value;
123 pbwidth_t frequency_hz;
124 };
125
126 struct kenwood_priv_caps
127 {
128 char cmdtrm; /* Command termination chars (ken=';' or th='\r') */
129 int if_len; /* length of IF; answer excluding ';' terminator */
130 rmode_t *mode_table;
131 struct kenwood_filter_width *filter_width; /* Last entry should have value == -1 and width_hz == -1 */
132 struct kenwood_slope_filter *slope_filter_high; /* Last entry should have value == -1 and frequency_hz == -1 */
133 struct kenwood_slope_filter *slope_filter_low; /* Last entry should have value == -1 and frequency_hz == -1 */
134 };
135
136 struct kenwood_priv_data
137 {
138 char info[KENWOOD_MAX_BUF_LEN];
139 split_t split; /* current split state */
140 vfo_t tx_vfo; /* split tx vfo */
141 int k2_ext_lvl; /* Initial K2 extension level */
142 int k3_ext_lvl; /* Initial K3 extension level */
143 int k2_md_rtty; /* K2 RTTY mode available flag, 1 = RTTY, 0 = N/A */
144 int has_kpa3; /* Elecraft K3 has k3pa for PC command */
145 int has_kpa100; /* Elecraft KX3/KX2 has kpa100 for PC command */
146 char *fw_rev; /* firmware revision level */
147 int trn_state; /* AI state discovered at startup */
148 unsigned fw_rev_uint; /* firmware revision as a number 1.07 -> 107 */
149 char verify_cmd[4]; /* command used to verify set commands */
150 int is_emulation; /* flag for TS-2000 emulations */
151 void *data; /* model specific data */
152 rmode_t curr_mode; /* used for is_emulation to avoid get_mode on VFOB */
153 struct timespec cache_start;
154 char last_if_response[KENWOOD_MAX_BUF_LEN];
155 int poweron; /* to avoid powering on more than once */
156 int ag_format; /* which AG command is being used...see LEVEL_AF in kenwood.c*/
157 int has_rit2; /* rig has set 2 rit command -- can set rit 0-99999 directly */
158 int micgain_min, micgain_max; /* varies by rig so we figure it out automagically */
159 int is_k2;
160 int is_k3;
161 int is_k3s;
162 int is_kx3;
163 int is_kx2;
164 int is_k4;
165 int is_k4d;
166 int is_k4hd;
167 int no_id; // if true will not send ID; with every set command
168 int opened; // true once rig_open is called to avoid setting VFOA every open call
169 };
170
171
172 #define kenwood_caps(rig) ((struct kenwood_priv_caps *)(rig)->caps->priv)
173
174
175 extern rmode_t kenwood_mode_table[KENWOOD_MODE_TABLE_MAX];
176
177 extern tone_t kenwood38_ctcss_list[];
178 extern tone_t kenwood42_ctcss_list[];
179
180 int kenwood_transaction(RIG *rig, const char *cmdstr, char *data, size_t datasize);
181 int kenwood_safe_transaction(RIG *rig, const char *cmd, char *buf,
182 size_t buf_size, size_t expected);
183
184 rmode_t kenwood2rmode(unsigned char mode, const rmode_t mode_table[]);
185 char rmode2kenwood(rmode_t mode, const rmode_t mode_table[]);
186
187 int kenwood_init(RIG *rig);
188 int kenwood_cleanup(RIG *rig);
189 int kenwood_open(RIG *rig);
190 int kenwood_close(RIG *rig);
191
192 int kenwood_set_vfo(RIG *rig, vfo_t vfo);
193 int kenwood_set_vfo_main_sub(RIG *rig, vfo_t vfo);
194 int kenwood_get_vfo_if(RIG *rig, vfo_t *vfo);
195 int kenwood_get_vfo_main_sub(RIG *rig, vfo_t *vfo);
196 int kenwood_set_split(RIG *rig, vfo_t vfo, split_t split, vfo_t txvfo);
197 int kenwood_set_split_vfo(RIG *rig, vfo_t vfo, split_t split, vfo_t txvfo);
198 int kenwood_get_split_vfo_if(RIG *rig, vfo_t rxvfo, split_t *split,
199 vfo_t *txvfo);
200
201 int kenwood_set_freq(RIG *rig, vfo_t vfo, freq_t freq);
202 int kenwood_get_freq(RIG *rig, vfo_t vfo, freq_t *freq);
203 int kenwood_get_freq_if(RIG *rig, vfo_t vfo, freq_t *freq);
204 int kenwood_set_rit(RIG *rig, vfo_t vfo, shortfreq_t rit);
205 int kenwood_get_rit(RIG *rig, vfo_t vfo, shortfreq_t *rit);
206 int kenwood_set_xit(RIG *rig, vfo_t vfo, shortfreq_t rit);
207 int kenwood_get_xit(RIG *rig, vfo_t vfo, shortfreq_t *rit);
208 int kenwood_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width);
209 int kenwood_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width);
210 int kenwood_get_mode_if(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width);
211 int kenwood_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val);
212 int kenwood_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val);
213 int kenwood_set_func(RIG *rig, vfo_t vfo, setting_t func, int status);
214 int kenwood_get_func(RIG *rig, vfo_t vfo, setting_t func, int *status);
215 int kenwood_set_ext_parm(RIG *rig, token_t token, value_t val);
216 int kenwood_get_ext_parm(RIG *rig, token_t token, value_t *val);
217 int kenwood_set_ctcss_tone(RIG *rig, vfo_t vfo, tone_t tone);
218 int kenwood_set_ctcss_tone_tn(RIG *rig, vfo_t vfo, tone_t tone);
219 int kenwood_get_ctcss_tone(RIG *rig, vfo_t vfo, tone_t *tone);
220 int kenwood_set_ctcss_sql(RIG *rig, vfo_t vfo, tone_t tone);
221 int kenwood_get_ctcss_sql(RIG *rig, vfo_t vfo, tone_t *tone);
222 int kenwood_set_powerstat(RIG *rig, powerstat_t status);
223 int kenwood_get_powerstat(RIG *rig, powerstat_t *status);
224 int kenwood_reset(RIG *rig, reset_t reset);
225 int kenwood_send_morse(RIG *rig, vfo_t vfo, const char *msg);
226 int kenwood_set_ant(RIG *rig, vfo_t vfo, ant_t ant, value_t option);
227 int kenwood_set_ant_no_ack(RIG *rig, vfo_t vfo, ant_t ant, value_t option);
228 int kenwood_get_ant(RIG *rig, vfo_t vfo, ant_t dummy, value_t *option, ant_t *ant_curr, ant_t *ant_tx, ant_t *ant_rx);
229 int kenwood_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt);
230 int kenwood_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt);
231 int kenwood_set_ptt_safe(RIG *rig, vfo_t vfo, ptt_t ptt);
232 int kenwood_get_dcd(RIG *rig, vfo_t vfo, dcd_t *dcd);
233 int kenwood_vfo_op(RIG *rig, vfo_t vfo, vfo_op_t op);
234 int kenwood_set_mem(RIG *rig, vfo_t vfo, int ch);
235 int kenwood_get_mem(RIG *rig, vfo_t vfo, int *ch);
236 int kenwood_get_mem_if(RIG *rig, vfo_t vfo, int *ch);
237 int kenwood_get_channel(RIG *rig, vfo_t vfo, channel_t *chan, int read_only);
238 int kenwood_set_channel(RIG *rig, vfo_t vfo, const channel_t *chan);
239 int kenwood_scan(RIG *rig, vfo_t vfo, scan_t scan, int ch);
240 const char *kenwood_get_info(RIG *rig);
241 int kenwood_get_id(RIG *rig, char *buf);
242 int kenwood_get_if(RIG *rig);
243
244 int kenwood_set_trn(RIG *rig, int trn);
245 int kenwood_get_trn(RIG *rig, int *trn);
246
247 /* only use if returned string has length 6, e.g. 'SQ011;' */
248 int get_kenwood_level(RIG *rig, const char *cmd, float *fval, int *ival);
249 int get_kenwood_func(RIG *rig, const char *cmd, int *status);
250
251 extern const struct rig_caps ts950s_caps;
252 extern const struct rig_caps ts950sdx_caps;
253 extern const struct rig_caps ts50s_caps;
254 extern const struct rig_caps ts140_caps;
255 extern const struct rig_caps ts450s_caps;
256 extern const struct rig_caps ts570d_caps;
257 extern const struct rig_caps ts570s_caps;
258 extern const struct rig_caps ts680s_caps;
259 extern const struct rig_caps ts690s_caps;
260 extern const struct rig_caps ts790_caps;
261 extern const struct rig_caps ts850_caps;
262 extern const struct rig_caps ts870s_caps;
263 extern const struct rig_caps ts930_caps;
264 extern const struct rig_caps ts2000_caps;
265 extern const struct rig_caps k2_caps;
266 extern const struct rig_caps k3_caps;
267 extern const struct rig_caps k3s_caps;
268 extern const struct rig_caps kx2_caps;
269 extern const struct rig_caps kx3_caps;
270 extern const struct rig_caps k4_caps;
271 extern const struct rig_caps xg3_caps;
272 extern const struct rig_caps trc80_caps;
273
274 extern const struct rig_caps thd7a_caps;
275 extern const struct rig_caps thd72a_caps;
276 extern const struct rig_caps thd74_caps;
277 extern const struct rig_caps tmd700_caps;
278 extern const struct rig_caps thf7a_caps;
279 extern const struct rig_caps thf7e_caps;
280 extern const struct rig_caps thg71_caps;
281 extern const struct rig_caps tmv7_caps;
282 extern const struct rig_caps tmd710_caps;
283
284 extern const struct rig_caps ts440_caps;
285 extern const struct rig_caps ts940_caps;
286 extern const struct rig_caps ts711_caps;
287 extern const struct rig_caps ts811_caps;
288 extern const struct rig_caps r5000_caps;
289
290 extern const struct rig_caps ts480_caps;
291 extern const struct rig_caps ts590_caps;
292 extern const struct rig_caps ts590sg_caps;
293 extern const struct rig_caps thf6a_caps;
294
295 extern const struct rig_caps transfox_caps;
296
297 extern const struct rig_caps f6k_caps;
298 extern const struct rig_caps powersdr_caps;
299 extern const struct rig_caps pihpsdr_caps;
300 extern const struct rig_caps ts890s_caps;
301 extern const struct rig_caps pt8000a_caps;
302 extern const struct rig_caps malachite_caps;
303
304 /* use when not interested in the answer, but want to check its len */
kenwood_simple_transaction(RIG * rig,const char * cmd,size_t expected)305 static int inline kenwood_simple_transaction(RIG *rig, const char *cmd,
306 size_t expected)
307 {
308 struct kenwood_priv_data *priv = rig->state.priv;
309 return kenwood_safe_transaction(rig, cmd, priv->info, KENWOOD_MAX_BUF_LEN,
310 expected);
311 }
312
313 #endif /* _KENWOOD_H */
314