~ubuntu-branches/ubuntu/wily/flrig/wily

« back to all changes in this revision

Viewing changes to .pc/0001-License-Declaration.patch/src/rigs/TS870S.cxx

  • Committer: Package Import Robot
  • Author(s): Kamal Mostafa
  • Date: 2014-10-25 11:17:10 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20141025111710-n32skgya3l9u1brw
Tags: 1.3.17-1
* New upstream release (Closes: #761839)
* Debian Standards-Version: 3.9.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Kenwood TS870S driver
3
 
 * Based on the TS870S driver by Dave Freese.
4
 
 * a part of flrig.
5
 
 *
6
 
 * Copyright 2009, Dave Freese, W1HKJ
7
 
 * Changes for the TS-870S March 2012, Dave Baxter, G0WBX
8
 
 */
9
 
 
10
 
 /* Todo:
11
 
 * Look at:-                                                                                            (Example)
12
 
 * Autonotch control:-  (SSB Only on the 870S)                          (TS-2000)
13
 
 * Noise Reduction control:-                                                            (IC-7700)
14
 
 * Extra controls for speach compressor etc:-                           (IC-9100 (and others))
15
 
 * Misc controls auto rig on/off with flrig startup/quit:-      (FT-450/950) (PS0; PS1;)
16
 
 * Check Autotune action, and any 'busy' status.
17
 
 */
18
 
 
19
 
#include "config.h"
20
 
#include "TS870S.h"
21
 
#include "support.h"
22
 
 
23
 
static const char TS870Sname_[] = "TS-870S";
24
 
 
25
 
//         mode array Index Values :-         0      1      2     3     4     5      6       7
26
 
static const char *TS870Smodes_[] = {   "LSB", "USB", "CW", "FM", "AM", "FSK", "CW-R", "FSK-R", NULL};
27
 
static const char TS870S_mode_chr[] =  { '1',   '2',   '3',  '4',  '5',  '6',   '7',    '9' };
28
 
static const char TS870S_mode_type[] = { 'L',   'U',   'U',  'U',  'U',  'L',   'L',    'U' };
29
 
 
30
 
//----------------------------------------------------------------------
31
 
static const char *TS870S_empty[] = { "N/A", NULL };
32
 
 
33
 
//----------------------------------------------------------------------
34
 
static const char *TS870S_SSB_lo[] = {                  // MD1; and MD2;
35
 
  "0",   "50", "100", "200", "300",                     // Available settings (Hz)
36
 
"400",  "500", "600", "800", "1000", NULL };
37
 
 
38
 
static const char *TS870S_CAT_ssb_lo[] = {              // Corresponding commands.
39
 
"FW0000;", "FW0005;", "FW0010;", "FW0020;", "FW0030;",
40
 
"FW0040;", "FW0050;", "FW0060;", "FW0080;", "FW0100;", NULL };
41
 
 
42
 
static const char *TS870S_SSB_lo_tooltip = "lo cutoff";
43
 
static const char *TS870S_SSB_btn_lo_label = "L";
44
 
 
45
 
 
46
 
static const char *TS870S_SSB_hi[] = {                  // MD1; and MD2;
47
 
"1400", "1600", "1800", "2000", "2200", "2400", // Available settings (Hz)
48
 
"2600", "2800", "3000", "3400", "4600", "6000", NULL };
49
 
 
50
 
static const char *TS870S_CAT_ssb_hi[] = {              // Corresponding commands.
51
 
"IS 1400;", "IS 1600;", "IS 1800;", "IS 2000;", "IS 2200;", "IS 2400;",
52
 
"IS 2600;", "IS 2800;", "IS 3000;", "IS 3400;", "IS 4600;", "IS 6000;", NULL };
53
 
 
54
 
static const char *TS870S_SSB_hi_tooltip = "hi cutoff";
55
 
static const char *TS870S_SSB_btn_hi_label = "H";
56
 
 
57
 
//----------------------------------------------------------------------
58
 
static const char *TS870S_AM_lo[] = { // Available values...
59
 
"0", "100", "200", "500", NULL };
60
 
 
61
 
static const char *TS870S_CAT_am_lo[] = { // ... Corresponding commands.
62
 
"FW0000;", "FW0010;", "FW0020;", "FW0050;", NULL};
63
 
 
64
 
static const char *TS870S_AM_lo_tooltip = "lo cutoff";
65
 
static const char *TS870S_AM_btn_lo_label = "L";
66
 
 
67
 
static const char *TS870S_AM_hi[] = {
68
 
"2500", "3000", "4000", "5000", "6000", "7000", NULL };
69
 
 
70
 
static const char *TS870S_CAT_am_hi[] = {
71
 
"IS 2500;", "IS 3000;", "IS 4000;", "IS 5000;", "IS 6000;", "IS 7000;", NULL};
72
 
 
73
 
static const char *TS870S_AM_hi_tooltip = "hi cutoff";
74
 
static const char *TS870S_AM_btn_hi_label = "H";
75
 
 
76
 
//----------------------------------------------------------------------
77
 
static const char *TS870S_CWwidths[] = { // Available CW bandwidths
78
 
"50", "100", "200", "400", "600", "1000", NULL};
79
 
 
80
 
static const char *TS870S_CWbw[] = { // Corresponding commands.
81
 
"FW0005;", "FW0010;", "FW0020;", "FW0040;", "FW0060;", "FW0100;", NULL};
82
 
 
83
 
//----------------------------------------------------------------------
84
 
static const char *TS870S_FSKwidths[] = { // Available FSK bandwidths
85
 
"250", "500", "1000", "1500", NULL};
86
 
 
87
 
static const char *TS870S_FSKbw[] = { // Corresponding commands.
88
 
"FW0025;", "FW0050;", "FW0100;", "FW0150;", NULL };
89
 
 
90
 
//----------------------------------------------------------------------
91
 
static const char *TS870S_FMwidths[] = { // Available FM bandwidths
92
 
"5000", "6000", "8000", "10000", "12000", "14000", NULL};
93
 
 
94
 
static const char *TS870S_FMbw[] = { // Corresponding commands.
95
 
"FW0500;", "FW0600;", "FW0800;", "FW1000;", "FW1200;", "FW1400;", NULL };
96
 
 
97
 
//----------------------------------------------------------------------
98
 
 
99
 
static GUI rig_widgets[]= {
100
 
        { (Fl_Widget *)btnVol,        2, 125,  50 },
101
 
        { (Fl_Widget *)sldrVOLUME,   54, 125, 156 },
102
 
        { (Fl_Widget *)btnIFsh,     214, 105,  50 },
103
 
        { (Fl_Widget *)sldrIFSHIFT, 266, 105, 156 },
104
 
        { (Fl_Widget *)sldrMICGAIN, 266, 125, 156 },
105
 
        { (Fl_Widget *)sldrPOWER,    54, 145, 368 },
106
 
        { (Fl_Widget *)NULL,          0,   0,   0 }
107
 
};
108
 
 
109
 
//----------------------------------------------------------------------
110
 
void RIG_TS870S::initialize()
111
 
{
112
 
        rig_widgets[0].W = btnVol;
113
 
        rig_widgets[1].W = sldrVOLUME;
114
 
        rig_widgets[2].W = btnIFsh;
115
 
        rig_widgets[3].W = sldrIFSHIFT;
116
 
        rig_widgets[4].W = sldrMICGAIN;
117
 
        rig_widgets[5].W = sldrPOWER;
118
 
 
119
 
        selectA();
120
 
//      cmd = "AC 00;";       sendCommand(cmd);  // ATU Off.
121
 
        cmd = "EX0270000;";   sendCommand(cmd);  // TX Enable.          wbx2
122
 
 
123
 
        get_preamp();
124
 
        get_attenuator();
125
 
        RIG_DEBUG = true;
126
 
}
127
 
 
128
 
// add code here for shutting down the transceiver ...
129
 
void RIG_TS870S::shutdown()
130
 
{
131
 
}
132
 
 
133
 
//----------------------------------------------------------------------
134
 
RIG_TS870S::RIG_TS870S() {
135
 
 
136
 
        name_ = TS870Sname_;
137
 
        modes_ = TS870Smodes_;
138
 
        bandwidths_ = TS870S_empty;
139
 
 
140
 
        dsp_lo     = TS870S_SSB_lo;
141
 
        lo_tooltip = TS870S_SSB_lo_tooltip;
142
 
        lo_label   = TS870S_SSB_btn_lo_label;
143
 
 
144
 
        dsp_hi     = TS870S_SSB_hi;
145
 
        hi_tooltip = TS870S_SSB_hi_tooltip;
146
 
        hi_label   = TS870S_SSB_btn_hi_label;
147
 
 
148
 
        widgets = rig_widgets;
149
 
 
150
 
        comm_baudrate = BR57600;
151
 
        stopbits = 1;
152
 
        comm_retries = 2;
153
 
        comm_wait = 5;
154
 
        comm_timeout = 50;
155
 
        comm_rtscts = true;
156
 
        comm_rtsplus = false;
157
 
        comm_dtrplus = false;
158
 
        comm_catptt = false;    // default to safe
159
 
        comm_rtsptt = false;    // ditto (used for hardware handshake)
160
 
        comm_dtrptt = false;    // ditto
161
 
 
162
 
//      Defaults.
163
 
        B.imode = A.imode = 1;      // USB
164
 
        B.iBW = A.iBW = 0x8704;     // hi=2800Hz .. lo=300Hz
165
 
        B.freq = A.freq = 14070000;
166
 
        can_change_alt_vfo = true;
167
 
 
168
 
        nb_level = 2;
169
 
 
170
 
        has_micgain_control =
171
 
        has_notch_control =
172
 
        has_ifshift_control =
173
 
        has_swr_control = false;
174
 
 
175
 
        has_dsp_controls =
176
 
        has_smeter =
177
 
        has_power_out =
178
 
        has_split =
179
 
        has_split_AB =
180
 
        has_noise_control =
181
 
        has_micgain_control =
182
 
        has_volume_control =      // see 'read_volume()' in support.cxx
183
 
        has_power_control = true;
184
 
 
185
 
        has_tune_control = false; // disabled for now
186
 
 
187
 
        has_attenuator_control = true;
188
 
 
189
 
        has_preamp_control = false;
190
 
 
191
 
        has_mode_control =
192
 
        has_bandwidth_control =
193
 
 
194
 
        has_ifshift_control =     // See 'update_ifshift' in support.cxx
195
 
 
196
 
        has_ptt_control = true;
197
 
 
198
 
        precision = 10;
199
 
        ndigits = 7;
200
 
 
201
 
}
202
 
 
203
 
//----------------------------------------------------------------------
204
 
const char * RIG_TS870S::get_bwname_(int n, int md)
205
 
{ // md is an index value, NOT a "mode" designator itself.
206
 
  //  n also is an index value, used to reference the name in the array.
207
 
 
208
 
  // This uses "ternary" methods, in the form of...
209
 
  // (boolean test) ? (do if true) : (do if false);
210
 
  // http://www.teach-me-c.com/blog/c-ternary-operator
211
 
 
212
 
        static char bwname[20];
213
 
 
214
 
        if (n > 256) { // hi/lo cutt off bw setting mode.
215
 
                int hi = (n >> 8) & 0x7F; // hi byte (not MSB)
216
 
                int lo = n & 0xFF;        // lo byte
217
 
                snprintf(bwname, sizeof(bwname), "%s/%s",
218
 
                        (md == 0 || md == 1) ? TS870S_SSB_lo[lo] :      // SSB lo
219
 
                        (md == 4) ? TS870S_AM_lo[lo] : "N/A",           //  AM lo
220
 
                        (md == 0 || md == 1) ? TS870S_SSB_hi[hi] :      // SSB hi
221
 
                        (md == 4) ? TS870S_AM_hi[hi] : "N/A" );         //  AM hi
222
 
 
223
 
        } else { // plain vanilla single bandwidth mode.
224
 
                snprintf(bwname, sizeof(bwname), "%s",
225
 
                        (md == 2 || md == 6) ? TS870S_CWwidths[n] :     //  CW or CW-R
226
 
                    (md == 5 || md == 7) ? TS870S_FSKwidths[n]: // FSK or FSK-R
227
 
                        (md == 3 ) ? TS870S_FMwidths[n] : "N/A" );  //  FM
228
 
        }
229
 
        return bwname;
230
 
}
231
 
 
232
 
//----------------------------------------------------------------------
233
 
void RIG_TS870S::selectA()
234
 
{
235
 
        cmd = "FR0;";
236
 
        sendCommand(cmd);
237
 
        showresp(WARN, ASC, "Rx/Tx A", cmd, replystr);
238
 
        vfo = 0;
239
 
}
240
 
 
241
 
//----------------------------------------------------------------------
242
 
void RIG_TS870S::selectB()
243
 
{
244
 
        cmd = "FR1;";
245
 
        sendCommand(cmd);
246
 
        showresp(WARN, ASC, "Rx/Tx B", cmd, replystr);
247
 
        vfo = 1;
248
 
}
249
 
 
250
 
//----------------------------------------------------------------------
251
 
// revision is similar to TS950S code
252
 
//----------------------------------------------------------------------
253
 
void RIG_TS870S::set_split(bool val)
254
 
{
255
 
// find out which VFO (or if Memory) is in use for RX.
256
 
 
257
 
        cmd = "FR;";   sendCommand(cmd);
258
 
        showresp(WARN, ASC, "RX-VFO?", cmd, replystr);
259
 
        int ret = waitN(4, 100, "get VFO for split", ASC);
260
 
// if incomplete data, change nothing.
261
 
        if (ret < 4) return;
262
 
 
263
 
        size_t p = replystr.rfind("FR");
264
 
// if bad data, change nothing.
265
 
        if (p == string::npos) return;
266
 
 
267
 
// '0' = VFO-A, '1' = VFO-B, '2' = Memory.
268
 
        switch (replystr[p+2]) {
269
 
                case '0' : useB = false; break;
270
 
                case '1' : useB = true; break;
271
 
                case '2' :
272
 
                default  : return;  // do nothing the xcvr is in memory mode
273
 
        }
274
 
 
275
 
        split = val;
276
 
        if (useB) {
277
 
                if (val) {
278
 
                        cmd = "FR1;FT0;";
279
 
                        sendCommand(cmd);
280
 
                        showresp(WARN, ASC, "Rx on B, Tx on A", cmd, replystr);
281
 
                } else {
282
 
                        cmd = "FR1;FT1;";
283
 
                        sendCommand(cmd);
284
 
                        showresp(WARN, ASC, "Rx on B, Tx on B", cmd, replystr);
285
 
                }
286
 
        } else {
287
 
                if (val) {
288
 
                        cmd = "FR0;FT1;";
289
 
                        sendCommand(cmd);
290
 
                        showresp(WARN, ASC, "Rx on A, Tx on B", cmd, replystr);
291
 
                } else {
292
 
                        cmd = "FR0;FT0;";
293
 
                        sendCommand(cmd);
294
 
                        showresp(WARN, ASC, "Rx on A, Tx on A", cmd, replystr);
295
 
                }
296
 
        }
297
 
        Fl::awake(highlight_vfo, (void *)0);
298
 
}
299
 
 
300
 
//----------------------------------------------------------------------
301
 
// This works for the 950S ... you can can revert to use your
302
 
//  IF byte 32 test if this does not work on the 870S
303
 
//----------------------------------------------------------------------
304
 
int RIG_TS870S::get_split()
305
 
{
306
 
        size_t p;
307
 
        int split = 0;
308
 
        char rx, tx;
309
 
// tx vfo
310
 
        cmd = rsp = "FT";
311
 
        cmd.append(";");
312
 
        waitN(4, 100, "get split tx vfo", ASC);
313
 
        p = replystr.rfind(rsp);
314
 
        if (p == string::npos) return split;
315
 
        tx = replystr[p+2];
316
 
 
317
 
// rx vfo
318
 
        cmd = rsp = "FR";
319
 
        cmd.append(";");
320
 
        waitN(4, 100, "get split rx vfo", ASC);
321
 
 
322
 
        p = replystr.rfind(rsp);
323
 
        if (p == string::npos) return split;
324
 
        rx = replystr[p+2];
325
 
// split test
326
 
        split = (tx == '1' ? 2 : 0) + (rx == '1' ? 1 : 0);
327
 
 
328
 
        return split;
329
 
}
330
 
 
331
 
//----------------------------------------------------------------------
332
 
long RIG_TS870S::get_vfoA ()
333
 
{
334
 
        cmd = "FA;";
335
 
        int ret = waitN(14, 100, "get vfoA", ASC);
336
 
 
337
 
        if (ret < 14) return A.freq;
338
 
        size_t p = replystr.rfind("FA");
339
 
        if (p == string::npos) return A.freq;
340
 
 
341
 
        long f = 0L;
342
 
        long mul = 1L;
343
 
        for (size_t n = 12; n > 1; n--) {
344
 
                f += (replystr[p + n] - '0') * mul;
345
 
                mul *= 10;
346
 
        }
347
 
        A.freq = f;
348
 
        return A.freq;
349
 
}
350
 
 
351
 
//----------------------------------------------------------------------
352
 
void RIG_TS870S::set_vfoA (long freq)
353
 
{
354
 
        A.freq = freq;
355
 
        cmd = "FA00000000000;";
356
 
        for (int i = 12; i > 1; i--) {
357
 
                cmd[i] += freq % 10;
358
 
                freq /= 10;
359
 
        }
360
 
        sendCommand(cmd, 0);
361
 
        showresp(WARN, ASC, "set vfo A", cmd, replystr);
362
 
}
363
 
 
364
 
//----------------------------------------------------------------------
365
 
long RIG_TS870S::get_vfoB ()
366
 
{
367
 
        cmd = "FB;";
368
 
        int ret = waitN(14, 100, "get vfoB", ASC);
369
 
 
370
 
        if (ret < 14) return B.freq;
371
 
        size_t p = replystr.rfind("FB");
372
 
        if (p == string::npos) return B.freq;
373
 
 
374
 
        long f = 0L;
375
 
        long mul = 1L;
376
 
        for (size_t n = 12; n > 1; n--) {
377
 
                f += (replystr[p + n] - '0') * mul;
378
 
                mul *= 10;
379
 
        }
380
 
        B.freq = f;
381
 
 
382
 
        return B.freq;
383
 
}
384
 
 
385
 
//----------------------------------------------------------------------
386
 
void RIG_TS870S::set_vfoB (long freq)
387
 
{
388
 
        B.freq = freq;
389
 
        cmd = "FB00000000000;";
390
 
        for (int i = 12; i > 1; i--) {
391
 
                cmd[i] += freq % 10;
392
 
                freq /= 10;
393
 
        }
394
 
        sendCommand(cmd, 0);
395
 
        showresp(WARN, ASC, "set vfo B", cmd, replystr);
396
 
}
397
 
 
398
 
//----------------------------------------------------------------------
399
 
/* int RIG_TS870S::get_smeter() {
400
 
        int mtr = 0;
401
 
        cmd = "SM;";
402
 
        int ret = waitN(8, 100, "get smeter", ASC);
403
 
 
404
 
        if (ret < 7) return 0;
405
 
        size_t p = replystr.find("SM");
406
 
        if (p == string::npos) return 0;
407
 
 
408
 
        replystr[p + 6] = 0;
409
 
        mtr = atoi(&replystr[p + 2]);
410
 
        mtr *= 50;
411
 
        mtr /= 15;
412
 
        if (mtr > 100) mtr = 100;
413
 
        return mtr;
414
 
} */
415
 
 
416
 
//----------------------------------------------------------------------
417
 
int RIG_TS870S::get_smeter() {   // scales correctly now 2012-02-24
418
 
        cmd = "SM;";
419
 
        int ret = sendCommand(cmd);
420
 
        showresp(WARN, ASC, "S meter", cmd, replystr);
421
 
        if (ret < 7) return 0;
422
 
        size_t p = replystr.rfind("SM");
423
 
        if (p == string::npos) return -1;
424
 
 
425
 
        replystr[p + 6] = 0;
426
 
        int mtr = atoi(&replystr[p + 2]);
427
 
        mtr = (mtr * 100) / 30;                                                                         //wbx
428
 
        return mtr;
429
 
}
430
 
 
431
 
//----------------------------------------------------------------------
432
 
int RIG_TS870S::get_power_out()
433
 
{ // Shares same command as the 'S' meter reading.
434
 
        int mtr = 0;
435
 
        cmd = "SM;";
436
 
        int ret = sendCommand(cmd);
437
 
        showresp(WARN, ASC, "Output Power", cmd, replystr);
438
 
        if (ret < 7) return mtr;
439
 
        size_t p = replystr.rfind("SM");
440
 
        if (p == string::npos) return mtr;
441
 
 
442
 
        replystr[p + 6] = 0;
443
 
        mtr = atoi(&replystr[p + 2]);
444
 
        mtr = (mtr * 100) / 30;                                                                         //wbx
445
 
        if (mtr > 100) mtr = 100; // but with a power limit!
446
 
        return mtr;
447
 
 
448
 
        // The power meter scale is not the same as Flrig's default.
449
 
        // a change is needed, one day.   wbx2
450
 
}
451
 
 
452
 
//----------------------------------------------------------------------
453
 
// Transceiver power level
454
 
void RIG_TS870S::set_power_control(double val)
455
 
{
456
 
        int ival = (int)val;
457
 
        cmd = "PC000;";
458
 
        for (int i = 4; i > 1; i--) {
459
 
                cmd[i] += ival % 10;
460
 
                ival /= 10;
461
 
        }
462
 
        sendCommand(cmd, 0); // 010 .. 100
463
 
}
464
 
 
465
 
//----------------------------------------------------------------------
466
 
int RIG_TS870S::get_power_control()
467
 
{
468
 
        cmd = "PC;";
469
 
        int ret = waitN(6, 100, "get pwr ctrl", ASC);
470
 
 
471
 
        if (ret < 6) return 0;
472
 
        size_t p = replystr.rfind("PC");
473
 
        if (p == string::npos) return 0;
474
 
        int mtr = 0;
475
 
        if (ret >= 6) {
476
 
                replystr[p + 5] = 0;
477
 
                mtr = atoi(&replystr[p + 2]);
478
 
        }
479
 
        return mtr;
480
 
}
481
 
 
482
 
//----------------------------------------------------------------------
483
 
// Volume control return (rig sends back 0 .. 255)
484
 
int RIG_TS870S::get_volume_control()
485
 
{
486
 
        cmd = "AG;";  // reply data is 'AGnnn;' nnn = 000 .. 255  wbx
487
 
 
488
 
        int ret = sendCommand(cmd);
489
 
        showresp(WARN, ASC, "get vol ctrl", cmd, replystr);
490
 
 
491
 
//      int ret = waitN(7, 100, "get vol ctrl", ASC);
492
 
 
493
 
        if (ret < 6) return 0;
494
 
        size_t p = replystr.rfind("AG");
495
 
        if (p == string::npos) return 0;
496
 
 
497
 
        replystr[p + 5] = 0; // change the ';' into a 'null'
498
 
        int val = atoi(&replystr[p + 2]);
499
 
        return (int)(val / 2.55);  // we only want 0 .. 100
500
 
}
501
 
 
502
 
//----------------------------------------------------------------------
503
 
void RIG_TS870S::set_volume_control(int val) // 0 .. 100
504
 
{
505
 
        int ivol = (int)(val * 2.55); // 0 .. 255
506
 
        cmd = "AG000;";
507
 
        for (int i = 4; i > 1; i--) {
508
 
                cmd[i] += ivol % 10;
509
 
                ivol /= 10;
510
 
        }
511
 
        sendCommand(cmd, 0);
512
 
}
513
 
 
514
 
//----------------------------------------------------------------------
515
 
// Tranceiver PTT on/off
516
 
 
517
 
/*
518
 
 * NOTE!  If you use these CAT commands TX and RX, then when in Transmit
519
 
 * the TS-870S *ONLY* takes audio from the front panel Mic socket.
520
 
 * If you need to use the audio going in the rear Acc socket, you MUST
521
 
 * use a hard wired PTT to the Acc socket.  THEN it will take audio from
522
 
 * there, and blank the mic.
523
 
 * To do that, in the Config/Xcvr Select menu, use one of the Hardware PTT options.
524
 
 * Just so it has been said...
525
 
 */
526
 
 
527
 
void RIG_TS870S::set_PTT_control(int val)
528
 
{
529
 
        if (val) cmd = "TX;";
530
 
        else     cmd = "RX;";
531
 
        sendCommand(cmd, 0);
532
 
}
533
 
 
534
 
//----------------------------------------------------------------------
535
 
// Play with the autotuner              // disabled for now wbx
536
 
void RIG_TS870S::tune_rig()
537
 
{
538
 
//      cmd = "AC111;";
539
 
//      sendCommand(cmd, 0);
540
 
 
541
 
        // this might take a while!
542
 
}
543
 
 
544
 
//----------------------------------------------------------------------
545
 
// the TS-870 actually has 4 attenuator settings.
546
 
// RA00; = Off,  RA01; = 6dB,  RA02; = 12dB,  RA03; = 18dB      wbx
547
 
void RIG_TS870S::set_attenuator(int val) {
548
 
 
549
 
        if (att_level == 0) {                   // If attenuator level = 0 (off)
550
 
                att_level = 1;                          // then turn it on, at 6dB
551
 
                cmd = "RA01;";                          // this is the command...
552
 
                atten_label("Att 6", true);     // show it in the button...
553
 
        }
554
 
        else if (att_level == 1) {              // If attenuator level = 1 (6dB)
555
 
                att_level = 2;                          // then make it 12dB
556
 
                cmd = "RA02;";
557
 
                atten_label("Att 12", true);
558
 
        }
559
 
        else if (att_level == 2) {              // if it's 12dB
560
 
                att_level = 3;                          // go to 18dB
561
 
                cmd = "RA03;";
562
 
                atten_label("Att 18", true);
563
 
        }
564
 
        else if (att_level == 3) {              // If it's 18dB
565
 
                att_level = 0;                          // Loop back to none.
566
 
                cmd = "RA00;";
567
 
                atten_label("Att", false);
568
 
        }
569
 
 
570
 
        sendCommand(cmd);
571
 
        showresp(WARN, ASC, "set Att", cmd, replystr);
572
 
}
573
 
 
574
 
//----------------------------------------------------------------------
575
 
//      Modified to read and show the actual radio setting, in the button.
576
 
int RIG_TS870S::get_attenuator() {
577
 
        cmd = "RA;";
578
 
        int ret = sendCommand(cmd);
579
 
        showresp(WARN, ASC, "get Att", cmd, replystr);
580
 
        if (ret < 5) return att_on;
581
 
        size_t p = replystr.rfind("RA");
582
 
        if (p == string::npos) return att_on;
583
 
 
584
 
        if (replystr[p + 2] == '0' && replystr[p + 3] == '0') {
585
 
                att_on = 0;                                             // Attenuator is OFF
586
 
                att_level = 0;                                  // remember it...
587
 
                atten_label("Att", false);              // show it...
588
 
        }
589
 
        else if (replystr[p + 2] == '0' && replystr[p + 3] == '1') {
590
 
                att_on = 1;                                             // Attenuator is ON, 6dB
591
 
                att_level = 1;                                  // remember the level
592
 
                atten_label("Att 6", true);             // show it...
593
 
        }
594
 
        else if (replystr[p + 2] == '0' && replystr[p + 3] == '2') {
595
 
                att_on = 1;                                             // .. still ON, 12dB
596
 
                att_level = 2;                                  // remember this level
597
 
                atten_label("Att 12", true);    // show it.
598
 
        }
599
 
        else if (replystr[p + 2] == '0' && replystr[p + 3] == '3') {
600
 
                att_on = 1;                                             // .. still ON 18dB
601
 
                att_level = 3;                                  // remember...
602
 
                atten_label("Att 18", true);    // show this too..
603
 
        }
604
 
 
605
 
        return att_on;                  // let the rest of the world know.
606
 
}
607
 
 
608
 
//----------------------------------------------------------------------
609
 
bool RIG_TS870S::get_TS870Sid() {
610
 
        cmd = "ID;";
611
 
        int ret = sendCommand(cmd);
612
 
        showresp(WARN, ASC, "Id", cmd, replystr);
613
 
        if (ret < 6) return false;
614
 
        size_t p = replystr.rfind("ID");                        // String "ID015;"
615
 
        if (p == string::npos) return false;            // Bytes   012345
616
 
        if      (replystr[p + 2] == '0' &&                              // wbx2
617
 
                 replystr[p + 3] == '1' &&
618
 
                 replystr[p + 4] == '5')  return true;  // wbx
619
 
        return false;
620
 
}
621
 
 
622
 
//======================================================================
623
 
// mode commands
624
 
//======================================================================
625
 
void RIG_TS870S::set_modeA(int val)
626
 
{
627
 
        active_mode = A.imode = val;
628
 
        cmd = "MD";
629
 
        cmd += TS870S_mode_chr[val];
630
 
        cmd += ';';
631
 
        sendCommand(cmd, 0);
632
 
        showresp(WARN, ASC, "set mode A", cmd, replystr);
633
 
 
634
 
        set_widths(val);
635
 
}
636
 
 
637
 
//----------------------------------------------------------------------
638
 
int RIG_TS870S::get_modeA()
639
 
{
640
 
        int md = A.imode;
641
 
        cmd = "MD;";
642
 
        int ret = waitN(4, 100, "get mode A", ASC);
643
 
 
644
 
        if (ret < 4) return A.imode;
645
 
        size_t p = replystr.rfind("MD");
646
 
        if (p == string::npos) return A.imode;
647
 
 
648
 
        switch (replystr[p + 2]) {
649
 
                case '1' : md = tsLSB;  break;
650
 
                case '2' : md = tsUSB;  break;
651
 
                case '3' : md = tsCW;   break;
652
 
                case '4' : md = tsFM;   break;
653
 
                case '5' : md = tsAM;   break;
654
 
                case '6' : md = tsFSK;  break;
655
 
                case '7' : md = tsCWR;  break;
656
 
                case '9' : md = tsFSKR; break;
657
 
                default  : md = A.imode;
658
 
        }
659
 
 
660
 
        if (md != A.imode) {
661
 
                active_mode = A.imode = md;
662
 
                set_widths(md);
663
 
        }
664
 
        return A.imode;
665
 
}
666
 
 
667
 
//----------------------------------------------------------------------
668
 
void RIG_TS870S::set_modeB(int val)
669
 
{
670
 
        active_mode = B.imode = val;
671
 
        cmd = "MD";
672
 
        cmd += TS870S_mode_chr[val];
673
 
        cmd += ';';
674
 
        sendCommand(cmd, 0);
675
 
        showresp(WARN, ASC, "set mode B", cmd, replystr);
676
 
 
677
 
        set_widths(val);
678
 
}
679
 
 
680
 
//----------------------------------------------------------------------
681
 
int RIG_TS870S::get_modeB()
682
 
{
683
 
        int md = B.imode;
684
 
        cmd = "MD;";
685
 
        int ret = waitN(4, 100, "get mode B", ASC);
686
 
 
687
 
        if (ret < 4) return B.imode;
688
 
        size_t p = replystr.rfind("MD");
689
 
        if (p == string::npos) return B.imode;
690
 
 
691
 
        switch (replystr[p + 2]) {
692
 
                case '1' : md = tsLSB;  break;
693
 
                case '2' : md = tsUSB;  break;
694
 
                case '3' : md = tsCW;   break;
695
 
                case '4' : md = tsFM;   break;
696
 
                case '5' : md = tsAM;   break;
697
 
                case '6' : md = tsFSK;  break;
698
 
                case '7' : md = tsCWR;  break;
699
 
                case '9' : md = tsFSKR; break;
700
 
                default  : md = B.imode;
701
 
        }
702
 
 
703
 
        if (md != B.imode) {
704
 
                active_mode = B.imode = md;
705
 
                set_widths(md);
706
 
        }
707
 
        return B.imode;
708
 
}
709
 
 
710
 
 
711
 
//======================================================================
712
 
// Bandpass filter commands
713
 
//======================================================================
714
 
// Comes here when user changes mode, among other things..
715
 
int RIG_TS870S::set_widths(int val) // val is from the mode list index, as selected by the user.
716
 
{
717
 
        int bw = 0;
718
 
 
719
 
        if (val == tsLSB || val == tsUSB ) {  // SSB modes
720
 
                bandwidths_ = TS870S_empty;
721
 
                dsp_lo = TS870S_SSB_lo;
722
 
                dsp_hi = TS870S_SSB_hi;
723
 
                lo_tooltip = TS870S_SSB_lo_tooltip;
724
 
                lo_label   = TS870S_SSB_btn_lo_label;
725
 
                hi_tooltip = TS870S_SSB_hi_tooltip;
726
 
                hi_label   = TS870S_SSB_btn_hi_label;
727
 
                bw = 0x8704; // 300 ... 2800 Hz
728
 
        }
729
 
 
730
 
        else if (val == tsCW || val == tsCWR) {  // CW modes
731
 
                bandwidths_ = TS870S_CWwidths;
732
 
                dsp_lo = TS870S_empty;
733
 
                dsp_hi = TS870S_empty;
734
 
                bw = 2; // 200Hz
735
 
        }
736
 
 
737
 
        else if (val == tsFSK || val == tsFSKR) {  // FSK modes
738
 
                bandwidths_ = TS870S_FSKwidths;
739
 
                dsp_lo = TS870S_empty;
740
 
                dsp_hi = TS870S_empty;
741
 
                bw = 1; // 500Hz
742
 
        }
743
 
 
744
 
        else if (val == tsAM) { // val == 5 ==> AM mode
745
 
                bandwidths_ = TS870S_empty;
746
 
                dsp_lo = TS870S_AM_lo;
747
 
                dsp_hi = TS870S_AM_hi;
748
 
                lo_tooltip = TS870S_AM_lo_tooltip;
749
 
                lo_label   = TS870S_AM_btn_lo_label;
750
 
                hi_tooltip = TS870S_AM_hi_tooltip;
751
 
                hi_label   = TS870S_AM_btn_hi_label;
752
 
                bw = 0x8401; // 100Hz .. 6000Hz
753
 
        }
754
 
 
755
 
// FM mode BW selection.
756
 
        else if (val == tsFM) {  // FM mode
757
 
                bandwidths_ = TS870S_FMwidths;  // load the dropdown with our list
758
 
                dsp_lo = TS870S_empty;
759
 
                dsp_hi = TS870S_empty;
760
 
                bw = 4; // 10000Hz
761
 
        }
762
 
 
763
 
        return bw;
764
 
}
765
 
 
766
 
//----------------------------------------------------------------------
767
 
const char **RIG_TS870S::bwtable(int m)
768
 
{
769
 
        if (m == tsLSB || m == tsUSB || m == tsAM)
770
 
                return NULL;  // these modes have lo and hi settings.
771
 
 
772
 
        else if (m == tsCW || m == tsCWR)
773
 
                return TS870S_CWwidths;
774
 
 
775
 
        else if (m == tsFSK || m == tsFSKR)
776
 
                return TS870S_FSKwidths;
777
 
 
778
 
        else if (m == tsFM)
779
 
                return TS870S_FMwidths;
780
 
 
781
 
        else
782
 
                return NULL;
783
 
}
784
 
 
785
 
const char **RIG_TS870S::lotable(int m)
786
 
{
787
 
        if (m == tsLSB || m == tsUSB || m == tsAM)
788
 
                return TS870S_SSB_lo;  // these modes have lo and hi settings.
789
 
 
790
 
        else if (m == tsCW || m == tsCWR)
791
 
                return NULL;
792
 
 
793
 
        else if (m == tsFSK || m == tsFSKR)
794
 
                return NULL;
795
 
 
796
 
        else if (m == tsFM)
797
 
                return NULL;
798
 
 
799
 
        else
800
 
                return TS870S_AM_lo;
801
 
}
802
 
 
803
 
const char **RIG_TS870S::hitable(int m)
804
 
{
805
 
        if (m == tsLSB || m == tsUSB || m == tsAM)
806
 
                return TS870S_SSB_hi;  // these modes have lo and hi settings.
807
 
 
808
 
        else if (m == tsCW || m == tsCWR)
809
 
                return NULL;
810
 
 
811
 
        else if (m == tsFSK || m == tsFSKR)
812
 
                return NULL;
813
 
 
814
 
        else if (m == tsFM)
815
 
                return NULL;
816
 
 
817
 
        else
818
 
                return TS870S_AM_hi;
819
 
}
820
 
 
821
 
//----------------------------------------------------------------------
822
 
int RIG_TS870S::adjust_bandwidth(int val)
823
 
{
824
 
        if (val == tsLSB || val == tsUSB )
825
 
                return 0x8704; // 2800Hz .. 300Hz
826
 
 
827
 
        else if (val == tsCW || val == tsCWR)
828
 
                return 2; // 200Hz
829
 
 
830
 
        else if (val == tsFSK || val == tsFSKR)
831
 
                return 1; // 500Hz
832
 
 
833
 
        else if (val == tsFM)
834
 
                return 3; // 10000Hz
835
 
 
836
 
//      else if (val == tsAM)
837
 
                return 0x8401; // 6000Hz .. 100Hz
838
 
}
839
 
 
840
 
//----------------------------------------------------------------------
841
 
int RIG_TS870S::def_bandwidth(int val)
842
 
{
843
 
        return adjust_bandwidth(val);
844
 
}
845
 
 
846
 
//----------------------------------------------------------------------
847
 
void RIG_TS870S::set_bwA(int val)
848
 
{
849
 
// LSB, USB
850
 
        if (A.imode == tsLSB || A.imode == tsUSB ) {
851
 
                if (val < 256) return;  // not hi/lo setting
852
 
                A.iBW = val;
853
 
 
854
 
                cmd = TS870S_CAT_ssb_lo[A.iBW & 0x7F];
855
 
                sendCommand(cmd,0);
856
 
                showresp(WARN, ASC, "set lower", cmd, replystr);
857
 
 
858
 
                cmd = TS870S_CAT_ssb_hi[(A.iBW >> 8) & 0x7F];
859
 
                sendCommand(cmd,0);
860
 
                showresp(WARN, ASC, "set upper", cmd, replystr);
861
 
 
862
 
                return;
863
 
        }
864
 
 
865
 
// AM
866
 
        if (A.imode == tsAM) {
867
 
                if (val < 256) return; // not hi/lo setting
868
 
                A.iBW = val;
869
 
 
870
 
                cmd = TS870S_CAT_am_lo[A.iBW & 0x7F];
871
 
                sendCommand(cmd,0);
872
 
                showresp(WARN, ASC, "set lower", cmd, replystr);
873
 
 
874
 
                cmd = TS870S_CAT_am_hi[(A.iBW >> 8) & 0x7F];
875
 
                sendCommand(cmd,0);
876
 
                showresp(WARN, ASC, "set upper", cmd, replystr);
877
 
 
878
 
                return;
879
 
        }
880
 
        if (val > 256) return;
881
 
 
882
 
// CW, CW-R
883
 
        if (A.imode == tsCW || A.imode == tsCWR) {
884
 
                A.iBW = val;
885
 
                cmd = TS870S_CWbw[A.iBW];
886
 
                sendCommand(cmd,0);
887
 
                showresp(WARN, ASC, "set CW bw", cmd, replystr);
888
 
                return;
889
 
        }
890
 
 
891
 
// FSK, FSK-R
892
 
        if (A.imode == tsFSK || A.imode == tsFSKR) {
893
 
                A.iBW = val;
894
 
                cmd = TS870S_FSKbw[A.iBW];
895
 
                sendCommand(cmd,0);
896
 
                showresp(WARN, ASC, "set FSK bw", cmd, replystr);
897
 
                return;
898
 
        }
899
 
 
900
 
// FM
901
 
        if (A.imode == tsFM) {
902
 
                A.iBW = val;
903
 
                cmd = TS870S_FMbw[A.iBW];
904
 
                sendCommand(cmd,0);
905
 
                showresp(WARN, ASC, "set FM bw", cmd, replystr);
906
 
                return;
907
 
        }
908
 
}
909
 
 
910
 
//----------------------------------------------------------------------
911
 
void RIG_TS870S::set_bwB(int val)
912
 
{
913
 
        if (B.imode == tsLSB || B.imode == tsUSB ) {
914
 
                if (val < 256) return;
915
 
                B.iBW = val;
916
 
 
917
 
                cmd = TS870S_CAT_ssb_lo[B.iBW & 0x7F];
918
 
                sendCommand(cmd,0);
919
 
                showresp(WARN, ASC, "set lower", cmd, replystr);
920
 
 
921
 
                cmd = TS870S_CAT_ssb_hi[(B.iBW >> 8) & 0x7F];
922
 
                sendCommand(cmd,0);
923
 
                showresp(WARN, ASC, "set upper", cmd, replystr);
924
 
 
925
 
                return;
926
 
        }
927
 
 
928
 
        if (B.imode == tsAM) {
929
 
                if (val < 256) return;
930
 
                B.iBW = val;
931
 
 
932
 
                cmd = TS870S_CAT_am_lo[B.iBW & 0x7F];                   // corrected wbx2
933
 
                sendCommand(cmd,0);
934
 
                showresp(WARN, ASC, "set lower", cmd, replystr);
935
 
 
936
 
                cmd = TS870S_CAT_am_hi[(B.iBW >> 8) & 0x7F];    // corrected wbx2
937
 
                sendCommand(cmd,0);
938
 
                showresp(WARN, ASC, "set upper", cmd, replystr);
939
 
 
940
 
                return;
941
 
        }
942
 
 
943
 
        if (val > 256) return;
944
 
 
945
 
        if (B.imode == tsCW || B.imode == tsCWR) {
946
 
                B.iBW = val;
947
 
                cmd = TS870S_CWbw[B.iBW];
948
 
                sendCommand(cmd,0);
949
 
                showresp(WARN, ASC, "set CW bw", cmd, replystr);
950
 
                return;
951
 
        }
952
 
 
953
 
        if (B.imode == tsFSK || B.imode == tsFSKR) {
954
 
                B.iBW = val;
955
 
                cmd = TS870S_FSKbw[B.iBW];
956
 
                sendCommand(cmd,0);
957
 
                showresp(WARN, ASC, "set FSK bw", cmd, replystr);
958
 
                return;
959
 
        }
960
 
 
961
 
        if (A.imode == tsFM) {
962
 
                A.iBW = val;
963
 
                cmd = TS870S_FMbw[A.iBW];
964
 
                sendCommand(cmd,0);
965
 
                showresp(WARN, ASC, "set FM bw", cmd, replystr);
966
 
                return;
967
 
        }
968
 
 
969
 
}
970
 
 
971
 
//----------------------------------------------------------------------
972
 
int RIG_TS870S::get_bwA() {
973
 
 
974
 
        int i = 0;
975
 
        size_t p;
976
 
 
977
 
        if (A.imode == tsFM) { // FM mode.
978
 
                cmd = "FW;"; // 'Filter Width' query
979
 
                waitN(7, 100, "get CW width", ASC);
980
 
                p = replystr.rfind("FW");
981
 
 
982
 
                if (p != string::npos) { // If 'FW' found then scan the known responces to find out what we got.
983
 
                        for (i = 0; TS870S_FMbw[i] != NULL; i++) // bump array index counter, till string match or end.
984
 
                                if (replystr.find(TS870S_FMbw[i]) == p) break;  // Found returned data, in string array.
985
 
 
986
 
                        if (TS870S_FMbw[i] != NULL) A.iBW = i; // if we didn't hit the end, return the array index value.
987
 
                        else A.iBW = 1; // Default.
988
 
                }
989
 
        }
990
 
 
991
 
        else if (A.imode == tsCW || A.imode == tsCWR) { // CW modes.
992
 
                cmd = "FW;"; // 'Filter Width' query
993
 
                waitN(7, 100, "get CW width", ASC);
994
 
                p = replystr.rfind("FW");
995
 
 
996
 
                if (p != string::npos) { // If 'FW' found then scan the known responces to find out what we got.
997
 
                        for (i = 0; TS870S_CWbw[i] != NULL; i++) // bump array index counter, till string match or end.
998
 
                                if (replystr.find(TS870S_CWbw[i]) == p) break;  // Found returned data, in string array.
999
 
 
1000
 
                        if (TS870S_CWbw[i] != NULL) A.iBW = i; // if we didn't hit the end, return the array index value.
1001
 
                        else A.iBW = 1; // Default.
1002
 
                }
1003
 
        }
1004
 
 
1005
 
        else if (A.imode == tsFSK || A.imode == tsFSKR ) { // FSK modes.
1006
 
                cmd = "FW;";
1007
 
                waitN(7, 100, "get FSK width", ASC);
1008
 
                p = replystr.rfind("FW");
1009
 
 
1010
 
                if (p != string::npos) { // If 'FW' found then scan the known responces to find out what we got.
1011
 
                        for (i = 0; TS870S_FSKbw[i] != NULL; i++) // bump array index counter, till string match or end.
1012
 
                                if (replystr.find(TS870S_FSKbw[i]) == p) break;         // Found returned data, in string array.
1013
 
 
1014
 
                        if (TS870S_FSKbw[i] != NULL) A.iBW = i; // if we didn't hit the end, return the array index value.
1015
 
                        else A.iBW = 1; // Default.
1016
 
                }
1017
 
        }
1018
 
 
1019
 
 
1020
 
        else if (A.imode == tsAM) { // AM mode only
1021
 
 
1022
 
                int lo = A.iBW & 0x7F, hi = (A.iBW >> 8) & 0x7F;
1023
 
                // High byte is hi cutoff index (not MSB though.) Low byte is lo cuttoff index.
1024
 
 
1025
 
                cmd = "FW;"; // Read Low cuttoff. Returns a two digit code as 'FLxxxx;' in 10Hz increments.
1026
 
                waitN(5, 100, "get lower", ASC);
1027
 
                p = replystr.rfind("FW");
1028
 
 
1029
 
                if (p != string::npos) { // If 'FW' found then scan the known responces to find out what we got.
1030
 
                        for (i = 0; TS870S_CAT_am_lo[i] != NULL; i++) // bump array index counter, till string match or end.
1031
 
                                if (replystr.find(TS870S_CAT_am_lo[i]) == p) break;     // Found returned data, in string array.
1032
 
 
1033
 
                        if (TS870S_CAT_am_lo[i] != NULL) lo = i; // if we didn't hit the end, return the array index value.
1034
 
                        else lo = 1; // Default.
1035
 
                }
1036
 
 
1037
 
                cmd = "IS;";
1038
 
                waitN(5, 100, "get upper", ASC);
1039
 
                p = replystr.rfind("IS ");
1040
 
 
1041
 
                if (p != string::npos) {
1042
 
                        for (i = 0; TS870S_CAT_am_hi[i] != NULL; i++) // bump array index counter, till string match or end.
1043
 
                                if (replystr.find(TS870S_CAT_am_hi[i]) == p) break;     // Found returned data, in string array.
1044
 
 
1045
 
                        if (TS870S_CAT_am_hi[i] != NULL) hi = i; // if we didn't hit the end, return the array index value.
1046
 
                        else hi = 1; // Default.
1047
 
                }
1048
 
                A.iBW = ((hi << 8) | (lo & 0x7F)) | 0x8000;
1049
 
                // Shift hi index up 8 bits into High Byte, then concatntat it with the Low byte, into one 16 bit value.
1050
 
        }
1051
 
 
1052
 
 
1053
 
        else if (A.imode == tsLSB || A.imode == tsUSB ) { // SSB (upper and lower)
1054
 
 
1055
 
                int lo = A.iBW & 0x7F, hi = (A.iBW >> 8) & 0x7F; // Same trick as above...
1056
 
 
1057
 
                cmd = "FW;"; // Read Low cuttoff. Returns a two digit code as 'FLxxxx;' in 10Hz increments.
1058
 
                waitN(5, 100, "get lower", ASC);
1059
 
                p = replystr.rfind("FW");
1060
 
 
1061
 
                if (p != string::npos) { // If 'FW' found then scan the known responces to find out what we got.
1062
 
                        for (i = 0; TS870S_CAT_ssb_lo[i] != NULL; i++) // bump array index counter, till string match or end.
1063
 
                                if (replystr.find(TS870S_CAT_ssb_lo[i]) == p) break;    // Found returned data, in string array.
1064
 
 
1065
 
                        if (TS870S_CAT_ssb_lo[i] != NULL) lo = i; // if we didn't hit the end, return the array index value.
1066
 
                        else lo = 1; // Default.
1067
 
                }
1068
 
 
1069
 
                cmd = "IS;";
1070
 
                waitN(5, 100, "get upper", ASC);
1071
 
                p = replystr.rfind("IS ");
1072
 
 
1073
 
                if (p != string::npos) {
1074
 
                        for (i = 0; TS870S_CAT_ssb_hi[i] != NULL; i++) // bump array index counter, till string match or end.
1075
 
                                if (replystr.find(TS870S_CAT_ssb_hi[i]) == p) break;    // Found returned data, in string array.
1076
 
 
1077
 
                        if (TS870S_CAT_ssb_hi[i] != NULL) hi = i; // if we didn't hit the end, return the array index value.
1078
 
                        else hi = 1; // Default.
1079
 
                }
1080
 
                A.iBW = ((hi << 8) | (lo & 0x7F)) | 0x8000;
1081
 
        }
1082
 
        return A.iBW;
1083
 
}
1084
 
 
1085
 
//----------------------------------------------------------------------
1086
 
int RIG_TS870S::get_bwB()
1087
 
{
1088
 
        int i = 0;
1089
 
        size_t p;
1090
 
 
1091
 
        if (B.imode == tsFM) {
1092
 
                cmd = "FW;"; // 'Filter Width' query
1093
 
                waitN(7, 100, "get CW width", ASC);
1094
 
                p = replystr.rfind("FW");
1095
 
 
1096
 
                if (p != string::npos) { // If 'FW' found then scan the known responces to find out what we got.
1097
 
                        for (i = 0; TS870S_FMbw[i] != NULL; i++) // bump array index counter, till string match or end.
1098
 
                                if (replystr.find(TS870S_FMbw[i]) == p) break;  // Found returned data, in string array.
1099
 
 
1100
 
                        if (TS870S_FMbw[i] != NULL) B.iBW = i; // if we didn't hit the end, return the array index value.
1101
 
                        else B.iBW = 1; // Default.
1102
 
                }
1103
 
        }
1104
 
 
1105
 
        else if (B.imode == tsCW || B.imode == tsCWR) { // CW modes.
1106
 
                cmd = "FW;"; // 'Filter Width' query
1107
 
                waitN(7, 100, "get CW width", ASC);
1108
 
                p = replystr.rfind("FW");
1109
 
 
1110
 
                if (p != string::npos) { // If 'FW' found then scan the known responces to find out what we got.
1111
 
                        for (i = 0; TS870S_CWbw[i] != NULL; i++) // bump array index counter, till string match or end.
1112
 
                                if (replystr.find(TS870S_CWbw[i]) == p) break;  // Found returned data, in string array.
1113
 
 
1114
 
                        if (TS870S_CWbw[i] != NULL) B.iBW = i; // if we didn't hit the end, return the array index value.
1115
 
                        else B.iBW = 1; // Default.
1116
 
                }
1117
 
        }
1118
 
 
1119
 
        else if (B.imode == tsFSK || B.imode == tsFSKR) { // FSK modes.
1120
 
                cmd = "FW;";
1121
 
                waitN(7, 100, "get FSK width", ASC);
1122
 
                p = replystr.rfind("FW");
1123
 
 
1124
 
                if (p != string::npos) { // If 'FW' found then scan the known responces to find out what we got.
1125
 
                        for (i = 0; TS870S_FSKbw[i] != NULL; i++) // bumb array index counter, till string match or end.
1126
 
                                if (replystr.find(TS870S_FSKbw[i]) == p) break;         // Found returned data, in string array.
1127
 
 
1128
 
                        if (TS870S_FSKbw[i] != NULL) B.iBW = i; // if we didn't hit the end, return the array index value.
1129
 
                        else B.iBW = 1; // Default.
1130
 
                }
1131
 
        }
1132
 
 
1133
 
        else if (B.imode == tsAM) { // AM mode only
1134
 
 
1135
 
                int lo = B.iBW & 0x7F, hi = (B.iBW >> 8) & 0x7F;
1136
 
 
1137
 
                cmd = "FW;"; // Read Low cuttoff. Returns a two digit code as 'FLxxxx;' in 10Hz increments.
1138
 
                waitN(5, 100, "get lower", ASC);
1139
 
                p = replystr.rfind("FW");
1140
 
 
1141
 
                if (p != string::npos) { // If 'FW' found then scan the known responces to find out what we got.
1142
 
                        for (i = 0; TS870S_CAT_am_lo[i] != NULL; i++) // bump array index counter, till string match or end.
1143
 
                                if (replystr.find(TS870S_CAT_am_lo[i]) == p) break;     // Found returned data, in string array.
1144
 
 
1145
 
                        if (TS870S_CAT_am_lo[i] != NULL) lo = i; // if we didn't hit the end, return the array index value.
1146
 
                        else lo = 1; // Default.
1147
 
                }
1148
 
 
1149
 
                cmd = "IS;";
1150
 
                waitN(5, 100, "get upper", ASC);
1151
 
                p = replystr.rfind("IS ");
1152
 
 
1153
 
                if (p != string::npos) {
1154
 
                        for (i = 0; TS870S_CAT_am_hi[i] != NULL; i++) // bump array index counter, till string match or end.
1155
 
                                if (replystr.find(TS870S_CAT_am_hi[i]) == p) break;     // Found returned data, in string array.
1156
 
 
1157
 
                        if (TS870S_CAT_am_hi[i] != NULL) hi = i; // if we didn't hit the end, return the array index value.
1158
 
                        else hi = 1; // Default.
1159
 
                }
1160
 
                B.iBW = ((hi << 8) | (lo & 0x7F)) | 0x8000;
1161
 
        }
1162
 
 
1163
 
 
1164
 
        else if (B.imode == tsLSB || B.imode == tsUSB ) { // SSB (Upper and lower)
1165
 
 
1166
 
                int lo = B.iBW & 0x7F, hi = (B.iBW >> 8) & 0x7F;
1167
 
 
1168
 
                cmd = "FW;"; // Read Low cuttoff. Returns a two digit code as 'FLxxxx;' in 10Hz increments.
1169
 
                waitN(5, 100, "get lower", ASC);
1170
 
                p = replystr.rfind("FW");
1171
 
 
1172
 
                if (p != string::npos) { // If 'FW' found then scan the known responces to find out what we got.
1173
 
                        for (i = 0; TS870S_CAT_ssb_lo[i] != NULL; i++) // bump array index counter, till string match or end.
1174
 
                                if (replystr.find(TS870S_CAT_ssb_lo[i]) == p) break;    // Found returned data, in string array.
1175
 
 
1176
 
                        if (TS870S_CAT_ssb_lo[i] != NULL) lo = i; // if we didn't hit the end, return the array index value.
1177
 
                        else lo = 1; // Default.
1178
 
                }
1179
 
 
1180
 
                cmd = "IS;";
1181
 
                waitN(5, 100, "get upper", ASC);
1182
 
                p = replystr.rfind("IS ");
1183
 
 
1184
 
                if (p != string::npos) {
1185
 
                        for (i = 0; TS870S_CAT_ssb_hi[i] != NULL; i++) // bump array index counter, till string match or end.
1186
 
                                if (replystr.find(TS870S_CAT_ssb_hi[i]) == p) break;    // Found returned data, in string array.
1187
 
 
1188
 
                        if (TS870S_CAT_ssb_hi[i] != NULL) hi = i; // if we didn't hit the end, return the array index value.
1189
 
                        else hi = 1; // Default.
1190
 
                }
1191
 
                B.iBW = ((hi << 8) | (lo & 0x7F)) | 0x8000;
1192
 
        }
1193
 
        return B.iBW;
1194
 
}
1195
 
 
1196
 
//----------------------------------------------------------------------
1197
 
int RIG_TS870S::get_modetype(int n)
1198
 
{
1199
 
        return TS870S_mode_type[n];
1200
 
}
1201
 
 
1202
 
//----------------------------------------------------------------------
1203
 
// val 0 .. 255
1204
 
void RIG_TS870S::set_mic_gain(int val)
1205
 
{
1206
 
        int imic = (int)(val * 2.55); // 0 .. 255
1207
 
        cmd = "MG000;";
1208
 
        for (int i = 3; i > 0; i--) {
1209
 
                cmd[1+i] += imic % 10;
1210
 
                imic /= 10;
1211
 
        }
1212
 
        sendCommand(cmd, 0);
1213
 
}
1214
 
 
1215
 
//----------------------------------------------------------------------
1216
 
int RIG_TS870S::get_mic_gain()
1217
 
{
1218
 
        int val = 0;
1219
 
        cmd = "MG;";
1220
 
        int ret = waitN(6, 100, "get mic ctrl", ASC);
1221
 
 
1222
 
        if (ret >= 6) {
1223
 
                size_t p = replystr.rfind("MG");
1224
 
                if (p == string::npos) return val;
1225
 
                replystr[p + 5] = 0;
1226
 
                val = atoi(&replystr[p + 2]);
1227
 
        }
1228
 
        return (int)(val / 2.55);  // we only want 0 .. 100
1229
 
}
1230
 
 
1231
 
//----------------------------------------------------------------------
1232
 
void RIG_TS870S::get_mic_min_max_step(int &min, int &max, int &step)
1233
 
{
1234
 
        min = 0;
1235
 
        max = 100;
1236
 
        step = 1;
1237
 
}
1238
 
 
1239
 
//----------------------------------------------------------------------
1240
 
void RIG_TS870S::set_noise(bool val)
1241
 
{
1242
 
        if (val)
1243
 
                cmd = "NB1;";
1244
 
        else
1245
 
                cmd = "NB0;";
1246
 
        sendCommand(cmd);
1247
 
        showresp(WARN, ASC, "set NB", cmd, replystr);
1248
 
}
1249
 
 
1250
 
int  RIG_TS870S::get_noise()
1251
 
{
1252
 
        cmd = "NB;";
1253
 
        int ret = sendCommand(cmd);
1254
 
        showresp(WARN, ASC, "get NB", cmd, replystr);
1255
 
        if (ret < 4) return 0;
1256
 
        size_t p = replystr.rfind("NB");
1257
 
        if (p == string::npos) return 0;
1258
 
 
1259
 
        return (replystr[p + 2] == '1'); // true if 1
1260
 
}
1261
 
 
1262
 
//======================================================================
1263
 
// IF shift command only available if the transceiver is in the CW mode
1264
 
// step size is 50 Hz
1265
 
//======================================================================
1266
 
// See also, the code in support.cxx
1267
 
//      setMode and setModeControl, calling 'checkTS870S'
1268
 
//
1269
 
void RIG_TS870S::set_if_shift(int val)
1270
 
{
1271
 
        if (active_mode == tsCW || active_mode == tsCWR) { // cw modes
1272
 
                progStatus.shift_val = val;
1273
 
                cmd = "IS ";
1274
 
                cmd.append(to_decimal(abs(val),4)).append(";");
1275
 
                sendCommand(cmd,0);
1276
 
                showresp(WARN, ASC, "set IF shift", cmd, replystr);
1277
 
        }
1278
 
}
1279
 
 
1280
 
//----------------------------------------------------------------------
1281
 
bool RIG_TS870S::get_if_shift(int &val)
1282
 
{
1283
 
        if (active_mode == tsCW || active_mode == tsCWR) { // cw modes
1284
 
                cmd = "IS;";
1285
 
                waitN(8, 100, "get IF shift", ASC);
1286
 
                size_t p = replystr.rfind("IS");
1287
 
                if (p != string::npos) {
1288
 
                        val = fm_decimal(&replystr[p+3], 4);
1289
 
                } else
1290
 
                        val = progStatus.shift_val;
1291
 
                return true;
1292
 
        }
1293
 
        val = progStatus.shift_val;
1294
 
        return false;
1295
 
}
1296
 
 
1297
 
//----------------------------------------------------------------------
1298
 
void RIG_TS870S::get_if_min_max_step(int &min, int &max, int &step)
1299
 
{
1300
 
        if_shift_min = min = 400;
1301
 
        if_shift_max = max = 1000;
1302
 
        if_shift_step = step = 50;
1303
 
        if_shift_mid = 800;
1304
 
}
1305
 
 
1306
 
//----------------------------------------------------------------------
1307
 
void RIG_TS870S::set_notch(bool on, int val)
1308
 
{
1309
 
        cmd = "BP00000;";
1310
 
        if (on == false) {
1311
 
                sendCommand(cmd, 0);
1312
 
                notch_on = false;
1313
 
                return;
1314
 
        }
1315
 
        if (!notch_on) {
1316
 
                cmd[6] = '1'; // notch ON
1317
 
                sendCommand(cmd, 0);
1318
 
                cmd[6] = '0';
1319
 
                notch_on = true;
1320
 
        }
1321
 
        cmd[3] = '1'; // manual NOTCH position
1322
 
// set notch value offset by 200, ie: 001 -> 400
1323
 
        val = (-val / 9) + 200;
1324
 
        if (val < 1) val = 1;
1325
 
        if (val > 400) val = 400;
1326
 
        for (int i = 3; i > 0; i--) {
1327
 
                cmd[3 + i] += val % 10;
1328
 
                val /=10;
1329
 
        }
1330
 
        sendCommand(cmd, 0);
1331
 
}
1332
 
 
1333
 
//----------------------------------------------------------------------
1334
 
//tbd
1335
 
bool  RIG_TS870S::get_notch(int &val)
1336
 
{
1337
 
        return false;
1338
 
//      bool ison = false;
1339
 
//      cmd = "BP;";
1340
 
//      int ret = sendCommand(cmd);
1341
 
//      return ison;
1342
 
}
1343
 
 
1344
 
//----------------------------------------------------------------------
1345
 
void RIG_TS870S::get_notch_min_max_step(int &min, int &max, int &step)
1346
 
{
1347
 
        min = -1143;
1348
 
        max = +1143;
1349
 
        step = 9;
1350
 
}
1351
 
 
1352
 
//----------------------------------------------------------------------
1353
 
//      The End.
1354
 
//----------------------------------------------------------------------