-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathudar_controller.cpp
More file actions
executable file
·3267 lines (2737 loc) · 119 KB
/
udar_controller.cpp
File metadata and controls
executable file
·3267 lines (2737 loc) · 119 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
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
#include "udar_controller.h"
#include "ui_udar_controller.h"
UDAR_Controller::UDAR_Controller(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::UDAR_Controller)
{
ui->setupUi(this);
setupPlotIQ();
// configure scroll bars:
// Since scroll bars only support integer values, we'll set a high default range of -500..500 and
// divide scroll bar position values by 100 to provide a scroll range -5..5 in floating point
// axis coordinates. if you want to dynamically grow the range accessible with the scroll bar,
// just increase the the minimum/maximum values of the scroll bars as needed.
// ui->horizontalScrollBarI->setRange(-500, 500);
// ui->verticalScrollBarI->setRange(-500, 500);
// ui->horizontalScrollBarQ->setRange(-500, 500);
// ui->verticalScrollBarQ->setRange(-500, 500);
// ui->horizontalScrollBarC->setRange(-500, 500);
// ui->verticalScrollBarC->setRange(-500, 500);
// ui->horizontalScrollBarFFTI->setRange(-500, 500);
// ui->verticalScrollBarFFTI->setRange(-500, 500);
// ui->horizontalScrollBarFFTQ->setRange(-500, 500);
// ui->verticalScrollBarFFTQ->setRange(-500, 500);
// initialize axis range (and scroll bar positions via signals we just connected):
ui->plotI->xAxis->setRange(0, DEFAULT_PLOT_RANGE, Qt::AlignLeft);
ui->plotI->yAxis->setRange(0, (1<<16), Qt::AlignCenter);
ui->plotQ->xAxis->setRange(0, DEFAULT_PLOT_RANGE, Qt::AlignLeft);
ui->plotQ->yAxis->setRange(0, (1<<16), Qt::AlignCenter);
ui->plotI2->xAxis->setRange(0, DEFAULT_PLOT_RANGE, Qt::AlignLeft);
ui->plotI2->yAxis->setRange(0, (1<<16), Qt::AlignCenter);
ui->plotQ2->xAxis->setRange(0, DEFAULT_PLOT_RANGE, Qt::AlignLeft);
ui->plotQ2->yAxis->setRange(0, (1<<16), Qt::AlignCenter);
ui->plotC->xAxis->setRange(0, 400, Qt::AlignLeft);
ui->plotC->yAxis->setRange(170,70, Qt::AlignLeft);
ui->plotC2->xAxis->setRange(0, 400, Qt::AlignLeft);
ui->plotC2->yAxis->setRange(170, 70, Qt::AlignLeft);
ui->plotFFTI->xAxis->setRange(0, 122, Qt::AlignLeft);
ui->plotFFTI->yAxis->setRange(60, 80, Qt::AlignLeft);
ui->plotFFTQ->xAxis->setRange(0, 122, Qt::AlignLeft);
ui->plotFFTQ->yAxis->setRange(60, 80, Qt::AlignLeft);
ui->plotFFTI2->xAxis->setRange(0, 122, Qt::AlignLeft);
ui->plotFFTI2->yAxis->setRange(60, 80, Qt::AlignLeft);
ui->plotFFTQ2->xAxis->setRange(0, 122, Qt::AlignLeft);
ui->plotFFTQ2->yAxis->setRange(60, 80, Qt::AlignLeft);
connectSignals();
controllerInit();
}
UDAR_Controller::~UDAR_Controller()
{
delete ui;
}
void UDAR_Controller::connectSignals()
{
//connect(ui->tabWidget_a, SIGNAL(currentChanged(int)), this, SLOT(tab_aSelected()));
connect(ui->networkInterfaces,SIGNAL(currentIndexChanged(const QString)),this,SLOT(updateInterfaceFields(const QString)));
rx_status_timer = new QTimer(this);
connect(rx_status_timer, SIGNAL(timeout()), this, SLOT(updateRXStatus()));
rx_status_timer->start(100);
//QMetaObject::connectSlotsByName(this);
// create connection between axes and scroll bars:
// connect(ui->horizontalScrollBar, SIGNAL(valueChanged(int)), this, SLOT(horzScrollBarChanged(int)));
// connect(ui->verticalScrollBar, SIGNAL(valueChanged(int)), this, SLOT(vertScrollBarChanged(int)));
// connect(ui->plot->xAxis, SIGNAL(rangeChanged(QCPRange)), this, SLOT(xAxisChanged(QCPRange)));
// connect(ui->plot->yAxis, SIGNAL(rangeChanged(QCPRange)), this, SLOT(yAxisChanged(QCPRange)));
// Plot Signals
// connect slot that ties some axis selections together (especially opposite axes):
connect(ui->plotI, SIGNAL(selectionChangedByUser()), this, SLOT(selectionChanged()));
// connect slots that takes care that when an axis is selected, only that direction can be dragged and zoomed:
connect(ui->plotI, SIGNAL(mousePress(QMouseEvent*)), this, SLOT(mousePress()));
connect(ui->plotI, SIGNAL(mouseWheel(QWheelEvent*)), this, SLOT(mouseWheel()));
// make bottom and left axes transfer their ranges to top and right axes:
connect(ui->plotI->xAxis, SIGNAL(rangeChanged(QCPRange)), ui->plotI->xAxis2, SLOT(setRange(QCPRange)));
connect(ui->plotI->yAxis, SIGNAL(rangeChanged(QCPRange)), ui->plotI->yAxis2, SLOT(setRange(QCPRange)));
// connect slot that ties some axis selections together (especially opposite axes):
connect(ui->plotI2, SIGNAL(selectionChangedByUser()), this, SLOT(selectionChanged()));
// connect slots that takes care that when an axis is selected, only that direction can be dragged and zoomed:
connect(ui->plotI2, SIGNAL(mousePress(QMouseEvent*)), this, SLOT(mousePress()));
connect(ui->plotI2, SIGNAL(mouseWheel(QWheelEvent*)), this, SLOT(mouseWheel()));
// make bottom and left axes transfer their ranges to top and right axes:
connect(ui->plotI2->xAxis, SIGNAL(rangeChanged(QCPRange)), ui->plotI->xAxis2, SLOT(setRange(QCPRange)));
connect(ui->plotI2->yAxis, SIGNAL(rangeChanged(QCPRange)), ui->plotI->yAxis2, SLOT(setRange(QCPRange)));
// connect slot that ties some axis selections together (especially opposite axes):
connect(ui->plotQ, SIGNAL(selectionChangedByUser()), this, SLOT(selectionChanged()));
// connect slots that takes care that when an axis is selected, only that direction can be dragged and zoomed:
connect(ui->plotQ, SIGNAL(mousePress(QMouseEvent*)), this, SLOT(mousePress()));
connect(ui->plotQ, SIGNAL(mouseWheel(QWheelEvent*)), this, SLOT(mouseWheel()));
// make bottom and left axes transfer their ranges to top and right axes:
connect(ui->plotQ->xAxis, SIGNAL(rangeChanged(QCPRange)), ui->plotQ->xAxis2, SLOT(setRange(QCPRange)));
connect(ui->plotQ->yAxis, SIGNAL(rangeChanged(QCPRange)), ui->plotQ->yAxis2, SLOT(setRange(QCPRange)));
// connect slot that ties some axis selections together (especially opposite axes):
connect(ui->plotQ2, SIGNAL(selectionChangedByUser()), this, SLOT(selectionChanged()));
// connect slots that takes care that when an axis is selected, only that direction can be dragged and zoomed:
connect(ui->plotQ2, SIGNAL(mousePress(QMouseEvent*)), this, SLOT(mousePress()));
connect(ui->plotQ2, SIGNAL(mouseWheel(QWheelEvent*)), this, SLOT(mouseWheel()));
// make bottom and left axes transfer their ranges to top and right axes:
connect(ui->plotQ2->xAxis, SIGNAL(rangeChanged(QCPRange)), ui->plotQ->xAxis2, SLOT(setRange(QCPRange)));
connect(ui->plotQ2->yAxis, SIGNAL(rangeChanged(QCPRange)), ui->plotQ->yAxis2, SLOT(setRange(QCPRange)));
// connect slot that ties some axis selections together (especially opposite axes):
connect(ui->plotC, SIGNAL(selectionChangedByUser()), this, SLOT(selectionChanged()));
// connect slots that takes care that when an axis is selected, only that direction can be dragged and zoomed:
connect(ui->plotC, SIGNAL(mousePress(QMouseEvent*)), this, SLOT(mousePress()));
connect(ui->plotC, SIGNAL(mouseWheel(QWheelEvent*)), this, SLOT(mouseWheel()));
// make bottom and left axes transfer their ranges to top and right axes:
connect(ui->plotC->xAxis, SIGNAL(rangeChanged(QCPRange)), ui->plotC->xAxis2, SLOT(setRange(QCPRange)));
connect(ui->plotC->yAxis, SIGNAL(rangeChanged(QCPRange)), ui->plotC->yAxis2, SLOT(setRange(QCPRange)));
// connect slot that ties some axis selections together (especially opposite axes):
connect(ui->plotC2, SIGNAL(selectionChangedByUser()), this, SLOT(selectionChanged()));
// connect slots that takes care that when an axis is selected, only that direction can be dragged and zoomed:
connect(ui->plotC2, SIGNAL(mousePress(QMouseEvent*)), this, SLOT(mousePress()));
connect(ui->plotC2, SIGNAL(mouseWheel(QWheelEvent*)), this, SLOT(mouseWheel()));
// make bottom and left axes transfer their ranges to top and right axes:
connect(ui->plotC2->xAxis, SIGNAL(rangeChanged(QCPRange)), ui->plotC2->xAxis2, SLOT(setRange(QCPRange)));
connect(ui->plotC2->yAxis, SIGNAL(rangeChanged(QCPRange)), ui->plotC2->yAxis2, SLOT(setRange(QCPRange)));
// connect slot that ties some axis selections together (especially opposite axes):
connect(ui->plotFFTI, SIGNAL(selectionChangedByUser()), this, SLOT(selectionChanged()));
// connect slots that takes care that when an axis is selected, only that direction can be dragged and zoomed:
connect(ui->plotFFTI, SIGNAL(mousePress(QMouseEvent*)), this, SLOT(mousePress()));
connect(ui->plotFFTI, SIGNAL(mouseWheel(QWheelEvent*)), this, SLOT(mouseWheel()));
// make bottom and left axes transfer their ranges to top and right axes:
connect(ui->plotFFTI->xAxis, SIGNAL(rangeChanged(QCPRange)), ui->plotFFTI->xAxis2, SLOT(setRange(QCPRange)));
connect(ui->plotFFTI->yAxis, SIGNAL(rangeChanged(QCPRange)), ui->plotFFTI->yAxis2, SLOT(setRange(QCPRange)));
// connect slot that ties some axis selections together (especially opposite axes):
connect(ui->plotFFTQ, SIGNAL(selectionChangedByUser()), this, SLOT(selectionChanged()));
// connect slots that takes care that when an axis is selected, only that direction can be dragged and zoomed:
connect(ui->plotFFTQ, SIGNAL(mousePress(QMouseEvent*)), this, SLOT(mousePress()));
connect(ui->plotFFTQ, SIGNAL(mouseWheel(QWheelEvent*)), this, SLOT(mouseWheel()));
// make bottom and left axes transfer their ranges to top and right axes:
connect(ui->plotFFTQ->xAxis, SIGNAL(rangeChanged(QCPRange)), ui->plotFFTQ->xAxis2, SLOT(setRange(QCPRange)));
connect(ui->plotFFTQ->yAxis, SIGNAL(rangeChanged(QCPRange)), ui->plotFFTQ->yAxis2, SLOT(setRange(QCPRange)));
// connect slot that ties some axis selections together (especially opposite axes):
connect(ui->plotFFTI2, SIGNAL(selectionChangedByUser()), this, SLOT(selectionChanged()));
// connect slots that takes care that when an axis is selected, only that direction can be dragged and zoomed:
connect(ui->plotFFTI2, SIGNAL(mousePress(QMouseEvent*)), this, SLOT(mousePress()));
connect(ui->plotFFTI2, SIGNAL(mouseWheel(QWheelEvent*)), this, SLOT(mouseWheel()));
// make bottom and left axes transfer their ranges to top and right axes:
connect(ui->plotFFTI2->xAxis, SIGNAL(rangeChanged(QCPRange)), ui->plotFFTI2->xAxis2, SLOT(setRange(QCPRange)));
connect(ui->plotFFTI2->yAxis, SIGNAL(rangeChanged(QCPRange)), ui->plotFFTI2->yAxis2, SLOT(setRange(QCPRange)));
// connect slot that ties some axis selections together (especially opposite axes):
connect(ui->plotFFTQ2, SIGNAL(selectionChangedByUser()), this, SLOT(selectionChanged()));
// connect slots that takes care that when an axis is selected, only that direction can be dragged and zoomed:
connect(ui->plotFFTQ2, SIGNAL(mousePress(QMouseEvent*)), this, SLOT(mousePress()));
connect(ui->plotFFTQ2, SIGNAL(mouseWheel(QWheelEvent*)), this, SLOT(mouseWheel()));
// make bottom and left axes transfer their ranges to top and right axes:
connect(ui->plotFFTQ2->xAxis, SIGNAL(rangeChanged(QCPRange)), ui->plotFFTQ2->xAxis2, SLOT(setRange(QCPRange)));
connect(ui->plotFFTQ2->yAxis, SIGNAL(rangeChanged(QCPRange)), ui->plotFFTQ2->yAxis2, SLOT(setRange(QCPRange)));
}
void UDAR_Controller::controllerInit()
{
time(&start_time);
gettimeofday(&start_tp, NULL);
interfaceNames = getNetworkInterfaces();
ui->networkInterfaces->addItems(interfaceNames);
if (interfaceNames.contains(DEFAULT_IF_DEV1))
ui->networkInterfaces->setCurrentIndex(interfaceNames.indexOf(DEFAULT_IF_DEV1));
else if(interfaceNames.contains(DEFAULT_IF_DEV2))
ui->networkInterfaces->setCurrentIndex(interfaceNames.indexOf(DEFAULT_IF_DEV2));
else
ui->networkInterfaces->setCurrentIndex(0);
ui->recOutputDirectory->setText(DEFAULT_DIRECTORY);
// ui->srcMacAddr->setText(DEFAULT_SRC_MAC);
ui->destMacAddr->setText(DEFAULT_DEST_MAC);
// ui->srcIpAddr->setText(DEFAULT_SRC_IP);
ui->destIpAddr->setText(DEFAULT_DEST_IP);
ui->fmc150RegisterAddr_spinBox->setRange(0,0xFFFF);
ui->fmc150RegisterAddr_spinBox->setValue(0x0004);
ui->fmc150RegisterData_spinBox->setValue(0x00000077);
ui->fmc150_Clk_iDelay_spinBox->setRange(0,0x1F);
ui->fmc150_CHA_Delay_spinBox->setRange(0,0x1F);
ui->fmc150_CHB_Delay_spinBox->setRange(0,0x1F);
ui->fmc150_Clk_iDelay_spinBox->setValue(0);
ui->fmc150_CHA_Delay_spinBox->setValue(0x1e);
ui->fmc150_CHB_Delay_spinBox->setValue(0);
on_chirpParamsResetButton_clicked();
calculateChirpParams();
storeChirpParams();
storeFMC150Params();
global_pkt_counter = 0;
memset(&radar_calib_zero,0,sizeof(radar_calib_zero));
memset(&radar_status,0,sizeof(radar_status));
ui->transcript->setText("Initialization Complete...Controller Ready");
}
void UDAR_Controller::setupDataPlot(QCustomPlot *plot, QPen pen){
// The following plot setup is mostly taken from the plot demos:
plot->addGraph();
// plot->graph()->setPen(QPen(Qt::blue));
plot->graph()->setPen(pen);
plot->xAxis->setTicks(true);
plot->xAxis->setTickLabels(true);
plot->xAxis->setTickLabelFont(QFont(QFont().family(), 9));
plot->yAxis->setTicks(true);
plot->yAxis->setTickLabels(true);
plot->yAxis->setTickLabelFont(QFont(QFont().family(), 9));
plot->legend->setVisible(true);
plot->legend->setFont(QFont(QFont().family(), 9));
plot->axisRect()->insetLayout()->setInsetAlignment(0, Qt::AlignBottom|Qt::AlignRight);
plot->axisRect()->setupFullAxesBox(true);
// plot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
plot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectAxes |
QCP::iSelectLegend | QCP::iSelectPlottables);
}
void UDAR_Controller::setupDataPlot(QCustomPlot *plot, QPen pen, QString xLabel){
// The following plot setup is mostly taken from the plot demos:
plot->addGraph();
// plot->graph()->setPen(QPen(Qt::blue));
plot->graph()->setPen(pen);
plot->xAxis->setTicks(true);
plot->xAxis->setTickLabels(true);
plot->xAxis->setTickLabelFont(QFont(QFont().family(), 9));
plot->yAxis->setTicks(true);
plot->yAxis->setTickLabels(true);
plot->yAxis->setTickLabelFont(QFont(QFont().family(), 9));
plot->xAxis->setLabel(xLabel);
plot->xAxis->setLabelFont(QFont(QFont().family(), 9));
plot->xAxis->setLabelPadding(0);
plot->legend->setVisible(true);
plot->legend->setFont(QFont(QFont().family(), 9));
plot->axisRect()->insetLayout()->setInsetAlignment(0, Qt::AlignBottom|Qt::AlignRight);
plot->axisRect()->setupFullAxesBox(true);
// plot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
plot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectAxes |
QCP::iSelectLegend | QCP::iSelectPlottables);
}
void UDAR_Controller::setupCounterPlot(QCustomPlot *plot, QPen pen){
// The following plot setup is mostly taken from the plot demos:
plot->addGraph();
plot->graph()->setPen(pen);
plot->xAxis->setTicks(true);
plot->xAxis->setTickLabels(true);
plot->xAxis->setTickLabelFont(QFont(QFont().family(), 9));
plot->yAxis->setTicks(true);
plot->yAxis->setTickLabels(true);
plot->yAxis->setTickLabelFont(QFont(QFont().family(), 9));
plot->addGraph();
plot->graph()->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCircle, QPen(Qt::black, 1.5), QBrush(Qt::white), 5));
plot->graph()->setLineStyle(QCPGraph::lsNone);
plot->graph()->setPen(QPen(QColor(120, 120, 120), 2));
plot->axisRect()->setupFullAxesBox(true);
//plot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
plot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectAxes |
QCP::iSelectLegend | QCP::iSelectPlottables);
}
void UDAR_Controller::setupPlotIQ(){
setupDataPlot(ui->plotI,QPen(Qt::blue),"Samples");
setupDataPlot(ui->plotQ,QPen(Qt::blue),"Samples");
setupDataPlot(ui->plotI2,QPen(Qt::red),"Samples");
setupDataPlot(ui->plotQ2,QPen(Qt::red),"Samples");
setupDataPlot(ui->plotFFTI,QPen(Qt::blue),"Freq(MHz)");
setupDataPlot(ui->plotFFTQ,QPen(Qt::blue),"Freq(MHz)");
setupDataPlot(ui->plotFFTI2,QPen(Qt::red),"Freq(MHz)");
setupDataPlot(ui->plotFFTQ2,QPen(Qt::red),"Freq(MHz)");
setupDataPlot(ui->plotC,QPen(Qt::blue),"Range(m)");
setupDataPlot(ui->plotC,QPen(Qt::red),"Range(m)");
setupDataPlot(ui->plotC2,QPen(Qt::red),"Range(m)");
// setupCounterPlot(ui->plotC,QPen(Qt::green));
// setupCounterPlot(ui->plotC2,QPen(Qt::green));
}
void UDAR_Controller::updateDataPlot(QCustomPlot *plot,QVector<double> &dataX,QVector<double> &dataY,int graph_num){
QCPRange xrng = plot->xAxis->range();
QCPRange yrng = plot->yAxis->range();
plot->graph(graph_num)->setData(dataX, dataY);
if (ui->autoScale_checkBox->isChecked()){
QPoint p = this->mapFromGlobal(QCursor::pos());
p.setX(p.x()-15);
p.setY(p.y()-44);
QRect plotPos = plot->geometry();//plot->viewport();
if(plotPos.contains(p)){
plot->xAxis->setRange(xrng);
plot->yAxis->setRange(yrng);
}
else {
plot->graph(graph_num)->rescaleAxes();
}
}
plot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectAxes |
QCP::iSelectLegend | QCP::iSelectPlottables);
plot->replot();
}
void UDAR_Controller::updateDataPlot(QCustomPlot *plot,QVector<double> &dataX,QVector<double> &dataY,int graph_num, QString name){
QCPRange xrng = plot->xAxis->range();
QCPRange yrng = plot->yAxis->range();
plot->graph(graph_num)->setData(dataX, dataY);
// if (plot->xAxis->selectedParts().testFlag(QCPAxis::spAxis))
// plot->xAxis->setRange(xrng);
// else if (plot->yAxis->selectedParts().testFlag(QCPAxis::spAxis))
// plot->yAxis->setRange(yrng);
if (ui->autoScale_checkBox->isChecked()){
QPoint p = this->mapFromGlobal(QCursor::pos());
p.setX(p.x()-15);
p.setY(p.y()-44);
QRect plotPos = plot->geometry();//plot->viewport();
if(plotPos.contains(p)){
plot->xAxis->setRange(xrng);
plot->yAxis->setRange(yrng);
}
else {
plot->graph(graph_num)->rescaleAxes();
}
}
plot->graph(graph_num)->setName(name);
plot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectAxes |
QCP::iSelectLegend | QCP::iSelectPlottables);
plot->replot();
}
void UDAR_Controller::updateDataPlotIQ(){
updateDataPlot(ui->plotI,plotTimeVec,plotDataI,0);
updateDataPlot(ui->plotQ,plotTimeVec,plotDataQ,0);
updateDataPlot(ui->plotI2,plotTimeVec,plotDataI2,0);
updateDataPlot(ui->plotQ2,plotTimeVec,plotDataQ2,0);
//updateDataPlot(ui->plotC,plotTimeVec,plotDataC,0);
//updateDataPlot(ui->plotC,ctrjumpsX,ctrjumpsY,1);
//updateDataPlot(ui->plotC2,plotTimeVec,plotDataC2,0);
//updateDataPlot(ui->plotC2,ctrjumpsX,ctrjumpsY2,1);
}
void UDAR_Controller::updateDataPlotIQ(QString nameL, QString nameU){
updateDataPlot(ui->plotI,plotTimeVec,plotDataI,0,nameL);
updateDataPlot(ui->plotQ,plotTimeVec,plotDataQ,0,nameL);
updateDataPlot(ui->plotI2,plotTimeVec,plotDataI2,0,nameU);
updateDataPlot(ui->plotQ2,plotTimeVec,plotDataQ2,0,nameU);
// updateDataPlot(ui->plotC,plotTimeVec,plotDataC,0);
//updateDataPlot(ui->plotC,ctrjumpsX,ctrjumpsY,1);
// updateDataPlot(ui->plotC2,plotTimeVec,plotDataC2,0);
//updateDataPlot(ui->plotC2,ctrjumpsX,ctrjumpsY2,1);
}
void UDAR_Controller::updateDataPlotIQ(QString nameL){
updateDataPlot(ui->plotI,plotTimeVec,plotDataI,0,nameL);
updateDataPlot(ui->plotQ,plotTimeVec,plotDataQ,0,nameL);
// updateDataPlot(ui->plotI2,plotTimeVec,plotDataI2,0);
// updateDataPlot(ui->plotQ2,plotTimeVec,plotDataQ2,0);
// updateDataPlot(ui->plotC,plotTimeVec,plotDataC,0);
//updateDataPlot(ui->plotC,ctrjumpsX,ctrjumpsY,1);
// updateDataPlot(ui->plotC2,plotTimeVec,plotDataC2,0);
//updateDataPlot(ui->plotC2,ctrjumpsX,ctrjumpsY2,1);
}
void UDAR_Controller::updateDSPPlotIQ(QString nameL, QString nameU){
updateDataPlot(ui->plotC,plotRngVec,plotDSPI,0,nameL);
updateDataPlot(ui->plotC2,plotRngVec,plotDSPQ,0,nameU);
}
void UDAR_Controller::updateFFTPlotIQ(QString nameL, QString nameU){
updateDataPlot(ui->plotFFTI,plotfftVec,plotfftI,0,nameL);
updateDataPlot(ui->plotFFTQ,plotfftVec,plotfftQ,0,nameL);
updateDataPlot(ui->plotFFTI2,plotfftVec,plotfftI2,0,nameU);
updateDataPlot(ui->plotFFTQ2,plotfftVec,plotfftQ2,0,nameU);
}
void UDAR_Controller::updateFFTPlotIQ(QString nameL){
updateDataPlot(ui->plotFFTI,plotfftVec,plotfftI,0,nameL);
updateDataPlot(ui->plotFFTQ,plotfftVec,plotfftQ,0,nameL);
// updateDataPlot(ui->plotFFTI2,plotfftVec,plotfftI2,0);
// updateDataPlot(ui->plotFFTQ2,plotfftVec,plotfftQ2,0);
}
void UDAR_Controller::updateFFTPlotIQ(){
updateDataPlot(ui->plotFFTI,plotfftVec,plotfftI,0);
updateDataPlot(ui->plotFFTQ,plotfftVec,plotfftQ,0);
updateDataPlot(ui->plotFFTI2,plotfftVec,plotfftI2,0);
updateDataPlot(ui->plotFFTQ2,plotfftVec,plotfftQ2,0);
}
void UDAR_Controller::selectionChanged(QCustomPlot *plot)
{
/*
normally, axis base line, axis tick labels and axis labels are selectable separately, but we want
the user only to be able to select the axis as a whole, so we tie the selected states of the tick labels
and the axis base line together. However, the axis label shall be selectable individually.
The selection state of the left and right axes shall be synchronized as well as the state of the
bottom and top axes.
Further, we want to synchronize the selection of the graphs with the selection state of the respective
legend item belonging to that graph. So the user can select a graph by either clicking on the graph itself
or on its legend item.
*/
// make top and bottom axes be selected synchronously, and handle axis and tick labels as one selectable object:
if (plot->xAxis->selectedParts().testFlag(QCPAxis::spAxis) || plot->xAxis->selectedParts().testFlag(QCPAxis::spTickLabels) ||
plot->xAxis2->selectedParts().testFlag(QCPAxis::spAxis) || plot->xAxis2->selectedParts().testFlag(QCPAxis::spTickLabels))
{
plot->xAxis2->setSelectedParts(QCPAxis::spAxis|QCPAxis::spTickLabels);
plot->xAxis->setSelectedParts(QCPAxis::spAxis|QCPAxis::spTickLabels);
}
// make left and right axes be selected synchronously, and handle axis and tick labels as one selectable object:
if (plot->yAxis->selectedParts().testFlag(QCPAxis::spAxis) || plot->yAxis->selectedParts().testFlag(QCPAxis::spTickLabels) ||
plot->yAxis2->selectedParts().testFlag(QCPAxis::spAxis) || plot->yAxis2->selectedParts().testFlag(QCPAxis::spTickLabels))
{
plot->yAxis2->setSelectedParts(QCPAxis::spAxis|QCPAxis::spTickLabels);
plot->yAxis->setSelectedParts(QCPAxis::spAxis|QCPAxis::spTickLabels);
}
}
void UDAR_Controller::selectionChanged()
{
selectionChanged(ui->plotI);
selectionChanged(ui->plotQ);
selectionChanged(ui->plotI2);
selectionChanged(ui->plotQ2);
selectionChanged(ui->plotC);
selectionChanged(ui->plotC2);
selectionChanged(ui->plotFFTI);
selectionChanged(ui->plotFFTQ);
selectionChanged(ui->plotFFTI2);
selectionChanged(ui->plotFFTQ2);
}
void UDAR_Controller::mousePress(QCustomPlot *plot)
{
// if an axis is selected, only allow the direction of that axis to be dragged
// if no axis is selected, both directions may be dragged
if (plot->xAxis->selectedParts().testFlag(QCPAxis::spAxis)){
plot->axisRect()->setRangeDrag(plot->xAxis->orientation());
}
else if (plot->yAxis->selectedParts().testFlag(QCPAxis::spAxis)){
plot->axisRect()->setRangeDrag(plot->yAxis->orientation());
}
else{
plot->axisRect()->setRangeDrag(Qt::Horizontal|Qt::Vertical);
}
}
void UDAR_Controller::mousePress()
{
// if an axis is selected, only allow the direction of that axis to be dragged
// if no axis is selected, both directions may be dragged
mousePress(ui->plotI);
mousePress(ui->plotQ);
mousePress(ui->plotI2);
mousePress(ui->plotQ2);
mousePress(ui->plotC);
mousePress(ui->plotC2);
mousePress(ui->plotFFTI);
mousePress(ui->plotFFTQ);
mousePress(ui->plotFFTI2);
mousePress(ui->plotFFTQ2);
}
void UDAR_Controller::mouseWheel(QCustomPlot *plot)
{
// if an axis is selected, only allow the direction of that axis to be zoomed
// if no axis is selected, both directions may be zoomed
if (plot->xAxis->selectedParts().testFlag(QCPAxis::spAxis))
plot->axisRect()->setRangeZoom(plot->xAxis->orientation());
else if (plot->yAxis->selectedParts().testFlag(QCPAxis::spAxis))
plot->axisRect()->setRangeZoom(plot->yAxis->orientation());
else
plot->axisRect()->setRangeZoom(Qt::Horizontal|Qt::Vertical);
}
void UDAR_Controller::mouseWheel()
{
// if an axis is selected, only allow the direction of that axis to be zoomed
// if no axis is selected, both directions may be zoomed
mouseWheel(ui->plotI);
mouseWheel(ui->plotQ);
mouseWheel(ui->plotI2);
mouseWheel(ui->plotQ2);
mouseWheel(ui->plotC);
mouseWheel(ui->plotC2);
mouseWheel(ui->plotFFTI);
mouseWheel(ui->plotFFTQ);
mouseWheel(ui->plotFFTI2);
mouseWheel(ui->plotFFTQ2);
}
void UDAR_Controller::horzScrollBarChanged(QCustomPlot *plot,int value)
{
if (qAbs(plot->xAxis->range().center()-value/100.0) > 0.01) // if user is dragging plot, we don't want to replot twice
{
plot->xAxis->setRange(value/100.0, plot->xAxis->range().size(), Qt::AlignCenter);
plot->replot();
}
}
void UDAR_Controller::vertScrollBarChanged(QCustomPlot *plot, int value)
{
if (qAbs(plot->yAxis->range().center()+value/100.0) > 0.01) // if user is dragging plot, we don't want to replot twice
{
plot->yAxis->setRange(-value/100.0, plot->yAxis->range().size(), Qt::AlignCenter);
plot->replot();
}
}
void UDAR_Controller::horzScrollBarIChanged(int value)
{
horzScrollBarChanged(ui->plotI,value);
}
void UDAR_Controller::horzScrollBarQChanged(int value)
{
horzScrollBarChanged(ui->plotQ,value);
}
void UDAR_Controller::horzScrollBarCChanged(int value)
{
horzScrollBarChanged(ui->plotC,value);
}
void UDAR_Controller::horzScrollBarFFTIChanged(int value)
{
horzScrollBarChanged(ui->plotFFTI,value);
}
void UDAR_Controller::horzScrollBarFFTQChanged(int value)
{
horzScrollBarChanged(ui->plotFFTQ,value);
}
void UDAR_Controller::vertScrollBarIChanged(int value)
{
vertScrollBarChanged(ui->plotI,value);
}
void UDAR_Controller::vertScrollBarQChanged(int value)
{
vertScrollBarChanged(ui->plotQ,value);
}
void UDAR_Controller::vertScrollBarCChanged(int value)
{
vertScrollBarChanged(ui->plotC,value);
}
void UDAR_Controller::vertScrollBarFFTIChanged(int value)
{
vertScrollBarChanged(ui->plotFFTI,value);
}
void UDAR_Controller::vertScrollBarFFTQChanged(int value)
{
vertScrollBarChanged(ui->plotFFTQ,value);
}
void UDAR_Controller::xAxisIChanged(QCPRange range)
{
ui->horizontalScrollBarI->setValue(qRound(range.center()*100.0)); // adjust position of scroll bar slider
ui->horizontalScrollBarI->setPageStep(qRound(range.size()*100.0)); // adjust size of scroll bar slider
}
void UDAR_Controller::yAxisIChanged(QCPRange range)
{
ui->verticalScrollBarI->setValue(qRound(-range.center()*100.0)); // adjust position of scroll bar slider
ui->verticalScrollBarI->setPageStep(qRound(range.size()*100.0)); // adjust size of scroll bar slider
}
u_char UDAR_Controller::GetRxDataFormat(){
u_char select_adc_l = (u_char)ui->adc_data_l_radioButton->isChecked();
u_char select_dac_l = (u_char)ui->dac_data_l_radioButton->isChecked();
u_char select_adc_ctr_l = (u_char)ui->adc_counter_l_radioButton->isChecked();
u_char select_glbl_ctr_l = (u_char)ui->global_counter_l_radioButton->isChecked();
u_char select_adc_u = (u_char)ui->adc_data_u_radioButton->isChecked();
u_char select_dac_u = (u_char)ui->dac_data_u_radioButton->isChecked();
u_char select_adc_ctr_u = (u_char)ui->adc_counter_u_radioButton->isChecked();
u_char select_glbl_ctr_u = (u_char)ui->global_counter_u_radioButton->isChecked();
uint32_t select_data_l = 0*select_adc_l + select_dac_l + 2*select_adc_ctr_l + 3*select_glbl_ctr_l;
uint32_t select_data_u = 0*select_adc_u + select_dac_u + 2*select_adc_ctr_u + 3*select_glbl_ctr_u;
uint32_t select_data = (select_data_l & 0x0F) + ((select_data_u<<4) & 0xF0);
u_char dataformat = (u_char)(select_data & 0x000000FF);
return dataformat;
}
QString UDAR_Controller::GetRxDataFormatName(int index){
// Lower word
if (index == 0) {
if (ui->adc_data_l_radioButton->isChecked()) return ("ADC Output");
else if(ui->dac_data_l_radioButton->isChecked()) return("DAC Input");
else if(ui->adc_counter_l_radioButton->isChecked()) return("ADC Counter");
else return("Global Counter");
}
else {
if (ui->adc_data_u_radioButton->isChecked()) return ("ADC Output");
else if(ui->dac_data_u_radioButton->isChecked()) return("DAC Input");
else if(ui->adc_counter_u_radioButton->isChecked()) return("ADC Counter");
else return("Global Counter");
}
}
void UDAR_Controller::storeChirpParams(){
double chirp_prf = ui->chirpPRF_dSpinBox->value();
// uint32_t chirp_prf_int = (uint32_t)chirp_prf;
// double chirp_prf_int_d = (double)chirp_prf_int;
// double chirp_prf_frac_d = chirp_prf - chirp_prf_int_d;
// chirp_prf_frac_d = 1000000.0*chirp_prf_frac_d;
// uint32_t chirp_prf_frac = (uint32_t)round(chirp_prf_frac_d);
// Changed so that chirp_prf_int and chirp_prf_frac are the upper and lower 32 bits of the
// 64 bit counter to be used by the fpga
double fClock = ui->clockFreq_dSpinBox->value(); //MHz
double max_prf_d = fClock*1000000.0*chirp_prf;
uint64_t max_chirp_prf_count = (uint64_t)round(max_prf_d);
uint32_t chirp_prf_int = (uint32_t)((max_chirp_prf_count>>32) & 0xFFFFFFFF);
uint32_t chirp_prf_frac = (uint32_t)(max_chirp_prf_count & 0xFFFFFFFF);
chirp_params.prf_int = chirp_prf_int;
chirp_params.prf_frac = chirp_prf_frac;
chirp_params.adc_count = (uint32_t)ui->adcSamples_spinBox->value();
chirp_params.freq_off = (uint32_t)ui->freqOffset_spinBox->value();
chirp_params.tuning_word = (uint32_t)ui->chirpTuningWord_spinBox->value();
chirp_params.num_samples = (uint32_t)ui->numSamples_spinBox->value();
// u_char select_adc_l = (u_char)ui->adc_data_l_radioButton->isChecked();
// u_char select_dac_l = (u_char)ui->dac_data_l_radioButton->isChecked();
// u_char select_adc_ctr_l = (u_char)ui->adc_counter_l_radioButton->isChecked();
// u_char select_glbl_ctr_l = (u_char)ui->global_counter_l_radioButton->isChecked();
// u_char select_adc_u = (u_char)ui->adc_data_u_radioButton->isChecked();
// u_char select_dac_u = (u_char)ui->dac_data_u_radioButton->isChecked();
// u_char select_adc_ctr_u = (u_char)ui->adc_counter_u_radioButton->isChecked();
// u_char select_glbl_ctr_u = (u_char)ui->global_counter_u_radioButton->isChecked();
// uint32_t select_data_l = 0*select_adc_l + select_dac_l + 2*select_adc_ctr_l + 3*select_glbl_ctr_l;
// uint32_t select_data_u = 0*select_adc_u + select_dac_u + 2*select_adc_ctr_u + 3*select_glbl_ctr_u;
// uint32_t select_data = (select_data_l & 0x0F) + ((select_data_u<<4) & 0xF0);
// chirp_params.control_word = (uint32_t)(select_data & 0x000000FF);
// u_char dataformat = GetRxDataFormat() ;
uint32_t dds_source_ctrl = 0;
if (ui->DDSsourceWave_radioButton->isChecked()) dds_source_ctrl = 3;
chirp_params.control_word = (uint32_t)(GetRxDataFormat() & 0x000000FF) + ((dds_source_ctrl<<8) & 0x0000FF00);
//chirp_params.control_word = (uint32_t)ui->dacLoopback_checkBox->isChecked();
}
void UDAR_Controller::storeFMC150Params(){
u_char chA_delay = (u_char)(ui->fmc150_CHA_Delay_spinBox->hexValue() & 0x0000001F);
u_char chB_delay = (u_char)(ui->fmc150_CHB_Delay_spinBox->hexValue() & 0x0000001F);
u_char clk_delay = (u_char)(ui->fmc150_Clk_iDelay_spinBox->hexValue() & 0x0000001F);
uint16_t reg_addr = (uint16_t)(ui->fmc150RegisterAddr_spinBox->hexValue() & 0x0000FFFF);
uint32_t reg_data = (uint32_t)(ui->fmc150RegisterData_spinBox->hexValue() & 0xFFFFFFFF);
u_char rw_val = (u_char)(ui->fmc150_read_radioButton->isChecked() & 0xFF);
u_char cdc_val = (u_char)(ui->fmc150_CDC_radioButton->isChecked() & 0xFF);
u_char ads_val = (u_char)(ui->fmc150_ADS_radioButton->isChecked() & 0xFF);
u_char dac_val = (u_char)(ui->fmc150_DAC_radioButton->isChecked() & 0xFF);
u_char amc_val = (u_char)(ui->fmc150_AMC_radioButton->isChecked() & 0xFF);
fmc150_params.set_CH_A_iDelay = chA_delay;
fmc150_params.set_CH_B_iDelay = chB_delay;
fmc150_params.set_CLK_iDelay = clk_delay;
fmc150_params.register_addres = reg_addr;
fmc150_params.spi_register_data_to_fmc150 = reg_data;
fmc150_params.rw = ((rw_val&0x000000FF)<<24) + ((rw_val&0x000000FF)<<16) + ((rw_val&0x000000FF)<<8) + (rw_val&0x000000FF);
fmc150_params.cdce72010 = cdc_val;
fmc150_params.ads62p49 = ads_val;
fmc150_params.dac3283 = dac_val;
fmc150_params.amc7823 = amc_val;
fmc150_params.set_user8 = 0x00;
fmc150_params.set_user16 = 0x0000;
uint16_t chk_code = ((cdc_val&0x01))+((ads_val&0x01)<<4)+((dac_val&0x01)<<8)+((amc_val&0x01)<<12);
u_char chk_code8 = ((cdc_val&0x01))+((ads_val&0x01)<<1)+((dac_val&0x01)<<2)+((amc_val&0x01)<<3);
fmc150_params.code_check1 = cdc_val + ads_val + dac_val + amc_val;
fmc150_params.code_check2 = chk_code8;
fmc150_params.code_check16 = chk_code;
fmc150_params.control_word = 0;
}
void UDAR_Controller::calculateChirpParams(){
// --------------DDS Chirp Generation Parameters-------------------
// -- period = 4.17 us, BW = 46.08 MHz
// -- 491.52 Mhz clock, 4096 samples, 16 bit phase accumulator (n = 16)
// -- tuning_word_coeff = 3 for BW = 46.08 MHz (2048 samples)
// -- tuning_word_coeff = 4 for BW = 61.44 MHz (2048 samples)
// -- tuning_word_coeff = 1.5 for BW = 46.08 MHz (4096 samples)
// -- tuning_word_coeff = 2 for BW = 61.44 MHz (4096 samples)
// -- Calculated Using:
// -- tuning_word_coeff = BW*(2^n)/(num_samples*fClock)
// -- Taken From:
// -- tuning_word_coeff = period*slope*(2^n)/(num_samples*fClock)
// -- Where:
// -- slope = BW/period
// -- num_samples = period*fclock
// --
// -- Note: Derived From:
// -- tuning_word = rect[t/period] t*slope*(2^n)/fclock
// -- And:
// -- t = sample_count*period/num_samples
// -- Therefore:
// -- tuning_word = sample_count*tuning_coeff
// -- Additoinally:
// -- min_freq = freq_offset*fclock/2^n
double tuning_word_coeff = (double) ui->chirpTuningWord_spinBox->value();
double num_samples = (double)ui->numSamples_spinBox->value();
double freq_offset = (double)ui->freqOffset_spinBox->value();
int n = ui->phaseAccLen_spinBox->value();
double fClock = ui->clockFreq_dSpinBox->value(); //MHz
double two_pow_n = (double)(1<<n);
double BW = (num_samples*fClock*tuning_word_coeff)/(two_pow_n); //MHz
double period = num_samples/fClock; //usec
double slope = BW/period; //MHz/usec
double min_freq = freq_offset*fClock/(two_pow_n);
ui->chirpBW_dSpinBox->setValue(BW);
ui->chirpTime_dSpinBox->setValue(period);
ui->chirpSlope_dSpinBox->setValue(slope);
ui->minFreq_dSpinBox->setValue(min_freq);
chirp_params.freq_off = (uint32_t)freq_offset;
chirp_params.tuning_word = (uint32_t)tuning_word_coeff;
chirp_params.num_samples = (uint32_t)num_samples;
}
void UDAR_Controller::updateInterfaceFields(const QString if_name){
NetInterface *currInterface = interfaceMap[if_name];
ui->srcMacAddr->setText(currInterface->GetMacString());
ui->srcIpAddr->setText(currInterface->GetIpString());
}
void UDAR_Controller::getMacArray(u_char mac[6],QString text){
QByteArray ba = text.toLatin1();
const char* str = ba.data();
unsigned int maci[6];
sscanf(str,"%02x:%02x:%02x:%02x:%02x:%02x",&maci[0],&maci[1],&maci[2],&maci[3],&maci[4],&maci[5]);
for(int i=0;i<6;i++) mac[i] = (u_char)maci[i];
}
void UDAR_Controller::getIpArray(u_char ip[4],QString text){
QByteArray ba = text.toLatin1();
const char* str = ba.data();
unsigned int ip_int[4];
//sscanf(str,"%d.%d.%d.%d",&ip[0],&ip[1],&ip[2],&ip[3]);
sscanf(str,"%d.%d.%d.%d",&ip_int[0],&ip_int[1],&ip_int[2],&ip_int[3]);
for(int i=0;i<4;i++) ip[i] = (u_char)ip_int[i];
}
void UDAR_Controller::sendWaveformData(const QString name, uint32_t cmd,uint32_t *data)
{
NetInterface *currInterface = interfaceMap[name];
QByteArray ba = name.toLatin1();
const char* if_name = ba.data();
int i,data_ind,pkt_count,data_size,full_data_size,data_offset,cmd_header_size;
//const char* if_name= "en0";//argv[1];
const char* target_ip_string = "192.168.1.10"; //argv[2];
u_char target_mac[6];
u_char target_ip_addr_in[4];
getMacArray(target_mac,ui->destMacAddr->text());
getIpArray(target_ip_addr_in,ui->destIpAddr->text());
uint32_t partial_packet_size,full_packet_size,partial_data_len8,num_full_pkts,waveform_data_len8;
uint16_t packet_size;
u_char *packet_data;
uint32_t packet_cmd_id;
// chirp command: ascii WWCC
if(cmd == DATA_WRITE_COMMAND){
full_packet_size = TX_DATA_PKT_SIZE-sizeof(struct ether_header);
cmd_header_size = 10; //2 byte counter, 4 byte cmd word, 4 byte cmd id
full_data_size = full_packet_size - sizeof(struct waveform_tx_header) - cmd_header_size;
data_offset = cmd_header_size+sizeof(struct waveform_tx_header);
//packet_data = new u_char[packet_size];
waveform_data_len8 = (waveform_header.len<<2);
num_full_pkts = floor(waveform_data_len8/full_data_size);
partial_data_len8 = waveform_data_len8 - num_full_pkts*full_data_size;
partial_packet_size = partial_data_len8 + cmd_header_size + sizeof(struct waveform_tx_header);
int num_pkts = num_full_pkts;
int need_partial_pkt = 0;
if (partial_data_len8 > 0) {
need_partial_pkt = 1;
num_pkts += 1;
}
// Construct Ethernet header (except for source MAC address).
// (Destination set to broadcast address, FF:FF:FF:FF:FF:FF.)
struct ether_header header;
// header.ether_type=htons(packet_size);
for (i=0;i<6;i++) header.ether_dhost[i] = target_mac[i];
// Convert target IP address from string, copy into ARP request.
struct in_addr target_ip_addr={0};
memcpy(&target_ip_addr,target_ip_addr_in,4);
// Write the interface name to an ifreq structure,
// for obtaining the source MAC and IP addresses.
struct ifreq ifr;
size_t if_name_len=strlen(if_name);
if (if_name_len<sizeof(ifr.ifr_name)) {
memcpy(ifr.ifr_name,if_name,if_name_len);
ifr.ifr_name[if_name_len]=0;
} else {
fprintf(stderr,"interface name is too long");
exit(1);
}
// Open an IPv4-family socket for use when calling ioctl.
int fd=socket(AF_INET,SOCK_DGRAM,0);
if (fd==-1) {
fprintf(stderr,"[SendCommand] Unable to open socket");
perror(0);
exit(1);
}
u_char *source_mac = currInterface->GetMac();
for (i=0;i<6;i++) header.ether_shost[i] = source_mac[i];
delete[] source_mac;
::close(fd);
// Open a PCAP packet capture descriptor for the specified interface.
char pcap_errbuf[PCAP_ERRBUF_SIZE];
pcap_errbuf[0]='\0';
pcap_t* pcap=pcap_open_live(if_name,96,0,0,pcap_errbuf);
if (pcap_errbuf[0]!='\0') {
fprintf(stderr,"[SendCommand] pcap_errbuf: %s\n",pcap_errbuf);
}
if (!pcap) {
exit(1);
}
data_ind = 0;
for(pkt_count = 0;pkt_count < num_pkts; pkt_count++){
if(need_partial_pkt & (pkt_count == num_pkts-1)){
packet_size = partial_packet_size;
}
else {
packet_size = full_packet_size;
}
data_size = packet_size - sizeof(struct waveform_tx_header) - cmd_header_size;
packet_data = new u_char[packet_size];
header.ether_type=htons(packet_size);
unsigned char frame[sizeof(struct ether_header)+ packet_size];
packet_cmd_id = genCommandIdentifier();
if(ui->byteReorderCheckBox->isChecked()){
*(uint16_t *)packet_data =htons(global_pkt_counter++);
// for (i=2;i<6;i++) packet_data[i] = 0x57; // Ascii W
*(uint32_t*)(packet_data+2) = htonl(cmd);
*(uint32_t*)(packet_data+6) = htonl(packet_cmd_id);
int j = 0;
for (i=0;i<sizeof(struct waveform_tx_header);i+=4)
*(uint32_t*)(packet_data+i+10) = htonl(*((uint32_t*)(&waveform_header)+(j++)));
for(i=0;i<data_size;i+=4){
*(uint32_t*)(packet_data+i+data_offset) = htonl(data[(i>>2)+(data_ind>>2)]);
}
}
else {
*(uint16_t *)packet_data = global_pkt_counter++;
// for (i=2;i<6;i++) packet_data[i] = cmd;
*(uint32_t*)(packet_data+2) = cmd;
*(uint32_t*)(packet_data+6) = packet_cmd_id;
memcpy(packet_data+10,&waveform_header,sizeof(struct waveform_tx_header));
memcpy(packet_data+data_offset,(u_char *)data+data_ind,data_size);
}
waveform_header.ind++;
data_ind+=data_size;
// Combine the Ethernet header and ARP request into a contiguous block.
memcpy(frame,&header,sizeof(struct ether_header));
memcpy(frame+sizeof(struct ether_header),packet_data,packet_size);
if (pcap_inject(pcap,frame,sizeof(frame))==-1) {
pcap_perror(pcap,0);
pcap_close(pcap);
exit(1);
}
if(pkt_count ==0){
char tempstr[STR_SIZE];
sprintf(tempstr,"First Waveform Packet Sent on Interface: %s",if_name);
setTranscript(tempstr);
setTranscript(frame,sizeof(struct ether_header)+ packet_size);
}
else if(pkt_count == (num_pkts-1)){
char tempstr[STR_SIZE];
sprintf(tempstr,"Final Waveform Packet Sent on Interface: %s",if_name);
setTranscript(tempstr);
setTranscript(frame,sizeof(struct ether_header)+ packet_size);
}
//Delete packet data
delete[] packet_data;
}
pcap_close(pcap);
}
else {
setTranscript("Incorrect Command Word Issued");
}
}
void UDAR_Controller::sendCommand(const QString name, uint32_t cmd)
{
NetInterface *currInterface = interfaceMap[name];
QByteArray ba = name.toLatin1();
const char* if_name = ba.data();
int i;
//const char* if_name= "en0";//argv[1];
const char* target_ip_string = "192.168.1.10"; //argv[2];
u_char target_mac[6];
u_char target_ip_addr_in[4];
getMacArray(target_mac,ui->destMacAddr->text());