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

« back to all changes in this revision

Viewing changes to .pc/0001-License-Declaration.patch/src/rigs/TS2000.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 TS2000 driver
3
 
 * 
4
 
 * a part of flrig
5
 
 * 
6
 
 * Copyright 2009, Dave Freese, W1HKJ
7
 
 * 
8
 
 */
9
 
 
10
 
 
11
 
#include "TS2000.h"
12
 
#include "support.h"
13
 
 
14
 
static const char TS2000name_[] = "TS-2000";
15
 
 
16
 
static const char *TS2000modes_[] = {
17
 
        "LSB", "USB", "CW", "FM", "AM", "FSK", "CW-R", "FSK-R", "DIGI-L", "DIGI-U", NULL};
18
 
 
19
 
static const char TS2000_mode_chr[] =  { '1', '2', '3', '4', '5', '6', '7', '9' };
20
 
static const char TS2000_mode_type[] = { 'L', 'U', 'U', 'U', 'U', 'L', 'L', 'U' };
21
 
 
22
 
static const char *TS2000_empty[] = { "N/A", NULL };
23
 
//------------------------------------------------------------------------------
24
 
static const char *TS2000_lo[] = {
25
 
 "10",   "50", "100", "200", "300", 
26
 
"400",  "500", "600", "700", "800", 
27
 
"900", "1000", NULL };
28
 
static const char *TS2000_CAT_lo[] = {
29
 
"SL00;", "SL01;", "SL02;", "SL03;", "SL04;", 
30
 
"SL05;", "SL06;", "SL07;", "SL08;", "SL09;",
31
 
"SL10;", "SL11;", NULL };
32
 
static const char *TS2000_lo_tooltip = "lo cutoff";
33
 
static const char *TS2000_SSB_btn_lo_label = "L";
34
 
//------------------------------------------------------------------------------
35
 
static const char *TS2000_hi[] = {
36
 
"1400", "1600", "1800", "2000", "2200",
37
 
"2400", "2600", "2800", "3000", "3400",
38
 
"4000", "5000", NULL };
39
 
static const char *TS2000_CAT_hi[] = {
40
 
"SH00;", "SH01;", "SH02;", "SH03;", "SH04;", 
41
 
"SH05;", "SH06;", "SH07;", "SH08;", "SH09;",
42
 
"SH10;", "SH11;", NULL };
43
 
static const char *TS2000_hi_tooltip = "hi cutoff";
44
 
static const char *TS2000_SSB_btn_hi_label = "H";
45
 
//------------------------------------------------------------------------------
46
 
static const char *TS2000_AM_lo[] = {
47
 
"0", "100", "200", "500",
48
 
NULL };
49
 
static const char *TS2000_AM_hi[] = {
50
 
"2500", "3000", "4000", "5000",
51
 
NULL };
52
 
//------------------------------------------------------------------------------
53
 
static const char *TS2000_CWwidths[] = {
54
 
"50", "80", "100", "150", "200", 
55
 
"300", "400", "500", "600", "1000", 
56
 
"1500", NULL};
57
 
static const char *TS2000_CWbw[] = {
58
 
"FW0050;", "FW0080;", "FW0100;", "FW0150;", "FW0200;", 
59
 
"FW0300;", "FW0400;", "FW0500;", "FW0600;", "FW1000;", 
60
 
"FW1500;" };
61
 
//------------------------------------------------------------------------------
62
 
static const char *TS2000_FSKwidths[] = {
63
 
"250", "500", "1000", "1500", NULL};
64
 
static const char *TS2000_FSKbw[] = {
65
 
"FW0250;", "FW0500;", "FW1000;", "FW1500;" };
66
 
//------------------------------------------------------------------------------
67
 
 
68
 
static GUI rig_widgets[]= {
69
 
        { (Fl_Widget *)btnVol,        2, 125,  50 },
70
 
        { (Fl_Widget *)sldrVOLUME,   54, 125, 156 },
71
 
        { (Fl_Widget *)sldrRFGAIN,   54, 145, 156 },
72
 
        { (Fl_Widget *)btnIFsh,     214, 105,  50 },
73
 
        { (Fl_Widget *)sldrIFSHIFT, 266, 105, 156 },
74
 
        { (Fl_Widget *)btnNotch,    214, 125,  50 },
75
 
        { (Fl_Widget *)sldrNOTCH,   266, 125, 156 },
76
 
        { (Fl_Widget *)sldrMICGAIN, 266, 145, 156 },
77
 
        { (Fl_Widget *)sldrPOWER,    54, 165, 368 },
78
 
        { (Fl_Widget *)NULL,          0,   0,   0 }
79
 
};
80
 
 
81
 
// mid range on loudness
82
 
static string menu012 = "EX01200004";
83
 
 
84
 
void RIG_TS2000::initialize()
85
 
{
86
 
        rig_widgets[0].W = btnVol;
87
 
        rig_widgets[1].W = sldrVOLUME;
88
 
        rig_widgets[2].W = sldrRFGAIN;
89
 
        rig_widgets[3].W = btnIFsh;
90
 
        rig_widgets[4].W = sldrIFSHIFT;
91
 
        rig_widgets[5].W = btnNotch;
92
 
        rig_widgets[6].W = sldrNOTCH;
93
 
        rig_widgets[7].W = sldrMICGAIN;
94
 
        rig_widgets[8].W = sldrPOWER;
95
 
 
96
 
        menu012.clear();
97
 
        cmd = "EX0120000;"; // read menu 012 state
98
 
//might return something like EX01200004;
99
 
 
100
 
        if (waitN(11, 100, "read ex 012", ASC) == 11)
101
 
                menu012 = replystr;
102
 
 
103
 
// disable beeps before resetting front panel display to SWR
104
 
        cmd = "EX01200000;";
105
 
        sendCommand(cmd);
106
 
        select_swr();
107
 
 
108
 
// restore state of xcvr beeps
109
 
//      cmd = menu012;
110
 
//      sendCommand(cmd);
111
 
 
112
 
// get current noise reduction values for NR1 and NR2
113
 
        string current_nr;
114
 
        cmd = "NR;";
115
 
        if (waitN(4, 100, "read current NR", ASC) == 4)
116
 
                current_nr = replystr;
117
 
        cmd = "NR1;";
118
 
        sendCommand(cmd);
119
 
        cmd = "RL;";
120
 
        waitN(5, 100, "GET noise reduction val", ASC);
121
 
        size_t p = replystr.rfind("RL");
122
 
        if (p != string::npos)
123
 
                _nrval1 = atoi(&replystr[p+2]);
124
 
        cmd = "NR2;";
125
 
        sendCommand(cmd);
126
 
        cmd = "RL;";
127
 
        waitN(5, 100, "GET noise reduction val", ASC);
128
 
        p = replystr.rfind("RL");
129
 
        if (p != string::npos)
130
 
                _nrval2 = atoi(&replystr[p+2]);
131
 
// restore xcvr setting for NR
132
 
        cmd = current_nr;
133
 
        sendCommand(cmd);
134
 
}
135
 
 
136
 
void RIG_TS2000::shutdown()
137
 
{
138
 
// restore state of xcvr beeps
139
 
        cmd = menu012;
140
 
        sendCommand(cmd);
141
 
}
142
 
 
143
 
 
144
 
RIG_TS2000::RIG_TS2000() {
145
 
// base class values    
146
 
        name_ = TS2000name_;
147
 
        modes_ = TS2000modes_;
148
 
        bandwidths_ = TS2000_empty;
149
 
 
150
 
        dsp_lo     = TS2000_lo;
151
 
        lo_tooltip = TS2000_lo_tooltip;
152
 
        lo_label   = TS2000_SSB_btn_lo_label;
153
 
 
154
 
        dsp_hi     = TS2000_hi;
155
 
        hi_tooltip = TS2000_hi_tooltip;
156
 
        hi_label   = TS2000_SSB_btn_hi_label;
157
 
 
158
 
        widgets = rig_widgets;
159
 
 
160
 
        comm_baudrate = BR4800;
161
 
        stopbits = 2;
162
 
        comm_retries = 2;
163
 
        comm_wait = 5;
164
 
        comm_timeout = 50;
165
 
        comm_rtscts = true;
166
 
        comm_rtsplus = false;
167
 
        comm_dtrplus = false;
168
 
        comm_catptt = true;
169
 
        comm_rtsptt = false;
170
 
        comm_dtrptt = false;
171
 
        B.imode = A.imode = 1;
172
 
        B.iBW = A.iBW = 0x8803;
173
 
        B.freq = A.freq = 14070000;
174
 
        can_change_alt_vfo = true;
175
 
 
176
 
        has_power_out =
177
 
        has_swr_control =
178
 
        has_alc_control =
179
 
        has_split =
180
 
        has_split_AB =
181
 
        has_dsp_controls =
182
 
        has_rf_control =
183
 
        has_notch_control =
184
 
        has_auto_notch =
185
 
        has_ifshift_control =
186
 
        has_smeter =
187
 
        has_noise_reduction =
188
 
        has_noise_reduction_control =
189
 
        has_noise_control =
190
 
        has_micgain_control =
191
 
        has_volume_control =
192
 
        has_power_control =
193
 
        has_tune_control =
194
 
        has_attenuator_control =
195
 
        has_preamp_control =
196
 
        has_mode_control =
197
 
        has_bandwidth_control =
198
 
        has_ptt_control = true;
199
 
 
200
 
        rxona = true;
201
 
 
202
 
        precision = 1;
203
 
        ndigits = 9;
204
 
 
205
 
        att_level = 0;
206
 
        preamp_level = 0;
207
 
        _noise_reduction_level = 0;
208
 
        _nrval1 = 2;
209
 
        _nrval2 = 4;
210
 
}
211
 
 
212
 
const char * RIG_TS2000::get_bwname_(int n, int md) 
213
 
{
214
 
        static char bwname[20];
215
 
        if (n > 256) {
216
 
                int hi = (n >> 8) & 0x7F;
217
 
                int lo = n & 0xFF;
218
 
                snprintf(bwname, sizeof(bwname), "%s/%s",
219
 
                        (md == LSB || md == USB || md == FM) ? TS2000_lo[lo] : TS2000_AM_lo[lo],
220
 
                        (md == LSB || md == USB || md == FM) ? TS2000_hi[hi] : TS2000_AM_hi[hi] );
221
 
        } else {
222
 
                snprintf(bwname, sizeof(bwname), "%s",
223
 
                        (md == CW || md == CWR) ? TS2000_CWwidths[n] : TS2000_FSKwidths[n]);
224
 
        }
225
 
        return bwname;
226
 
}
227
 
 
228
 
void RIG_TS2000::selectA()
229
 
{
230
 
        cmd = "FR0;";
231
 
        sendCommand(cmd);
232
 
        showresp(WARN, ASC, "Rx on A", cmd, replystr);
233
 
        cmd = "FT0;";
234
 
        sendCommand(cmd);
235
 
        showresp(WARN, ASC, "Tx on A", cmd, replystr);
236
 
        rxona = true;
237
 
}
238
 
 
239
 
void RIG_TS2000::selectB()
240
 
{
241
 
        cmd = "FR1;";
242
 
        sendCommand(cmd);
243
 
        showresp(WARN, ASC, "Rx on B", cmd, replystr);
244
 
        cmd = "FT1;";
245
 
        sendCommand(cmd);
246
 
        showresp(WARN, ASC, "Tx on B", cmd, replystr);
247
 
        rxona = false;
248
 
}
249
 
 
250
 
void RIG_TS2000::set_split(bool val) 
251
 
{
252
 
        split = val;
253
 
        if (useB) {
254
 
                if (val) {
255
 
                        cmd = "FR1;";
256
 
                        sendCommand(cmd);
257
 
                        showresp(WARN, ASC, "Rx on B", cmd, replystr);
258
 
                        cmd = "FT0;";
259
 
                        sendCommand(cmd);
260
 
                        showresp(WARN, ASC, "Tx on A", cmd, replystr);
261
 
                } else {
262
 
                        cmd = "FR1;";
263
 
                        sendCommand(cmd);
264
 
                        showresp(WARN, ASC, "Rx on B", cmd, replystr);
265
 
                        cmd = "FT1;";
266
 
                        sendCommand(cmd);
267
 
                        showresp(WARN, ASC, "Tx on B", cmd, replystr);
268
 
                }
269
 
                rxona = false;
270
 
        } else {
271
 
                if (val) {
272
 
                        cmd = "FR0;";
273
 
                        sendCommand(cmd);
274
 
                        showresp(WARN, ASC, "Rx on A", cmd, replystr);
275
 
                        cmd = "FT1;";
276
 
                        sendCommand(cmd);
277
 
                        showresp(WARN, ASC, "Tx on B", cmd, replystr);
278
 
                } else {
279
 
                        cmd = "FR0;";
280
 
                        sendCommand(cmd);
281
 
                        showresp(WARN, ASC, "Rx on A", cmd, replystr);
282
 
                        cmd = "FT0;";
283
 
                        sendCommand(cmd);
284
 
                        showresp(WARN, ASC, "Tx on A", cmd, replystr);
285
 
                }
286
 
                rxona = true;
287
 
        }
288
 
        Fl::awake(highlight_vfo, (void *)0);
289
 
}
290
 
 
291
 
int RIG_TS2000::get_split()
292
 
{
293
 
        size_t p;
294
 
        int split = 0;
295
 
        int rx, tx;
296
 
// tx vfo
297
 
        cmd = "FT;";
298
 
        waitN(4, 100, "get split tx vfo", ASC);
299
 
        p = replystr.rfind("FT");
300
 
        if (p == string::npos) return split;
301
 
        tx = replystr[p+2] - '0';
302
 
 
303
 
// rx vfo
304
 
        cmd = "FR;";
305
 
        waitN(4, 100, "get split rx vfo", ASC);
306
 
 
307
 
        p = replystr.rfind("FR");
308
 
        if (p == string::npos) return split;
309
 
        rx = replystr[p+2] - '0';
310
 
// split test
311
 
        split = tx * 2 + rx;
312
 
 
313
 
        return split;
314
 
}
315
 
 
316
 
long RIG_TS2000::get_vfoA ()
317
 
{
318
 
        cmd = "FA;";
319
 
        waitN(14, 100, "get vfo A", ASC);
320
 
        size_t p = replystr.rfind("FA");
321
 
        if (p != string::npos) {
322
 
                int f = 0;
323
 
                for (size_t n = 2; n < 13; n++)
324
 
                        f = f*10 + replystr[p+n] - '0';
325
 
                A.freq = f;
326
 
        }
327
 
        return A.freq;
328
 
}
329
 
 
330
 
void RIG_TS2000::set_vfoA (long freq)
331
 
{
332
 
        A.freq = freq;
333
 
        cmd = "FA00000000000;";
334
 
        for (int i = 12; i > 1; i--) {
335
 
                cmd[i] += freq % 10;
336
 
                freq /= 10;
337
 
        }
338
 
        sendCommand(cmd,0);
339
 
        showresp(WARN, ASC, "set vfo A", cmd, replystr);
340
 
}
341
 
 
342
 
long RIG_TS2000::get_vfoB ()
343
 
{
344
 
        cmd = "FB;";
345
 
        waitN(14, 100, "get vfo B", ASC);
346
 
        size_t p = replystr.rfind("FB");
347
 
        if (p != string::npos) {
348
 
                int f = 0;
349
 
                for (size_t n = 2; n < 13; n++)
350
 
                        f = f*10 + replystr[p+n] - '0';
351
 
                B.freq = f;
352
 
        }
353
 
        return B.freq;
354
 
}
355
 
 
356
 
void RIG_TS2000::set_vfoB (long freq)
357
 
{
358
 
        B.freq = freq;
359
 
        cmd = "FB00000000000;";
360
 
        for (int i = 12; i > 1; i--) {
361
 
                cmd[i] += freq % 10;
362
 
                freq /= 10;
363
 
        }
364
 
        sendCommand(cmd,0);
365
 
        showresp(WARN, ASC, "set vfo B", cmd, replystr);
366
 
}
367
 
 
368
 
int RIG_TS2000::get_smeter()
369
 
{
370
 
        if (rxona)
371
 
                cmd = "SM0;";
372
 
        else
373
 
                cmd = "SM1;";
374
 
        waitN(8, 100, "get smeter", ASC);
375
 
        size_t p = replystr.rfind("SM");
376
 
        if (p != string::npos) {
377
 
                int mtr = fm_decimal(&replystr[p+3],4);
378
 
                if (rxona)
379
 
                        mtr = (mtr * 100) / 30;
380
 
                else
381
 
                        mtr = (mtr * 100) / 15;
382
 
                return mtr;
383
 
        }
384
 
        return 0;
385
 
}
386
 
 
387
 
int RIG_TS2000::get_swr()
388
 
{
389
 
        cmd = "RM;";
390
 
        waitN(8, 100, "get swr", ASC);
391
 
        size_t p = replystr.rfind("RM1");
392
 
        if (p != string::npos) {
393
 
                int mtr = fm_decimal(&replystr[p+3], 4);
394
 
                mtr = (mtr * 10) / 3;
395
 
                return mtr;
396
 
        }
397
 
        return 0;
398
 
}
399
 
 
400
 
int  RIG_TS2000::get_alc(void) 
401
 
{
402
 
        cmd = "RM;";
403
 
        waitN(8, 100, "get alc", ASC);
404
 
        size_t p = replystr.rfind("RM3");
405
 
        if (p != string::npos) {
406
 
                int mtr = fm_decimal(&replystr[p+3], 4);
407
 
                mtr = (mtr * 10) / 3;
408
 
                return mtr;
409
 
        }
410
 
        return 0;
411
 
}
412
 
 
413
 
void  RIG_TS2000::select_swr()
414
 
{
415
 
        cmd = "RM1;";
416
 
        sendCommand(cmd);
417
 
}
418
 
 
419
 
void  RIG_TS2000::select_alc()
420
 
{
421
 
        cmd = "RM3;";
422
 
        sendCommand(cmd);
423
 
}
424
 
 
425
 
// Transceiver power level
426
 
void RIG_TS2000::set_power_control(double val)
427
 
{
428
 
        int ival = (int)val;
429
 
        cmd = "PC";
430
 
        cmd.append(to_decimal(ival, 3)).append(";");
431
 
        sendCommand(cmd);
432
 
        showresp(WARN, ASC, "set pwr ctrl", cmd, replystr);
433
 
}
434
 
 
435
 
int RIG_TS2000::get_power_out()
436
 
{
437
 
        cmd = "SM0;";
438
 
        waitN(8, 100, "get power out", ASC);
439
 
        size_t p = replystr.rfind("SM0");
440
 
        if (p != string::npos) {
441
 
                int mtr = fm_decimal(&replystr[p+3],4);
442
 
                if (mtr <= 6) mtr = mtr * 2;
443
 
                else if (mtr <= 11) mtr = 11 + (mtr - 6)*(26 - 11)/(11 - 6);
444
 
                else if (mtr <= 18) mtr = 26 + (mtr - 11)*(50 - 26)/(18 - 11);
445
 
                else mtr = 50 + (mtr - 18)*(100 - 50)/(27 - 18);
446
 
                if (mtr > 100) mtr = 100;
447
 
                return mtr;
448
 
        }
449
 
        return 0;
450
 
}
451
 
 
452
 
int RIG_TS2000::get_power_control()
453
 
{
454
 
        cmd = "PC;";
455
 
        waitN(6, 100, "get pout", ASC);
456
 
        size_t p = replystr.rfind("PC");
457
 
        if (p != string::npos) {
458
 
                int mtr = fm_decimal(&replystr[p+2], 3);
459
 
                return mtr;
460
 
        }
461
 
        return 0;
462
 
}
463
 
 
464
 
// Volume control return 0 ... 100
465
 
int RIG_TS2000::get_volume_control()
466
 
{
467
 
        cmd = "AG0;";
468
 
        waitN(7, 100, "get vol", ASC);
469
 
        size_t p = replystr.rfind("AG");
470
 
        if (p != string::npos) {
471
 
                int val = fm_decimal(&replystr[p+3],3);
472
 
                return (int)(val / 2.55);
473
 
        }
474
 
        return 0;
475
 
}
476
 
 
477
 
void RIG_TS2000::set_volume_control(int val) 
478
 
{
479
 
        int ivol = (int)(val * 2.55);
480
 
        cmd = "AG0";
481
 
        cmd.append(to_decimal(ivol, 3)).append(";");
482
 
        sendCommand(cmd,0);
483
 
        showresp(WARN, ASC, "set vol", cmd, replystr);
484
 
}
485
 
 
486
 
// Tranceiver PTT on/off
487
 
void RIG_TS2000::set_PTT_control(int val)
488
 
{
489
 
        if (val) cmd = "TX;";
490
 
        else     cmd = "RX;";
491
 
        sendCommand(cmd,0);
492
 
        showresp(WARN, ASC, "set PTT", cmd, replystr);
493
 
}
494
 
 
495
 
void RIG_TS2000::tune_rig()
496
 
{
497
 
        cmd = "AC111;";
498
 
        sendCommand(cmd,0);
499
 
        showresp(WARN, ASC, "tune", cmd, replystr);
500
 
}
501
 
 
502
 
void RIG_TS2000::set_attenuator(int val)
503
 
{
504
 
        att_level = val;
505
 
        if (val) cmd = "RA01;";
506
 
        else     cmd = "RA00;";
507
 
        sendCommand(cmd,0);
508
 
        showresp(WARN, ASC, "set ATT", cmd, replystr);
509
 
}
510
 
 
511
 
int RIG_TS2000::get_attenuator()
512
 
{
513
 
        cmd = "RA;";
514
 
        waitN(7, 100, "get ATT", ASC);
515
 
        size_t p = replystr.rfind("RA");
516
 
        if (p != string::npos && (p+3 < replystr.length())) {
517
 
                if (replystr[p+2] == '0' && replystr[p+3] == '0')
518
 
                        att_level = 0;
519
 
                else
520
 
                        att_level = 1;
521
 
        }
522
 
        return att_level;
523
 
}
524
 
 
525
 
void RIG_TS2000::set_preamp(int val)
526
 
{
527
 
        preamp_level = val;
528
 
        if (val) cmd = "PA1;";
529
 
        else     cmd = "PA0;";
530
 
        sendCommand(cmd,0);
531
 
        showresp(WARN, ASC, "set PRE", cmd, replystr);
532
 
}
533
 
 
534
 
int RIG_TS2000::get_preamp()
535
 
{
536
 
        cmd = "PA;";
537
 
        waitN(5, 100, "get PRE", ASC);
538
 
        size_t p = replystr.rfind("PA");
539
 
        if (p != string::npos && (p+2 < replystr.length())) {
540
 
                if (replystr[p+2] == '1') 
541
 
                        preamp_level = 1;
542
 
                else
543
 
                        preamp_level = 0;
544
 
        }
545
 
        return preamp_level;
546
 
}
547
 
 
548
 
int RIG_TS2000::set_widths(int val)
549
 
{
550
 
        int bw;
551
 
        switch (val) {
552
 
        case LSB: case USB: case FM:
553
 
                bandwidths_ = TS2000_hi;
554
 
                dsp_lo = TS2000_lo;
555
 
                lo_tooltip = TS2000_lo_tooltip;
556
 
                lo_label   = TS2000_SSB_btn_lo_label;
557
 
                dsp_hi = TS2000_hi;
558
 
                hi_tooltip = TS2000_hi_tooltip;
559
 
                hi_label   = TS2000_SSB_btn_hi_label;
560
 
                if (val == FM) bw = 0x8A03; // 200 ... 4000 Hz
561
 
                else bw = 0x8803; // 200 ... 3000 Hz
562
 
                break;
563
 
        case CW: case CWR:
564
 
                bandwidths_ = TS2000_CWwidths;
565
 
                dsp_lo = TS2000_empty;
566
 
                dsp_hi = TS2000_empty;
567
 
                bw = 7;
568
 
                break;
569
 
        case FSK: case FSKR:
570
 
                bandwidths_ = TS2000_FSKwidths;
571
 
                dsp_lo = TS2000_empty;
572
 
                dsp_hi = TS2000_empty;
573
 
                bw = 1;
574
 
                break;
575
 
        case AM: default:
576
 
                bandwidths_ = TS2000_AM_hi;
577
 
                dsp_lo = TS2000_AM_lo;
578
 
                dsp_hi = TS2000_AM_hi;
579
 
                bw = 0x8201;
580
 
                break;
581
 
        }
582
 
        return bw;
583
 
}
584
 
 
585
 
const char **RIG_TS2000::bwtable(int val)
586
 
{
587
 
        if (val == LSB || val == USB || val == FM)
588
 
                return TS2000_hi;
589
 
        else if (val == CW || val == CWR)
590
 
                return TS2000_CWwidths;
591
 
        else if (val == FSK || val == FSKR)
592
 
                return TS2000_FSKwidths;
593
 
//else AM m == 4
594
 
        return TS2000_AM_hi;
595
 
}
596
 
 
597
 
const char **RIG_TS2000::lotable(int val)
598
 
{
599
 
        if (val == LSB || val == USB || val == FM)
600
 
                return TS2000_lo;
601
 
        else if (val == CW || val == CWR)
602
 
                return NULL;
603
 
        else if (val == FSK || val == FSKR)
604
 
                return NULL;
605
 
        return TS2000_AM_lo;
606
 
}
607
 
 
608
 
const char **RIG_TS2000::hitable(int val)
609
 
{
610
 
        if (val == LSB || val == USB || val == FM)
611
 
                return TS2000_hi;
612
 
        else if (val == CW || val == CWR)
613
 
                return NULL;
614
 
        else if (val == FSK || val == FSKR)
615
 
                return NULL;
616
 
        return TS2000_AM_hi;
617
 
}
618
 
 
619
 
void RIG_TS2000::set_modeA(int val)
620
 
{
621
 
        _currmode = A.imode = val;
622
 
        cmd = "MD";
623
 
        cmd += TS2000_mode_chr[val];
624
 
        cmd += ';';
625
 
        sendCommand(cmd,0);
626
 
        showresp(WARN, ASC, "set mode", cmd, replystr);
627
 
        A.iBW = set_widths(val);
628
 
}
629
 
 
630
 
int RIG_TS2000::get_modeA()
631
 
{
632
 
        cmd = "MD;";
633
 
        waitN(4, 100, "get mode A", ASC);
634
 
        size_t p = replystr.rfind("MD");
635
 
        if (p != string::npos) {
636
 
                int md = replystr[p+2];
637
 
                md = md - '1';
638
 
                if (md == 8) md = 7;
639
 
                A.imode = md;
640
 
                A.iBW = set_widths(A.imode);
641
 
        }
642
 
        _currmode = A.imode;
643
 
        return A.imode;
644
 
}
645
 
 
646
 
void RIG_TS2000::set_modeB(int val)
647
 
{
648
 
        _currmode = B.imode = val;
649
 
        cmd = "MD";
650
 
        cmd += TS2000_mode_chr[val];
651
 
        cmd += ';';
652
 
        sendCommand(cmd);
653
 
        showresp(WARN, ASC, "set mode B", cmd, replystr);
654
 
        B.iBW = set_widths(val);
655
 
}
656
 
 
657
 
int RIG_TS2000::get_modeB()
658
 
{
659
 
        cmd = "MD;";
660
 
        waitN(4, 100, "get mode B", ASC);
661
 
        size_t p = replystr.rfind("MD");
662
 
        if (p != string::npos) {
663
 
                int md = replystr[p+2];
664
 
                md = md - '1';
665
 
                if (md == 8) md = 7;
666
 
                B.imode = md;
667
 
                B.iBW = set_widths(B.imode);
668
 
        }
669
 
        _currmode = B.imode;
670
 
        return B.imode;
671
 
}
672
 
 
673
 
int RIG_TS2000::adjust_bandwidth(int val)
674
 
{
675
 
        int bw = 0;
676
 
        if (val == LSB || val == USB)
677
 
                bw = 0x8803;
678
 
        else if (val == FM)
679
 
                bw = 0x8A03;
680
 
        else if (val == AM)
681
 
                bw = 0x8301;
682
 
        else if (val == CW || val == CWR)
683
 
                bw = 7;
684
 
        else if (val == FSK || val == FSKR)
685
 
                bw = 1;
686
 
        return bw;
687
 
}
688
 
 
689
 
int RIG_TS2000::def_bandwidth(int val)
690
 
{
691
 
        return adjust_bandwidth(val);
692
 
}
693
 
 
694
 
void RIG_TS2000::set_bwA(int val)
695
 
{
696
 
        if (A.imode == LSB || A.imode == USB || A.imode == FM || A.imode == AM) {
697
 
                if (val < 256) return;
698
 
                A.iBW = val;
699
 
                cmd = "SL";
700
 
                cmd = TS2000_CAT_lo[A.iBW & 0x7F];
701
 
                sendCommand(cmd,0);
702
 
                showresp(WARN, ASC, "set lower", cmd, replystr);
703
 
                cmd = "SH";
704
 
                cmd = TS2000_CAT_hi[(A.iBW >> 8) & 0x7F];
705
 
                sendCommand(cmd,0);
706
 
                showresp(WARN, ASC, "set upper", cmd, replystr);
707
 
        }
708
 
        if (val > 256) return;
709
 
        else if (A.imode == CW || A.imode == CWR) {
710
 
                A.iBW = val;
711
 
                cmd = TS2000_CWbw[A.iBW];
712
 
                sendCommand(cmd,0);
713
 
                showresp(WARN, ASC, "set CW bw", cmd, replystr);
714
 
        }else if (A.imode == FSK || A.imode == FSKR) {
715
 
                A.iBW = val;
716
 
                cmd = TS2000_FSKbw[A.iBW];
717
 
                sendCommand(cmd,0);
718
 
                showresp(WARN, ASC, "set FSK bw", cmd, replystr);
719
 
        }
720
 
}
721
 
 
722
 
int RIG_TS2000::get_bwA()
723
 
{
724
 
        int i = 0;
725
 
        size_t p;
726
 
        if (A.imode == LSB || A.imode == USB || A.imode == FM || A.imode == AM) {
727
 
                int lo = A.iBW & 0xFF, hi = (A.iBW >> 8) & 0x7F;
728
 
                cmd = "SL;";
729
 
                waitN(5, 100, "get SL", ASC);
730
 
                p = replystr.rfind("SL");
731
 
                if (p != string::npos)
732
 
                        lo = fm_decimal(&replystr[2], 2);
733
 
                cmd = "SH;";
734
 
                waitN(5, 100, "get SH", ASC);
735
 
                p = replystr.rfind("SH");
736
 
                if (p != string::npos)
737
 
                        hi = fm_decimal(&replystr[2], 2);
738
 
                A.iBW = ((hi << 8) | (lo & 0xFF)) | 0x8000;
739
 
        } else if (A.imode == CW || A.imode == CWR) { // CW
740
 
                cmd = "FW;";
741
 
                waitN(7, 100, "get FW", ASC);
742
 
                p = replystr.rfind("FW");
743
 
                if (p != string::npos) {
744
 
                        for (i = 0; i < 11; i++)
745
 
                                if (replystr.find(TS2000_CWbw[i]) == p)
746
 
                                        break;
747
 
                        if (i == 11) i = 10;
748
 
                        A.iBW = i;
749
 
                }
750
 
        } else if (A.imode == FSK || A.imode == FSKR) {
751
 
                cmd = "FW;";
752
 
                waitN(7, 100, "get FW", ASC);
753
 
                p = replystr.rfind("FW");
754
 
                if (p != string::npos) {
755
 
                        for (i = 0; i < 4; i++)
756
 
                                if (replystr.find(TS2000_FSKbw[i]) == p)
757
 
                                        break;
758
 
                        if (i == 4) i = 3;
759
 
                        A.iBW = i;
760
 
                }
761
 
        }
762
 
        return A.iBW;
763
 
}
764
 
 
765
 
void RIG_TS2000::set_bwB(int val)
766
 
{
767
 
        if (B.imode == LSB || B.imode == USB || B.imode == FM || B.imode == AM) {
768
 
                if (val < 256) return;
769
 
                B.iBW = val;
770
 
                cmd = "SL";
771
 
                cmd = TS2000_CAT_lo[B.iBW & 0x7F];
772
 
                sendCommand(cmd,0);
773
 
                showresp(WARN, ASC, "set lower", cmd, replystr);
774
 
                cmd = "SH";
775
 
                cmd = TS2000_CAT_hi[(B.iBW >> 8) & 0x7F];
776
 
                sendCommand(cmd,0);
777
 
                showresp(WARN, ASC, "set upper", cmd, replystr);
778
 
        }
779
 
        if (val > 256) return;
780
 
        else if (B.imode == CW || B.imode == CWR) { // CW
781
 
                B.iBW = val;
782
 
                cmd = TS2000_CWbw[B.iBW];
783
 
                sendCommand(cmd,0);
784
 
                showresp(WARN, ASC, "set CW bw", cmd, replystr);
785
 
        }else if (B.imode == FSK || B.imode == FSKR) {
786
 
                B.iBW = val;
787
 
                cmd = TS2000_FSKbw[B.iBW];
788
 
                sendCommand(cmd,0);
789
 
                showresp(WARN, ASC, "set FSK bw", cmd, replystr);
790
 
        }
791
 
}
792
 
 
793
 
int RIG_TS2000::get_bwB()
794
 
{
795
 
        int i = 0;
796
 
        size_t p;
797
 
        if (B.imode == LSB || B.imode == USB || B.imode == FM || B.imode == AM) {
798
 
                int lo = B.iBW & 0xFF, hi = (B.iBW >> 8) & 0x7F;
799
 
                cmd = "SL;";
800
 
                waitN(5, 100, "get SL", ASC);
801
 
                p = replystr.rfind("SL");
802
 
                if (p != string::npos)
803
 
                        lo = fm_decimal(&replystr[2], 2);
804
 
                cmd = "SH;";
805
 
                waitN(5, 100, "get SH", ASC);
806
 
                p = replystr.rfind("SH");
807
 
                if (p != string::npos)
808
 
                        hi = fm_decimal(&replystr[2], 2);
809
 
                B.iBW = ((hi << 8) | (lo & 0xFF)) | 0x8000;
810
 
        } else if (B.imode == CW || B.imode == CWR) {
811
 
                cmd = "FW;";
812
 
                waitN(7, 100, "get FW", ASC);
813
 
                p = replystr.rfind("FW");
814
 
                if (p != string::npos) {
815
 
                        for (i = 0; i < 11; i++)
816
 
                                if (replystr.find(TS2000_CWbw[i]) == p)
817
 
                                        break;
818
 
                        if (i == 11) i = 10;
819
 
                        B.iBW = i;
820
 
                }
821
 
        } else if (B.imode == FSK || B.imode == FSKR) {
822
 
                cmd = "FW;";
823
 
                waitN(7, 100, "get FW", ASC);
824
 
                p = replystr.rfind("FW");
825
 
                if (p != string::npos) {
826
 
                        for (i = 0; i < 4; i++)
827
 
                                if (replystr.find(TS2000_FSKbw[i]) == p)
828
 
                                        break;
829
 
                        if (i == 4) i = 3;
830
 
                        B.iBW = i;
831
 
                }
832
 
        }
833
 
        return B.iBW;
834
 
}
835
 
 
836
 
int RIG_TS2000::get_modetype(int n)
837
 
{
838
 
        return TS2000_mode_type[n];
839
 
}
840
 
 
841
 
// val 0 .. 100
842
 
void RIG_TS2000::set_mic_gain(int val)
843
 
{
844
 
        cmd = "MG";
845
 
        cmd.append(to_decimal(val,3)).append(";");
846
 
        sendCommand(cmd);
847
 
        showresp(WARN, ASC, "set mic", cmd, replystr);
848
 
}
849
 
 
850
 
int RIG_TS2000::get_mic_gain()
851
 
{
852
 
        cmd = "MG;";
853
 
        waitN(6, 100, "get mic", ASC);
854
 
        size_t p = replystr.rfind("MG");
855
 
        if (p != string::npos)
856
 
                return fm_decimal(&replystr[p+2], 3);
857
 
        return 0;
858
 
}
859
 
 
860
 
void RIG_TS2000::get_mic_min_max_step(int &min, int &max, int &step)
861
 
{
862
 
        min = 0;
863
 
        max = 100;
864
 
        step = 1;
865
 
}
866
 
 
867
 
void RIG_TS2000::set_noise(bool b)
868
 
{
869
 
        if (b)
870
 
                cmd = "NB1;";
871
 
        else
872
 
                cmd = "NB0;";
873
 
        sendCommand(cmd,0);
874
 
        showresp(WARN, ASC, "set NB", cmd, replystr);
875
 
}
876
 
 
877
 
int RIG_TS2000::get_noise()
878
 
{
879
 
        cmd = "NB;";
880
 
        waitN(4, 100, "get Noise Blanker", ASC);
881
 
        size_t p = replystr.rfind("NB");
882
 
        if (p == string::npos) return 0;
883
 
        if (replystr[p+2] == '0') return 0;
884
 
        return 1;
885
 
}
886
 
 
887
 
//======================================================================
888
 
// IF shift only available if the transceiver is in the CW mode
889
 
// step size is 50 Hz
890
 
//======================================================================
891
 
 
892
 
void RIG_TS2000::set_if_shift(int val)
893
 
{
894
 
        bool cw = (useB && (B.imode == 2 || B.imode == 6)) ||
895
 
                  (!useB && (A.imode == 2 || A.imode == 6));
896
 
        if (!cw) {
897
 
                setIFshiftButton((void*)0);
898
 
                return;
899
 
        }
900
 
 
901
 
        cmd = "IS ";
902
 
        cmd.append(to_decimal(val,4)).append(";");
903
 
        sendCommand(cmd,0);
904
 
        showresp(WARN, ASC, "set IF shift", cmd, replystr);
905
 
}
906
 
 
907
 
bool RIG_TS2000::get_if_shift(int &val)
908
 
{
909
 
        cmd = "IS;";
910
 
        waitN(8, 100, "get IF shift", ASC);
911
 
        size_t p = replystr.rfind("IS ");
912
 
        if (p != string::npos) {
913
 
                val = fm_decimal(&replystr[p+3], 4);
914
 
                return true;
915
 
        }
916
 
        val = if_shift_mid;
917
 
        return false;
918
 
}
919
 
 
920
 
void RIG_TS2000::get_if_min_max_step(int &min, int &max, int &step)
921
 
{
922
 
        if_shift_min = min = 400;
923
 
        if_shift_max = max = 1000;
924
 
        if_shift_step = step = 50;
925
 
        if_shift_mid = 700;
926
 
}
927
 
 
928
 
void RIG_TS2000::set_notch(bool on, int val)
929
 
{
930
 
        if (on) {
931
 
                cmd = "BC2;"; // set manual notch
932
 
                sendCommand(cmd,0);
933
 
                showresp(WARN, ASC, "set notch on", cmd, replystr);
934
 
                cmd = "BP";
935
 
                val = round((val - 300) * 64.0 / 2700.0);
936
 
                cmd.append(to_decimal(val, 3)).append(";");
937
 
                sendCommand(cmd,0);
938
 
                showresp(WARN, ASC, "set notch val", cmd, replystr);
939
 
        } else {
940
 
                cmd = "BC0;"; // no notch action
941
 
                sendCommand(cmd,0);
942
 
                showresp(WARN, ASC, "set notch off", cmd, replystr);
943
 
        }
944
 
}
945
 
 
946
 
bool  RIG_TS2000::get_notch(int &val)
947
 
{
948
 
        bool ison = false;
949
 
        cmd = "BC;";
950
 
        waitN(4, 100, "get notch on/off", ASC);
951
 
        size_t p = replystr.rfind("BC");
952
 
        if (p != string::npos) {
953
 
                if (replystr[p+2] == '2') {
954
 
                        ison = true;
955
 
                        cmd = "BP;";
956
 
                        waitN(6, 100, "get notch val", ASC);
957
 
                        p = replystr.rfind("BP");
958
 
                        if (p != string::npos)
959
 
                                val = 300 + (2700.0 / 64.0) * fm_decimal(&replystr[p+2],3);
960
 
                }
961
 
        }
962
 
        return ison;
963
 
}
964
 
 
965
 
void RIG_TS2000::get_notch_min_max_step(int &min, int &max, int &step)
966
 
{
967
 
        min = 300;
968
 
        max = 3000;
969
 
        step = 50;
970
 
}
971
 
 
972
 
void RIG_TS2000::set_auto_notch(int v)
973
 
{
974
 
        cmd = v ? "NT1;" : "NT0;";
975
 
        sendCommand(cmd);
976
 
        showresp(WARN, ASC, "set auto notch", cmd, replystr);
977
 
}
978
 
 
979
 
int  RIG_TS2000::get_auto_notch()
980
 
{
981
 
        cmd = "NT;";
982
 
        waitN(4, 100, "get auto notch", ASC);
983
 
        size_t p = replystr.rfind("NT");
984
 
        if (p != string::npos)
985
 
                return (replystr[p+2] == '1');
986
 
        return 0;
987
 
}
988
 
 
989
 
void RIG_TS2000::set_rf_gain(int val)
990
 
{
991
 
        cmd = "RG";
992
 
        cmd.append(to_decimal(val * 255 / 100, 3)).append(";");
993
 
        sendCommand(cmd);
994
 
        showresp(WARN, ASC, "set rf gain", cmd, replystr);
995
 
}
996
 
 
997
 
int  RIG_TS2000::get_rf_gain()
998
 
{
999
 
        cmd = "RG;";
1000
 
        waitN(6, 100, "get rf gain", ASC);
1001
 
        size_t p = replystr.rfind("RG");
1002
 
        if (p != string::npos)
1003
 
                return fm_decimal(&replystr[p+2] ,3) * 100 / 255;
1004
 
        return 100;
1005
 
}
1006
 
 
1007
 
void RIG_TS2000::set_noise_reduction(int val)
1008
 
{
1009
 
        if (val == -1) {
1010
 
//              if (_noise_reduction_level == 1) {
1011
 
//                      nr_label("NR1", true);
1012
 
//              } else if (_noise_reduction_level == 2) {
1013
 
//                      nr_label("NR2", true);
1014
 
//              }
1015
 
                return;
1016
 
        }
1017
 
        _noise_reduction_level = val;
1018
 
        if (_noise_reduction_level == 0) {
1019
 
                nr_label("NR", false);
1020
 
        } else if (_noise_reduction_level == 1) {
1021
 
                nr_label("NR1", true);
1022
 
        } else if (_noise_reduction_level == 2) {
1023
 
                nr_label("NR2", true);
1024
 
        }
1025
 
        cmd.assign("NR");
1026
 
        cmd += '0' + _noise_reduction_level;
1027
 
        cmd += ';';
1028
 
        sendCommand (cmd);
1029
 
        showresp(WARN, ASC, "SET noise reduction", cmd, replystr);
1030
 
}
1031
 
 
1032
 
int  RIG_TS2000::get_noise_reduction()
1033
 
{
1034
 
        cmd = rsp = "NR";
1035
 
        cmd.append(";");
1036
 
        waitN(4, 100, "GET noise reduction", ASC);
1037
 
        size_t p = replystr.rfind(rsp);
1038
 
        if (p == string::npos) return _noise_reduction_level;
1039
 
        _noise_reduction_level = replystr[p+2] - '0';
1040
 
 
1041
 
        if (_noise_reduction_level == 1) {
1042
 
                nr_label("NR1", true);
1043
 
        } else if (_noise_reduction_level == 2) {
1044
 
                nr_label("NR2", true);
1045
 
        } else {
1046
 
                nr_label("NR", false);
1047
 
        }
1048
 
 
1049
 
        return _noise_reduction_level;
1050
 
}
1051
 
 
1052
 
void RIG_TS2000::set_noise_reduction_val(int val)
1053
 
{
1054
 
        if (_noise_reduction_level == 0) return;
1055
 
        if (_noise_reduction_level == 1) _nrval1 = val;
1056
 
        else _nrval2 = val;
1057
 
 
1058
 
        cmd.assign("RL").append(to_decimal(val, 2)).append(";");
1059
 
        sendCommand(cmd);
1060
 
        showresp(WARN, ASC, "SET_noise_reduction_val", cmd, replystr);
1061
 
}
1062
 
 
1063
 
int  RIG_TS2000::get_noise_reduction_val()
1064
 
{
1065
 
        if (_noise_reduction_level == 0) return 0;
1066
 
        int val = progStatus.noise_reduction_val;
1067
 
        cmd = rsp = "RL";
1068
 
        cmd.append(";");
1069
 
        waitN(5, 100, "GET noise reduction val", ASC);
1070
 
        size_t p = replystr.rfind(rsp);
1071
 
        if (p == string::npos)
1072
 
                return (_noise_reduction_level == 1 ? _nrval1 : _nrval2);
1073
 
 
1074
 
        val = atoi(&replystr[p+2]);
1075
 
 
1076
 
        if (_noise_reduction_level == 1) _nrval1 = val;
1077
 
        else _nrval2 = val;
1078
 
 
1079
 
        return val;
1080
 
}
1081