-
Notifications
You must be signed in to change notification settings - Fork 26
/
Unit1.h
906 lines (794 loc) · 31.3 KB
/
Unit1.h
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
// (c) OneOfEleven 2020
//
// This code can be used on terms of WTFPL Version 2 (http://www.wtfpl.net)
#ifndef Unit1H
#define Unit1H
#define VC_EXTRALEAN
#define WIN32_EXTRA_LEAN
#define WIN32_LEAN_AND_MEAN
#include <System.Classes.hpp>
#include <System.ImageList.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
#include <Vcl.Buttons.hpp>
#include <Vcl.ComCtrls.hpp>
#include <Vcl.Dialogs.hpp>
#include <Vcl.Graphics.hpp>
#include <Vcl.Menus.hpp>
#include <Vcl.Dialogs.hpp>
#include <Vcl.ExtCtrls.hpp>
#include <Vcl.ExtDlgs.hpp>
#include <Vcl.Graphics.hpp>
#include <Vcl.Menus.hpp>
#include <Vcl.Graphics.hpp>
#include <Vcl.WinXCtrls.hpp>
#include <Vcl.ImgList.hpp>
#include <Vcl.ButtonGroup.hpp>
#include "SerialPort.h"
//#include "TCPIP.h" // our own TCPIP client
#include "CriticalSection.h"
#include "HighResolutionTick.h"
#include "st_dfu.h"
#include "Graphs.h"
#include "GraphUnit.h"
#include "NanoVNA_v1_comms.h"
#include "NanoVNA_v2_comms.h"
#include "JanVNA2_comms.h"
#include "DataUnit.h"
#ifndef TCPIPH
// use the Indy TCPIP client
#include <IdBaseComponent.hpp>
#include <IdComponent.hpp>
#include <IdTCPClient.hpp>
#include <IdTCPConnection.hpp>
#endif
// ******************************************************************************
typedef void __fastcall (__closure *mainForm_threadProcess)();
class CMainFormThread : public TThread
{
private:
//mainForm_threadProcess m_process;
HANDLE m_event;
protected:
void __fastcall Execute()
{
// m_event = ::CreateEvent(NULL, TRUE, FALSE, NULL);
while (!Terminated)
{
// give time to other system threads
if (m_event != NULL)
{
::WaitForSingleObject(m_event, 1);
}
else
{
this->Sleep(1);
}
if (m_process)
{
#ifndef _DEBUG
m_process();
#else
Synchronize(m_process); // thread safe mode
#endif
}
}
if (m_event)
CloseHandle(m_event);
m_event = NULL;
ReturnValue = 0;
}
public:
__fastcall CMainFormThread(mainForm_threadProcess process, TThreadPriority priority, bool start) : TThread(!start)
{
m_event = NULL;
m_process = process;
// FreeOnTerminate = false;
FreeOnTerminate = true;
Priority = priority;
}
virtual __fastcall ~CMainFormThread()
{
m_process = NULL;
}
mainForm_threadProcess m_process;
};
// ******************************************************************************
class TForm1 : public TForm
{
__published:
TComboBox *SerialPortBaudrateComboBox;
TComboBox *DeviceComboBox;
TPopupMenu *GraphPopupMenu;
TMenuItem *Enablespline1;
TMenuItem *Cancel1;
TMenuItem *N2;
TMenuItem *Showpoints1;
TStatusBar *StatusBar1;
TTimer *Timer1;
TComboBox *VelocityFactorComboBox;
TTrackBar *TimeAverageLevelTrackBar;
TLabel *Label12;
TMenuItem *N3;
TMenuItem *Saveimage1;
TEdit *VelocityFactorEdit;
TLabel *MovingAverageFilterLabel;
TSaveDialog *SaveDialog1;
TSpeedButton *MemorySpeedButton1;
TSpeedButton *MemorySpeedButton2;
TSpeedButton *MemorySpeedButton3;
TTrackBar *TDRWindowTrackBar;
TLabel *TDRWindowLabel2;
TLabel *TDRWindowLabel1;
TLabel *Label3;
TLabel *Label1;
TLabel *Label2;
TLabel *Label4;
TLabel *Label13;
TEdit *CWMHzEdit;
TEdit *StopMHzEdit;
TEdit *SpanMHzEdit;
TEdit *CenterMHzEdit;
TEdit *StartMHzEdit;
TPanel *Panel1;
TPanel *InfoPanel;
TLabel *Label14;
TLabel *Label16;
TLabel *Label23;
TLabel *Label19;
TLabel *Label22;
TLabel *Label25;
TLabel *Label27;
TLabel *Label29;
TLabel *Label35;
TLabel *Label31;
TLabel *Label20;
TLabel *Label53;
TLabel *Label51;
TLabel *MarkerS21GainLabel;
TLabel *MarkerS21Label;
TLabel *MarkerS21RealImagLabel;
TLabel *MarkerS11ParallelCLabel;
TLabel *MarkerS11ParallelLLabel;
TLabel *MarkerS11ParallelXLabel;
TLabel *MarkerS11ParallelRLabel;
TLabel *MarkerS11SeriesCLabel;
TLabel *MarkerS11SeriesLLabel;
TLabel *MarkerS11SeriesXLabel;
TLabel *MarkerS11SeriesRLabel;
TLabel *MarkerS11RealImagLabel;
TLabel *MarkerFrequencyLabel;
TLabel *Label37;
TLabel *Label39;
TLabel *Label47;
TLabel *Label41;
TLabel *Label43;
TLabel *Label46;
TLabel *Label49;
TLabel *Label34;
TLabel *Label15;
TLabel *MarkerS11AdmittanceLabel1;
TLabel *Label59;
TLabel *Label55;
TLabel *Label58;
TLabel *MarkerS21GroupDelayLabel;
TLabel *MarkerS21PolarLabel;
TLabel *MarkerS21PhaseLabel;
TLabel *MarkerS11ImpedanceLabel;
TLabel *MarkerS11AdmittanceLabel2;
TLabel *MarkerS11GroupDelayLabel;
TLabel *MarkerS11PolarLabel;
TLabel *MarkerS11PhaseLabel;
TLabel *MarkerS11ZLabel;
TLabel *MarkerS11QualityFactorLabel;
TLabel *MarkerS11Label;
TLabel *MarkerS11ReturnLossLabel;
TLabel *MarkerS11VSWRLabel;
TLabel *PointBandwidthLabel;
TLabel *PointsPerSegmentLabel;
TLabel *S21OffsetLabel;
TEdit *S21OffsetEdit;
TToggleSwitch *FreqBandEnableToggleSwitch;
TLabel *Label33;
TEdit *SweepNameEdit;
TLabel *SweepNameFontLabel;
TComboBox *NumberOfPointsComboBox;
TComboBox *PointBandwidthHzComboBox;
TToggleSwitch *LCMatchingToggleSwitch;
TLabel *LCMatchingLabel;
TSpeedButton *ScanOnceSpeedButton;
TLabel *Label40;
TTrackBar *CurveSmoothingTrackBar;
TLabel *CurveSmoothingLabel;
TLabel *EDelayLabel;
TEdit *EDelayEdit;
TGroupBox *MarkersGroupBox;
TListBox *MarkerListBox;
TListView *MarkerListView;
TToggleSwitch *ShowMarkersOnGraphToggleSwitch;
TLabel *OutputPowerLabel2;
TLabel *OutputPowerLabel1;
TTrackBar *OutputPowerTrackBar;
TBitBtn *SetScanRangeToVNAScanRangeBitBtn;
TMenuItem *N4;
TMenuItem *Deselectmarker1;
TMenuItem *Deletemarker1;
TMenuItem *Addmarker1;
TSpeedButton *ConnectDisconnectSpeedButton;
TSpeedButton *MemorySpeedButton0;
TSpeedButton *RecordSpeedButton;
TBitBtn *NewGraphBitBtn;
TBitBtn *CloseBitBtn;
TSpeedButton *ScanSpeedButton;
TBitBtn *UploadFirmwareBitBtn;
TBitBtn *SettingsBitBtn;
TBitBtn *BatteryVoltageBitBtn;
TBitBtn *CaptureVNAScreenBitBtn;
TBitBtn *VNACommsBitBtn;
TBitBtn *VNAUsartCommsBitBtn;
TBitBtn *CalibrationBitBtn;
TMenuItem *N1;
TMenuItem *Setasstartfrequency1;
TMenuItem *Setasstopfrequency1;
TMenuItem *Setascenterfrequency1;
TToggleSwitch *InfoPanelToggleSwitch;
TLabel *InfoPanelLabel2;
TButton *SetNormaliseButton;
TMenuItem *Showmaxmarker1;
TMenuItem *Showminmarker1;
TMenuItem *N5;
TMenuItem *N6;
TMenuItem *Automaxscale1;
TMenuItem *Autominscale1;
TMenuItem *Setmaxscale1;
TMenuItem *Setminscale1;
TEdit *TCPIPAddressEdit;
TEdit *TCPIPPortEdit;
TPopupMenu *MarkersListBoxPopupMenu;
TMenuItem *Deltamarker1;
TMenuItem *N7;
TMenuItem *Cancel2;
TMenuItem *Deltamarker2;
TMenuItem *Setmarkerfrequency1;
TMenuItem *Markergraph1;
TMenuItem *Allgraphs1;
TMenuItem *Graph11;
TMenuItem *Graph21;
TMenuItem *Graph31;
TMenuItem *Graph41;
TMenuItem *Markertrace1;
TMenuItem *Alltraces1;
TMenuItem *Trace11;
TMenuItem *Trace21;
TPaintBox *GraphPaintBox;
TToggleSwitch *ShowMarkerTextToggleSwitch;
TMenuItem *Showminmaxtext1;
TMenuItem *N8;
TPopupMenu *GraphTypePopupMenu;
TMenuItem *Graphtype1;
TMenuItem *Deletemarker2;
TMenuItem *Addmarker2;
TMenuItem *N9;
TMenuItem *Grapharrange1;
TMenuItem *GraphArrange1a;
TMenuItem *GraphArrange2a;
TMenuItem *GraphArrange2b;
TMenuItem *GraphArrange3a;
TMenuItem *GraphArrange3b;
TMenuItem *GraphArrange3c;
TMenuItem *GraphArrange3d;
TMenuItem *GraphArrange4a;
TMenuItem *GraphArrange4b;
TMenuItem *GraphArrange4c;
TMenuItem *GraphArrange4d;
TMenuItem *GraphArrange4e;
TMenuItem *GraphArrange4h;
TMenuItem *GraphArrange4i;
TMenuItem *GraphArrange3e;
TMenuItem *GraphArrange3f;
TMenuItem *GraphArrange4j;
TMenuItem *GraphArrange4k;
TMenuItem *GraphArrange4l;
TMenuItem *GraphArrange4m;
TMenuItem *GraphArrange4f;
TMenuItem *GraphArrange4g;
TLabel *Label5;
TTrackBar *MedianFilterTrackBar;
TLabel *MedianFilterLabel;
TMenuItem *Scaletomaxvalue1;
TMenuItem *Scaletominvalue1;
TMenuItem *Deleteallmarkers1;
TBevel *Bevel1;
TBevel *Bevel2;
TBevel *Bevel3;
TPopupMenu *MemoryPopupMenu;
TMenuItem *SetScanRangeFromMemory1;
TMenuItem *N10;
TMenuItem *Cancel3;
TMenuItem *LoadMemoryFromFile1;
TMenuItem *SetMemory1;
TMenuItem *ClearMemory1;
TMenuItem *N11;
TSpeedButton *MemorySpeedButton4;
TTrackBar *TraceLPFTrackBar;
TMenuItem *Cliptraces1;
TMenuItem *Scaletominmaxvalues1;
TMenuItem *Showmarkers1;
TMenuItem *Snaptonearestpoint1;
TMenuItem *Autoscalepeakhold1;
TLabel *Label6;
TLabel *MarkerWavelengthLabel1;
TLabel *Label8;
TLabel *MarkerWavelengthLabel2;
TMenuItem *Copyimage1;
TBitBtn *SaveGraphImageBitBtn;
TBitBtn *SaveS1PFileBitBtn;
TBitBtn *Save2PFileBitBtn;
TBitBtn *SaveCSVFileBitBtn;
TBitBtn *CopyGraphImageBitBtn;
TBitBtn *StopScanBitBtn;
TBitBtn *DeleteFrequencyMarkersBitBtn;
TBitBtn *SpareBitBtn;
TMenuItem *Memoryname1;
TMenuItem *N12;
TMenuItem *Clearmemoryname1;
TStatusBar *StatusBar2;
TSpeedButton *EnableNormaliseSpeedButton;
TPanel *Panel2;
TTrackBar *HistoryTrackBar;
TBitBtn *BitBtn1;
TLabel *Label18;
TComboBox *CalibrationSelectComboBox;
TSpeedButton *CWModeSpeedButton;
TPanel *GLPanel;
void __fastcall FormCreate(TObject *Sender);
void __fastcall FormDestroy(TObject *Sender);
void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
void __fastcall FormKeyDown(TObject *Sender, WORD &Key,
TShiftState Shift);
void __fastcall GraphPaintBoxPaint(TObject *Sender);
void __fastcall GraphPopupMenuPopup(TObject *Sender);
void __fastcall Enablespline1Click(TObject *Sender);
void __fastcall Showpoints1Click(TObject *Sender);
void __fastcall Timer1Timer(TObject *Sender);
void __fastcall SerialPortBaudrateComboBoxChange(TObject *Sender);
void __fastcall VelocityFactorComboBoxChange(TObject *Sender);
void __fastcall TimeAverageLevelTrackBarChange(TObject *Sender);
void __fastcall Saveimage1Click(TObject *Sender);
void __fastcall VelocityFactorEditChange(TObject *Sender);
void __fastcall TDRWindowTrackBarChange(TObject *Sender);
void __fastcall DeviceComboBoxClick(TObject *Sender);
void __fastcall MarkerListViewData(TObject *Sender, TListItem *Item);
void __fastcall MarkerListViewKeyDown(TObject *Sender, WORD &Key,
TShiftState Shift);
void __fastcall MarkerListViewChange(TObject *Sender, TListItem *Item,
TItemChange Change);
void __fastcall MarkerListBoxKeyDown(TObject *Sender, WORD &Key,
TShiftState Shift);
void __fastcall MarkerListBoxClick(TObject *Sender);
void __fastcall DeviceComboBoxDropDown(TObject *Sender);
void __fastcall FormDblClick(TObject *Sender);
void __fastcall StartMHzEditKeyDown(TObject *Sender, WORD &Key,
TShiftState Shift);
void __fastcall StopMHzEditKeyDown(TObject *Sender, WORD &Key,
TShiftState Shift);
void __fastcall CenterMHzEditKeyDown(TObject *Sender, WORD &Key,
TShiftState Shift);
void __fastcall SpanMHzEditKeyDown(TObject *Sender, WORD &Key,
TShiftState Shift);
void __fastcall CWMHzEditKeyDown(TObject *Sender, WORD &Key,
TShiftState Shift);
void __fastcall S21OffsetEditKeyDown(TObject *Sender,
WORD &Key, TShiftState Shift);
void __fastcall S21OffsetEditChange(TObject *Sender);
void __fastcall GraphPaintBoxMouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y);
void __fastcall GraphPaintBoxMouseUp(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y);
void __fastcall GraphPaintBoxMouseMove(TObject *Sender,
TShiftState Shift, int X, int Y);
void __fastcall FreqBandEnableToggleSwitchClick(TObject *Sender);
void __fastcall GraphPaintBoxMouseLeave(TObject *Sender);
void __fastcall PointBandwidthHzComboBoxKeyDown(TObject *Sender, WORD &Key, TShiftState Shift);
void __fastcall LCMatchingToggleSwitchClick(TObject *Sender);
void __fastcall ScanOnceSpeedButtonClick(TObject *Sender);
void __fastcall CurveSmoothingTrackBarChange(TObject *Sender);
void __fastcall EDelayEditChange(TObject *Sender);
void __fastcall EDelayEditKeyDown(TObject *Sender, WORD &Key, TShiftState Shift);
void __fastcall ShowMarkersOnGraphToggleSwitchClick(TObject *Sender);
void __fastcall OutputPowerTrackBarChange(TObject *Sender);
void __fastcall MemorySpeedButtonClick(TObject *Sender);
void __fastcall MarkerListBoxDblClick(TObject *Sender);
void __fastcall GraphPaintBoxMouseEnter(TObject *Sender);
void __fastcall SetScanRangeToVNAScanRangeBitBtnClick(TObject *Sender);
void __fastcall MarkerListBoxMouseDown(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y);
void __fastcall Deselectmarker1Click(TObject *Sender);
void __fastcall Deletemarker1Click(TObject *Sender);
void __fastcall GraphPaintBoxDblClick(TObject *Sender);
void __fastcall Addmarker1Click(TObject *Sender);
void __fastcall DeviceComboBoxChange(TObject *Sender);
void __fastcall ConnectDisconnectSpeedButtonClick(TObject *Sender);
void __fastcall SweepNameEditChange(TObject *Sender);
void __fastcall FormShow(TObject *Sender);
void __fastcall RecordSpeedButtonClick(TObject *Sender);
void __fastcall RecordSpeedButtonMouseDown(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y);
void __fastcall FreqEditChange(TObject *Sender);
void __fastcall NewGraphBitBtnClick(TObject *Sender);
void __fastcall Panel2Resize(TObject *Sender);
void __fastcall CloseBitBtnClick(TObject *Sender);
void __fastcall ScanSpeedButtonClick(TObject *Sender);
void __fastcall UploadFirmwareBitBtnClick(TObject *Sender);
void __fastcall SettingsBitBtnClick(TObject *Sender);
void __fastcall BatteryVoltageBitBtnClick(TObject *Sender);
void __fastcall CaptureVNAScreenBitBtnClick(TObject *Sender);
void __fastcall VNACommsBitBtnClick(TObject *Sender);
void __fastcall VNAUsartCommsBitBtnClick(TObject *Sender);
void __fastcall CalibrationBitBtnClick(TObject *Sender);
void __fastcall Setasstartfrequency1Click(TObject *Sender);
void __fastcall Setasstopfrequency1Click(TObject *Sender);
void __fastcall Setascenterfrequency1Click(TObject *Sender);
void __fastcall FormMouseEnter(TObject *Sender);
void __fastcall InfoPanelToggleSwitchClick(TObject *Sender);
void __fastcall FormMouseWheel(TObject *Sender, TShiftState Shift, int WheelDelta,
TPoint &MousePos, bool &Handled);
void __fastcall SetNormaliseButtonClick(TObject *Sender);
void __fastcall Showmaxmarker1Click(TObject *Sender);
void __fastcall Showminmarker1Click(TObject *Sender);
void __fastcall Automaxscale1Click(TObject *Sender);
void __fastcall Autominscale1Click(TObject *Sender);
void __fastcall Setmaxscale1Click(TObject *Sender);
void __fastcall Setminscale1Click(TObject *Sender);
void __fastcall TCPIPAddressPortEditChange(TObject *Sender);
void __fastcall MarkersListBoxPopupMenuPopup(TObject *Sender);
void __fastcall Deltamarker1Click(TObject *Sender);
void __fastcall Deltamarker2Click(TObject *Sender);
void __fastcall Setmarkerfrequency1Click(TObject *Sender);
void __fastcall Allgraphs1Click(TObject *Sender);
void __fastcall Graph11Click(TObject *Sender);
void __fastcall Graph21Click(TObject *Sender);
void __fastcall Graph31Click(TObject *Sender);
void __fastcall Graph41Click(TObject *Sender);
void __fastcall Alltraces1Click(TObject *Sender);
void __fastcall Trace11Click(TObject *Sender);
void __fastcall Trace21Click(TObject *Sender);
void __fastcall ShowMarkerTextToggleSwitchClick(TObject *Sender);
void __fastcall Showminmaxtext1Click(TObject *Sender);
void __fastcall GraphTypePopupMenuPopup(TObject *Sender);
void __fastcall Deletemarker2Click(TObject *Sender);
void __fastcall Addmarker2Click(TObject *Sender);
void __fastcall GraphArrangeClick(TObject *Sender);
void __fastcall OnGraphArrangeMeasureItem(TObject *Sender, TCanvas *ACanvas,
int &Width, int &Height);
void __fastcall OnMenuItemDraw(TObject *Sender, TCanvas *ACanvas, TRect &ARect,
bool Selected);
void __fastcall MedianFilterTrackBarChange(TObject *Sender);
void __fastcall Scaletomaxvalue1Click(TObject *Sender);
void __fastcall Scaletominvalue1Click(TObject *Sender);
void __fastcall Deleteallmarkers1Click(TObject *Sender);
void __fastcall GraphPaintBoxGesture(TObject *Sender, const TGestureEventInfo &EventInfo,
bool &Handled);
void __fastcall MemoryPopupMenuPopup(TObject *Sender);
void __fastcall SetScanRangeFromMemory1Click(TObject *Sender);
void __fastcall MemorySpeedButtonMouseDown(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y);
void __fastcall LoadMemoryFromFile1Click(TObject *Sender);
void __fastcall SetMemory1Click(TObject *Sender);
void __fastcall ClearMemory1Click(TObject *Sender);
void __fastcall TraceLPFTrackBarChange(TObject *Sender);
void __fastcall Cliptraces1Click(TObject *Sender);
void __fastcall Scaletominmaxvalues1Click(TObject *Sender);
void __fastcall Showmarkers1Click(TObject *Sender);
void __fastcall Snaptonearestpoint1Click(TObject *Sender);
void __fastcall Autoscalepeakhold1Click(TObject *Sender);
void __fastcall NumberOfPointsComboBoxChange(TObject *Sender);
void __fastcall PointBandwidthHzComboBoxChange(TObject *Sender);
void __fastcall StatusBarMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift,
int X, int Y);
void __fastcall Copyimage1Click(TObject *Sender);
void __fastcall SaveGraphImageBitBtnClick(TObject *Sender);
void __fastcall SaveS1PFileBitBtnClick(TObject *Sender);
void __fastcall Save2PFileBitBtnClick(TObject *Sender);
void __fastcall SaveCSVFileBitBtnClick(TObject *Sender);
void __fastcall CopyGraphImageBitBtnClick(TObject *Sender);
void __fastcall StopScanBitBtnClick(TObject *Sender);
void __fastcall DeleteFrequencyMarkersBitBtnClick(TObject *Sender);
void __fastcall SpareBitBtnClick(TObject *Sender);
void __fastcall Memoryname1Click(TObject *Sender);
void __fastcall Clearmemoryname1Click(TObject *Sender);
void __fastcall EnableNormaliseSpeedButtonClick(TObject *Sender);
void __fastcall HistoryTrackBarChange(TObject *Sender);
void __fastcall MemorySpeedButtonMouseUp(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y);
void __fastcall BitBtn1Click(TObject *Sender);
void __fastcall CalibrationSelectComboBoxChange(TObject *Sender);
void __fastcall CWModeSpeedButtonClick(TObject *Sender);
void __fastcall GLPanelResize(TObject *Sender);
void __fastcall GLPanelDblClick(TObject *Sender);
void __fastcall GLPanelEndDrag(TObject *Sender, TObject *Target, int X, int Y);
void __fastcall GLPanelGesture(TObject *Sender, const TGestureEventInfo &EventInfo,
bool &Handled);
void __fastcall GLPanelMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift,
int X, int Y);
void __fastcall GLPanelMouseLeave(TObject *Sender);
void __fastcall GLPanelMouseMove(TObject *Sender, TShiftState Shift, int X,
int Y);
void __fastcall GLPanelMouseEnter(TObject *Sender);
void __fastcall GLPanelMouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift,
int X, int Y);
private:
int m_screen_width;
int m_screen_height;
// TWindowState m_window_state;
int m_window_not_minimized_count;
bool m_initialised;
int m_memory_but_index;
int m_popup_menu_memory_index;
int m_popup_menu_graph_type_graph;
int m_popup_menu_mouse_graph;
int64_t m_popup_menu_mouse_Hz;
int m_popup_menu_mouse_marker;
int m_popup_menu_marker_index;
std::vector <TColor> m_info_panel_colours;
CMainFormThread *m_thread;
bool __fastcall startThread();
void __fastcall stopThread();
CGraphs graphs;
#ifdef GraphUnitH
std::vector <TGraphForm *> m_graph_form;
#endif
struct
{
CCriticalSectionObj cs;
std::vector <String> list;
} m_comm_messages;
struct
{
bool enabled;
String folder;
String filename;
int file_number;
// std::vector <t_data_point> points;
} m_record;
std::vector <HDEVNOTIFY> m_notification_handle;
CHighResolutionTick m_button_timer;
// **********
/*
std::vector <t_usb_device> usb_devices;
DFU_FUNCTIONAL_DESCRIPTOR m_DfuDesc;
UINT m_DfuInterfaceIdx;
UINT m_NbOfAlternates;
USB_DEVICE_DESCRIPTOR m_DeviceDesc;
*/
// **********
void __fastcall myTerminate();
void __fastcall onIdle(TObject *Sender, bool &done);
void __fastcall onRestore(TObject *Sender);
void __fastcall fetchResource(AnsiString name, std::vector <uint8_t> &buffer);
void __fastcall sortMarkers();
bool __fastcall updateInfoPanel2(const int graph);
void __fastcall updateInfoPanel();
void __fastcall poll();
//void __fastcall updateComboDropDownWidth(TComboBox *cb, bool add_scrollbar_allowance);
#if (__BORLANDC__ < 0x0600)
void __fastcall OnShowHint(AnsiString &HintStr, bool &CanShow, THintInfo &HintInfo);
#else
void __fastcall OnShowHint(String &HintStr, bool &CanShow, THintInfo &HintInfo);
#endif
void __fastcall OnHint(TObject *Sender);
void __fastcall WndProc(TMessage &msg);
void __fastcall ActiveFormChanged(TObject *Sender);
void __fastcall ActiveControlChanged(TObject *Sender);
void __fastcall createGraphTypeMenus();
void __fastcall saveSettings();
void __fastcall updateDeviceComboBox();
void __fastcall tcpipClientDisconnect();
void __fastcall processEDelayEdit();
void __fastcall processS21OffsetEdit();
bool __fastcall processStartMHzEdit(const bool update_other_edits, const bool update_own_edit);
bool __fastcall processStopMHzEdit(const bool update_other_edits, const bool update_own_edit);
bool __fastcall processCenterMHzEdit(const bool update_other_edits, const bool update_own_edit);
bool __fastcall processSpanMHzEdit(const bool update_other_edits, const bool update_own_edit);
bool __fastcall processCWMHzEdit(const bool update_other_edits, const bool update_own_edit);
bool __fastcall processPointBandwidthHzComboBox();
bool __fastcall processNumberOfPointsComboBox();
void __fastcall init();
void __fastcall configGUI();
void __fastcall updatePointBandwidthComboBox(const bool create = false);
void __fastcall updateNumberOfPointsComboBox(const bool process = true);
void __fastcall updateVelocityFactorComboBox();
void __fastcall updateCalibrationSelectComboBox();
void __fastcall updateOutputPowerTrackBar(const int value);
void __fastcall updateEDelayEdit();
void __fastcall updateS21OffsetEdit();
void __fastcall updateStepDisplay();
bool __fastcall scanUSB(const GUID guid, const uint16_t vid, const uint16_t pid);
void __fastcall OnDeviceChange(TMessage &msg);
void __fastcall WMWindowPosChanging(TWMWindowPosChanging &msg);
void __fastcall WMInitGUI(TMessage &msg);
void __fastcall WMConnect(TMessage &msg);
void __fastcall WMDisconnect(TMessage &msg);
void __fastcall WMCaptureScan(TMessage &msg);
void __fastcall WMCaptureStop(TMessage &msg);
void __fastcall WMScreenCapture(TMessage &msg);
void __fastcall WMComDeviceChanged(TMessage &msg);
void __fastcall WMUpdateEDelay(TMessage &msg);
void __fastcall WMUpdateThresholdHz(TMessage &msg);
void __fastcall WMUpdatePointBandwidth(TMessage &msg);
void __fastcall WMUpdateOutputPower(TMessage &msg);
void __fastcall WMUpdateBatteryVoltage(TMessage &msg);
void __fastcall WMNewUnitType(TMessage &msg);
void __fastcall WMNewData(TMessage &msg);
void __fastcall WMIncomingPoints(TMessage &msg);
void __fastcall WMUpdateGraph(TMessage &msg);
void __fastcall WMRebuildFonts(TMessage &msg);
void __fastcall WMUpdateInfoPanel(TMessage &msg);
void __fastcall WMGraphFormClosed(TMessage &msg);
void __fastcall WMGraphFormDestroyed(TMessage &msg);
bool __fastcall processRxLine();
void __fastcall fetchUserInput();
bool __fastcall requestCapture();
void __fastcall requestScan();
int __fastcall processRx(t_serial_buffer &serial_buffer, bool force_print);
void __fastcall processSerial();
void __fastcall threadProcess();
void __fastcall showWarnings();
void __fastcall saveFormImage();
void __fastcall saveImage(const bool to_clipboard);
// int __fastcall getNumberOfPointsUserInput();
void __fastcall updateDateTime();
void __fastcall buildMarkerListBox();
bool __fastcall recordDataStart();
void __fastcall recordDataToFile(std::vector <t_data_point> &points);
void __fastcall arrangeGraphs();
//DWORD __fastcall saveDIBToFile(IN LPCSTR filename, IN const BITMAPINFO &bmi, IN const unsigned char *pBits);
void __fastcall enterMarkerFrequency(const int index);
void __fastcall PopupMeasureItem(System::TObject *Sender, Vcl::Graphics::TCanvas *ACanvas, int &Width, int &Height);
void __fastcall MenuItemGraphTypeClick(TObject *Sender);
void __fastcall MenuItemChangeGraphTypeClick(TObject *Sender);
void __fastcall clearMemory(const int mem);
void __fastcall loadMemoryFile(const int mem);
void __fastcall setMemory(const int mem);
void __fastcall updateNumberOfPointsIndicator(const int index = -1);
void __fastcall cwPopupWindow(TObject *sender, const bool open, String title = "");
void __fastcall cwPopupWindowupdatenTrackBar(TObject *Sender);
void __fastcall cwPopupWindowOnTrackBarChange(TObject *Sender);
void __fastcall cwPopupWindowOnClick(TObject *Sender);
void __fastcall cwPopupWindowOnMouseLeave(TObject *Sender);
protected:
#pragma option push -vi-
BEGIN_MESSAGE_MAP
VCL_MESSAGE_HANDLER(WM_WINDOWPOSCHANGING, TWMWindowPosMsg, WMWindowPosChanging);
VCL_MESSAGE_HANDLER(WM_DEVICECHANGE, TMessage, OnDeviceChange);
VCL_MESSAGE_HANDLER(WM_CONNECT, TMessage, WMConnect);
VCL_MESSAGE_HANDLER(WM_DISCONNECT, TMessage, WMDisconnect);
VCL_MESSAGE_HANDLER(WM_CAPTURE_SCAN, TMessage, WMCaptureScan);
VCL_MESSAGE_HANDLER(WM_CAPTURE_STOP, TMessage, WMCaptureStop);
VCL_MESSAGE_HANDLER(WM_COM_DEVICE_CHANGED, TMessage, WMComDeviceChanged);
VCL_MESSAGE_HANDLER(WM_UPDATE_EDELAY, TMessage, WMUpdateEDelay);
VCL_MESSAGE_HANDLER(WM_UPDATE_THRESHOLD_HZ, TMessage, WMUpdateThresholdHz);
VCL_MESSAGE_HANDLER(WM_UPDATE_POINT_BANDWIDTH, TMessage, WMUpdatePointBandwidth);
VCL_MESSAGE_HANDLER(WM_UPDATE_OUTPUT_POWER, TMessage, WMUpdateOutputPower);
VCL_MESSAGE_HANDLER(WM_UPDATE_BATTERY_VOLTAGE, TMessage, WMUpdateBatteryVoltage);
VCL_MESSAGE_HANDLER(WM_NEW_UNIT_TYPE, TMessage, WMNewUnitType);
VCL_MESSAGE_HANDLER(WM_NEW_DATA, TMessage, WMNewData);
VCL_MESSAGE_HANDLER(WM_SCREEN_CAPTURE, TMessage, WMScreenCapture);
VCL_MESSAGE_HANDLER(WM_INCOMING_POINTS, TMessage, WMIncomingPoints);
VCL_MESSAGE_HANDLER(WM_UPDATE_GRAPH, TMessage, WMUpdateGraph);
VCL_MESSAGE_HANDLER(WM_REBUILD_FONTS, TMessage, WMRebuildFonts);
VCL_MESSAGE_HANDLER(WM_UPDATE_INFO_PANEL, TMessage, WMUpdateInfoPanel);
VCL_MESSAGE_HANDLER(WM_INIT_GUI, TMessage, WMInitGUI);
VCL_MESSAGE_HANDLER(WM_GRAPH_FORM_CLOSED, TMessage, WMGraphFormClosed);
VCL_MESSAGE_HANDLER(WM_GRAPH_FORM_DESTROYED, TMessage, WMGraphFormDestroyed);
END_MESSAGE_MAP(TForm)
#pragma option pop
public:
__fastcall TForm1(TComponent* Owner);
struct
{
int connect_timer_tick;
CHighResolutionTick points_speed_timer;
int points_per_sec_buf_count;
float points_per_sec_buf[9]; // history buffer .. better to be even in size (median)
float points_per_sec; // history buffer output
t_serial_buffer rx;
CHighResolutionTick rx_timer;
CHighResolutionTick link_timer;
CSerialPort serial;
#ifdef TCPIPH
CTCPIP tcpip;
#else
TIdTCPClient *tcpip;
TMemoryStream *tcpip_stream_rx;
#endif
} m_comms;
std::vector <t_data_point> m_freq_data_list;
void __fastcall clearCommMessages();
unsigned int __fastcall commMessagesCount();
void printfCommMessage(const char *fmt, ...);
void __fastcall pushCommMessage(String s);
String __fastcall pullCommMessage();
void __fastcall resetFreqArray();
bool __fastcall connected();
bool __fastcall scanning();
bool __fastcall generating();
t_mode __fastcall commsMode();
void __fastcall waitTxCommandEmpty(const DWORD max_ms)
{
if (connected())
{ // wait for the tx command queue to empty
const DWORD tick = GetTickCount();
while ((GetTickCount() - tick) < max_ms && serialCommandsSize() > 0)
Application->ProcessMessages();
}
}
int __fastcall serialCommandsSize()
{
return (connected() && data_unit.m_vna_data.type != UNIT_TYPE_NANOVNA_V2 && data_unit.m_vna_data.type != UNIT_TYPE_JANVNA_V2) ?
nanovna1_comms.serialCommandsSize() : 0;
}
void __fastcall insertSerialTxCommand(String s, const int command_ends = 0)
{
if (connected() && data_unit.m_vna_data.type != UNIT_TYPE_NANOVNA_V2 && data_unit.m_vna_data.type != UNIT_TYPE_JANVNA_V2)
nanovna1_comms.insertSerialTxCommand(s, command_ends);
}
void __fastcall addSerialTxCommand(String s, const int command_ends = 0)
{
if (connected() && data_unit.m_vna_data.type != UNIT_TYPE_NANOVNA_V2 && data_unit.m_vna_data.type != UNIT_TYPE_JANVNA_V2)
nanovna1_comms.addSerialTxCommand(s, command_ends);
}
void __fastcall addSerialTxCommand(std::vector <uint8_t> &data)
{
if (connected() && data_unit.m_vna_data.type == UNIT_TYPE_NANOVNA_V2 && data_unit.m_vna_data.type != UNIT_TYPE_JANVNA_V2 && nanovna2_comms.mode == MODE_IDLE)
nanovna2_comms.sendData(&data[0], data.size());
}
void __fastcall sendOutputPowerCommand()
{
if (connected())
{
if (data_unit.m_vna_data.type == UNIT_TYPE_JANVNA_V2)
{
const float level = (float)(OutputPowerTrackBar->Position - OutputPowerTrackBar->Min) / (OutputPowerTrackBar->Max - OutputPowerTrackBar->Min); // 0.0 to 1.0
const float dBm_max = janvna2_comms.maxOutputPowerdBm();
const float dBm_min = janvna2_comms.minOutputPowerdBm();
const float dBm = dBm_min + (ABS(dBm_max - dBm_min) * level); // dBm_min to dBm_max
janvna2_comms.setOutputPower(dBm);
}
else
if (data_unit.m_vna_data.type == UNIT_TYPE_NANOVNA_V2)
{ // V2
nanovna2_comms.setADF4350OutputPower(settings.outputPower);
}
else
{ // V1
nanovna1_comms.sendOutputPowerCommand(settings.outputPower);
}
}
}
void __fastcall sendBandwidthCommand()
{
if (connected() && data_unit.m_vna_data.type != UNIT_TYPE_NANOVNA_V2 && data_unit.m_vna_data.type != UNIT_TYPE_JANVNA_V2)
nanovna1_comms.sendBandwidthCommand();
}
void __fastcall disconnect();
void __fastcall connect();
void __fastcall scan();
void __fastcall stop();
int __fastcall fetchCommsData(const bool clear_rx_buffer);
void __fastcall setStartStopHz(int64_t low_Hz, int64_t high_Hz, bool start_scan);
void __fastcall getVNAScreenCapture();
void __fastcall addNewRxData(std::vector <t_data_point> &new_points);
void __fastcall pauseComms(bool pause);
void __fastcall addMarker(const int64_t freq_Hz, const int type = MARKER_TYPE_NORMAL, const int graph = -1, const int mem = -1, const int trace = -1);
void __fastcall deleteMarker(const int index);
void __fastcall moveMarker(const int index, const int64_t freq_Hz);
int __fastcall nonDeltaMarker(int start_index = 0);
int __fastcall selectedMarker();
void __fastcall setCalibrationSelection(t_calibration_selection cal_select);
void __fastcall updateHistoryFramesInfo(const bool update = false);
};
extern PACKAGE TForm1 *Form1;
// ******************************************************************************
#endif