forked from Hamlib/Hamlib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrigctlcom.c
1619 lines (1356 loc) · 44.2 KB
/
rigctlcom.c
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
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* rigctlcom.c - (C) Stephane Fillod 2000-2011
* (C) Nate Bargmann 2008,2010,2011,2012,2013
* (C) Michael Black W9MDB 2018 - derived from rigctld.c
* (C) The Hamlib Group 2012
*
* This program is a TS-2000 emulator
* It takes TS-2000 commands on the -R comport and sends them to the rig
* on the -r comport. The -R port speed can be set with -S and always runs 8N1
* This allows programs that can do a TS-2000-over-serial-port to talk
* to any rig that hamlib supports.
* Also supports rigctld or flrig for multiple connections (i.e. rig sharing).
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; 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
#ifdef WIN32
#define WIN32_LEAN_AND_MEAN
// cppcheck-suppress *
#include <windows.h>
#endif
// cppcheck-suppress *
#include <stdio.h>
// cppcheck-suppress *
#include <stdlib.h>
// cppcheck-suppress *
#include <string.h>
// cppcheck-suppress *
#include <unistd.h>
// cppcheck-suppress *
#include <ctype.h>
// cppcheck-suppress *
#include <errno.h>
// cppcheck-suppress *
#include <signal.h>
// cppcheck-suppress *
#include <getopt.h>
// cppcheck-suppress *
#include <sys/types.h>
#ifdef HAVE_NETINET_IN_H
// cppcheck-suppress *
# include <netinet/in.h>
#endif
#ifdef HAVE_ARPA_INET_H
// cppcheck-suppress *
# include <arpa/inet.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
// cppcheck-suppress *
# include <sys/socket.h>
#elif HAVE_WS2TCPIP_H
# include <ws2tcpip.h>
# include <fcntl.h>
# if defined(HAVE_WSPIAPI_H)
# include <wspiapi.h>
# endif
#endif
#include <hamlib/rig.h>
#include "misc.h"
#include "iofunc.h"
#include "serial.h"
#include "sprintflst.h"
#include "rigctl_parse.h"
/*
* Reminder: when adding long options,
* keep up to date SHORT_OPTIONS, usage()'s output and man page. thanks.
* NB: do NOT use -W since it's reserved by POSIX.
* TODO: add an option to read from a file
*/
#define SHORT_OPTIONS "m:r:R:p:d:P:D:s:S:c:C:lLuvhVZ"
static struct option long_options[] =
{
{"model", 1, 0, 'm'},
{"rig-file", 1, 0, 'r'},
{"rig-file2", 1, 0, 'R'},
{"ptt-file", 1, 0, 'p'},
{"dcd-file", 1, 0, 'd'},
{"ptt-type", 1, 0, 'P'},
{"dcd-type", 1, 0, 'D'},
{"serial-speed", 1, 0, 's'},
{"serial-speed2", 1, 0, 'S'},
{"civaddr", 1, 0, 'c'},
{"set-conf", 1, 0, 'C'},
{"list", 0, 0, 'l'},
{"show-conf", 0, 0, 'L'},
{"dump-caps", 0, 0, 'u'},
{"verbose", 0, 0, 'v'},
{"help", 0, 0, 'h'},
{"version", 0, 0, 'V'},
{"debug-time-stamps", 0, 0, 'Z'},
{0, 0, 0, 0}
};
void usage();
static int handle_ts2000(void *arg);
static RIG *my_rig; /* handle to rig */
static hamlib_port_t my_com; /* handle to virtual COM port */
static int verbose;
#ifdef HAVE_SIG_ATOMIC_T
static sig_atomic_t volatile ctrl_c;
#else
static int volatile ctrl_c;
#endif
#define MAXCONFLEN 1024
#if 0
# ifdef WIN32
static BOOL WINAPI CtrlHandler(DWORD fdwCtrlType)
{
rig_debug(RIG_DEBUG_VERBOSE, "CtrlHandler called\n");
switch (fdwCtrlType)
{
case CTRL_C_EVENT:
case CTRL_CLOSE_EVENT:
ctrl_c = 1;
return TRUE;
default:
return FALSE;
}
}
# else
static void signal_handler(int sig)
{
switch (sig)
{
case SIGINT:
ctrl_c = 1;
break;
default:
/* do nothing */
break;
}
}
# endif /* ifdef WIN32 */
#endif /* if 0 */
#if 0
static void handle_error(enum rig_debug_level_e lvl, const char *msg)
{
int e;
# ifdef __MINGW32__
LPVOID lpMsgBuf;
lpMsgBuf = (LPVOID)"Unknown error";
e = WSAGetLastError();
if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
e,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
// Default language
(LPTSTR)&lpMsgBuf,
0,
NULL))
{
rig_debug(lvl, "%s: Network error %d: %s\n", msg, e, lpMsgBuf);
LocalFree(lpMsgBuf);
}
else
{
rig_debug(lvl, "%s: Network error %d\n", msg, e);
}
# else
e = errno;
rig_debug(lvl, "%s: Network error %d: %s\n", msg, e, strerror(e));
# endif /* ifdef __MINGW32__ */
}
#endif /* if 0 */
int main(int argc, char *argv[])
{
rig_model_t my_model = RIG_MODEL_DUMMY;
int retcode; /* generic return code from functions */
int show_conf = 0;
int dump_caps_opt = 0;
const char *rig_file = NULL, *rig_file2 = NULL, *ptt_file = NULL,
*dcd_file = NULL;
ptt_type_t ptt_type = RIG_PTT_NONE;
dcd_type_t dcd_type = RIG_DCD_NONE;
int serial_rate = 0;
int serial_rate2 = 115200; /* virtual com port default speed */
char *civaddr = NULL; /* NULL means no need to set conf */
char conf_parms[MAXCONFLEN] = "";
int status;
printf("rigctlcom Version 1.1\n");
while (1)
{
int c;
int option_index = 0;
char dummy[2];
c = getopt_long(argc,
argv,
SHORT_OPTIONS,
long_options,
&option_index);
if (c == -1)
{
break;
}
switch (c)
{
case 'h':
usage();
exit(0);
case 'V':
version();
exit(0);
case 'm':
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
my_model = atoi(optarg);
break;
case 'r':
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
rig_file = optarg;
break;
case 'R':
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
rig_file2 = optarg;
break;
case 'p':
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
ptt_file = optarg;
break;
case 'd':
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
dcd_file = optarg;
break;
case 'P':
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
if (!strcmp(optarg, "RIG"))
{
ptt_type = RIG_PTT_RIG;
}
else if (!strcmp(optarg, "DTR"))
{
ptt_type = RIG_PTT_SERIAL_DTR;
}
else if (!strcmp(optarg, "RTS"))
{
ptt_type = RIG_PTT_SERIAL_RTS;
}
else if (!strcmp(optarg, "PARALLEL"))
{
ptt_type = RIG_PTT_PARALLEL;
}
else if (!strcmp(optarg, "CM108"))
{
ptt_type = RIG_PTT_CM108;
}
else if (!strcmp(optarg, "NONE"))
{
ptt_type = RIG_PTT_NONE;
}
else
{
ptt_type = atoi(optarg);
}
break;
case 'D':
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
if (!strcmp(optarg, "RIG"))
{
dcd_type = RIG_DCD_RIG;
}
else if (!strcmp(optarg, "DSR"))
{
dcd_type = RIG_DCD_SERIAL_DSR;
}
else if (!strcmp(optarg, "CTS"))
{
dcd_type = RIG_DCD_SERIAL_CTS;
}
else if (!strcmp(optarg, "CD"))
{
dcd_type = RIG_DCD_SERIAL_CAR;
}
else if (!strcmp(optarg, "PARALLEL"))
{
dcd_type = RIG_DCD_PARALLEL;
}
else if (!strcmp(optarg, "NONE"))
{
dcd_type = RIG_DCD_NONE;
}
else
{
dcd_type = atoi(optarg);
}
break;
case 'c':
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
civaddr = optarg;
break;
case 's':
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
if (sscanf(optarg, "%d%1s", &serial_rate, dummy) != 1)
{
fprintf(stderr, "Invalid baud rate of %s\n", optarg);
exit(1);
}
break;
case 'S':
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
serial_rate2 = atoi(optarg);
break;
case 'C':
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
if (*conf_parms != '\0')
{
strcat(conf_parms, ",");
}
if (strlen(conf_parms) + strlen(optarg) > MAXCONFLEN - 24)
{
printf("Length of conf_parms exceeds internal maximum of %d\n",
MAXCONFLEN - 24);
return 1;
}
strncat(conf_parms, optarg, MAXCONFLEN - strlen(conf_parms));
break;
case 'v':
verbose++;
break;
case 'L':
show_conf++;
break;
case 'l':
rig_set_debug(verbose);
list_models();
exit(0);
case 'u':
dump_caps_opt++;
break;
case 'Z':
rig_set_debug_time_stamp(1);
break;
default:
usage(); /* unknown option? */
exit(1);
}
}
rig_set_debug(verbose);
rig_debug(RIG_DEBUG_VERBOSE, "%s, %s\n", "rigctlcom", hamlib_version);
rig_debug(RIG_DEBUG_VERBOSE, "%s",
"Report bugs to <[email protected]>\n\n");
if (argc == 1)
{
usage();
exit(2);
}
my_rig = rig_init(my_model);
if (!my_rig)
{
fprintf(stderr,
"Unknown rig num %d, or initialization error.\n",
my_model);
fprintf(stderr, "Please check with --list option.\n");
exit(2);
}
retcode = set_conf(my_rig, conf_parms);
if (retcode != RIG_OK)
{
fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode));
exit(2);
}
if (my_model > 5 && !rig_file)
{
fprintf(stderr, "-r rig com port not provided\n");
exit(2);
}
if (rig_file)
{
strncpy(my_rig->state.rigport.pathname, rig_file, FILPATHLEN - 1);
}
if (!rig_file2)
{
fprintf(stderr, "-R com port not provided\n");
exit(2);
}
strncpy(my_com.pathname, rig_file2, FILPATHLEN - 1);
/*
* ex: RIG_PTT_PARALLEL and /dev/parport0
*/
if (ptt_type != RIG_PTT_NONE)
{
my_rig->state.pttport.type.ptt = ptt_type;
}
if (dcd_type != RIG_DCD_NONE)
{
my_rig->state.dcdport.type.dcd = dcd_type;
}
if (ptt_file)
{
strncpy(my_rig->state.pttport.pathname, ptt_file, FILPATHLEN - 1);
}
if (dcd_file)
{
strncpy(my_rig->state.dcdport.pathname, dcd_file, FILPATHLEN - 1);
}
/* FIXME: bound checking and port type == serial */
if (serial_rate != 0)
{
my_rig->state.rigport.parm.serial.rate = serial_rate;
}
if (serial_rate2 != 0)
{
my_com.parm.serial.rate = serial_rate2;
}
if (civaddr)
{
rig_set_conf(my_rig, rig_token_lookup(my_rig, "civaddr"), civaddr);
}
/*
* print out conf parameters
*/
if (show_conf)
{
rig_token_foreach(my_rig, print_conf_list, (rig_ptr_t)my_rig);
}
/*
* print out conf parameters, and exits immediately
* We may be interested only in only caps, and rig_open may fail.
*/
if (dump_caps_opt)
{
dumpcaps(my_rig, stdout);
rig_cleanup(my_rig); /* if you care about memory */
exit(0);
}
/* open and close rig connection to check early for issues */
retcode = rig_open(my_rig);
if (retcode != RIG_OK)
{
fprintf(stderr, "rig_open: error = %s \n", rigerror(retcode));
exit(2);
}
if (verbose > 0)
{
printf("Opened rig model %d, '%s'\n",
my_rig->caps->rig_model,
my_rig->caps->model_name);
}
rig_debug(RIG_DEBUG_VERBOSE, "Backend version: %s, Status: %s\n",
my_rig->caps->version, rig_strstatus(my_rig->caps->status));
/*
* main loop
*/
my_com.type.rig = RIG_PORT_SERIAL;
my_com.parm.serial.data_bits = 8;
my_com.parm.serial.stop_bits = 1;
my_com.timeout = 5000;
my_com.parm.serial.parity = RIG_PARITY_NONE;
my_com.parm.serial.handshake = RIG_HANDSHAKE_NONE;
status = port_open(&my_com);
if (status != RIG_OK)
{
rig_debug(RIG_DEBUG_ERR, "Unable to open %s\n", my_com.pathname);
exit(2);
}
if (verbose > 0)
{
fprintf(stderr, " %s opened for application program\n", my_com.pathname);
}
do
{
char ts2000[1024];
char *stop_set = ";\n\r";
memset(ts2000, 0, sizeof(ts2000));
status = read_string(&my_com,
ts2000,
sizeof(ts2000),
stop_set,
strlen(stop_set));
rig_debug(RIG_DEBUG_TRACE, "%s: status=%d\n", __func__, status);
if (strlen(ts2000) > 0)
{
int retval = handle_ts2000(ts2000);
if (retval != RIG_OK)
{
rig_debug(RIG_DEBUG_ERR, "%s: %s\n", __func__, rigerror(retval));
}
}
}
while (retcode == 0 && !ctrl_c);
rig_close(my_rig); /* close port */
rig_cleanup(my_rig); /* if you care about memory */
return 0;
}
static rmode_t ts2000_get_mode()
{
rmode_t mode;
pbwidth_t width;
rig_get_mode(my_rig, vfo_fixup(my_rig, RIG_VFO_A), &mode, &width);
// Perhaps we should emulate a rig that has PKT modes instead??
switch (mode)
{
case RIG_MODE_LSB: mode = 1; break;
case RIG_MODE_USB: mode = 2; break;
case RIG_MODE_CW: mode = 3; break;
case RIG_MODE_FM: mode = 4; break;
case RIG_MODE_AM: mode = 5; break;
case RIG_MODE_RTTY: mode = 6; break;
case RIG_MODE_CWR: mode = 7; break;
case RIG_MODE_NONE: mode = 8; break;
case RIG_MODE_RTTYR: mode = 9; break;
case RIG_MODE_PKTUSB: mode = 2; break; // need to change to a TS_2000 mode
case RIG_MODE_PKTLSB: mode = 1; break; // need to change to a TS_2000 mode
default: mode = 0; break;
}
return mode;
}
static int write_block2(void *func,
hamlib_port_t *p,
const char *txbuffer,
size_t count)
{
int retval = write_block(p, txbuffer, count);
hl_usleep(5000);
if (retval != RIG_OK)
{
rig_debug(RIG_DEBUG_ERR, "%s: %s\n", __func__, rigerror(retval));
}
return retval;
}
/*
* This handles the TS-2000 emulation
*/
static int handle_ts2000(void *arg)
{
rig_debug(RIG_DEBUG_VERBOSE, "%s: cmd=%s\n", __func__, (char *)arg);
// Handle all the queries
if (strcmp(arg, "ID;") == 0)
{
char *reply = "ID019;";
return write_block2((void *)__func__, &my_com, reply, strlen(reply));
}
if (strcmp(arg, "AI;") == 0)
{
char *reply = "AI0;";
return write_block2((void *)__func__, &my_com, reply, strlen(reply));
}
else if (strcmp(arg, "IF;") == 0)
{
freq_t freq; // P1
int freq_step = 10; // P2 just use default value for now
int rit_xit_freq = 0; // P3 dummy value for now
int rit = 0; // P4 dummy value for now
int xit = 0; // P5 dummy value for now
int bank1 = 0; // P6 dummy value for now
int bank2 = 0; // P7 dummy value for now
ptt_t ptt; // P8
rmode_t mode; // P9
vfo_t vfo; // P10
int scan = 0; // P11 dummy value for now
split_t split = 0; // P1 2
int p13 = 0; // P13 Tone dummy value for now
int p14 = 0; // P14 Tone Freq dummy value for now
int p15 = 0; // P15 Shift status dummy value for now
int retval = rig_get_freq(my_rig, vfo_fixup(my_rig, RIG_VFO_A), &freq);
char response[64];
char *fmt =
// cppcheck-suppress *
"IF%011"PRIll"%04d+%05d%1d%1d%1d%02d%1d%1"PRIll"%1d%1d%1d%1d%02d%1d;";
if (retval != RIG_OK)
{
return retval;
}
mode = ts2000_get_mode();
retval = rig_get_ptt(my_rig, vfo_fixup(my_rig, RIG_VFO_A), &ptt);
if (retval != RIG_OK)
{
return retval;
}
// we need to know split status -- don't care about the vfo
retval = rig_get_split_vfo(my_rig, RIG_VFO_CURR, &split, &vfo);
if (retval != RIG_OK)
{
return retval;
}
retval = rig_get_vfo(my_rig, &vfo);
if (retval != RIG_OK)
{
return retval;
}
switch (vfo)
{
case RIG_VFO_A:
case RIG_VFO_MAIN:
case RIG_VFO_MAIN_A:
case RIG_VFO_SUB_A:
vfo = 0;
break;
case RIG_VFO_B:
case RIG_VFO_SUB:
case RIG_VFO_MAIN_B:
case RIG_VFO_SUB_B:
vfo = 1;
break;
default:
rig_debug(RIG_DEBUG_ERR, "%s: unexpected vfo=%d\n", __func__, vfo);
}
snprintf(response,
sizeof(response),
fmt,
(uint64_t)freq,
freq_step,
rit_xit_freq,
rit, xit,
bank1,
bank2,
ptt,
mode,
vfo,
scan,
split,
p13,
p14,
p15);
return write_block2((void *)__func__, &my_com, response, strlen(response));
}
else if (strcmp(arg, "MD;") == 0)
{
rmode_t mode = ts2000_get_mode();
char response[32];
snprintf(response, sizeof(response), "MD%1d;", (int)mode);
return write_block2((void *)__func__, &my_com, response, strlen(response));
}
else if (strcmp(arg, "AG0;") == 0)
{
char response[32];
snprintf(response, sizeof(response), "AG0000;");
return write_block2((void *)__func__, &my_com, response, strlen(response));
}
else if (strcmp(arg, "FA;") == 0)
{
freq_t freq = 0;
char response[32];
int retval = rig_get_freq(my_rig, vfo_fixup(my_rig, RIG_VFO_A), &freq);
if (retval != RIG_OK)
{
rig_debug(RIG_DEBUG_ERR, "%s: get freqA failed: %s\n", __func__,
rigerror(retval));
return retval;
}
snprintf(response, sizeof(response), "FA%011"PRIll";", (uint64_t)freq);
return write_block2((void *)__func__, &my_com, response, strlen(response));
}
else if (strcmp(arg, "FB;") == 0)
{
char response[32];
freq_t freq = 0;
int retval = rig_get_freq(my_rig, vfo_fixup(my_rig, RIG_VFO_B), &freq);
if (retval != RIG_OK)
{
rig_debug(RIG_DEBUG_ERR, "%s: get freqB failed: %s\n", __func__,
rigerror(retval));
return retval;
}
snprintf(response, sizeof(response), "FB%011"PRIll";", (uint64_t)freq);
return write_block2((void *)__func__, &my_com, response, strlen(response));
}
else if (strcmp(arg, "SA;") == 0)
{
char response[32];
snprintf(response, sizeof(response), "SA0;");
return write_block2((void *)__func__, &my_com, response, strlen(response));
}
else if (strcmp(arg, "RX;") == 0)
{
char response[32];
snprintf(response, sizeof(response), "RX0;");
return write_block2((void *)__func__, &my_com, response, strlen(response));
}
// Now some commands to set things
else if (strcmp(arg, "TX;") == 0)
{
return rig_set_ptt(my_rig, vfo_fixup(my_rig, RIG_VFO_A), 1);
}
else if (strcmp(arg, "AI0;") == 0)
{
// nothing to do
return RIG_OK;
}
else if (strcmp(arg, ";") == 0)
{
// nothing to do
return RIG_OK;
}
else if (strcmp(arg, "FR0;") == 0)
{
return rig_set_vfo(my_rig, vfo_fixup(my_rig, RIG_VFO_A));
}
else if (strcmp(arg, "FR1;") == 0)
{
return rig_set_vfo(my_rig, vfo_fixup(my_rig, RIG_VFO_B));
}
else if (strcmp(arg, "FR;") == 0)
{
char response[32];
vfo_t vfo;
int retval = rig_get_vfo(my_rig, &vfo);
int nvfo = 0;
if (retval != RIG_OK)
{
rig_debug(RIG_DEBUG_ERR, "%s: get vfo failed: %s\n", __func__,
rigerror(retval));
return retval;
}
if (vfo == vfo_fixup(my_rig, RIG_VFO_A)) { nvfo = 0; }
else if (vfo == vfo_fixup(my_rig, RIG_VFO_B)) { nvfo = 1; }
else
{
retval = -RIG_EPROTO;
return retval;
}
snprintf(response, sizeof(response), "FR%c;", nvfo + '0');
return write_block2((void *)__func__, &my_com, response, strlen(response));
return retval;
}
else if (strcmp(arg, "FT;") == 0)
{
char response[32];
vfo_t vfo, vfo_curr = vfo_fixup(my_rig, RIG_VFO_A);
split_t split;
int nvfo = 0;
int retval = rig_get_split_vfo(my_rig, vfo_curr, &split, &vfo);
if (retval != RIG_OK)
{
rig_debug(RIG_DEBUG_ERR, "%s: get split vfo failed: %s\n", __func__,
rigerror(retval));
return retval;
}
if (vfo == vfo_fixup(my_rig, RIG_VFO_A)) { nvfo = 0; }
else if (vfo == vfo_fixup(my_rig, RIG_VFO_B)) { nvfo = 1; }
else
{
retval = -RIG_EPROTO;
return retval;
}
snprintf(response, sizeof(response), "FT%c;", nvfo + '0');
return write_block2((void *)__func__, &my_com, response, strlen(response));
return retval;
}
else if (strcmp(arg, "TN;") == 0)
{
char response[32];
tone_t val;
int retval = rig_get_ctcss_tone(my_rig, RIG_VFO_CURR, &val);
if (retval != RIG_OK)
{
rig_debug(RIG_DEBUG_ERR, "%s: get_func XIT failed: %s\n", __func__,
rigerror(retval));
return retval;
}
snprintf(response, sizeof(response), "TN%02d;", val);
return write_block2((void *)__func__, &my_com, response, strlen(response));
}
else if (strncmp(arg, "TN", 2) == 0)
{
tone_t val;
int ival = 0;
int retval;
sscanf(arg, "TN%d", &ival);
val = ival;
retval = rig_set_ctcss_tone(my_rig, RIG_VFO_CURR, val);
if (retval != RIG_OK)
{
rig_debug(RIG_DEBUG_ERR, "%s: set_ctcss_tone failed: %s\n", __func__,
rigerror(retval));
}
return retval;
}
else if (strcmp(arg, "PA;") == 0)
{
char response[32];
int valA;
int retval = rig_get_func(my_rig, vfo_fixup(my_rig, RIG_VFO_A), RIG_FUNC_AIP,
&valA);
int valB;
if (retval != RIG_OK)