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

« back to all changes in this revision

Viewing changes to .pc/0001-License-Declaration.patch/src/rigs/RAY152.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
 
 * Global Marine, Raytheon 152 transceiver driver
3
 
 *
4
 
 * a part of flrig
5
 
 *
6
 
 * Copyright 2011, Dave Freese, W1HKJ
7
 
 *
8
 
 */
9
 
 
10
 
#include <stdlib.h>
11
 
#include <stdio.h>
12
 
#include <string.h>
13
 
#include <math.h>
14
 
 
15
 
#include "RAY152.h"
16
 
 
17
 
//=============================================================================
18
 
 
19
 
const char RIG_RAY152name_[] = "RAY 152";
20
 
 
21
 
const char *RIG_RAY152modes_[] = { "USB", "LSB", "H3E", "A1A", "F1B", NULL};
22
 
static const char RIG_RAY152_mode_type[] = {'U', 'L', 'U', 'L', 'U'};
23
 
 
24
 
static GUI rig_widgets[]= {
25
 
        { (Fl_Widget *)btnVol, 2, 145,  50 },
26
 
        { (Fl_Widget *)sldrVOLUME, 54, 145, 368 },
27
 
        { (Fl_Widget *)sldrRFGAIN, 54, 125, 156 },
28
 
        { (Fl_Widget *)sldrSQUELCH, 266, 125, 156 },
29
 
        { (Fl_Widget *)NULL, 0, 0, 0 }
30
 
};
31
 
 
32
 
RIG_RAY152::RIG_RAY152() {
33
 
        name_ = RIG_RAY152name_;
34
 
        modes_ = RIG_RAY152modes_;
35
 
 
36
 
        widgets = rig_widgets;
37
 
 
38
 
        comm_baudrate = BR1200;
39
 
        stopbits = 1;
40
 
        comm_retries = 2;
41
 
        comm_wait = 10;
42
 
        comm_timeout = 50;
43
 
        comm_echo = true;
44
 
        comm_rtscts = false;
45
 
        comm_rtsplus = false;
46
 
        comm_dtrplus = true;
47
 
        comm_catptt = true;
48
 
        comm_rtsptt = false;
49
 
        comm_dtrptt = false;
50
 
 
51
 
        A.freq = 14070000;
52
 
        A.imode = 0;
53
 
        A.iBW = 0;
54
 
 
55
 
        B.freq = 3580000;
56
 
        B.imode = 0;
57
 
        B.iBW = 0;
58
 
 
59
 
        precision = 100;
60
 
        ndigits = 6;
61
 
 
62
 
        has_mode_control = true;
63
 
        has_ptt_control = true;
64
 
        has_rf_control = true;
65
 
        has_volume_control = true;
66
 
        has_rit = true;
67
 
        has_sql_control = true;
68
 
        has_noise_control = true;
69
 
        has_auto_notch = true;
70
 
};
71
 
 
72
 
 
73
 
static void nocr( string & s)
74
 
{
75
 
        for (size_t i = 0; i < s.length(); i++)
76
 
                if (s[i] == '\r') s[i] = ' ';
77
 
}
78
 
 
79
 
/*
80
 
Data string returned by the 'O' command
81
 
                3       A*\r         AGC ON/OFF
82
 
                5       C***\r       Memory channel #
83
 
                5       D+/-**\r     Clarifier frequency
84
 
                9       FT******\r  Transmit frequemcy
85
 
                9       FR******\r  Receive frequency
86
 
                6       I****\r      ITU channel #
87
 
                3       M*\r         Mode
88
 
                3       N*\r         Noise blanker status
89
 
                3       P*\r         Power reduction status
90
 
                5       Q***\r       Squelch setting 
91
 
                5       R***\r       RF gain setting
92
 
                5       V***\r       Volume setting
93
 
                3       Z*\r         Meter function
94
 
total  64
95
 
*/
96
 
void RIG_RAY152::get_data()
97
 
{
98
 
        int ret = sendCommand("O\r");
99
 
        if (ret < 66) return;
100
 
// test string
101
 
//replystr = "A1\rC000\rD-05\rFT1407000\rFR1407000\rI0000\rM1\rN1\rP0\rQ000\rR100\rV128\rZ1\r";
102
 
 
103
 
        if (dumpdata)
104
 
                LOG_WARN("\n%s", replystr.c_str());
105
 
        dumpdata = false;
106
 
 
107
 
        size_t pos;
108
 
 
109
 
        pos = replystr.find("FR"); // receive frequency
110
 
        if (pos != string::npos) {
111
 
                int freq;
112
 
                sscanf(&replystr[pos + 2], "%d", &freq);
113
 
                A.freq = 100 * freq;
114
 
        }
115
 
 
116
 
        pos = replystr.find("M"); // mode
117
 
        if (pos != string::npos)
118
 
                A.imode = replystr[pos + 1] - '1';
119
 
 
120
 
        pos = replystr.find("D");
121
 
        if (pos != string::npos) {
122
 
                sscanf(&replystr[pos + 1], "%d", &RitFreq);
123
 
                RitFreq *= 10;
124
 
        }
125
 
 
126
 
        pos = replystr.find("\rR");
127
 
        if (pos != string::npos)
128
 
                sscanf(&replystr[pos + 2], "%d", &rfg);
129
 
 
130
 
        pos = replystr.find("V");
131
 
        if (pos != string::npos) {
132
 
                sscanf(&replystr[pos + 1], "%d", &vol);
133
 
                vol *= 100;
134
 
                vol /= 255;
135
 
        }
136
 
 
137
 
        pos = replystr.find("Q");
138
 
        if (pos != string::npos) {
139
 
                sscanf(&replystr[pos + 1], "%d", &squelch);
140
 
        }
141
 
 
142
 
        pos = replystr.find("N");
143
 
        if (pos != string::npos) {
144
 
                if (replystr[pos + 1] > '0') {
145
 
                        nb_set = replystr[pos+1];
146
 
                        nb = 1;
147
 
                }
148
 
                else {
149
 
                        nb = 0;
150
 
                        nb_set = '2';
151
 
                }
152
 
        }
153
 
 
154
 
// RAY152 usurps the autonotch button for AGC control
155
 
        pos = replystr.find("A");
156
 
        if (pos != string::npos)
157
 
                agc = replystr[1] == '1' ? 1 : 0;
158
 
 
159
 
}
160
 
 
161
 
void RIG_RAY152::initialize()
162
 
{
163
 
        rig_widgets[0].W = btnVol;
164
 
        rig_widgets[1].W = sldrVOLUME;
165
 
        rig_widgets[2].W = sldrRFGAIN;
166
 
        rig_widgets[3].W = sldrSQUELCH;
167
 
 
168
 
        sendCommand("E1\r", 0);
169
 
        sendCommand("Z1\r", 0);
170
 
        dumpdata = true;
171
 
        get_data();
172
 
        set_auto_notch(agc);
173
 
}
174
 
 
175
 
void RIG_RAY152::shutdown()
176
 
{
177
 
        sendCommand("E0\r", 0);
178
 
LOG_INFO("%s", cmd.c_str());
179
 
}
180
 
 
181
 
long RIG_RAY152::get_vfoA ()
182
 
{
183
 
        return A.freq;
184
 
}
185
 
 
186
 
void RIG_RAY152::set_vfoA (long freq)
187
 
{
188
 
        A.freq = freq;
189
 
        cmd = "FT000000\r";
190
 
        freq /= 100;
191
 
        cmd[7] += freq % 10; freq /= 10;
192
 
        cmd[6] += freq % 10; freq /= 10;
193
 
        cmd[5] += freq % 10; freq /= 10;
194
 
        cmd[4] += freq % 10; freq /= 10;
195
 
        cmd[3] += freq % 10; freq /=10;
196
 
        cmd[2] += freq;
197
 
        sendCommand(cmd, 0);
198
 
LOG_INFO("%s", cmd.c_str());
199
 
        cmd[1] = 'R';
200
 
        sendCommand(cmd, 0);
201
 
LOG_INFO("%s", cmd.c_str());
202
 
}
203
 
 
204
 
long RIG_RAY152::get_vfoB ()
205
 
{
206
 
        return B.freq;
207
 
}
208
 
 
209
 
void RIG_RAY152::set_vfoB (long freq)
210
 
{
211
 
        B.freq = freq;
212
 
        cmd = "FT000000\r";
213
 
        freq /= 100;
214
 
        cmd[7] += freq % 10; freq /= 10;
215
 
        cmd[6] += freq % 10; freq /= 10;
216
 
        cmd[5] += freq % 10; freq /= 10;
217
 
        cmd[4] += freq % 10; freq /= 10;
218
 
        cmd[3] += freq % 10; freq /=10;
219
 
        cmd[2] += freq;
220
 
        sendCommand(cmd, 0);
221
 
LOG_INFO("%s", cmd.c_str());
222
 
        cmd[1] = 'R';
223
 
        sendCommand(cmd, 0);
224
 
LOG_INFO("%s", cmd.c_str());
225
 
}
226
 
 
227
 
void RIG_RAY152::set_PTT_control(int val)
228
 
{
229
 
        cmd = val ? "X1\r" : "X0\r";
230
 
        sendCommand(cmd,0);
231
 
LOG_INFO("%s", cmd.c_str());
232
 
}
233
 
 
234
 
void RIG_RAY152::set_modeA(int md)
235
 
{
236
 
        A.imode = md;
237
 
        cmd = "M";
238
 
        cmd += (md  + '1');
239
 
        cmd += '\r';
240
 
        sendCommand(cmd, 0);
241
 
LOG_INFO("%s", cmd.c_str());
242
 
}
243
 
 
244
 
int RIG_RAY152::get_modeA()
245
 
{
246
 
        return A.imode;
247
 
}
248
 
 
249
 
void RIG_RAY152::set_modeB(int md)
250
 
{
251
 
        B.imode = md;
252
 
        cmd = "M";
253
 
        cmd += (md  + '1');
254
 
        cmd += '\r';
255
 
        sendCommand(cmd, 0);
256
 
LOG_INFO("%s", cmd.c_str());
257
 
}
258
 
 
259
 
int RIG_RAY152::get_modeB()
260
 
{
261
 
        return B.imode;
262
 
}
263
 
 
264
 
int RIG_RAY152::get_modetype(int n)
265
 
{
266
 
        return RIG_RAY152_mode_type[n];
267
 
}
268
 
 
269
 
void RIG_RAY152::set_volume_control(int val)
270
 
{
271
 
        vol = val;
272
 
        string cmd = "V000\r";
273
 
        val *= 255;
274
 
        val /= 100;
275
 
        cmd[3] += val % 10; val /= 10;
276
 
        cmd[2] += val % 10; val /= 10;
277
 
        cmd[1] += val;
278
 
        sendCommand(cmd, 0);
279
 
LOG_INFO("%s", cmd.c_str());
280
 
}
281
 
 
282
 
void RIG_RAY152::set_rf_gain(int val)
283
 
{
284
 
        rfg = val;
285
 
        cmd = "R000\r";
286
 
        cmd[3] += val % 10; val /= 10;
287
 
        cmd[2] += val % 10; val /= 10;
288
 
        cmd[1] += val;
289
 
        sendCommand(cmd, 0);
290
 
LOG_INFO("%s", cmd.c_str());
291
 
}
292
 
 
293
 
int RIG_RAY152::get_smeter(void)
294
 
{
295
 
        cmd = "U\r";
296
 
        int ret = sendCommand(cmd);
297
 
        string s = replystr;
298
 
        nocr(s);
299
 
LOG_WARN("%s", s.c_str());
300
 
        if (ret < 5) return 0;
301
 
        if (replystr[ret - 5] == 'U') {
302
 
                int val;
303
 
                sscanf(&replystr[ret - 5 + 1], "%d", &val);
304
 
                val = (int)(60.0 * (256.0 / (val + 16.0) - 1.0));
305
 
                if (val > 100) val = 100;
306
 
                if (val < 0) val = 0;
307
 
                return val;
308
 
        }
309
 
        return 0;
310
 
}
311
 
 
312
 
int RIG_RAY152::get_power_out(void)
313
 
{
314
 
        int ret = sendCommand("U\r");
315
 
        if (ret < 5) return 0;
316
 
        if (replystr[ret - 5] == 'U') {
317
 
                int val;
318
 
                sscanf(&replystr[ret - 5 + 1], "%d", &val);
319
 
                val /= 128;
320
 
                val *= 100;
321
 
                return val;
322
 
        }
323
 
        return -1;
324
 
}
325
 
 
326
 
 
327
 
void RIG_RAY152::setRit(int v)
328
 
{
329
 
        RitFreq = v;
330
 
        cmd = "D+00\r";
331
 
        if (v < 0) cmd[1] = '-';
332
 
        v /= 10;
333
 
        v = abs(v);
334
 
        cmd[3] += v % 10; v /= 10;
335
 
        cmd[2] += v % 10;
336
 
        sendCommand(cmd, 0);
337
 
LOG_INFO("%s", cmd.c_str());
338
 
}
339
 
 
340
 
int  RIG_RAY152::getRit()
341
 
{
342
 
        return RitFreq;
343
 
}
344
 
 
345
 
void RIG_RAY152::set_squelch(int val)
346
 
{
347
 
        squelch = val;
348
 
        cmd = "Q000\r";
349
 
        cmd[3] += val % 10; val /= 10;
350
 
        cmd[2] += val % 10; val /= 10;
351
 
        cmd[1] += val;
352
 
        sendCommand(cmd, 0);
353
 
LOG_INFO("%s", cmd.c_str());
354
 
}
355
 
 
356
 
int RIG_RAY152::get_squelch()
357
 
{
358
 
        return squelch;
359
 
}
360
 
 
361
 
void RIG_RAY152::set_noise(bool on) 
362
 
{
363
 
        cmd = "Nx\r";
364
 
        cmd[1] = on ? nb_set : '0';
365
 
        sendCommand(cmd, 0);
366
 
LOG_INFO("%s", cmd.c_str());
367
 
}
368
 
 
369
 
int RIG_RAY152::get_noise()
370
 
{
371
 
        return nb;
372
 
}
373
 
 
374
 
void RIG_RAY152::set_auto_notch(int v)
375
 
{
376
 
        cmd = "Ax\r";
377
 
        cmd[1] = v ? '1' : '0';
378
 
        sendCommand(cmd, 0);
379
 
LOG_INFO("%s", cmd.c_str());
380
 
}
381
 
 
382
 
int RIG_RAY152::get_auto_notch()
383
 
{
384
 
        return agc;
385
 
}
386