-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrig.go
1322 lines (1150 loc) · 34.5 KB
/
rig.go
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
package goHamlib
/*
#cgo pkg-config: hamlib
#include <stdio.h>
#include <stdlib.h>
#include <hamlib/rig.h>
extern int set_port(RIG *myrig,int rig_port_type, char* portname, int baudrate, int databits, int stopbits, int parity, int handshake);
extern RIG * init_rig(int rig_model);
extern int open_rig(RIG *myrig);
extern int has_set_vfo(RIG *myrig);
extern int set_vfo(RIG *myrig,int vfo);
extern int has_get_vfo(RIG *myrig);
extern int get_vfo(RIG *myrig,int *vfo);
extern int has_set_freq(RIG *myrig);
extern int set_freq(RIG *myrig,int vfo, double freq);
extern int has_set_mode(RIG *myrig);
extern int set_mode(RIG *myrig, int vfo, int mode, int pb_width);
extern int get_passband_narrow(RIG *myrig, int mode);
extern int get_passband_normal(RIG *myrig, int mode);
extern int get_passband_wide(RIG *myrig, int mode);
extern int has_get_freq(RIG *myrig);
extern int get_freq(RIG *myrig, int vfo, double *freq);
extern int has_get_mode(RIG *myrig);
extern int get_mode(RIG *myrig, int vfo, int *mode, long *pb_width);
extern int has_set_ptt(RIG *myrig);
extern int set_ptt(RIG *myrig, int vfo, int ptt);
extern int has_get_ptt(RIG *myrig);
extern int get_ptt(RIG *myrig, int vfo, int *ptt);
extern int has_set_rit(RIG *myrig);
extern int set_rit(RIG *myrig, int vfo, int offset);
extern int has_get_rit(RIG *myrig);
extern int get_rit(RIG *myrig, int vfo, long *offset);
extern int has_set_xit(RIG *myrig);
extern int set_xit(RIG *myrig, int vfo, int offset);
extern int has_get_xit(RIG *myrig);
extern int get_xit(RIG *myrig, int vfo, long *offset);
extern int has_set_split_freq(RIG *myrig);
extern int set_split_freq(RIG *myrig, int vfo, double tx_freq);
extern int has_get_split_freq(RIG *myrig);
extern int get_split_freq(RIG *myrig, int vfo, double *tx_freq);
extern int has_set_split_mode(RIG *myrig);
extern int set_split_mode(RIG *myrig, int vfo, int tx_mode, int tx_width);
extern int has_get_split_mode(RIG *myrig);
extern int get_split_mode(RIG *myrig, int vfo, int *tx_mode, long *tx_width);
extern int has_set_split_vfo(RIG *myrig);
extern int set_split_vfo(RIG *myrig, int vfo, int split, int tx_vfo);
extern int has_get_split_vfo(RIG *myrig);
extern int get_split_vfo(RIG *myrig, int vfo, int *split, int *tx_vfo);
extern int has_set_powerstat(RIG *myrig);
extern int set_powerstat(RIG *myrig, int status);
extern int has_get_powerstat(RIG *myrig);
extern int get_powerstat(RIG *myrig, int *status);
extern const char* get_info(RIG *myrig);
extern void get_model_name(RIG *myrig, char *rig_name);
extern void get_version(RIG *myrig, char *version);
extern void get_mfg_name(RIG *myrig, char *mfg_name);
extern int get_status(RIG *myrig);
extern int has_set_ant(RIG *myrig);
extern int set_ant(RIG *myrig, int vfo, int ant);
extern int has_get_ant(RIG *myrig);
extern int get_ant(RIG *myrig, int vfo, int *ant);
extern int has_set_ts(RIG *myrig);
extern int set_ts(RIG *myrig, int vfo, int ts);
extern int has_get_ts(RIG *myrig);
extern int get_ts(RIG *myrig, int vfo, long *ts);
extern signed long get_rig_resolution(RIG *myrig, int mode);
extern unsigned long has_get_level(RIG *myrig, unsigned long level);
extern unsigned long has_set_level(RIG *myrig, unsigned long level);
extern unsigned long has_get_func(RIG *myrig, unsigned long func);
extern unsigned long has_set_func(RIG *myrig, unsigned long func);
extern unsigned long has_get_parm(RIG *myrig, unsigned long parm);
extern unsigned long has_set_parm(RIG *myrig, unsigned long parm);
extern int has_token(RIG *myrig, char *token);
extern int has_get_conf(RIG *myrig);
extern int get_conf(RIG *myrig, char* token, char* val);
extern int has_set_conf(RIG *myrig);
extern int set_conf(RIG *myrig, char* token, char* val);
extern int get_level(RIG *myrig, int vfo, unsigned long level, float *value);
extern int get_level_gran(RIG *myrig, unsigned long level, float *step, float *min, float *max);
extern int set_level(RIG *myrig, int vfo, unsigned long level, float value);
extern int get_func(RIG *myrig, int vfo, unsigned long function, int *value);
extern int set_func(RIG *myrig, int vfo, unsigned long function, int value);
extern int get_parm(RIG *myrig, unsigned long parm, float *value);
extern int get_parm_gran(RIG *myrig, unsigned long parm, float *step, float *min, float *max);
extern int set_parm(RIG *myrig, unsigned long parm, float value);
extern int vfo_op(RIG *myrig, int vfo, int op);
extern int get_caps_max_rit(RIG *myrig, int *rit);
extern int get_caps_max_xit(RIG *myrig, int *xit);
extern int get_caps_max_if_shift(RIG *myrig, int *if_shift);
extern int* get_caps_attenuator_list_pointer_and_length(RIG *myrig, int *length);
extern int* get_caps_preamp_list_pointer_and_length(RIG *myrig, int *length);
extern int get_supported_vfos(RIG *myrig, int *vfo_list);
extern int get_supported_vfo_operations(RIG *myrig, int *vfo_ops);
extern int get_supported_modes(RIG *myrig, int *modes);
extern int get_filter_count(RIG *myrig, int *filter_count);
extern int get_filter_mode_width(RIG *myrig, int filter, int *mode, signed long *width);
extern int get_ts_count(RIG *myrig, int *ts_count);
extern int get_tuning_steps(RIG *myrig, int el, int *mode, signed long *ts);
extern int get_int_from_array(RIG *myrig, int *array, int *el, int index);
extern void set_debug_level(int debug_level);
extern int close_rig(RIG *myrig);
extern int cleanup_rig(RIG *myrig);
typedef struct rig_caps rig_caps_t;
extern int rig_list_foreach_wrap(void *list);
extern void set_debug_callback();
extern int internal_debug_cb(enum rig_debug_level_e debug_level, rig_ptr_t user_data, const char *fmt, va_list ap);
*/
import "C"
import (
"errors"
"log"
"sort"
"strings"
"unsafe"
)
// RigModelID is a unique ID that identifies a particular rig driver
type RigModelID int
// RigModel is a supported rig in hamlib
type RigModel struct {
Manufacturer string
Model string
ModelID RigModelID
}
// ListModels enumerates all of the hamlib supported rigs
func ListModels() []RigModel {
C.rig_load_all_backends()
knownRigs := []RigModel{}
C.rig_list_foreach_wrap(unsafe.Pointer(&knownRigs))
return knownRigs
}
//export go_rig_list_callback
func go_rig_list_callback(p unsafe.Pointer, d unsafe.Pointer) C.int {
caps := (*C.rig_caps_t)(p)
knownRigs := (*[]RigModel)(d)
*knownRigs = append(*knownRigs, RigModel{
Manufacturer: C.GoString(caps.mfg_name),
Model: C.GoString(caps.model_name),
ModelID: RigModelID(caps.rig_model),
})
return 1
}
// Set Debug level
func SetDebugLevel(dbgLevel DebugLevel) {
C.set_debug_level(C.int(dbgLevel))
}
//export go_debug_print
func go_debug_print(lvl DebugLevel, msg *C.char) {
if debug_cb_fn != nil {
debug_cb_fn(lvl, C.GoString(msg))
} else {
log.Println(lvl, C.GoString(msg))
}
}
var debug_cb_fn func(level DebugLevel, msg string)
// SetDebugCallback replaces the function that handles debug messages, preventing
// them from being written to STDOUT
func SetDebugCallback(fn func(level DebugLevel, msg string)) {
debug_cb_fn = fn
C.set_debug_callback()
}
// Initialize Rig
func (rig *Rig) Init(rigModel RigModelID) error {
if rigModel <= 0 {
return checkError(C.int(HamlibErrEINVAL), errors.New("invalid rig model"), "init_rig")
}
rig.handle = C.init_rig(C.int(rigModel))
if rig.handle == nil {
return checkError(0, errors.New("error initializing rig"), "init_rig")
}
err := rig.getCaps()
rig.Caps.RigModel = int(rigModel)
return checkError(0, err, "init_rig")
}
// Set Port of Rig
func (rig *Rig) SetPort(p Port) error {
res, err := C.set_port(rig.handle, C.int(p.RigPortType), C.CString(p.Portname), C.int(p.Baudrate), C.int(p.Databits), C.int(p.Stopbits), C.int(p.Parity), C.int(p.Handshake))
return checkError(res, err, "set_port")
}
// Open Radio / Port
func (rig *Rig) Open() error {
res, err := C.open_rig(rig.handle)
return checkError(res, err, "open_rig")
}
// SetVfo sets the default VFO
func (rig *Rig) SetVfo(vfo VFOType) error {
res, err := C.set_vfo(rig.handle, C.int(vfo))
return checkError(res, err, "set_vfo")
}
// GetVfo returns the default VFO
func (rig *Rig) GetVfo() (VFOType, error) {
var v C.int
res, err := C.get_vfo(rig.handle, &v)
return VFOType(v), checkError(res, err, "get_vfo")
}
// SetFreq sets the Frequency for a VFO
func (rig *Rig) SetFreq(vfo VFOType, freq float64) error {
res, err := C.set_freq(rig.handle, C.int(vfo), C.double(freq))
return checkError(res, err, "set_freq")
}
// SetMode sets the Mode for a VFO
func (rig *Rig) SetMode(vfo VFOType, mode Mode, pbWidth int) error {
res, err := C.set_mode(rig.handle, C.int(vfo), C.int(mode), C.int(pbWidth))
return checkError(res, err, "set_mode")
}
// Find the next suitable narrow available filter
func (rig *Rig) GetPbNarrow(mode Mode) (int, error) {
pb, err := C.get_passband_narrow(rig.handle, C.int(mode))
pb_width := int(pb)
return pb_width, err
}
// Find the next suitable normal available filter
func (rig *Rig) GetPbNormal(mode Mode) (int, error) {
pb, err := C.get_passband_normal(rig.handle, C.int(mode))
pb_width := int(pb)
return pb_width, err
}
// Find the next suitable wide available filter
func (rig *Rig) GetPbWide(mode Mode) (int, error) {
pb, err := C.get_passband_wide(rig.handle, C.int(mode))
pb_width := int(pb)
return pb_width, err
}
// Get Frequency from a VFO
func (rig *Rig) GetFreq(vfo VFOType) (freq float64, err error) {
var f C.double
var res C.int
res, err = C.get_freq(rig.handle, C.int(vfo), &f)
freq = float64(f)
return freq, checkError(res, err, "get_freq")
}
// GetMode gets the Mode and Passband width for a VFO
func (rig *Rig) GetMode(vfo VFOType) (mode Mode, pb_width int, err error) {
var m C.int
var pb C.long
var res C.int
res, err = C.get_mode(rig.handle, C.int(vfo), &m, &pb)
pb_width = int(pb)
mode = Mode(m)
return mode, pb_width, checkError(res, err, "get_mode")
}
// Set Ptt
func (rig *Rig) SetPtt(vfo VFOType, ptt int) error {
res, err := C.set_ptt(rig.handle, C.int(vfo), C.int(ptt))
return checkError(res, err, "set_ptt")
}
// Get Ptt state
func (rig *Rig) GetPtt(vfo VFOType) (ptt int, err error) {
var p C.int
res, err := C.get_ptt(rig.handle, C.int(vfo), &p)
ptt = int(p)
return ptt, checkError(res, err, "get_ptt")
}
// Set Rit offset value
func (rig *Rig) SetRit(vfo VFOType, offset int) error {
res, err := C.set_rit(rig.handle, C.int(vfo), C.int(offset))
return checkError(res, err, "set_rit")
}
// Get Rit offset value
func (rig *Rig) GetRit(vfo VFOType) (offset int, err error) {
var o C.long
res, err := C.get_rit(rig.handle, C.int(vfo), &o)
offset = int(o)
return offset, checkError(res, err, "get_rit")
}
// Set Xit offset value
func (rig *Rig) SetXit(vfo VFOType, offset int) error {
res, err := C.set_xit(rig.handle, C.int(vfo), C.int(offset))
return checkError(res, err, "set_xit")
}
// Get Xit offset value
func (rig *Rig) GetXit(vfo VFOType) (offset int, err error) {
var o C.long
res, err := C.get_xit(rig.handle, C.int(vfo), &o)
offset = int(o)
return offset, checkError(res, err, "get_xit")
}
// Set Split Frequency
func (rig *Rig) SetSplitFreq(vfo VFOType, txFreq float64) error {
res, err := C.set_split_freq(rig.handle, C.int(vfo), C.double(txFreq))
return checkError(res, err, "set_split_freq")
}
// Get Split Frequency
func (rig *Rig) GetSplitFreq(vfo VFOType) (txFreq float64, err error) {
var f C.double
res, err := C.get_split_freq(rig.handle, C.int(vfo), &f)
txFreq = float64(f)
return txFreq, checkError(res, err, "get_split_freq")
}
// Set Split Mode
func (rig *Rig) SetSplitMode(vfo VFOType, txMode Mode, txWidth int) error {
res, err := C.set_split_mode(rig.handle, C.int(vfo), C.int(txMode), C.int(txWidth))
return checkError(res, err, "set_split_mode")
}
// Get Split Mode
func (rig *Rig) GetSplitMode(vfo VFOType) (txMode Mode, txWidth int, err error) {
var m C.int
var w C.long
res, err := C.get_split_mode(rig.handle, C.int(vfo), &m, &w)
txMode = Mode(m)
txWidth = int(w)
return txMode, txWidth, checkError(res, err, "get_split_mode")
}
// Set Split Vfo
func (rig *Rig) SetSplitVfo(vfo VFOType, split int, txVfo VFOType) error {
res, err := C.set_split_vfo(rig.handle, C.int(vfo), C.int(split), C.int(txVfo))
return checkError(res, err, "set_split_vfo")
}
// Get Split Vfo
func (rig *Rig) GetSplitVfo(vfo VFOType) (split int, txVfo VFOType, err error) {
var s C.int
var v C.int
res, err := C.get_split_vfo(rig.handle, C.int(vfo), &s, &v)
split = int(s)
txVfo = VFOType(v)
return split, txVfo, checkError(res, err, "get_split_vfo")
}
// Get Split (shortcut for GetSplitVfo)
func (rig *Rig) GetSplit(vfo VFOType) (split int, txVfo VFOType, err error) {
var s C.int
var t C.int
res, err := C.get_split_vfo(rig.handle, C.int(vfo), &s, &t)
split = int(s)
txVfo = VFOType(t)
return split, txVfo, checkError(res, err, "get_split")
}
// SetPowerState sets the Rig Power On/Off/Standby state
func (rig *Rig) SetPowerState(status Power) error {
res, err := C.set_powerstat(rig.handle, C.int(status))
return checkError(res, err, "set_powerstat")
}
// GetPowerStat gets the Rig Power On/Off/Standby state
func (rig *Rig) GetPowerState() (status Power, err error) {
var s C.int
var res C.int
res, err = C.get_powerstat(rig.handle, &s)
status = Power(s)
return status, checkError(res, err, "get_powerstat")
}
// Get Rig info
func (rig *Rig) GetInfo() (info string, err error) {
i, err := C.get_info(rig.handle)
info = C.GoString(i)
return info, checkError(C.int(0), err, "get_info")
}
// Set Antenna
func (rig *Rig) SetAnt(vfo VFOType, ant int) error {
res, err := C.set_ant(rig.handle, C.int(vfo), C.int(ant))
return checkError(res, err, "set_ant")
}
// Get Antenna
func (rig *Rig) GetAnt(vfo VFOType) (ant int, err error) {
var a C.int
res, err := C.get_ant(rig.handle, C.int(vfo), &a)
ant = int(a)
return ant, checkError(res, err, "get_ant")
}
// Set Tuning step
func (rig *Rig) SetTs(vfo VFOType, ts int) error {
res, err := C.set_ts(rig.handle, C.int(vfo), C.int(ts))
return checkError(res, err, "set_ts")
}
// Get Tuning step
func (rig *Rig) GetTs(vfo VFOType) (ts int, err error) {
var t C.long
res, err := C.get_ts(rig.handle, C.int(vfo), &t)
ts = int(t)
return ts, checkError(res, err, "get_ts")
}
// has supports getting a specific level
func (rig *Rig) HasGetLevel(level uint32) (res uint32, err error) {
var c C.ulong
c, err = C.has_get_level(rig.handle, C.ulong(level))
res = uint32(c)
return res, checkError(0, err, "has_get_level")
}
// get the best frequency resolution for this rig (minimum step size)
func (rig *Rig) GetRigResolution(mode Mode) (resolution int, err error) {
var r C.long
r, err = C.get_rig_resolution(rig.handle, C.int(mode))
resolution = int(r)
return resolution, checkError(0, err, "get_rig_resolution")
}
// has supports setting a specific level
func (rig *Rig) HasSetLevel(level uint32) (res uint32, err error) {
var c C.ulong
c, err = C.has_set_level(rig.handle, C.ulong(level))
res = uint32(c)
return res, checkError(0, err, "has_set_level")
}
// has supports getting a specific function
func (rig *Rig) HasGetFunc(function uint32) (res uint32, err error) {
var c C.ulong
c, err = C.has_get_func(rig.handle, C.ulong(function))
res = uint32(c)
return res, checkError(0, err, "has_get_func")
}
// has supports setting a specific function
func (rig *Rig) HasSetFunc(function uint32) (res uint32, err error) {
var c C.ulong
c, err = C.has_set_func(rig.handle, C.ulong(function))
res = uint32(c)
return res, checkError(0, err, "has_set_func")
}
// has supports getting a specific parameter
func (rig *Rig) HasGetParm(parm uint32) (res uint32, err error) {
var c C.ulong
c, err = C.has_get_parm(rig.handle, C.ulong(parm))
res = uint32(c)
return res, checkError(0, err, "has_get_parm")
}
// has supports setting a specific parameter
func (rig *Rig) HasSetParm(parm uint32) (res uint32, err error) {
var c C.ulong
c, err = C.has_set_parm(rig.handle, C.ulong(parm))
res = uint32(c)
return res, checkError(0, err, "has_set_parm")
}
//get Level
func (rig *Rig) GetLevel(vfo VFOType, level uint32) (value float32, err error) {
var v C.float
var res C.int
res, err = C.get_level(rig.handle, C.int(vfo), C.ulong(level), &v)
value = float32(v)
return value, checkError(res, err, "get_level")
}
//set Level
func (rig *Rig) SetLevel(vfo VFOType, level uint32, value float32) error {
res, err := C.set_level(rig.handle, C.int(vfo), C.ulong(level), C.float(value))
return checkError(res, err, "set_level")
}
//Get granularity (stepsize, minimum, maximum) for a Level
func (rig *Rig) GetLevelGran(level uint32) (step float32, min float32, max float32, err error) {
var cStep C.float
var cMin C.float
var cMax C.float
res, err := C.get_level_gran(rig.handle, C.ulong(level), &cStep, &cMin, &cMax)
if checkError(res, err, "get_level_gran") != nil {
return 0, 0, 0, err
}
return float32(cStep), float32(cMin), float32(cMax), nil
}
//get Function
func (rig *Rig) GetFunc(vfo VFOType, function uint32) (value bool, err error) {
var v C.int
var res C.int
res, err = C.get_func(rig.handle, C.int(vfo), C.ulong(function), &v)
value, err2 := CIntToBool(v)
if err2 != nil { //not so nice...
return value, checkError(0, err2, "get_func")
}
return value, checkError(res, err, "get_func")
}
//set Function
func (rig *Rig) SetFunc(vfo VFOType, function uint32, value bool) error {
var v C.int
v, err := BoolToCint(value)
if err != nil {
return checkError(0, err, "set_func")
}
res, err := C.set_func(rig.handle, C.int(vfo), C.ulong(function), v)
return checkError(res, err, "set_func")
}
//get Parameter
func (rig *Rig) GetParm(vfo VFOType, parm uint32) (value float32, err error) {
var v C.float
var res C.int
res, err = C.get_parm(rig.handle, C.ulong(parm), &v)
value = float32(v)
return value, checkError(res, err, "get_parm")
}
//set Parameter
func (rig *Rig) SetParm(vfo VFOType, parm uint32, value float32) error {
res, err := C.set_parm(rig.handle, C.ulong(parm), C.float(value))
return checkError(res, err, "set_parm")
}
//Get granularity (stepsize, minimum, maximum) for a Parameter
func (rig *Rig) GetParmGran(parm uint32) (step float32, min float32, max float32, err error) {
var cStep C.float
var cMin C.float
var cMax C.float
res, err := C.get_parm_gran(rig.handle, C.ulong(parm), &cStep, &cMin, &cMax)
if checkError(res, err, "get_parm_gran") != nil {
return 0, 0, 0, err
}
return float32(cStep), float32(cMin), float32(cMax), nil
}
//Set configuration token
func (rig *Rig) SetConf(token string, val string) error {
res, err := C.set_conf(rig.handle, C.CString(token), C.CString(val))
return checkError(res, err, "set_conf")
}
//HasToken checks if the rig supports a given token
func (rig *Rig) HasToken(token string) bool {
//dirty hack - provide fix length char*
//there should be a better way
res, _ := C.has_token(rig.handle, C.CString(token))
if HamlibErrorCode(res) == HamlibErrOK {
return true
}
return false
}
//Get configuration token
func (rig *Rig) GetConf(token string) (val string, err error) {
//dirty hack - provide fix length char*
//there should be a better way
v := C.CString(" ")
res, err := C.get_conf(rig.handle, C.CString(token), v)
val = C.GoString(v)
C.free(unsafe.Pointer(v))
return val, checkError(res, err, "get_conf")
}
//Execute VFO Operation
func (rig *Rig) VfoOp(vfo VFOType, op VFOOp) error {
res, err := C.vfo_op(rig.handle, C.int(vfo), C.int(op))
return checkError(res, err, "vfo_op")
}
//Copy capabilities into Rig->Caps struct
func (rig *Rig) getCaps() error {
if err := rig.getMaxRit(); err != nil {
return err
}
if err := rig.getMaxXit(); err != nil {
return err
}
if err := rig.getMaxIfShift(); err != nil {
return err
}
if err := rig.getAttenuators(); err != nil {
return err
}
if err := rig.getPreamps(); err != nil {
return err
}
if err := rig.getVfos(); err != nil {
return err
}
if err := rig.getOperations(); err != nil {
return err
}
if err := rig.getModes(); err != nil {
return err
}
if err := rig.getGetFunctions(); err != nil {
return err
}
if err := rig.getSetFunctions(); err != nil {
return err
}
if err := rig.getGetLevels(); err != nil {
return err
}
if err := rig.getSetLevels(); err != nil {
return err
}
if err := rig.getGetParameter(); err != nil {
return err
}
if err := rig.getSetParameter(); err != nil {
return err
}
if err := rig.getFilters(); err != nil {
return err
}
if err := rig.getTuningSteps(); err != nil {
return err
}
rig.getModelName()
rig.getVersion()
rig.getMfgName()
rig.getStatus()
rig.hasGetPowerStat()
rig.hasSetPowerStat()
rig.hasGetVfo()
rig.hasSetVfo()
rig.hasSetFreq()
rig.hasGetFreq()
rig.hasGetMode()
rig.hasSetMode()
rig.hasGetPtt()
rig.hasSetPtt()
rig.hasGetRit()
rig.hasSetRit()
rig.hasGetXit()
rig.hasSetXit()
rig.hasSetSplitVfo()
rig.hasGetSplitVfo()
rig.hasGetSplitFreq()
rig.hasSetSplitVfo()
rig.hasSetSplitMode()
rig.hasGetSplitMode()
rig.hasGetAnt()
rig.hasSetAnt()
rig.hasSetTs()
rig.hasGetTs()
rig.hasGetConf()
rig.hasSetConf()
return nil
}
//get Capabilities > Max Rit
func (rig *Rig) getMaxRit() error {
var rit C.int
res, err := C.get_caps_max_rit(rig.handle, &rit)
if checkError(res, err, "get_caps_max_rit") != nil {
return checkError(res, err, "get_caps_max_rit")
}
rig.Caps.MaxRit = int(rit)
return nil
}
//get Capabilities > Max Xit
func (rig *Rig) getMaxXit() error {
var xit C.int
res, err := C.get_caps_max_xit(rig.handle, &xit)
if checkError(res, err, "get_caps_max_xit") != nil {
return checkError(res, err, "get_caps_max_xit")
}
rig.Caps.MaxXit = int(xit)
return nil
}
//get Capabilities > Max IF Shift
func (rig *Rig) getMaxIfShift() error {
var ifShift C.int
res, err := C.get_caps_max_if_shift(rig.handle, &ifShift)
if checkError(res, err, "get_caps_max_if_shift") != nil {
return checkError(res, err, "get_caps_max_if_shift")
}
rig.Caps.MaxIfShift = int(ifShift)
return nil
}
//get Capabilities > List of supported Attenuators
func (rig *Rig) getAttenuators() error {
var att_array *C.int
var length C.int
var el C.int
att_array, err := C.get_caps_attenuator_list_pointer_and_length(rig.handle, &length)
if att_array == nil {
return &HamlibError{"getAttenuators", HamlibErrEINTERNAL, "invalid pointer"}
}
if err != nil {
return &Error{"getAttenuators", err}
}
var att []int
for i := 0; i < int(length); i++ {
C.get_int_from_array(rig.handle, att_array, &el, C.int(i))
if int(el) == 0 {
break
}
att = append(att, int(el))
}
rig.Caps.Attenuators = att
return nil
}
//get Capabilities > List of supported Preamp Levels
func (rig *Rig) getPreamps() error {
var preamp_array *C.int
var length C.int
var el C.int
preamp_array, err := C.get_caps_preamp_list_pointer_and_length(rig.handle, &length)
if preamp_array == nil {
return &HamlibError{"getPreamp", HamlibErrEINTERNAL, "invalid pointer"}
}
if err != nil {
return &Error{"getPreamp", err}
}
var preamps []int
for i := 0; i < int(length); i++ {
C.get_int_from_array(rig.handle, preamp_array, &el, C.int(i))
if int(el) == 0 {
break
}
preamps = append(preamps, int(el))
}
rig.Caps.Preamps = preamps
return nil
}
//get Capabilities > List of supported VFOs
func (rig *Rig) getVfos() error {
var vfoClist C.int
var vfoList []string
res, err := C.get_supported_vfos(rig.handle, &vfoClist)
if checkError(res, err, "get_supported_vfos") != nil {
return checkError(res, err, "get_supported_vfos")
}
for vfo, vfoStr := range VFOName {
if VFOType(vfoClist)&vfo > 0 {
vfoList = append(vfoList, vfoStr)
}
}
sort.Strings(vfoList)
rig.Caps.Vfos = vfoList
return nil
}
//get Capabilities > List of supported VFO Operations
func (rig *Rig) getOperations() error {
var vfoOpClist C.int
var vfoOpList []string
res, err := C.get_supported_vfo_operations(rig.handle, &vfoOpClist)
if checkError(res, err, "get_supported_vfo_operations") != nil {
return checkError(res, err, "get_supported_vfo_operations")
}
for op, opStr := range VFOOperationName {
if VFOOp(vfoOpClist)&op > 0 {
vfoOpList = append(vfoOpList, opStr)
}
}
sort.Strings(vfoOpList)
rig.Caps.Operations = vfoOpList
return nil
}
//get Capabilities > List of supported Modes
func (rig *Rig) getModes() error {
var modesClist C.int
var modesList []string
res, err := C.get_supported_modes(rig.handle, &modesClist)
if checkError(res, err, "get_supported_modes") != nil {
return checkError(res, err, "get_supported_modes")
}
for mode, modeStr := range ModeName {
if int(modesClist)&int(mode) > 0 {
modesList = append(modesList, modeStr)
}
}
sort.Strings(modesList)
rig.Caps.Modes = modesList
return nil
}
//get Capabilities > List of supported Functions that can be read
func (rig *Rig) getGetFunctions() error {
var funcList []string
for f, fStr := range FuncName {
if res, err := rig.HasGetFunc(f); err != nil {
return err
} else {
if res > 0 {
funcList = append(funcList, fStr)
}
}
}
sort.Strings(funcList)
rig.Caps.GetFunctions = funcList
return nil
}
//get Capabilities > List of supported Functions that can be set
func (rig *Rig) getSetFunctions() error {
var funcList []string
for f, fStr := range FuncName {
if res, err := rig.HasSetFunc(f); err != nil {
return err
} else {
if res > 0 {
funcList = append(funcList, fStr)
}
}
}
sort.Strings(funcList)
rig.Caps.SetFunctions = funcList
return nil
}
//get Capabilities > List of supported Levels that can be read
func (rig *Rig) getGetLevels() error {
var levelList Values
for l, lStr := range LevelName {
res, err := rig.HasGetLevel(l)
if err != nil {
return err
}
if res > 0 {
var level Value
level.Step, level.Min, level.Max, err = rig.GetLevelGran(l)
if err != nil {
return err
}
level.Name = lStr
levelList = append(levelList, level)
}
}
sort.Sort(levelList)
rig.Caps.GetLevels = levelList
return nil
}
//get Capabilities > List of supported Levels that can be set
func (rig *Rig) getSetLevels() error {
var levelList Values
for l, lStr := range LevelName {
res, err := rig.HasSetLevel(l)
if err != nil {
return err
}
if res > 0 {
var level Value
level.Step, level.Min, level.Max, err = rig.GetLevelGran(l)
if err != nil {
return err
}
level.Name = lStr
levelList = append(levelList, level)
}
}
sort.Sort(levelList)
rig.Caps.SetLevels = levelList
return nil
}
//get Capabilities > List of supported Parameters that can be read
func (rig *Rig) getGetParameter() error {
var parmList Values
for p, pStr := range ParmName {
if res, err := rig.HasGetParm(p); err != nil {
return err
} else {
if res > 0 {
var parm Value
parm.Step, parm.Min, parm.Max, err = rig.GetParmGran(p)
if err != nil {
return err
}
parm.Name = pStr
parmList = append(parmList, parm)
}
}
}
sort.Sort(parmList)
rig.Caps.GetParameters = parmList
return nil
}
//get Capabilities > List of supported Parameters that can be set
func (rig *Rig) getSetParameter() error {
var parmList Values
for p, pStr := range ParmName {
if res, err := rig.HasSetParm(p); err != nil {
return err
} else {
if res > 0 {
var parm Value
parm.Step, parm.Min, parm.Max, err = rig.GetParmGran(p)
if err != nil {
return err
}
parm.Name = pStr
parmList = append(parmList, parm)
}
}
}
sort.Sort(parmList)
rig.Caps.SetParameters = parmList
return nil
}
// get Capabilities > Rig Model Name
func (rig *Rig) getModelName() {
cModelName := C.CString(" ")
C.get_model_name(rig.handle, cModelName)
rig.Caps.ModelName = strings.TrimSpace(C.GoString(cModelName))
C.free(unsafe.Pointer(cModelName))
}
// get Capabilities > Version
func (rig *Rig) getVersion() {
cVersion := C.CString(" ")
C.get_version(rig.handle, cVersion)
rig.Caps.Version = strings.TrimSpace(C.GoString(cVersion))
C.free(unsafe.Pointer(cVersion))
}
// get Capabilities > Manufacturer Name
func (rig *Rig) getMfgName() {
cMfGName := C.CString(" ")
C.get_mfg_name(rig.handle, cMfGName)
rig.Caps.MfgName = strings.TrimSpace(C.GoString(cMfGName))
C.free(unsafe.Pointer(cMfGName))
}
// get Capabilities > Status
func (rig *Rig) getStatus() {