[go: up one dir, main page]

Menu

[073328]: / icom / optoscan.c  Maximize  Restore  History

Download this file

719 lines (599 with data), 18.9 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
/*
* Hamlib CI-V backend - OptoScan extensions
* Copyright (c) 2000-2005 by Stephane Fillod
*
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h> /* String function definitions */
#include <unistd.h> /* UNIX standard function definitions */
#include <math.h>
#include <sys/time.h>
#include "hamlib/rig.h"
#include "serial.h"
#include "misc.h"
#include "cal.h"
#include "token.h"
#include "icom.h"
#include "icom_defs.h"
#include "frame.h"
#include "optoscan.h"
const struct confparams opto_ext_parms[] = {
{ TOK_TAPECNTL, "tapecntl", "Toggle Tape Switch", "Toggles built in tape switch", 0, RIG_CONF_CHECKBUTTON, {} },
{ TOK_5KHZWIN, "5khzwin", "Toggle 5kHz Search Window", "Toggles 5kHz search window", 0, RIG_CONF_CHECKBUTTON, {} },
{ TOK_SPEAKER, "speaker", "Toggle speaker audio", "Toggles speaker audio", 0, RIG_CONF_CHECKBUTTON, {} },
{ TOK_AUDIO, "audio", "Audio present", "Audio present", NULL, RIG_CONF_CHECKBUTTON, {} },
{ TOK_DTMFPEND, "dtmfpend", "DTMF Digit Pending", "DTMF Digit Pending", NULL, RIG_CONF_CHECKBUTTON, {} },
{ TOK_DTMFOVRR, "dtmfovrr", "DTMF Buffer Overflow", "DTMF Buffer Overflow", NULL, RIG_CONF_CHECKBUTTON, {} },
{ TOK_CTCSSACT, "ctcssact", "CTCSS Tone Active", "CTCSS Tone Active", NULL, RIG_CONF_CHECKBUTTON, {} },
{ TOK_DCSACT, "dcsact", "DCS Code Active", "DCS Code Active", NULL, RIG_CONF_CHECKBUTTON, {} },
{ RIG_CONF_END, NULL, }
};
static int optoscan_get_status_block(RIG *rig, struct optostat *status_block);
static int optoscan_send_freq(RIG *rig,pltstate_t *state);
static int optoscan_RTS_toggle(RIG *rig);
static int optoscan_start_timer(RIG *rig, pltstate_t *state);
static int optoscan_wait_timer(RIG *rig, pltstate_t *state);
/*
* optoscan_open
* Assumes rig!=NULL, rig->state.priv!=NULL
*/
int optoscan_open(RIG *rig)
{
struct icom_priv_data *priv;
struct rig_state *rs;
pltstate_t *pltstate;
unsigned char ackbuf[16];
int ack_len, retval;
rs = &rig->state;
priv = (struct icom_priv_data*)rs->priv;
pltstate = malloc(sizeof(pltstate_t));
if (!pltstate) {
return -RIG_ENOMEM;
}
memset(pltstate, 0, sizeof(pltstate_t));
priv->pltstate = pltstate;
/* select REMOTE control */
retval = icom_transaction (rig, C_CTL_MISC, S_OPTO_REMOTE,
NULL, 0, ackbuf, &ack_len);
if (retval != RIG_OK) {
free(pltstate);
return retval;
}
if (ack_len != 1 || ackbuf[0] != ACK) {
rig_debug(RIG_DEBUG_ERR,"optoscan_open: ack NG (%#.2x), "
"len=%d\n", ackbuf[0], ack_len);
free(pltstate);
return -RIG_ERJCTED;
}
return RIG_OK;
}
/*
* optoscan_close
* Assumes rig!=NULL, rig->state.priv!=NULL
*/
int optoscan_close(RIG *rig)
{
struct icom_priv_data *priv;
struct rig_state *rs;
unsigned char ackbuf[16];
int ack_len, retval;
rs = &rig->state;
priv = (struct icom_priv_data*)rs->priv;
/* select LOCAL control */
retval = icom_transaction (rig, C_CTL_MISC, S_OPTO_LOCAL,
NULL, 0, ackbuf, &ack_len);
if (retval != RIG_OK)
return retval;
if (ack_len != 1 || ackbuf[0] != ACK) {
rig_debug(RIG_DEBUG_ERR,"optoscan_close: ack NG (%#.2x), "
"len=%d\n", ackbuf[0], ack_len);
return -RIG_ERJCTED;
}
free(priv->pltstate);
return RIG_OK;
}
/*
* optoscan_get_info
* Assumes rig!=NULL, rig->state.priv!=NULL
*/
const char* optoscan_get_info(RIG *rig)
{
unsigned char ackbuf[16];
int ack_len, retval;
static char info[64];
/* select LOCAL control */
retval = icom_transaction (rig, C_CTL_MISC, S_OPTO_RDID,
NULL, 0, ackbuf, &ack_len);
if (retval != RIG_OK)
return NULL;
if (ack_len != 7) {
rig_debug(RIG_DEBUG_ERR,"optoscan_get_info: ack NG (%#.2x), "
"len=%d\n", ackbuf[0], ack_len);
return NULL;
}
sprintf(info, "OptoScan%c%c%c, software version %d.%d, "
"interface version %d.%d\n",
ackbuf[2], ackbuf[3], ackbuf[4],
ackbuf[5] >> 4, ackbuf[5] & 0xf,
ackbuf[6] >> 4, ackbuf[6] & 0xf);
return info;
}
/*
* optoscan_get_ctcss_tone
* Assumes rig!=NULL, rig->state.priv!=NULL
*/
int optoscan_get_ctcss_tone(RIG *rig, vfo_t vfo, tone_t *tone)
{
unsigned char tonebuf[MAXFRAMELEN];
int tone_len, retval;
retval = icom_transaction(rig, C_CTL_MISC, S_OPTO_RDCTCSS, NULL, 0,
tonebuf, &tone_len);
if (retval != RIG_OK)
return retval;
if (tone_len != 4) {
rig_debug(RIG_DEBUG_ERR,"optoscan_get_ctcss_tone: ack NG (%#.2x), "
"len=%d\n", tonebuf[0], tone_len);
return -RIG_ERJCTED;
}
tone_len -= 2;
*tone = from_bcd_be(tonebuf+2, tone_len*2);
rig_debug(RIG_DEBUG_ERR,"optoscan_get_ctcss_tone: *tone=%d\n",*tone);
return RIG_OK;
}
/*
* optoscan_get_dcs_code
* Assumes rig!=NULL, rig->state.priv!=NULL
*/
int optoscan_get_dcs_code(RIG * rig, vfo_t vfo, tone_t *code)
{
unsigned char tonebuf[MAXFRAMELEN];
int tone_len, retval;
retval = icom_transaction(rig, C_CTL_MISC, S_OPTO_RDDCS, NULL, 0,
tonebuf, &tone_len);
if (retval != RIG_OK)
return retval;
if (tone_len != 4) {
rig_debug(RIG_DEBUG_ERR,"optoscan_get_dcs_code: ack NG (%#.2x), "
"len=%d\n", tonebuf[0], tone_len);
return -RIG_ERJCTED;
}
tone_len -= 2;
*code = from_bcd_be(tonebuf+2, tone_len*2);
rig_debug(RIG_DEBUG_ERR,"optoscan_get_dcs_code: *code=%d\n",*code);
return RIG_OK;
}
int optoscan_recv_dtmf(RIG *rig, vfo_t vfo, char *digits, int *length)
{
unsigned char dtmfbuf[MAXFRAMELEN],digit;
int len, retval, digitpos;
unsigned char xlate[] = {'0','1','2','3','4','5','6',
'7','8','9','A','B','C','D',
'*','#'};
digitpos=0;
do {
retval = icom_transaction(rig, C_CTL_MISC, S_OPTO_RDDTMF,
NULL,0,dtmfbuf, &len);
if (retval != RIG_OK)
return retval;
if (len != 3) {
rig_debug(RIG_DEBUG_ERR,"optoscan_recv_dtmf: ack NG (%#.2x), len=%d\n", dtmfbuf[0], len);
return -RIG_ERJCTED;
}
digit = dtmfbuf[2];
if( digit < 0x16 )
{
digits[digitpos] = xlate[digit];
digitpos++;
}
} while( (digit != 0x99) && (digitpos < *length) );
*length = digitpos;
digits[digitpos]=0;
if(*length > 0)
{
rig_debug(RIG_DEBUG_ERR,"optoscan_recv_dtmf: %d digits - %s\n",*length,digits);
}
else
{
rig_debug(RIG_DEBUG_ERR,"optoscan_recv_dtmf: no digits to read.\n");
}
return RIG_OK;
}
/*
* Assumes rig!=NULL, rig->state.priv!=NULL
*/
int optoscan_set_ext_parm(RIG *rig, token_t token, value_t val)
{
unsigned char epbuf[MAXFRAMELEN], ackbuf[MAXFRAMELEN];
int ack_len;
int retval,subcode;
memset(epbuf,0,MAXFRAMELEN);
memset(ackbuf,0,MAXFRAMELEN);
switch(token) {
case TOK_TAPECNTL:
if( val.i == 0 ) {
subcode = S_OPTO_TAPE_OFF;
}
else {
subcode = S_OPTO_TAPE_ON;
}
break;
case TOK_5KHZWIN:
if( val.i == 0 ) {
subcode = S_OPTO_5KSCOFF;
}
else {
subcode = S_OPTO_5KSCON;
}
break;
case TOK_SPEAKER:
if( val.i == 0 ) {
subcode = S_OPTO_SPKROFF;
}
else {
subcode = S_OPTO_SPKRON;
}
break;
default:
return -RIG_EINVAL;
}
retval = icom_transaction (rig, C_CTL_MISC, subcode, epbuf, 0,
ackbuf, &ack_len);
if (retval != RIG_OK)
return retval;
if (ack_len != 1 || ackbuf[0] != ACK) {
rig_debug(RIG_DEBUG_ERR, "%s: ack NG (%#.2x), "
"len=%d\n", __FUNCTION__, ackbuf[0], ack_len);
return -RIG_ERJCTED;
}
return RIG_OK;
}
/*
* Assumes rig!=NULL, rig->state.priv!=NULL
* and val points to a buffer big enough to hold the conf value.
*/
int optoscan_get_ext_parm(RIG *rig, token_t token, value_t *val)
{
struct optostat status_block;
int retval;
retval = optoscan_get_status_block(rig,&status_block);
if (retval != RIG_OK)
return retval;
switch(token) {
case TOK_TAPECNTL:
val->i = status_block.tape_enabled;
break;
case TOK_5KHZWIN:
val->i = status_block.fivekhz_enabled;
break;
case TOK_SPEAKER:
val->i = status_block.speaker_enabled;
break;
case TOK_AUDIO:
val->i = status_block.audio_present;
break;
case TOK_DTMFPEND:
val->i = status_block.DTMF_pending;
break;
case TOK_DTMFOVRR:
val->i = status_block.DTMF_overrun;
break;
case TOK_CTCSSACT:
val->i = status_block.CTCSS_active;
break;
case TOK_DCSACT:
val->i = status_block.DCS_active;
break;
default:
return -RIG_ENIMPL;
}
return RIG_OK;
}
/*
* optoscan_set_level
* Assumes rig!=NULL, rig->state.priv!=NULL
*/
int optoscan_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val)
{
unsigned char lvlbuf[MAXFRAMELEN], ackbuf[MAXFRAMELEN];
int ack_len;
int lvl_cn, lvl_sc; /* Command Number, Subcommand */
int icom_val;
int retval;
memset(lvlbuf,0,MAXFRAMELEN);
/*
* So far, levels of float type are in [0.0..1.0] range
*/
if (RIG_LEVEL_IS_FLOAT(level))
icom_val = val.f * 255;
else
icom_val = val.i;
switch (level) {
case RIG_LEVEL_AF:
lvl_cn = C_CTL_MISC;
if( icom_val == 0 ) {
lvl_sc = S_OPTO_SPKROFF;
}
else {
lvl_sc = S_OPTO_SPKRON;
}
break;
default:
rig_debug(RIG_DEBUG_ERR,"Unsupported set_level %d", level);
return -RIG_EINVAL;
}
retval = icom_transaction (rig, lvl_cn, lvl_sc, lvlbuf, 0,
ackbuf, &ack_len);
if (retval != RIG_OK)
return retval;
if (ack_len != 1 || ackbuf[0] != ACK) {
rig_debug(RIG_DEBUG_ERR,"optoscan_set_level: ack NG (%#.2x), "
"len=%d\n", ackbuf[0], ack_len);
return -RIG_ERJCTED;
}
return RIG_OK;
}
/*
* optoscan_get_level
* Assumes rig!=NULL, rig->state.priv!=NULL, val!=NULL
*/
int optoscan_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val)
{
struct optostat status_block;
unsigned char lvlbuf[MAXFRAMELEN];
int lvl_len;
int lvl_cn, lvl_sc; /* Command Number, Subcommand */
int icom_val;
int cmdhead;
int retval;
if( level != RIG_LEVEL_AF )
{
switch (level) {
case RIG_LEVEL_RAWSTR:
lvl_cn = C_RD_SQSM;
lvl_sc = S_SML;
break;
default:
rig_debug(RIG_DEBUG_ERR,"Unsupported get_level %d", level);
return -RIG_EINVAL;
}
retval = icom_transaction (rig, lvl_cn, lvl_sc, NULL, 0,
lvlbuf, &lvl_len);
if (retval != RIG_OK)
return retval;
/*
* strbuf should contain Cn,Sc,Data area
*/
cmdhead = (lvl_sc == -1) ? 1:2;
lvl_len -= cmdhead;
if (lvlbuf[0] != ACK && lvlbuf[0] != lvl_cn) {
rig_debug(RIG_DEBUG_ERR,"optoscan_get_level: ack NG (%#.2x), "
"len=%d\n", lvlbuf[0],lvl_len);
return -RIG_ERJCTED;
}
/*
* The result is a 3 digit BCD, but in *big endian* order: 0000..0255
* (from_bcd is little endian)
*/
icom_val = from_bcd_be(lvlbuf+cmdhead, lvl_len*2);
}
else /* level == RIG_LEVEL_AF */
{
retval = optoscan_get_status_block(rig,&status_block);
if (retval != RIG_OK)
return retval;
icom_val = 0;
if( status_block.speaker_enabled == 1 )
icom_val = 255;
}
switch (level) {
case RIG_LEVEL_RAWSTR:
val->i = icom_val;
break;
default:
if (RIG_LEVEL_IS_FLOAT(level))
val->f = (float)icom_val/255;
else
val->i = icom_val;
}
rig_debug(RIG_DEBUG_TRACE,"optoscan_get_level: %d %d %d %f\n", lvl_len,
icom_val, val->i, val->f);
return RIG_OK;
}
/* OS456 Pipeline tuning algorithm:
* Step 2: Send the next frequency and mode to the receiver using the
* TRANSFER NEXT FREQUENCY/MODE command.
*
* Step 3: Change the state of the RTS interface signal to cause the
* next frequency and mode to become the current frequency and
* mode, and the receiver to begin settling.
*
* Step 4: While the receiver is still settling on the current
* frequency and mode, send the next frequency and mode to the
* receiver using the TRANSFER NEXT FREQUENCY/MODE command.
*
* Step 5: Wait for the receiver to finish settling. The total
* settling time, including sending the next frequency and
* mode, is 20 milliseconds (0.02 seconds).
*
* Step 6: Check the squelch status by reading the DCD interface
* signal. If the squelch is open, scanning is stopped.
* Otherwise, scanning continues. Optionally, the status of
* the CTCSS/DCS/DTMF decoder can be checked, and the
* appropriate action taken.
*
* Step 7: Continuously repeat steps 3 through 6 above.
*/
int optoscan_scan(RIG *rig, vfo_t vfo, scan_t scan, int ch)
{
pltstate_t *state;
pltune_cb_t cb;
int rc, pin_state;
struct rig_state *rs;
if(scan != RIG_SCAN_PLT)
return -RIG_ENAVAIL;
rs=&rig->state;
cb = rig->callbacks.pltune;
state = ((struct icom_priv_data*)rs->priv)->pltstate;
if(state==NULL)
return -RIG_EINTERNAL;
if(state->freq==0) /* pltstate_t is not initialized - perform setup */
{
/* time for CIV command to be sent. this is subtracted from */
/* rcvr settle time */
state->usleep_time = (1000000 / (rig->state.rigport.parm.serial.rate))
* 13 * 9;
rc=cb(rig,vfo,&(state->next_freq),&(state->next_mode),
&(state->next_width),rig->callbacks.pltune_arg);
if(rc==RIG_SCAN_STOP)
return RIG_OK; /* callback halted loop */
/* Step 1 is implicit, since hamlib does this when it opens the device */
optoscan_send_freq(rig,state); /*Step 2*/
}
rc=!RIG_SCAN_STOP;
while(rc!=RIG_SCAN_STOP)
{
optoscan_RTS_toggle(rig); /*Step 3*/
state->freq = state->next_freq;
state->mode = state->next_mode;
optoscan_start_timer(rig,state);
rc=cb(rig,vfo,&(state->next_freq),&(state->next_mode),
&(state->next_width),rig->callbacks.pltune_arg);
if(rc!=RIG_SCAN_STOP)
{
optoscan_send_freq(rig,state); /*Step 4*/
}
optoscan_wait_timer(rig,state); /*Step 5*/
ser_get_car(&rs->rigport,&pin_state);
if( pin_state ) /*Step 6*/
{
return RIG_OK; /* we've broken squelch - return(). caller can */
/* get current freq & mode out of state str */
}
}
/* exiting pipeline loop - force state init on next call */
state->freq=0;
return RIG_OK;
}
/*
* Assumes rig!=NULL, status_block !=NULL
*/
static int optoscan_get_status_block(RIG *rig, struct optostat *status_block)
{
int retval, ack_len, expected_len;
unsigned char ackbuf[MAXFRAMELEN];
memset(status_block,0,sizeof(struct optostat));
retval = icom_transaction (rig, C_CTL_MISC, S_OPTO_RDSTAT, NULL, 0,
ackbuf, &ack_len);
if (retval != RIG_OK)
return retval;
switch( rig->caps->rig_model )
{
case RIG_MODEL_OS456:
expected_len=4;
break;
case RIG_MODEL_OS535:
expected_len=5;
break;
default:
rig_debug(RIG_DEBUG_ERR,"optoscan_get_status_block: unknown rig model");
return -RIG_ERJCTED;
break;
}
if (ack_len != expected_len ) {
rig_debug(RIG_DEBUG_ERR,"optoscan_get_status_block: ack NG (%#.2x), "
"len=%d\n", ackbuf[0], ack_len);
return -RIG_ERJCTED;
}
if( ackbuf[2] & 1 ) status_block->remote_control = 1;
if( ackbuf[2] & 2 ) status_block->DTMF_pending = 1;
if( ackbuf[2] & 4 ) status_block->DTMF_overrun = 1;
if( ackbuf[2] & 16 ) status_block->squelch_open = 1;
if( ackbuf[2] & 32 ) status_block->CTCSS_active = 1;
if( ackbuf[2] & 64 ) status_block->DCS_active = 1;
if( ackbuf[3] & 1 ) status_block->tape_enabled = 1;
if( ackbuf[3] & 2 ) status_block->speaker_enabled = 1;
if( ackbuf[3] & 4 ) status_block->fivekhz_enabled = 1;
if( ackbuf[3] & 16 ) status_block->audio_present = 1;
rig_debug(RIG_DEBUG_VERBOSE,"remote_control = %d\n",status_block->remote_control);
rig_debug(RIG_DEBUG_VERBOSE,"DTMF_pending = %d\n",status_block->DTMF_pending);
rig_debug(RIG_DEBUG_VERBOSE,"DTMF_overrun = %d\n",status_block->DTMF_overrun);
rig_debug(RIG_DEBUG_VERBOSE,"squelch_open = %d\n",status_block->squelch_open);
rig_debug(RIG_DEBUG_VERBOSE,"CTCSS_active = %d\n",status_block->CTCSS_active);
rig_debug(RIG_DEBUG_VERBOSE,"DCS_active = %d\n",status_block->DCS_active);
rig_debug(RIG_DEBUG_VERBOSE,"tape_enabled = %d\n",status_block->tape_enabled );
rig_debug(RIG_DEBUG_VERBOSE,"speaker_enabled = %d\n",status_block->speaker_enabled);
rig_debug(RIG_DEBUG_VERBOSE,"fivekhz_enabled = %d\n",status_block->fivekhz_enabled);
rig_debug(RIG_DEBUG_VERBOSE,"audio_present = %d\n",status_block->audio_present);
return RIG_OK;
}
static int optoscan_send_freq(RIG *rig,pltstate_t *state)
{
unsigned char buff[OPTO_BUFF_SIZE];
char md,pd;
freq_t freq;
rmode_t mode;
freq=state->next_freq;
mode=state->next_mode;
memset(buff,0,OPTO_BUFF_SIZE);
to_bcd(buff,freq,5*2); /* to_bcd requires nibble len */
rig2icom_mode(rig,mode,0,(unsigned char *) &md, (signed char *) &pd);
buff[5]=md;
/* read echo'd chars only...there will be no ACK from this command
*
* Note:
* It may have waited fro pltstate->usleep_time before reading the echo'd
* chars, but the read will be blocking anyway. --SF
* */
return icom_transaction (rig, C_CTL_MISC, S_OPTO_NXT, buff, 6, NULL, NULL);
return RIG_OK;
}
static int optoscan_RTS_toggle(RIG *rig)
{
struct rig_state *rs;
int state=0;
rs=&rig->state;
ser_get_rts(&rs->rigport,&state);
ser_set_rts(&rs->rigport,!state);
return RIG_OK;
}
static int optoscan_start_timer(RIG *rig, pltstate_t *state)
{
gettimeofday(&(state->timer_start),NULL);
return RIG_OK;
}
static int optoscan_wait_timer(RIG *rig, pltstate_t *state)
{
struct icom_priv_caps *priv_caps;
int usec_diff;
int settle_usec;
priv_caps = (struct icom_priv_caps *)rig->caps->priv;
settle_usec = priv_caps->settle_time * 1000; /*convert settle time (ms) to */
/* settle time (usec) */
gettimeofday(&(state->timer_current),NULL);
usec_diff = abs( (state->timer_current.tv_usec) -
(state->timer_start.tv_usec) );
if( usec_diff < settle_usec )
{
usleep( settle_usec - usec_diff ); /* sleep balance of settle_time */
}
return RIG_OK;
}