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

« back to all changes in this revision

Viewing changes to .pc/0001-License-Declaration.patch/src/rigs/TT516.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
 
 * TenTec ArgoV (TT516) drivers
3
 
 * 
4
 
 * a part of flrig
5
 
 * 
6
 
 * Copyright 2009, Dave Freese, W1HKJ
7
 
 * 
8
 
 */
9
 
 
10
 
/*
11
 
 *      Note for anyone wishing to expand on the command set.
12
 
 *
13
 
 *      The Argo V always sends a response and ends the response with a "G\r" to
14
 
 *      indicate that the command was accepted.  A rejected command is responded to by a
15
 
 *      two character sequence "Z\r".  You should always expect a maximum response equal
16
 
 *      to the number of data bytes plus two.
17
 
 *
18
 
 *      For example:
19
 
 *              A request for the present receiver filter bandwidth is the the string:
20
 
 *                      "?W\r" which is 3 bytes in length
21
 
 *              The response from the Argonaut V will be:
22
 
 *                      "Wn\rG\r" which is 5 bytes in length, where n is an unsigned char (byte)
23
 
 *              If the transceiver failed to receive the command correctly it will respond:
24
 
 *                      "Z\r" ----> you need to check for that condition
25
 
 *
26
 
*/
27
 
 
28
 
#include "TT516.h"
29
 
#include "support.h"
30
 
 
31
 
static const char TT516name_[] = "TT-516";
32
 
 
33
 
static const char *TT516modes_[] = {
34
 
                "AM", "USB", "LSB", "CW", "FM", NULL};
35
 
 
36
 
static int TT516_def_bw[] = { 26, 36, 36, 12, 36 };
37
 
static const char TT516mode_chr[] =  { '0', '1', '2', '3', '4' };
38
 
static const char TT516mode_type[] = { 'U', 'U', 'L', 'U', 'U' };
39
 
 
40
 
static const char *TT516_widths[] = {
41
 
"200", "250", "300", "350", "400", "450", "500", "550", "600", "650",
42
 
"700", "750", "800", "850", "900", "950", "1000", "1100", "1200", "1300",
43
 
"1400", "1500", "1600", "1700", "1800", "1900", "2000", "2100", "2200", "2300",
44
 
"2400", "2500", "2600", "2700", "2800", "2900", "3000", NULL};
45
 
 
46
 
static const char *TT516_AM_widths[] = {
47
 
"400", "500", "600", "700", "800", "900", "1000", "1100", "1200", "1350",
48
 
"1400", "1500", "1600", "1700", "1800", "1900", "2000", "2200", "2400", "2600",
49
 
"2800", "3000", "3200", "3400", "3600", "3800", "4000", "4200", "4400", "4600",
50
 
"4800", "5000", "5200", "5400", "5600", "5800", "6000", NULL};
51
 
 
52
 
static char TT516setBW[]                = "*Wx\r";
53
 
static char TT516setPBT[]               = "*Pxx\r";
54
 
static char TT516setMODE[]              = "*Mnn\r";
55
 
static char TT516setFREQA[]             = "*Annnn\r";
56
 
static char TT516setFREQB[]             = "*Bnnnn\r";
57
 
static char TT516setNB[]                = "*Kn\r";
58
 
static char TT516setXMT[]               = "#1\r";
59
 
static char TT516setRCV[]               = "#0\r";
60
 
static char TT516setSPLIT[]             = "*On\r";
61
 
static char TT516setATT[]               = "*Jn\r";
62
 
static char TT516getFREQA[]             = "?A\r";
63
 
static char TT516getFREQB[]             = "?B\r";
64
 
static char TT516getFWDPWR[]    = "?F\r";
65
 
static char TT516getATT[]               = "?J\r";
66
 
static char TT516getMODE[]              = "?M\r";
67
 
//static char TT516getPBT[]             = "?P\r";
68
 
static char TT516getREFPWR[]    = "?R\r";
69
 
static char TT516getSMETER[]    = "?S\r";
70
 
static char TT516getBW[]                = "?W\r";
71
 
static char TT516setVfo[]               = "*EVx\r";
72
 
 
73
 
static GUI rig_widgets[]= {
74
 
        { (Fl_Widget *)btnIFsh,     214, 105,  50 },
75
 
        { (Fl_Widget *)sldrIFSHIFT, 266, 105, 156 },
76
 
        { (Fl_Widget *)NULL,          0,   0,   0 }
77
 
};
78
 
 
79
 
RIG_TT516::RIG_TT516() {
80
 
// base class values    
81
 
        name_ = TT516name_;
82
 
        modes_ = TT516modes_;
83
 
        bandwidths_ = TT516_widths;
84
 
 
85
 
        widgets = rig_widgets;
86
 
 
87
 
        comm_baudrate = BR1200;
88
 
        stopbits = 1;
89
 
        comm_retries = 2;
90
 
        comm_wait = 20;
91
 
        comm_timeout = 50;
92
 
        comm_rtscts = false;
93
 
        comm_rtsplus = false;
94
 
        comm_dtrplus = false;
95
 
        comm_catptt = true;
96
 
        comm_rtsptt = false;
97
 
        comm_dtrptt = false;
98
 
        serloop_timing = 200;
99
 
 
100
 
        def_mode = modeB = modeA = B.imode = A.imode = 1;
101
 
        def_bw = bwB = bwA = B.iBW = A.iBW = 34;
102
 
        def_freq = freqB = freqA = B.freq = A.freq = 14070000;
103
 
 
104
 
        max_power = 25;
105
 
        can_change_alt_vfo = true;
106
 
 
107
 
        has_power_control =
108
 
        has_volume_control =
109
 
        has_micgain_control =
110
 
        has_notch_control =
111
 
        has_preamp_control =
112
 
        has_tune_control =
113
 
        has_swr_control = false;
114
 
 
115
 
        has_smeter =
116
 
        has_power_out =
117
 
        has_swr_control =
118
 
        has_split =
119
 
        has_noise_control =
120
 
        has_attenuator_control =
121
 
        has_ifshift_control =
122
 
        has_ptt_control =
123
 
        has_bandwidth_control =
124
 
        has_mode_control = true;
125
 
 
126
 
        precision = 10;
127
 
        ndigits = 7;
128
 
 
129
 
}
130
 
 
131
 
void RIG_TT516::initialize()
132
 
{
133
 
        rig_widgets[0].W = btnIFsh;
134
 
        rig_widgets[1].W = sldrIFSHIFT;
135
 
}
136
 
 
137
 
long RIG_TT516::get_vfoA ()
138
 
{
139
 
        cmd = TT516getFREQA;
140
 
        int ret = waitN(8, 150, "get vfo A", HEX);
141
 
        if (ret != 8) return A.freq;
142
 
        if (replystr[0] != 'A') return A.freq;
143
 
        if (replystr[6] != 'G') return A.freq;
144
 
        int f = 0;
145
 
        for (size_t n = 1; n < 5; n++) {
146
 
                f = f*256 + ((unsigned char)replystr[n] & 0xFF) ;
147
 
                A.freq = f;
148
 
        }
149
 
        return A.freq;
150
 
}
151
 
 
152
 
void RIG_TT516::set_vfoA (long freq)
153
 
{
154
 
        A.freq = freq;
155
 
        cmd = TT516setFREQA;
156
 
        cmd[5] = freq & 0xff; freq = freq >> 8;
157
 
        cmd[4] = freq & 0xff; freq = freq >> 8;
158
 
        cmd[3] = freq & 0xff; freq = freq >> 8;
159
 
        cmd[2] = freq & 0xff;
160
 
        LOG_INFO(" %c%c %02X %02X %02X %02X %02X", cmd[0], cmd[1],
161
 
                cmd[2] & 0xFF, cmd[3] & 0xFF, cmd[4] & 0xFF, cmd[5] & 0xFF, cmd[6]);
162
 
        sendCommand(cmd);
163
 
        return;
164
 
}
165
 
 
166
 
long RIG_TT516::get_vfoB ()
167
 
{
168
 
        cmd = TT516getFREQB;
169
 
        int ret = waitN(8, 150, "get vfo B", HEX);
170
 
        if (ret != 8) return B.freq;
171
 
        if (replystr[0] != 'B') return B.freq;
172
 
        if (replystr[6] != 'G') return B.freq;
173
 
 
174
 
        int f = 0;
175
 
        for (size_t n = 1; n < 5; n++) {
176
 
                f = f*256 + ((unsigned char)replystr[n] & 0xFF) ;
177
 
                B.freq = f;
178
 
        }
179
 
 
180
 
        return B.freq;
181
 
}
182
 
 
183
 
void RIG_TT516::set_vfoB (long freq)
184
 
{
185
 
        B.freq = freq;
186
 
        cmd = TT516setFREQB;
187
 
        cmd[5] = freq & 0xff; freq = freq >> 8;
188
 
        cmd[4] = freq & 0xff; freq = freq >> 8;
189
 
        cmd[3] = freq & 0xff; freq = freq >> 8;
190
 
        cmd[2] = freq & 0xff;
191
 
        LOG_INFO(" %c%c %02X %02X %02X %02X %02X", cmd[0], cmd[1],
192
 
                cmd[2] & 0xFF, cmd[3] & 0xFF, cmd[4] & 0xFF, cmd[5] & 0xFF, cmd[6]);
193
 
        sendCommand(cmd);
194
 
        return;
195
 
}
196
 
 
197
 
void RIG_TT516::selectA()
198
 
{
199
 
        cmd = TT516setVfo;
200
 
        cmd[3] = 'A';
201
 
        sendCommand(cmd);
202
 
        inuse = onA;
203
 
        set_bwA(A.iBW);
204
 
        return;
205
 
}
206
 
 
207
 
void RIG_TT516::selectB()
208
 
{
209
 
        cmd = TT516setVfo;
210
 
        cmd[3] = 'B';
211
 
        sendCommand(cmd);
212
 
        inuse = onB;
213
 
        set_bwB(B.iBW);
214
 
        return;
215
 
}
216
 
 
217
 
void RIG_TT516::set_split(bool val)
218
 
{
219
 
        cmd = TT516setSPLIT;
220
 
        cmd[2] = val ? '\x01' : '\x00';
221
 
        sendCommand(cmd);
222
 
        return;
223
 
}
224
 
 
225
 
// Tranceiver PTT on/off
226
 
void RIG_TT516::set_PTT_control(int val)
227
 
{
228
 
        if (val) sendCommand(TT516setXMT);
229
 
        else     sendCommand(TT516setRCV);
230
 
}
231
 
 
232
 
int RIG_TT516::get_modetype(int n)
233
 
{
234
 
        return TT516mode_type[n];
235
 
}
236
 
 
237
 
const char **RIG_TT516::bwtable(int m)
238
 
{
239
 
        if (m == 0) return TT516_AM_widths;
240
 
        return TT516_widths;
241
 
}
242
 
 
243
 
int RIG_TT516::def_bandwidth(int m)
244
 
{
245
 
        return TT516_def_bw[m];
246
 
}
247
 
 
248
 
int RIG_TT516::adjust_bandwidth(int m)
249
 
{
250
 
        bwtable(m);
251
 
        return def_bandwidth(m);
252
 
}
253
 
 
254
 
void RIG_TT516::set_modeA(int val)
255
 
{
256
 
        A.imode = val;
257
 
        cmd = TT516setMODE;
258
 
        cmd[2] = TT516mode_chr[A.imode];
259
 
        cmd[3] = TT516mode_chr[B.imode];
260
 
        sendCommand(cmd);
261
 
}
262
 
 
263
 
int RIG_TT516::get_modeA()
264
 
{
265
 
        cmd = TT516getMODE;
266
 
        int ret = waitN(6, 150, "get mode A", HEX);
267
 
        if (ret < 6) return A.imode;
268
 
        if (replystr[ret - 2] != 'G') return A.imode;
269
 
        size_t p = replystr.rfind("M");
270
 
        if (p == string::npos) return A.imode;
271
 
 
272
 
        A.imode = replystr[p+1] - '0';
273
 
 
274
 
        return A.imode;
275
 
}
276
 
 
277
 
void RIG_TT516::set_modeB(int val)
278
 
{
279
 
        B.imode = val;
280
 
        cmd = TT516setMODE;
281
 
        cmd[2] = TT516mode_chr[A.imode];
282
 
        cmd[3] = TT516mode_chr[B.imode];
283
 
        sendCommand(cmd);
284
 
}
285
 
 
286
 
int RIG_TT516::get_modeB()
287
 
{
288
 
        cmd = TT516getMODE;
289
 
        int ret = waitN(6, 150, "get mode B", HEX);
290
 
        if (ret < 6) return B.imode;
291
 
        if (replystr[ret - 2] != 'G') return B.imode;
292
 
        size_t p = replystr.rfind("M");
293
 
        if (p == string::npos) return B.imode;
294
 
 
295
 
        B.imode = replystr[p+2] - '0';
296
 
 
297
 
        return B.imode;
298
 
}
299
 
 
300
 
int RIG_TT516::get_bwA()
301
 
{
302
 
        if (inuse == onA) {
303
 
                cmd = TT516getBW;
304
 
                int ret = waitN(5, 150, "get bw A", HEX);
305
 
                if (ret < 5) return A.iBW;
306
 
                if (replystr[ret - 2] != 'G') return A.iBW;
307
 
                size_t p = replystr.rfind("W");
308
 
                if (p == string::npos) return A.iBW;
309
 
                A.iBW = (unsigned char)replystr[p+1];
310
 
        }
311
 
        return A.iBW;
312
 
}
313
 
 
314
 
void RIG_TT516::set_bwA(int val)
315
 
{
316
 
        A.iBW = val;
317
 
        if (inuse == onA) {
318
 
                cmd = TT516setBW;
319
 
                cmd[2] = val;
320
 
                sendCommand(cmd);
321
 
        }
322
 
}
323
 
 
324
 
int RIG_TT516::get_bwB()
325
 
{
326
 
        if (inuse == onB) {
327
 
                cmd = TT516getBW;
328
 
                int ret = waitN(5, 150, "get bw B", HEX);
329
 
                if (ret < 5) return B.iBW;
330
 
                if (replystr[ret - 2] != 'G') return B.iBW;
331
 
                size_t p = replystr.rfind("W");
332
 
                if (p == string::npos) return B.iBW;
333
 
                B.iBW = (unsigned char)replystr[p+1];
334
 
        }
335
 
        return B.iBW;
336
 
}
337
 
 
338
 
void RIG_TT516::set_bwB(int val)
339
 
{
340
 
        B.iBW = val;
341
 
        if (inuse == onB) {
342
 
                cmd = TT516setBW;
343
 
                cmd[2] = val;
344
 
                sendCommand(cmd);
345
 
        }
346
 
}
347
 
 
348
 
void RIG_TT516::set_if_shift(int val)
349
 
{
350
 
        cmd = TT516setPBT;
351
 
        short int si = val;
352
 
        cmd[2] = (si & 0xff00) >> 8;
353
 
        cmd[3] = (si & 0xff);
354
 
        sendCommand(cmd);
355
 
}
356
 
 
357
 
bool RIG_TT516::get_if_shift(int &val)
358
 
{
359
 
        val = 0;
360
 
        return false;
361
 
}
362
 
 
363
 
void RIG_TT516::get_if_min_max_step(int &min, int &max, int &step)
364
 
{
365
 
        min = -2900;
366
 
        max = 2900;
367
 
        step = 100;
368
 
}
369
 
 
370
 
void RIG_TT516::set_attenuator(int val)
371
 
{
372
 
        cmd = TT516setATT;
373
 
        if (val) cmd[2] = '1';
374
 
        else     cmd[2] = '0';
375
 
        sendCommand(cmd);
376
 
}
377
 
 
378
 
 
379
 
int RIG_TT516::get_attenuator()
380
 
{
381
 
        cmd = TT516getATT;
382
 
        int ret = sendCommand(cmd);
383
 
        if (ret < 5) return 0;
384
 
        size_t p = replystr.rfind("J");
385
 
        if (p == string::npos) return 0;
386
 
        if (replystr[p+1] == '1')
387
 
                return 1;
388
 
        return 0;
389
 
}
390
 
 
391
 
void RIG_TT516::set_noise(bool b)
392
 
{
393
 
        cmd = TT516setNB;
394
 
        if (b)
395
 
                cmd[2] = '4';
396
 
        else
397
 
                cmd[2] = '0';
398
 
        sendCommand(cmd);
399
 
}
400
 
 
401
 
int RIG_TT516::get_smeter()
402
 
{
403
 
        double sig = 0.0;
404
 
        cmd = TT516getSMETER;
405
 
        int ret = sendCommand(cmd);
406
 
        if (ret < 6) return 0;
407
 
        size_t p = replystr.rfind("S");
408
 
        if (p == string::npos) return 0;
409
 
 
410
 
        sig = (50.0 / 9.0) * ((unsigned char)replystr[p+1] + (unsigned char)replystr[p+2] / 256.0);
411
 
 
412
 
        return (int)sig;
413
 
}
414
 
 
415
 
int RIG_TT516::get_swr()
416
 
{
417
 
        double swr = (fwdv + refv) / (fwdv - refv + .0001);
418
 
        swr -= 1.0;
419
 
        swr *= 25.0;
420
 
        if (swr < 0) swr = 0;
421
 
        if (swr > 100) swr = 100;
422
 
        return (int)swr;
423
 
}
424
 
 
425
 
int RIG_TT516::get_power_out()
426
 
{
427
 
        fwdpwr = refpwr = fwdv = refv = 0;
428
 
        cmd = TT516getFWDPWR;
429
 
        int ret = sendCommand(cmd);
430
 
        if (ret < 5) return fwdpwr;
431
 
        size_t p = replystr.rfind("F");
432
 
        if (p == string::npos) return fwdpwr;
433
 
 
434
 
        fwdv = 1.0 * (unsigned char)replystr[p+1];
435
 
        cmd = TT516getREFPWR;
436
 
        ret = sendCommand(cmd);
437
 
        if (ret < 5) return fwdpwr;
438
 
        p = replystr.rfind("R");
439
 
        if (p == string::npos) return fwdpwr;
440
 
 
441
 
        refv = 1.0 * (unsigned char)replystr[p+1];
442
 
 
443
 
        fwdpwr = 30.0 * (fwdv * fwdv) / (256 * 256);
444
 
        refpwr = 30.0 * (refv * refv) / (256 * 256);
445
 
 
446
 
        return fwdpwr;
447
 
}