-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvnalibrary.cpp
More file actions
954 lines (858 loc) · 28.7 KB
/
vnalibrary.cpp
File metadata and controls
954 lines (858 loc) · 28.7 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
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
#include <QDebug>
#include <QLibrary>
#include <QTime>
#include <cstdio>
#include "vnalibrary.h"
typedef int *intProto;
typedef const char* (*versionStringProto)();
typedef TaskHandle (*createTaskProto)();
typedef void (*deleteTaskProto)(TaskHandle t);
typedef ErrCode (*initializeProto)(TaskHandle t, progress_callback callback, void* user);
typedef ErrCode (*startProto)(TaskHandle t);
typedef ErrCode (*stopProto)(TaskHandle t);
typedef ErrCode (*setIPAddressProto)(TaskHandle t, const char* ipv4);
typedef ErrCode (*setIPPortProto)(TaskHandle t, const int port);
typedef ErrCode (*setTimeoutProto)(TaskHandle t, const unsigned int timeout);
typedef ErrCode (*setHopRateProto)(TaskHandle t, const HopRate rate);
typedef ErrCode (*setAttenuationProto)(TaskHandle t, const Attenuation atten);
typedef ErrCode (*setFrequenciesProto)(TaskHandle t, const double* freqs, const unsigned int N);
typedef TaskState (*getStateProto)(TaskHandle t);
typedef unsigned int (*getTimeoutProto)(TaskHandle t);
typedef const char* (*getIPAddressProto)(TaskHandle t);
typedef int (*getIPPortProto)(TaskHandle t);
typedef HopRate (*getHopRateProto)(TaskHandle t);
typedef Attenuation (*getAttenuationProto)(TaskHandle t);
typedef unsigned int (*getNumberOfFrequenciesProto)(TaskHandle t);
typedef ErrCode (*getFrequenciesProto)(TaskHandle t, double* freqs, int fcnt);
typedef HardwareDetails (*getHardwareDetailsProto)(TaskHandle t);
typedef ErrCode (*utilNearestLegalFreqProto)(TaskHandle t, double& freq);
typedef ErrCode (*utilFixLinearSweepLimitsProto)(TaskHandle t, double& startFreq, double& endFreq, const unsigned int N);
typedef ErrCode (*utilPingUnitProto)(TaskHandle t);
typedef ErrCode (*utilGenerateLinearSweepProto)(TaskHandle t, const double startFreq, const double endFreq, const unsigned int N);
typedef ErrCode (*measureUncalibratedProto)(TaskHandle t, ComplexData T1R1, ComplexData T1R2,
ComplexData T2R1, ComplexData T2R2,
ComplexData Ref);
typedef ErrCode (*measure2PortCalibratedProto)(TaskHandle t, ComplexData S11, ComplexData S21,
ComplexData S12, ComplexData S22);
typedef ErrCode (*measureCalibrationStepProto)(TaskHandle t, CalibrationStep step);
typedef bool (*haveCalP1OpenProto)(TaskHandle t);
typedef bool (*haveCalP1ShortProto)(TaskHandle t);
typedef bool (*haveCalP1LoadProto)(TaskHandle t);
typedef bool (*haveCalP2OpenProto)(TaskHandle t);
typedef bool (*haveCalP2ShortProto)(TaskHandle t);
typedef bool (*haveCalP2LoadProto)(TaskHandle t);
typedef bool (*haveCalThruProto)(TaskHandle t);
typedef ErrCode (*interruptMeasurementProto)(TaskHandle t);
typedef ErrCode (*clearCalibrationProto)(TaskHandle t);
typedef bool (*isCalibrationCompleteProto)(TaskHandle t);
typedef unsigned int (*getCalibrationNumberOfFrequenciesProto)(TaskHandle t);
typedef const double* (*getCalibrationFrequenciesProto)(TaskHandle t);
typedef ErrCode (*exportCalibrationProto)(TaskHandle t,
ComplexData e00, /* EDF */
ComplexData e11, /* ESF */
ComplexData e10e01, /* ERF */
ComplexData e30, /* EXF */
ComplexData e22, /* ELF */
ComplexData e10e32, /* ETF */
ComplexData ep33, /* EDR */
ComplexData ep22, /* ESR */
ComplexData ep23ep32, /* ERR */
ComplexData ep03, /* EXR */
ComplexData ep11, /* ELR */
ComplexData ep23ep01 /* ETR */);
typedef ErrCode (*importCalibrationProto)(TaskHandle t, const double* freqs, const unsigned int N,
const ComplexData e00, /* EDF */
const ComplexData e11, /* ESF */
const ComplexData e10e01, /* ERF */
const ComplexData e30, /* EXF */
const ComplexData e22, /* ELF */
const ComplexData e10e32, /* ETF */
const ComplexData ep33, /* EDR */
const ComplexData ep22, /* ESR */
const ComplexData ep23ep32, /* ERR */
const ComplexData ep03, /* EXR */
const ComplexData ep11, /* ELR */
const ComplexData ep23ep01 /* ETR */);
typedef bool (*hasFactoryCalibrationProto)(TaskHandle t);
typedef ErrCode (*importFactoryCalibrationProto)(TaskHandle t);
//typedef ErrCode (*setOpenPhaseCorrectionProto)(TaskHandle t, const double* const phaseCorrections);
class PrivateData
{
public:
bool loaded, ok;
QLibrary* lib;
intProto p_ERR_OK;
intProto p_ERR_BAD_ATTEN;
intProto p_ERR_BAD_CAL;
intProto p_ERR_BAD_HANDLE;
intProto p_ERR_BAD_HOP;
intProto p_ERR_BAD_PATH;
intProto p_ERR_BAD_PROM;
intProto p_ERR_BYTES;
intProto p_ERR_FREQ_OUT_OF_BOUNDS;
intProto p_ERR_INTERRUPTED;
intProto p_ERR_NO_RESPONSE;
intProto p_ERR_MISSING_IP;
intProto p_ERR_MISSING_PORT;
intProto p_ERR_MISSING_HOP;
intProto p_ERR_MISSING_ATTEN;
intProto p_ERR_MISSING_FREQS;
intProto p_ERR_PROG_OVERFLOW;
intProto p_ERR_SOCKET;
intProto p_ERR_TOO_MANY_POINTS;
intProto p_ERR_WRONG_STATE;
intProto ERR_BAD_HANDLE;
intProto p_ERR_EMPTY_PROM;
intProto p_ERR_FEATURE_NOT_PRESENT;
intProto p_ERR_NO_PATHS_MEASURED;
intProto p_ERR_PATH_ALREADY_MEASURED;
intProto p_ERR_UNKNOWN_FEATURE;
intProto p_ERR_WRONG_PROGRAM_TYPE;
intProto p_ERR_NO_ATTEN_PRESENT;
intProto p_ERR_BAD_PORT;
intProto p_HOP_UNDEFINED;
intProto p_HOP_45K;
intProto p_HOP_30K;
intProto p_HOP_15K;
intProto p_HOP_7K;
intProto p_HOP_3K;
intProto p_HOP_2K;
intProto p_HOP_1K;
intProto p_HOP_550;
intProto p_HOP_312;
intProto p_HOP_156;
intProto p_HOP_78;
intProto p_HOP_39;
intProto p_HOP_20;
intProto p_ATTEN_UNDEFINED;
intProto p_ATTEN_0;
intProto p_ATTEN_1;
intProto p_ATTEN_2;
intProto p_ATTEN_3;
intProto p_ATTEN_4;
intProto p_ATTEN_5;
intProto p_ATTEN_6;
intProto p_ATTEN_7;
intProto p_ATTEN_8;
intProto p_ATTEN_9;
intProto p_ATTEN_10;
intProto p_ATTEN_11;
intProto p_ATTEN_12;
intProto p_ATTEN_13;
intProto p_ATTEN_14;
intProto p_ATTEN_15;
intProto p_ATTEN_16;
intProto p_ATTEN_17;
intProto p_ATTEN_18;
intProto p_ATTEN_19;
intProto p_ATTEN_20;
intProto p_ATTEN_21;
intProto p_ATTEN_22;
intProto p_ATTEN_23;
intProto p_ATTEN_24;
intProto p_ATTEN_25;
intProto p_ATTEN_26;
intProto p_ATTEN_27;
intProto p_ATTEN_28;
intProto p_ATTEN_29;
intProto p_ATTEN_30;
intProto p_ATTEN_31;
intProto p_TASK_UNINITIALIZED;
intProto p_TASK_STOPPED;
intProto p_TASK_STARTED;
intProto p_PATH_T1R1;
intProto p_PATH_T1R2;
intProto p_PATH_T2R1;
intProto p_PATH_T2R2;
intProto p_PATH_REF;
intProto p_PARAM_S11;
intProto p_PARAM_S21;
intProto p_PARAM_S12;
intProto p_PARAM_S22;
intProto p_STEP_P1_OPEN;
intProto p_STEP_P1_SHORT;
intProto p_STEP_P1_LOAD;
intProto p_STEP_P2_OPEN;
intProto p_STEP_P2_SHORT;
intProto p_STEP_P2_LOAD;
intProto p_STEP_THRU;
versionStringProto p_versionString;
createTaskProto p_createTask;
deleteTaskProto p_deleteTask;
initializeProto p_initialize;
startProto p_start;
stopProto p_stop;
setIPAddressProto p_setIPAddress;
setIPPortProto p_setIPPort;
setTimeoutProto p_setTimeout;
setHopRateProto p_setHopRate;
setAttenuationProto p_setAttenuation;
setFrequenciesProto p_setFrequencies;
getStateProto p_getState;
getTimeoutProto p_getTimeout;
getIPAddressProto p_getIPAddress;
getIPPortProto p_getIPPort;
getHopRateProto p_getHopRate;
getAttenuationProto p_getAttenuation;
getNumberOfFrequenciesProto p_getNumberOfFrequencies;
getFrequenciesProto p_getFrequencies;
getHardwareDetailsProto p_getHardwareDetails;
utilNearestLegalFreqProto p_utilNearestLegalFreq;
utilFixLinearSweepLimitsProto p_utilFixLinearSweepLimits;
utilPingUnitProto p_utilPingUnit;
utilGenerateLinearSweepProto p_utilGenerateLinearSweep;
measureUncalibratedProto p_measureUncalibrated;
measure2PortCalibratedProto p_measure2PortCalibrated;
measureCalibrationStepProto p_measureCalibrationStep;
haveCalP1OpenProto p_haveCalP1Open;
haveCalP1ShortProto p_haveCalP1Short;
haveCalP1LoadProto p_haveCalP1Load;
haveCalP2OpenProto p_haveCalP2Open;
haveCalP2ShortProto p_haveCalP2Short;
haveCalP2LoadProto p_haveCalP2Load;
haveCalThruProto p_haveCalThru;
interruptMeasurementProto p_interruptMeasurement;
clearCalibrationProto p_clearCalibration;
isCalibrationCompleteProto p_isCalibrationComplete;
getCalibrationNumberOfFrequenciesProto p_getCalibrationNumberOfFrequencies;
getCalibrationFrequenciesProto p_getCalibrationFrequencies;
exportCalibrationProto p_exportCalibration;
importCalibrationProto p_importCalibration;
hasFactoryCalibrationProto p_hasFactoryCalibration;
importFactoryCalibrationProto p_importFactoryCalibration;
// setOpenPhaseCorrectionProto p_setOpenPhaseCorrection;
PrivateData() : loaded(false),ok(false), lib(0)
{}
};
void VNALibrary::loadAsync(QString path)
{
bool result = load(path);
emit loadFinished(result);
}
typedef struct
{
VNALibrary* lib;
void* data;
} CallbackData;
static bool static_callback(int percent, void* user)
{
if(user)
{
CallbackData* c = (CallbackData*)user;
VNALibrary* v = (VNALibrary*)c->lib;
return v->callback(percent, c->data);
}
return true;
}
bool VNALibrary::callback(int percent, void *user)
{
emit initializeProgress(percent, Qtvoidptr(user));
return true;
}
void VNALibrary::initializeAsync(QtTaskHandle t, Qtvoidptr user)
{
printf("Initializing...\n");
CallbackData c;
c.lib = this;
c.data = user.val;
ErrCode result = initialize(t.val, static_callback, (void*)&c);
printf("Done.\n");
emit initializeFinished(QtErrCode(result));
}
void VNALibrary::startAsync(QtTaskHandle t)
{
printf("Starting...\n");
ErrCode result = start(t.val);
printf("Done.\n");
emit startFinished(QtErrCode(result));
}
void VNALibrary::stopAsync(QtTaskHandle t)
{
ErrCode result = stop(t.val);
emit stopFinished(QtErrCode(result));
}
void VNALibrary::utilPingUnitAsync(QtTaskHandle t)
{
ErrCode result = utilPingUnit(t.val);
emit utilPingUnitFinished(QtErrCode(result));
}
void VNALibrary::measureUncalibratedAsync(QtTaskHandle t, QtComplexData T1R1, QtComplexData T1R2, QtComplexData T2R1, QtComplexData T2R2, QtComplexData Ref)
{
QTime timer;
timer.start();
ErrCode result = measureUncalibrated(t.val, T1R1.val, T1R2.val, T2R1.val, T2R2.val, Ref.val);
QtErrCode out = QtErrCode(result);
out.time = timer.elapsed();
emit measureUncalibratedFinished(out);
}
void VNALibrary::measure2PortCalibratedAsync(QtTaskHandle t, QtComplexData S11, QtComplexData S21, QtComplexData S12, QtComplexData S22)
{
QTime timer;
timer.start();
ErrCode result = measure2PortCalibrated(t.val, S11.val, S21.val, S12.val, S22.val);
QtErrCode out = QtErrCode(result);
out.time = timer.elapsed();
emit measure2PortCalibratedFinished(out);
}
void VNALibrary::measureCalibrationStepAsync(QtTaskHandle t, QtCalibrationStep step)
{
ErrCode result = measureCalibrationStep(t.val, step.val);
emit measureCalibrationStepFinished(QtErrCode(result));
}
void VNALibrary::importCalibrationAsync(QtTaskHandle t, const double* freqs, const unsigned int N,
const QtComplexData e00, /* EDF */
const QtComplexData e11, /* ESF */
const QtComplexData e10e01, /* ERF */
const QtComplexData e30, /* EXF */
const QtComplexData e22, /* ELF */
const QtComplexData e10e32, /* ETF */
const QtComplexData ep33, /* EDR */
const QtComplexData ep22, /* ESR */
const QtComplexData ep23ep32, /* ERR */
const QtComplexData ep03, /* EXR */
const QtComplexData ep11, /* ELR */
const QtComplexData ep23ep01 /* ETR */)
{
ErrCode result = importCalibration(t.val, freqs, N, e00.val, e11.val, e10e01.val,
e30.val, e22.val, e10e32.val, ep33.val,
ep22.val, ep23ep32.val, ep03.val,
ep11.val, ep23ep01.val);
emit importCalibrationFinished(QtErrCode(result));
}
void VNALibrary::clearCalibrationAsync(QtTaskHandle t)
{
ErrCode result = clearCalibration(t.val);
emit clearCalibrationFinished(QtErrCode(result));
}
VNALibrary::VNALibrary()
{
d = new PrivateData();
}
VNALibrary::~VNALibrary()
{
if(d->loaded) unload();
delete d;
}
#define GET_INT(a) \
d->p_##a = (intProto) d->lib->resolve(#a); \
if(d->p_##a) \
{ \
printf("%s: OK\n",#a); \
VNALibrary::a = *(d->p_##a); \
} \
else printf("%s: FAIL\n", #a); \
#define GET_FUNC(a) \
d->p_##a = (a##Proto) d->lib->resolve(#a); \
if(d->p_##a) printf("%s: OK\n",#a); \
else printf("%s: FAIL\n", #a);
bool VNALibrary::load(QString path)
{
if(d->loaded)
{
unload();
}
d->lib = new QLibrary(path);
bool loadstate = d->lib->load();
// qDebug() << "DLL path:" << path;
// qDebug() << "DLL :" << d->lib;
// qDebug() << "DLL loadstate:" << loadstate;
// qDebug() << "DLL loaded:" << d->lib->isLoaded();
// qDebug() << "DLL load error:" << d->lib->errorString();
GET_INT(ERR_OK);
GET_INT(ERR_BAD_ATTEN);
GET_INT(ERR_BAD_CAL);
GET_INT(ERR_BAD_HANDLE);
GET_INT(ERR_BAD_HOP);
GET_INT(ERR_BAD_PATH);
GET_INT(ERR_BAD_PROM);
GET_INT(ERR_BYTES);
GET_INT(ERR_FREQ_OUT_OF_BOUNDS);
GET_INT(ERR_INTERRUPTED);
GET_INT(ERR_NO_RESPONSE);
GET_INT(ERR_MISSING_IP);
GET_INT(ERR_MISSING_PORT);
GET_INT(ERR_MISSING_HOP);
GET_INT(ERR_MISSING_ATTEN);
GET_INT(ERR_MISSING_FREQS);
GET_INT(ERR_PROG_OVERFLOW);
GET_INT(ERR_SOCKET);
GET_INT(ERR_TOO_MANY_POINTS);
GET_INT(ERR_WRONG_STATE);
GET_INT(ERR_EMPTY_PROM);
GET_INT(ERR_FEATURE_NOT_PRESENT);
GET_INT(ERR_NO_PATHS_MEASURED);
GET_INT(ERR_PATH_ALREADY_MEASURED);
GET_INT(ERR_UNKNOWN_FEATURE);
GET_INT(ERR_WRONG_PROGRAM_TYPE);
GET_INT(ERR_NO_ATTEN_PRESENT);
GET_INT(HOP_UNDEFINED);
GET_INT(HOP_45K);
GET_INT(HOP_30K);
GET_INT(HOP_15K);
GET_INT(HOP_7K);
GET_INT(HOP_3K);
GET_INT(HOP_2K);
GET_INT(HOP_1K);
GET_INT(HOP_550);
GET_INT(HOP_312);
GET_INT(HOP_156);
GET_INT(HOP_78);
GET_INT(HOP_39);
GET_INT(HOP_20);
GET_INT(ATTEN_UNDEFINED);
GET_INT(ATTEN_0);
GET_INT(ATTEN_1);
GET_INT(ATTEN_2);
GET_INT(ATTEN_3);
GET_INT(ATTEN_4);
GET_INT(ATTEN_5);
GET_INT(ATTEN_6);
GET_INT(ATTEN_7);
GET_INT(ATTEN_8);
GET_INT(ATTEN_9);
GET_INT(ATTEN_10);
GET_INT(ATTEN_11);
GET_INT(ATTEN_12);
GET_INT(ATTEN_13);
GET_INT(ATTEN_14);
GET_INT(ATTEN_15);
GET_INT(ATTEN_16);
GET_INT(ATTEN_17);
GET_INT(ATTEN_18);
GET_INT(ATTEN_19);
GET_INT(ATTEN_20);
GET_INT(ATTEN_21);
GET_INT(ATTEN_22);
GET_INT(ATTEN_23);
GET_INT(ATTEN_24);
GET_INT(ATTEN_25);
GET_INT(ATTEN_26);
GET_INT(ATTEN_27);
GET_INT(ATTEN_28);
GET_INT(ATTEN_29);
GET_INT(ATTEN_30);
GET_INT(ATTEN_31);
GET_INT(TASK_UNINITIALIZED);
GET_INT(TASK_STOPPED);
GET_INT(TASK_STARTED);
GET_INT(PATH_T1R1);
GET_INT(PATH_T1R2);
GET_INT(PATH_T2R1);
GET_INT(PATH_T2R2);
GET_INT(PATH_REF);
GET_INT(PARAM_S11);
GET_INT(PARAM_S21);
GET_INT(PARAM_S12);
GET_INT(PARAM_S22);
GET_INT(STEP_P1_OPEN);
GET_INT(STEP_P1_SHORT);
GET_INT(STEP_P1_LOAD);
GET_INT(STEP_P2_OPEN);
GET_INT(STEP_P2_SHORT);
GET_INT(STEP_P2_LOAD);
GET_INT(STEP_THRU);
GET_FUNC(versionString);
GET_FUNC(createTask);
GET_FUNC(deleteTask);
GET_FUNC(initialize);
GET_FUNC(start);
GET_FUNC(stop);
GET_FUNC(setIPAddress);
GET_FUNC(setIPPort);
GET_FUNC(setTimeout);
GET_FUNC(setHopRate);
GET_FUNC(setAttenuation);
GET_FUNC(setFrequencies);
GET_FUNC(getState);
GET_FUNC(getTimeout);
GET_FUNC(getIPAddress);
GET_FUNC(getIPPort);
GET_FUNC(getHopRate);
GET_FUNC(getAttenuation);
GET_FUNC(getNumberOfFrequencies);
GET_FUNC(getFrequencies);
GET_FUNC(getHardwareDetails);
GET_FUNC(utilNearestLegalFreq);
GET_FUNC(utilFixLinearSweepLimits);
GET_FUNC(utilPingUnit);
GET_FUNC(utilGenerateLinearSweep);
GET_FUNC(measureUncalibrated);
GET_FUNC(measure2PortCalibrated);
GET_FUNC(measureCalibrationStep);
GET_FUNC(haveCalP1Open);
GET_FUNC(haveCalP1Short);
GET_FUNC(haveCalP1Load);
GET_FUNC(haveCalP2Open);
GET_FUNC(haveCalP2Short);
GET_FUNC(haveCalP2Load);
GET_FUNC(haveCalThru);
GET_FUNC(interruptMeasurement);
GET_FUNC(clearCalibration);
GET_FUNC(isCalibrationComplete);
GET_FUNC(getCalibrationNumberOfFrequencies);
GET_FUNC(getCalibrationFrequencies);
GET_FUNC(exportCalibration);
GET_FUNC(importCalibration);
GET_FUNC(hasFactoryCalibration);
GET_FUNC(importFactoryCalibration);
// GET_FUNC(setOpenPhaseCorrection);
d->loaded = true;
d->ok = d->p_versionString != NULL
&& d->p_createTask != NULL
&& d->p_deleteTask != NULL
&& d->p_initialize != NULL
&& d->p_start != NULL
&& d->p_stop != NULL
&& d->p_setIPAddress != NULL
&& d->p_setIPPort != NULL
&& d->p_setTimeout != NULL
&& d->p_setHopRate != NULL
&& d->p_setAttenuation != NULL
&& d->p_setFrequencies != NULL
&& d->p_getState != NULL
&& d->p_getTimeout != NULL
&& d->p_getIPAddress != NULL
&& d->p_getIPPort != NULL
&& d->p_getHopRate != NULL
&& d->p_getAttenuation != NULL
&& d->p_getNumberOfFrequencies != NULL
&& d->p_getFrequencies != NULL
&& d->p_getHardwareDetails != NULL
&& d->p_utilNearestLegalFreq != NULL
&& d->p_utilFixLinearSweepLimits != NULL
&& d->p_utilPingUnit != NULL
&& d->p_utilGenerateLinearSweep != NULL
&& d->p_measureUncalibrated != NULL
&& d->p_measure2PortCalibrated != NULL
&& d->p_measureCalibrationStep != NULL
&& d->p_haveCalP1Open != NULL
&& d->p_haveCalP1Short != NULL
&& d->p_haveCalP1Load != NULL
&& d->p_haveCalP2Open != NULL
&& d->p_haveCalP2Short != NULL
&& d->p_haveCalP2Load != NULL
&& d->p_haveCalThru != NULL
&& d->p_interruptMeasurement != NULL
&& d->p_clearCalibration != NULL
&& d->p_isCalibrationComplete != NULL
&& d->p_getCalibrationNumberOfFrequencies != NULL
&& d->p_getCalibrationFrequencies != NULL
&& d->p_exportCalibration != NULL
&& d->p_importCalibration != NULL
&& d->p_hasFactoryCalibration != NULL
&& d->p_importFactoryCalibration != NULL;
// && d->p_setOpenPhaseCorrection;
return d->ok;
}
bool VNALibrary::unload()
{
d->loaded = false;
d->ok = false;
return d->lib->unload();
}
bool VNALibrary::isOK()
{
return d->ok;
}
QString VNALibrary::ErrToString(int code)
{
QString out = "UNKNOWN";
if (code == VNALibrary::ERR_OK) out = "ERR_OK";
if (code == VNALibrary::ERR_BAD_ATTEN) out = "ERR_BAD_ATTEN";
if (code == VNALibrary::ERR_BAD_CAL) out = "ERR_BAD_CAL";
if (code == VNALibrary::ERR_BAD_HANDLE) out = "ERR_BAD_HANDLE";
if (code == VNALibrary::ERR_BAD_HOP) out = "ERR_BAD_HOP";
if (code == VNALibrary::ERR_BAD_PATH) out = "ERR_BAD_PATH";
if (code == VNALibrary::ERR_BAD_PROM) out = "ERR_BAD_PROM";
if (code == VNALibrary::ERR_BYTES) out = "ERR_BYTES";
if (code == VNALibrary::ERR_FREQ_OUT_OF_BOUNDS) out = "ERR_FREQ_OUT_OF_BOUNDS";
if (code == VNALibrary::ERR_INTERRUPTED) out = "ERR_INTERRUPTED";
if (code == VNALibrary::ERR_NO_RESPONSE) out = "ERR_NO_RESPONSE";
if (code == VNALibrary::ERR_MISSING_IP) out = "ERR_MISSING_IP";
if (code == VNALibrary::ERR_MISSING_PORT) out = "ERR_MISSING_PORT";
if (code == VNALibrary::ERR_MISSING_HOP) out = "ERR_MISSING_HOP";
if (code == VNALibrary::ERR_MISSING_ATTEN) out = "ERR_MISSING_ATTEN";
if (code == VNALibrary::ERR_MISSING_FREQS) out = "ERR_MISSING_FREQS";
if (code == VNALibrary::ERR_PROG_OVERFLOW) out = "ERR_PROG_OVERFLOW";
if (code == VNALibrary::ERR_SOCKET) out = "ERR_SOCKET";
if (code == VNALibrary::ERR_TOO_MANY_POINTS) out = "ERR_TOO_MANY_POINTS";
if (code == VNALibrary::ERR_WRONG_STATE) out = "ERR_WRONG_STATE";
if (code == VNALibrary::ERR_EMPTY_PROM) out = "ERR_EMPTY_PROM";
if (code == VNALibrary::ERR_FEATURE_NOT_PRESENT) out = "ERR_FEATURE_NOT_PRESENT";
if (code == VNALibrary::ERR_NO_PATHS_MEASURED) out = "ERR_NO_PATHS_MEASURED";
if (code == VNALibrary::ERR_PATH_ALREADY_MEASURED) out = "ERR_PATH_ALREADY_MEASURED";
if (code == VNALibrary::ERR_UNKNOWN_FEATURE) out = "ERR_UNKNOWN_FEATURE";
if (code == VNALibrary::ERR_WRONG_PROGRAM_TYPE) out = "ERR_WRONG_PROGRAM_TYPE";
if (code == VNALibrary::ERR_NO_ATTEN_PRESENT) out = "ERR_NO_ATTEN_PRESENT";
if (code == VNALibrary::ERR_BAD_PORT) out = "ERR_BAD_PORT";
return out;
}
const char *VNALibrary::versionString()
{
if(d->p_versionString)
return d->p_versionString();
else return "";
}
TaskHandle VNALibrary::createTask()
{
if(d->p_createTask)
return d->p_createTask();
else return 0;
}
void VNALibrary::deleteTask(TaskHandle t)
{
if(d->p_deleteTask) d->p_deleteTask(t);
}
ErrCode VNALibrary::initialize(TaskHandle t, progress_callback callback, void *user)
{
if(d->p_initialize)
return d->p_initialize(t, callback, user);
else return VNALibrary::ERR_BAD_HANDLE;
}
ErrCode VNALibrary::start(TaskHandle t)
{
if(d->p_start)
return d->p_start(t);
else return VNALibrary::ERR_BAD_HANDLE;
}
ErrCode VNALibrary::stop(TaskHandle t)
{
if(d->p_stop)
return d->p_stop(t);
else return VNALibrary::ERR_BAD_HANDLE;
}
ErrCode VNALibrary::setIPAddress(TaskHandle t, const char *ipv4)
{
if(d->p_setIPAddress)
return d->p_setIPAddress(t, ipv4);
else return VNALibrary::ERR_BAD_HANDLE;
}
ErrCode VNALibrary::setIPPort(TaskHandle t, const int port)
{
if(d->p_setIPPort)
return d->p_setIPPort(t, port);
else return VNALibrary::ERR_BAD_HANDLE;
}
ErrCode VNALibrary::setTimeout(TaskHandle t, const unsigned int timeout)
{
if(d->p_setTimeout)
return d->p_setTimeout(t, timeout);
else return VNALibrary::ERR_BAD_HANDLE;
}
ErrCode VNALibrary::setHopRate(TaskHandle t, const HopRate rate)
{
if(d->p_setHopRate)
return d->p_setHopRate(t, rate);
else return VNALibrary::ERR_BAD_HANDLE;
}
ErrCode VNALibrary::setAttenuation(TaskHandle t, const Attenuation atten)
{
if(d->p_setAttenuation)
return d->p_setAttenuation(t, atten);
else return VNALibrary::ERR_BAD_HANDLE;
}
ErrCode VNALibrary::setFrequencies(TaskHandle t, const double *freqs, const unsigned int N)
{
if(d->p_setFrequencies)
return d->p_setFrequencies(t, freqs, N);
else return VNALibrary::ERR_BAD_HANDLE;
}
TaskState VNALibrary::getState(TaskHandle t)
{
if(d->p_getState)
return d->p_getState(t);
else return VNALibrary::TASK_UNINITIALIZED;
}
unsigned int VNALibrary::getTimeout(TaskHandle t)
{
if(d->p_getTimeout)
return d->p_getTimeout(t);
else return 0;
}
const char *VNALibrary::getIPAddress(TaskHandle t)
{
if(d->p_getIPAddress)
return d->p_getIPAddress(t);
else return "";
}
int VNALibrary::getIPPort(TaskHandle t)
{
if(d->p_getIPPort)
return d->p_getIPPort(t);
else return 0;
}
HopRate VNALibrary::getHopRate(TaskHandle t)
{
if(d->p_getHopRate)
return d->p_getHopRate(t);
else return VNALibrary::HOP_UNDEFINED;
}
Attenuation VNALibrary::getAttenuation(TaskHandle t)
{
if(d->p_getAttenuation)
return d->p_getAttenuation(t);
else return VNALibrary::ATTEN_UNDEFINED;
}
unsigned int VNALibrary::getNumberOfFrequencies(TaskHandle t)
{
if(d->p_getNumberOfFrequencies)
return d->p_getNumberOfFrequencies(t);
else return 0;
}
ErrCode VNALibrary::getFrequencies(TaskHandle t, double* freqs, int nfreqs)
{
if(d->p_getFrequencies)
return d->p_getFrequencies(t, freqs, nfreqs);
else return 0;
}
HardwareDetails VNALibrary::getHardwareDetails(TaskHandle t)
{
HardwareDetails h;
if(d->p_getHardwareDetails)
return d->p_getHardwareDetails(t);
else return h;
}
ErrCode VNALibrary::utilNearestLegalFreq(TaskHandle t, double &freq)
{
if(d->p_utilNearestLegalFreq)
return d->p_utilNearestLegalFreq(t, freq);
else return VNALibrary::ERR_BAD_HANDLE;
}
ErrCode VNALibrary::utilFixLinearSweepLimits(TaskHandle t, double &startFreq, double &endFreq, const unsigned int N)
{
if(d->p_utilFixLinearSweepLimits)
return d->p_utilFixLinearSweepLimits(t, startFreq, endFreq, N);
else return VNALibrary::ERR_BAD_HANDLE;
}
ErrCode VNALibrary::utilPingUnit(TaskHandle t)
{
if(d->p_utilPingUnit)
return d->p_utilPingUnit(t);
else return VNALibrary::ERR_BAD_HANDLE;
}
ErrCode VNALibrary::utilGenerateLinearSweep(TaskHandle t, const double startFreq, const double endFreq, const unsigned int N)
{
if(d->p_utilGenerateLinearSweep)
return d->p_utilGenerateLinearSweep(t, startFreq, endFreq, N);
else return VNALibrary::ERR_BAD_HANDLE;
}
ErrCode VNALibrary::measureUncalibrated(TaskHandle t, ComplexData T1R1, ComplexData T1R2, ComplexData T2R1, ComplexData T2R2, ComplexData Ref)
{
if(d->p_measureUncalibrated)
return d->p_measureUncalibrated(t, T1R1, T1R2, T2R1, T2R2, Ref);
else return VNALibrary::ERR_BAD_HANDLE;
}
ErrCode VNALibrary::measure2PortCalibrated(TaskHandle t, ComplexData S11, ComplexData S21, ComplexData S12, ComplexData S22)
{
if(d->p_measure2PortCalibrated)
return d->p_measure2PortCalibrated(t, S11, S21, S12, S22);
else return VNALibrary::ERR_BAD_HANDLE;
}
ErrCode VNALibrary::measureCalibrationStep(TaskHandle t, CalibrationStep step)
{
if(d->p_measureCalibrationStep)
return d->p_measureCalibrationStep(t, step);
else return VNALibrary::ERR_BAD_HANDLE;
}
bool VNALibrary::haveCalP1Open(TaskHandle t)
{
if(d->p_haveCalP1Open)
return d->p_haveCalP1Open(t);
else return VNALibrary::ERR_BAD_HANDLE;
}
bool VNALibrary::haveCalP1Short(TaskHandle t)
{
if(d->p_haveCalP1Short)
return d->p_haveCalP1Short(t);
else return VNALibrary::ERR_BAD_HANDLE;
}
bool VNALibrary::haveCalP1Load(TaskHandle t)
{
if(d->p_haveCalP1Load)
return d->p_haveCalP1Load(t);
else return VNALibrary::ERR_BAD_HANDLE;
}
bool VNALibrary::haveCalP2Open(TaskHandle t)
{
if(d->p_haveCalP2Open)
return d->p_haveCalP2Open(t);
else return VNALibrary::ERR_BAD_HANDLE;
}
bool VNALibrary::haveCalP2Short(TaskHandle t)
{
if(d->p_haveCalP2Short)
return d->p_haveCalP2Short(t);
else return VNALibrary::ERR_BAD_HANDLE;
}
bool VNALibrary::haveCalP2Load(TaskHandle t)
{
if(d->p_haveCalP2Load)
return d->p_haveCalP2Load(t);
else return VNALibrary::ERR_BAD_HANDLE;
}
bool VNALibrary::haveCalThru(TaskHandle t)
{
if(d->p_haveCalThru)
return d->p_haveCalThru(t);
else return VNALibrary::ERR_BAD_HANDLE;
}
ErrCode VNALibrary::interruptMeasurement(TaskHandle t)
{
if(d->p_interruptMeasurement)
return d->p_interruptMeasurement(t);
else return VNALibrary::ERR_BAD_HANDLE;
}
ErrCode VNALibrary::clearCalibration(TaskHandle t)
{
if(d->p_clearCalibration)
return d->p_clearCalibration(t);
else return VNALibrary::ERR_BAD_HANDLE;
}
bool VNALibrary::isCalibrationComplete(TaskHandle t)
{
if(d->p_isCalibrationComplete)
return d->p_isCalibrationComplete(t);
else return false;
}
unsigned int VNALibrary::getCalibrationNumberOfFrequencies(TaskHandle t)
{
if(d->p_getCalibrationNumberOfFrequencies)
return d->p_getCalibrationNumberOfFrequencies(t);
else return 0;
}
const double *VNALibrary::getCalibrationFrequencies(TaskHandle t)
{
if(d->p_getCalibrationFrequencies)
return d->p_getCalibrationFrequencies(t);
else return 0;
}
ErrCode VNALibrary::exportCalibration(TaskHandle t, ComplexData e00, ComplexData e11, ComplexData e10e01, ComplexData e30, ComplexData e22, ComplexData e10e32, ComplexData ep33, ComplexData ep22, ComplexData ep23ep32, ComplexData ep03, ComplexData ep11, ComplexData ep23ep01)
{
if(d->p_exportCalibration)
return d->p_exportCalibration(t, e00, e11, e10e01, e30, e22, e10e32, ep33, ep22, ep23ep32, ep03, ep11, ep23ep01);
else return VNALibrary::ERR_BAD_HANDLE;
}
ErrCode VNALibrary::importCalibration(TaskHandle t, const double *freqs, const unsigned int N, const ComplexData e00, const ComplexData e11, const ComplexData e10e01, const ComplexData e30, const ComplexData e22, const ComplexData e10e32, const ComplexData ep33, const ComplexData ep22, const ComplexData ep23ep32, const ComplexData ep03, const ComplexData ep11, const ComplexData ep23ep01)
{
if(d->p_importCalibration)
return d->p_importCalibration(t, freqs, N, e00, e11, e10e01, e30, e22, e10e32, ep33, ep22, ep23ep32, ep03, ep11, ep23ep01);
else return VNALibrary::ERR_BAD_HANDLE;
}
bool VNALibrary::hasFactoryCalibration(TaskHandle t)
{
if(d->p_hasFactoryCalibration)
return d->p_hasFactoryCalibration(t);
else return VNALibrary::ERR_BAD_HANDLE;
}
ErrCode VNALibrary::importFactoryCalibration(TaskHandle t)
{
if(d->p_importFactoryCalibration)
return d->p_importFactoryCalibration(t);
else return VNALibrary::ERR_BAD_HANDLE;
}
//ErrCode VNALibrary::setOpenPhaseCorrection(TaskHandle t, const double* const phaseCorrections)
//{
// if(d->p_setOpenPhaseCorrection)
// return d->p_setOpenPhaseCorrection(t, phaseCorrections);
// else return VNALibrary::ERR_BAD_HANDLE;
//}