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

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Kamal Mostafa
  • Date: 2014-06-07 11:28:52 UTC
  • Revision ID: package-import@ubuntu.com-20140607112852-pj9xhtlvwpgqjy5x
Tags: 1.3.15-1
* Initial release (Closes: #750861)
  flrig version 1.3.15 plus the following upstream commits:
  - 0001-License-Declaration.patch
  - 0002-FL_APPS-folder.patch
  - 0003-rig-home-dir.patch
  - 0004-RTS-DTR-restore.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "rigbase.h"
 
2
#include "util.h"
 
3
#include "debug.h"
 
4
#include "rig_io.h"
 
5
#include "support.h"
 
6
 
 
7
 
 
8
const char *szNORIG = "NONE";
 
9
const char *szNOMODES[] = {"LSB", "USB", NULL};
 
10
const char *szNOBWS[] = {"NONE", NULL};
 
11
const char *szDSPLO[] = {"NONE", NULL};
 
12
const char *szDSPHI[] = {"NONE", NULL};
 
13
const char *szdsptooltip = "dsp tooltip";
 
14
const char *szbtnlabel = " ";
 
15
const int  ibw_val = -1;
 
16
 
 
17
static GUI basewidgets[] = { {NULL, 0, 0} };
 
18
 
 
19
rigbase::rigbase()
 
20
{
 
21
        name_ = szNORIG;
 
22
        modes_ = szNOMODES;
 
23
        bandwidths_ = szNOBWS;
 
24
        dsp_lo = szDSPLO;
 
25
        lo_tooltip = szdsptooltip;
 
26
        lo_label = szbtnlabel;
 
27
        dsp_hi = szDSPHI;
 
28
        hi_tooltip = szdsptooltip;
 
29
        hi_label = szbtnlabel;
 
30
        bw_vals_ = &ibw_val;
 
31
 
 
32
        widgets = basewidgets;
 
33
 
 
34
        serloop_timing = 200; // msec, 5x / second
 
35
 
 
36
        stopbits = 2;
 
37
 
 
38
        CIV = 0;
 
39
        defaultCIV = 0;
 
40
        USBaudio = false;
 
41
 
 
42
        has_xcvr_auto_on_off =
 
43
        comm_echo =
 
44
        has_vfo_adj =
 
45
        has_rit =
 
46
        has_xit =
 
47
        has_bfo =
 
48
        has_power_control =
 
49
        has_volume_control =
 
50
        has_mode_control =
 
51
        has_bandwidth_control =
 
52
        has_dsp_controls =
 
53
        has_micgain_control =
 
54
        has_mic_line_control =
 
55
        has_auto_notch = 
 
56
        has_notch_control =
 
57
        has_noise_control =
 
58
        has_noise_reduction_control =
 
59
        has_noise_reduction =
 
60
        has_attenuator_control =
 
61
        has_preamp_control =
 
62
        has_ifshift_control =
 
63
        has_ptt_control =
 
64
        has_tune_control =
 
65
        has_swr_control =
 
66
        has_alc_control =
 
67
        has_rf_control =
 
68
        has_sql_control = 
 
69
        has_data_port =
 
70
        restore_mbw =
 
71
 
 
72
        has_extras = 
 
73
        has_nb_level =
 
74
        has_agc_level =
 
75
        has_cw_wpm =
 
76
        has_cw_vol =
 
77
        has_cw_spot =
 
78
        has_cw_spot_tone =
 
79
        has_cw_qsk =
 
80
        has_cw_weight =
 
81
        has_cw_keyer =
 
82
        has_vox_onoff =
 
83
        has_vox_gain =
 
84
        has_vox_anti =
 
85
        has_vox_hang =
 
86
        has_vox_on_dataport =
 
87
        has_compression =
 
88
        has_compON =
 
89
        use_line_in =
 
90
        has_bpf_center =
 
91
        has_special =  
 
92
        has_smeter =
 
93
        has_power_out =
 
94
        has_split =
 
95
        has_split_AB =
 
96
        has_a2b =
 
97
        has_band_selection =
 
98
        has_get_info = false;
 
99
 
 
100
        A.freq = 14070000L;
 
101
        A.imode = 1;
 
102
        A.iBW = 0;
 
103
        B.freq = 14070000L;
 
104
        B.imode = 1;
 
105
        B.iBW = 0;
 
106
        inuse = onA;
 
107
        precision = 1;
 
108
        ndigits = 9;
 
109
        can_change_alt_vfo = false;
 
110
 
 
111
        freqA = 14070000L;
 
112
        modeA = 1;
 
113
        bwA = 0;
 
114
        freqB = 14070000L;
 
115
        modeB = 1;
 
116
        bwB = 0;
 
117
 
 
118
        def_freq = 14070000L;
 
119
        def_mode = 1;
 
120
        def_bw = 0;
 
121
        bpf_center = 0;
 
122
        pbt = 0;
 
123
 
 
124
        max_power = 100;
 
125
 
 
126
        active_mode = 0; // wbx
 
127
 
 
128
        if_shift_min = -1500;
 
129
        if_shift_max = 1500;
 
130
        if_shift_step = 10;
 
131
        if_shift_mid = 0;
 
132
}
 
133
 
 
134
string rigbase::to_bcd_be(long freq, int len)
 
135
{
 
136
        unsigned char a;
 
137
        int numchars = len / 2;
 
138
        string bcd = "";
 
139
        if (len & 1) numchars ++;
 
140
        for (int i = 0; i < numchars; i++) {
 
141
                a = 0;
 
142
                a |= freq % 10;
 
143
                freq /= 10;
 
144
                a |= (freq % 10)<<4;
 
145
                freq /= 10;
 
146
                bcd += a;
 
147
        }
 
148
        return bcd;
 
149
}
 
150
 
 
151
string rigbase::to_bcd(long freq, int len)
 
152
{
 
153
        string bcd_be = to_bcd_be(freq, len);
 
154
        string bcd = "";
 
155
        int bcdlen = bcd_be.size();
 
156
        for (int i = bcdlen - 1; i >= 0; i--)
 
157
                bcd += bcd_be[i];
 
158
        return bcd;
 
159
}
 
160
 
 
161
long rigbase::fm_bcd (char *bcd, int len)
 
162
{
 
163
        int i;
 
164
        long f = 0;
 
165
        int numchars = len/2;
 
166
        if (len & 1) numchars ++;
 
167
        for (i = 0; i < numchars; i++) {
 
168
                f *=10;
 
169
                f += (bcd[i] >> 4) & 0x0F;
 
170
                f *= 10;
 
171
                f += bcd[i] & 0x0F;
 
172
        }
 
173
        return f;
 
174
}
 
175
 
 
176
 
 
177
long rigbase::fm_bcd_be(char *bcd, int len)
 
178
{
 
179
        char temp;
 
180
        int numchars = len/2;
 
181
        if (len & 1) numchars++;
 
182
        for (int i = 0; i < numchars / 2; i++) {
 
183
                temp = bcd[i];
 
184
                bcd[i] = bcd[numchars -1 - i];
 
185
                bcd[numchars -1 - i] = temp;
 
186
        }
 
187
        return fm_bcd(bcd, len);
 
188
}
 
189
 
 
190
string rigbase::to_binary_be(long freq, int len)
 
191
{
 
192
        static string bin = "";
 
193
        for (int i = 0; i < len; i++) {
 
194
                bin += freq & 0xFF;
 
195
                freq >>= 8;
 
196
        }
 
197
        return bin;
 
198
}
 
199
 
 
200
string rigbase::to_binary(long freq, int len)
 
201
{
 
202
        static string bin = "";
 
203
        string bin_be = to_binary_be(freq, len);
 
204
        int binlen = bin_be.size();
 
205
        for (int i = binlen - 1; i >= 0; i--)
 
206
                bin += bin_be[i];
 
207
        return bin;
 
208
}
 
209
 
 
210
long rigbase::fm_binary(char *binary, int len)
 
211
{
 
212
        int i;
 
213
        long f = 0;
 
214
        for (i = 0; i < len; i++) {
 
215
                f *= 256;
 
216
                f += (unsigned char)binary[i];
 
217
        }
 
218
        return f;
 
219
}
 
220
 
 
221
long rigbase::fm_binary_be(char *binary_be, int len)
 
222
{
 
223
        unsigned char temp;
 
224
        int numchars = len/2;
 
225
        if (len & 1) numchars++;
 
226
        for (int i = 0; i < numchars / 2; i++) {
 
227
                temp = binary_be[i];
 
228
                binary_be[i] = binary_be[numchars -1 - i];
 
229
                binary_be[numchars -1 - i] = temp;
 
230
        }
 
231
        return fm_binary(binary_be, len);
 
232
}
 
233
 
 
234
string rigbase::to_decimal_be(long d, int len)
 
235
{
 
236
        static string sdec_be;
 
237
        sdec_be.clear();
 
238
        for (int i = 0; i < len; i++) {
 
239
                sdec_be += (char)((d % 10) + '0');
 
240
                d /= 10;
 
241
        }
 
242
        return sdec_be;
 
243
}
 
244
 
 
245
string rigbase::to_decimal(long d, int len)
 
246
{
 
247
        static string sdec;
 
248
        sdec.clear();
 
249
        string sdec_be = to_decimal_be(d, len);
 
250
        int bcdlen = sdec_be.size();
 
251
        for (int i = bcdlen - 1; i >= 0; i--)
 
252
                sdec += sdec_be[i];
 
253
        return sdec;
 
254
}
 
255
 
 
256
long rigbase::fm_decimal(char *decimal, int len)
 
257
{
 
258
        long d = 0;
 
259
        for (int i = 0; i < len; i++) {
 
260
                d *= 10;
 
261
                d += decimal[i] - '0';
 
262
        }
 
263
        return d;
 
264
}
 
265
 
 
266
long rigbase::fm_decimal_be(char *decimal_be, int len)
 
267
{
 
268
        unsigned char temp;
 
269
        int numchars = len/2;
 
270
        if (len & 1) numchars++;
 
271
        for (int i = 0; i < numchars / 2; i++) {
 
272
                temp = decimal_be[i];
 
273
                decimal_be[i] = decimal_be[numchars -1 - i];
 
274
                decimal_be[numchars -1 - i] = temp;
 
275
        }
 
276
        return fm_decimal(decimal_be, len);
 
277
}
 
278
 
 
279
void rigbase::showresp(int level, int how, string s, string tx, string rx) 
 
280
{
 
281
        time_t now;
 
282
        time(&now);
 
283
        struct tm *local = localtime(&now);
 
284
        char sztm[20];
 
285
        strftime(sztm, sizeof(sztm), "%H:%M:%S", local);
 
286
 
 
287
        string s1 = how == HEX ? str2hex(tx.c_str(), tx.length()) : tx;
 
288
        string s2 = how == HEX ? str2hex(rx.c_str(), rx.length()) : rx;
 
289
        if (how == ASC) {
 
290
                size_t p;
 
291
                while((p = s1.find('\r')) != string::npos)
 
292
                        s1.replace(p, 1, "<cr>");
 
293
                while((p = s1.find('\n')) != string::npos)
 
294
                        s1.replace(p, 1, "<lf>");
 
295
                while((p = s2.find('\r')) != string::npos)
 
296
                        s2.replace(p, 1, "<cr>");
 
297
                while((p = s2.find('\n')) != string::npos)
 
298
                        s2.replace(p, 1, "<lf>");
 
299
        }
 
300
 
 
301
        switch (level) {
 
302
        case ERR:
 
303
                SLOG_ERROR("%s: %10s\ncmd %s\nans %s", sztm, s.c_str(), s1.c_str(), s2.c_str());
 
304
                break;
 
305
        case WARN:
 
306
                SLOG_WARN("%s: %10s\ncmd %s\nans %s", sztm, s.c_str(), s1.c_str(), s2.c_str());
 
307
                break;
 
308
        case INFO:
 
309
                SLOG_INFO("%s: %10s\ncmd %s\nans %s", sztm, s.c_str(), s1.c_str(), s2.c_str());
 
310
                break;
 
311
        default:
 
312
                SLOG_DEBUG("%s: %10s\ncmd %s\nans %s", sztm, s.c_str(), s1.c_str(), s2.c_str());
 
313
        }
 
314
}
 
315
 
 
316
int rigbase::waitN(size_t n, int timeout, const char *sz, int pr)
 
317
{
 
318
        char sztemp[50];
 
319
        string returned = "";
 
320
        string tosend = cmd;
 
321
        int cnt = 0, repeat = 0;
 
322
        int waited = 0;
 
323
        size_t num = n + cmd.length();
 
324
        int delay =  num * 11000.0 / RigSerial.Baud();
 
325
 
 
326
        replystr.clear();
 
327
 
 
328
        if (!RigSerial.IsOpen()) {
 
329
                snprintf(sztemp, sizeof(sztemp), "TEST %s", sz);
 
330
                showresp(WARN, pr, sztemp, tosend, replystr);
 
331
                return 0;
 
332
        }
 
333
 
 
334
        sendCommand(tosend, 0);
 
335
        MilliSleep(delay);
 
336
        returned = "";
 
337
        for ( cnt = 0; cnt < timeout / 10; cnt++) {
 
338
                readResponse();
 
339
                returned.append(replystr);
 
340
                if (returned.length() >= n) {
 
341
                        replystr = returned;
 
342
                        waited = cnt * 10 * repeat + delay;
 
343
                        snprintf(sztemp, sizeof(sztemp), "%s OK %d ms", sz, waited);
 
344
                        showresp(WARN, pr, sztemp, cmd, returned);
 
345
                        return replystr.length();
 
346
                }
 
347
                MilliSleep(10);
 
348
                Fl::awake();
 
349
        }
 
350
 
 
351
        replystr = returned;
 
352
        waited = cnt * 10 * repeat + delay;
 
353
        snprintf(sztemp, sizeof(sztemp), "%s failed %d ms", sz, waited);
 
354
        showresp(WARN, pr, sztemp, cmd, returned);
 
355
        return 0;
 
356
}
 
357
 
 
358