-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrmMain.vb
11042 lines (9957 loc) · 567 KB
/
frmMain.vb
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
Imports System.IO
Imports DirectShowLib
Imports System.Runtime.InteropServices
Imports System.Threading
Imports System
Imports System.Globalization
Imports System.Resources
Imports System.Xml
Imports System.Data
Imports GEPlugin
Imports System.Security.Permissions
Imports System.Net.Sockets
Imports Toub.Sound.Midi
<PermissionSet(SecurityAction.Demand, Name:="FullTrust")> _
<System.Runtime.InteropServices.ComVisibleAttribute(True)> _
<ProgId("HK_GCS")> _
<ClassInterface(ClassInterfaceType.AutoDual)> _
Public Class frmMain
'Public Declare Function OleCreatePropertyFrame Lib "oleaut32.dll" (ByVal hwndOwner As IntPtr, ByVal x As Integer, ByVal y As Integer, ByVal lpszCaption As String, ByVal cObjects As Integer, ByRef ppUnk As Object, ByVal cPages As Integer, ByVal lpPageClsID As IntPtr, ByVal lcid As Integer, ByVal dwReserved As Integer, ByVal lpvReserved As IntPtr) As Integer
'Declare Function OleCreatePropertyFrame Lib "oleaut32.dll" (ByVal hwndOwner As IntPtr, ByVal x As Long, ByVal y As Long, <MarshalAs(UnmanagedType.LPWStr)> ByVal lpszCaption As String, ByVal cObjects As Integer, <MarshalAs(UnmanagedType.Interface, ArraySubType:=UnmanagedType.IUnknown)> ByRef ppUnk As System.IntPtr, ByVal cPages As Long, ByVal pPageClsID As IntPtr, ByVal lcid As Integer, ByVal dwReserved As Integer, ByVal pvReserved As IntPtr) As Integer
Declare Function OleCreatePropertyFrame Lib "oleaut32.dll" (ByVal hwndOwner As IntPtr, ByVal x As Long, ByVal y As Long, <MarshalAs(UnmanagedType.LPWStr)> ByVal lpszCaption As String, ByVal cObjects As Integer, ByRef ppUnk As Object, ByVal cPages As Long, ByVal pPageClsID As IntPtr, ByVal lcid As Integer, ByVal dwReserved As Integer, ByVal pvReserved As IntPtr) As Integer
Const g_DefaultAttoTrigger As String = "00000010"
Private mediaControl As IMediaControl = Nothing
'Private graphBuilder As IGraphBuilder = Nothing
Private theCompressor As IBaseFilter = Nothing
Public caGUID As DsCAUUID = New DsCAUUID()
Dim m_ge As IGEPlugin = Nothing
Dim ds As New System.Data.DataSet
Dim dt As New System.Data.DataTable
'Dim ds As DataSet = New DataSet
'Dim dt As DataTable = New DataTable
Dim drow As DataRow
Dim nMavlinkHandshake As e_MavlinkHandshake = e_MavlinkHandshake.e_MavlinkHandshake_None
Dim nMavlinkCurrentWaypointSend As Integer
Dim dLastMavlinkCommandTime As Long
Dim nMavlinkRetryAttempts As Integer
Dim nHomeLat As String = ""
Dim nHomeLong As String
Dim nLastGPS As Long
Dim nLastMapUpdate As Long
Dim sOutputFile As StreamWriter
Dim sOutputFileHex As StreamWriter
Dim rawData(0) As String
Dim nDataIndex As Long
Dim bLockMissionReload As Boolean = False
Dim bLockMissionCenter As Boolean = False
'Public Event AttitudeChange(ByVal pitch As Single, ByVal roll As Single, ByVal yaw As Single)
'Public Event GpsData(ByVal latitude As String, ByVal longitude As String, ByVal altitude As Single, ByVal speed As Single, ByVal heading As Single, ByVal satellites As Integer, ByVal fix As Integer, ByVal hdop As Single, ByVal verticalChange As Single)
'Public Event Waypoints(ByVal waypointNumber As Integer, ByVal distance As Single)
'Public Event RawPacket(ByVal messageString As String)
Dim baudRates() As Long = {4800, 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600}
'Dim baudRates() As Long = {38400, 57600, 19200, 9600, 115200, 4800}
'Dim nBaudRateIndex As Integer = 3
Dim nMaxListboxRecords As Integer = 300
Dim eSelectedInstrument As e_Instruments = e_Instruments.e_Instruments_None
Public bStartup As Boolean = True
Dim bButtonStateLocked As Boolean = False
Dim bNewGPS As Boolean
Dim bNewAttitude As Boolean
Dim bNewWaypoint As Boolean
Dim bNewServo As Boolean
Dim bNewDateTime As Boolean
Dim dLastAtto As Long
Dim dLastAtto2 As Long
Dim dCommandLineNew As Long
'Dim PrevNote As Integer
'Dim NoteNum As Integer
Dim oVario As cVario
Private trd As Thread
Dim dLastHeartbeat1 As Long
Dim dLastHeartbeat2 As Long
Dim dLastHeartbeat3 As Long
Dim dLastHeartbeat4 As Long
Dim dLastHeartbeat5 As Long
Dim dLastHeartbeat6 As Long
Dim dLastHeartbeatMAVlink As Long
Dim dLastHeartbeatMAVlinkJoystick As Long
Dim dLastNewDevice As Long
Dim eNewDeviceBootState As e_NewDevice_BootState
Dim nAttitudeInterval As Integer
Dim nWaypointInterval As Integer
Dim nGPSInterval As Integer
Dim nLastAttitude As Long
Dim nLastWaypoint As Long
Dim nLastSpeechInterval As Long
Dim nLastServos As Long
Dim nLastTimeDate As Long
'Dim nLastGPS As Long
Dim nLastAlt As Single
Dim nDataPoints As Long
Dim bIsRecording As Boolean = False
Dim sSelectedCamera1 As String
Dim sSelectedCamera2 As String
'Dim eOutputDistance As e_DistanceFormat
'Dim eOutputSpeed As e_SpeedFormat
Dim eOutputLatLongFormat As e_LatLongFormat = e_LatLongFormat.e_LatLongFormat_DD_DDDDDD
Dim nLastComPort As Integer
Dim bFirstPaint As Boolean = False
Dim bFirstVideoCapture1 As Boolean = False
Dim bFirstVideoCapture2 As Boolean = False
Dim nPlayerState As e_PlayerState
'Dim bWaypointExtrude As Boolean = True
'Dim sWaypointColor As String = "00ffffff"
'Dim nWaypointWidth As Integer = 1
Dim nCameraTracking As Integer
Dim nCommandLineDelim As Integer
Dim nInputStringLength As Long
Dim nLastBandwidthCheck As Long
Dim bExpandInstruments As Boolean = False
Dim bUltraSmall As Boolean = False
'Dim dl As GeneralMidiInstruments
'Private GraphBuilder2 As ICaptureGraphBuilder2 = New CaptureGraphBuilder2
'Private GraphBuilder As IGraphBuilder = New FilterGraph
'Private m_filtergraph As IFilterGraph2 = New FilterGraph
'Private CapFilter As IBaseFilter = Nothing
'Private mediaCtrl As DirectShowLib.IMediaControl = Nothing
'Private vmr9 As IBaseFilter = New VideoMixingRenderer9
'Private hr As Integer
'Private SampGrabber As ISampleGrabber = New SampleGrabber
'Private baseGrabFlt As IBaseFilter = SampGrabber
'Private windowlessCtrl As IVMRWindowlessControl9 = Nothing
'Private capGraph As ICaptureGraphBuilder2 = Nothing
Dim nTimeZoneOffset As Double
'Dim SocketServer As TCPSrv
Dim SocketServer As AsynchronousSocketListener
Public Sub ResetForm()
LoadLanguageFile()
Me.Text = "HK's " & GetResString(, "Ground_Control_Station") & " - Lite - " & Version
GetResString(mnuFile, "File")
GetResString(mnuSettings, "Settings")
GetResString(mnuExit, "Exit_Label")
GetResString(mnuHelp, "Help")
GetResString(mnuOpenHomepage, "Open_Homepage")
GetResString(mnuOpenDownloads, "Open_Downloads")
GetResString(mnuAbout, "About")
GetResString(tabInstruments, "Instruments")
GetResString(tabSerialData, "Serial Data")
GetResString(tabCommandLine, "Command Line")
GetResString(tabInstrumentLiveCamera, "Live Camera")
GetResString(tabViewMapView, "Map View")
GetResString(tabViewLiveCamera, "Live Camera")
GetResString(cmdZeroYaw, "Zero Yaw")
GetResString(lblRawData, "Raw Data")
GetResString(lblTranslatedData, "Translated Data")
GetResString(grpSerialSettings, "Serial Settings")
GetResString(lblMaxAttitude, "Max Attitude")
GetResString(lblMaxGPS, "Max GPS")
GetResString(lblMaxWaypoint, "Max Waypoint")
GetResString(cmdCommandLineSend, "Send")
GetResString(chkCommandLineAutoScroll, "Auto Scroll")
GetResString(cmdLiveCameraProperties1, "Properties")
GetResString(cmdLiveCameraProperties2, "Properties")
GetResString(chkViewNoTracking, "No Tracking")
GetResString(chkViewOverhead, "Overhead")
GetResString(chkViewChaseCam, "Chase Cam")
GetResString(chkViewFirstPerson, "First Person")
GetResString(cmdCenterOnPlane, "Center On Plane")
GetResString(cmdSetHome, "Set Home")
GetResString(cmdClearMap, "Clear Map")
GetResString(cmdExit, "Exit_Label")
GetResString(tabPortComPort, "COM Port")
GetResString(tabPortDataFile, "Data File")
'GetResString(tabPortTracking, "Tracking")
GetResString(tabPortServos, "Servos")
GetResString(tabPortSensors, "Sensors")
'COM Port
GetResString(lblComPort, "COM Port", True)
If cboComPort.Text = "TCP" Or cboComPort.Text = "UDP" Then
GetResString(lblBaudRate, "Socket_Num", True)
Else
GetResString(lblBaudRate, "Baud Rate", True)
End If
GetResString(lblGPSTypeLabel, "GPS Type", True)
GetResString(lblGPSMessageLabel, "GPS Message", True)
GetResString(lblStatusLabel, "Status", True)
'GetResString(cmdSearch, "Search Baud")
'GetResString(cmdSearchCOM, "Search COM")
If serialPortIn.IsOpen = True Then
GetResString(cmdConnect, "Disconnect")
Else
GetResString(cmdConnect, "Connect")
End If
'Tracking
GetResString(lblComPortTracking, "COM Port", True)
GetResString(lblBaudRateTracking, "Baud Rate", True)
'GetResString(lblOutputTypeTracking, "Protocol", True)
'GetResString(lblHertzTracking, "Hertz", True)
GetResString(lblStatusLabel, "Status", True)
If serialPortTracking.IsOpen = True Then
GetResString(cmdConnectTracking, "Disconnect")
Else
GetResString(cmdConnectTracking, "Connect")
End If
ToolTip1.SetToolTip(cmdReloadComPorts, GetResString(, "Reload_Com_Port_List"))
ToolTip1.SetToolTip(cmdReloadOutputFileList, GetResString(, "Reload_Output_File_List"))
GetResString(cmdReloadOutputFileList, "Reload_Letter")
GetResString(cmdViewFile, "View File")
ToolTip1.SetToolTip(chkPlay, GetResString(, "Play"))
ToolTip1.SetToolTip(chkPause, GetResString(, "Pause"))
ToolTip1.SetToolTip(chkFullDataFile, GetResString(, "Draw_Full_Mission"))
GetResString(chkFullDataFile, GetResString(, "Full"))
ToolTip1.SetToolTip(chkReverse, GetResString(, "Rewind_To_Beginning"))
ToolTip1.SetToolTip(chkStepBack, GetResString(, "Step Back"))
ToolTip1.SetToolTip(chkStepForward, GetResString(, "Step Forward"))
ToolTip1.SetToolTip(cmdOutputFolder, GetResString(, "Select_Data_File_Directory"))
GetResString(lblMissionLabel, "Mission", True)
ToolTip1.SetToolTip(cmdReloadMissionDirectory, GetResString(, "Reload_Mission"))
GetResString(cmdReloadMissionDirectory, "Reload_Letter")
ToolTip1.SetToolTip(cmdReloadMissions, GetResString(, "Reload_Mission_Directory"))
GetResString(lblGPSLockLabel, "GPS Lock", True)
GetResString(lblSatellitesLabel, "Satellites", True)
GetResString(lblModeLabel, "Mode", True)
GetResString(lblThrottleLabel, "Throttle", True)
GetResString(lblWaypointLabel, "Waypoint", True)
GetResString(lblDistanceLabel, "Distance", True)
GetResString(lblTargetAltLabel, "Target Alt", True)
GetResString(lblBatteryLabel, "Battery", True)
GetResString(lblAmpsLabel, "Amps", True)
GetResString(lblHDOPLabel, "HDOP", True)
GetResString(lblLatitudeLabel, "Latitude", True)
GetResString(lblLongitudeLabel, "Longitude", True)
GetResString(lblRunTimeLabel, "Run Time", True)
GetResString(lblDatapointsLabel, "Data Points", True)
ToolTip1.SetToolTip(cmdResetRuntime, GetResString(, "Reset_Run_Timer"))
ToolTip1.SetToolTip(tbarModelScale, GetResString(, "Change_Model_Scale"))
lblMissionAttoAltUnits.Text = GetDistanceUnitsText()
lblMissionAttoSpeedUnits.Text = GetSpeedUnitsText()
lblMissionDefaultAltLabel.Text = GetDistanceUnitsText()
lblMissionAttoDefaultSpeedLabel.Text = GetSpeedUnitsText()
lblControlAttoSetSpeedUnit.Text = GetSpeedUnitsText()
If bStartup = False Then
ResizeForm()
End If
End Sub
Public Sub LoadGEFeatures()
If Not webDocument Is Nothing And bGoogleLoaded = True Then
webDocument.InvokeScript("setFeatures", New Object() {bGEBorders, bGEBuildings, bGERoads, bGETerrain, bGETrees})
End If
End Sub
Private Sub SetPlayerState(ByVal newState As e_PlayerState, Optional ByVal fileExists As Boolean = False, Optional ByVal fullPlay As Boolean = False)
Dim bRecord As Boolean
Dim bPlay As Boolean
Dim bPause As Boolean
Dim bReverse As Boolean
Dim bFastForward As Boolean
Dim bStepReverse As Boolean
Dim bStepForward As Boolean
Dim bLoaded As Boolean
Dim bRecordReady As Boolean
Dim bFullPlay As Boolean
nAltChange = 0
nPlayerState = newState
bFullPlay = fullPlay
Select Case nPlayerState
Case e_PlayerState.e_PlayerState_None
bRecord = False
bPlay = False
bPause = False
bReverse = False
bFastForward = False
bStepReverse = False
bStepForward = False
bLoaded = False
bRecordReady = False
bFullPlay = False
Case e_PlayerState.e_PlayerState_Loaded
bRecord = False
bPlay = False
bPause = False
bReverse = False
bFastForward = False
bStepReverse = False
bStepForward = False
bLoaded = True
bRecordReady = True
bFullPlay = False
Case e_PlayerState.e_PlayerState_RecordReady
bRecord = False
bPlay = False
bPause = False
bReverse = False
bFastForward = False
bStepReverse = False
bStepForward = False
bLoaded = False
bRecordReady = True
bFullPlay = False
Case e_PlayerState.e_PlayerState_Play
bRecord = False
bPlay = True
bPause = False
bReverse = False
bFastForward = False
bStepReverse = False
bStepForward = False
bLoaded = True
bRecordReady = False
Case e_PlayerState.e_PlayerState_Record
bRecord = True
bPlay = False
bPause = False
bReverse = False
bFastForward = False
bStepReverse = False
bStepForward = False
bLoaded = fileExists
bRecordReady = True
bFullPlay = False
Case e_PlayerState.e_PlayerState_Pause, e_PlayerState.e_PlayerState_StepBack, e_PlayerState.e_PlayerState_StepForward
bRecord = False
bPlay = False
bPause = True
bReverse = False
bFastForward = False
bStepReverse = False
bStepForward = False
bLoaded = True
bRecordReady = True
bFullPlay = False
End Select
If bRecord = True Then
nDataIndex = 0
TrackBar1.Value = 0
End If
bButtonStateLocked = True
chkRecord.Checked = bRecord
chkPlay.Checked = bPlay
chkPause.Checked = bPause
chkReverse.Checked = bReverse
chkStepBack.Checked = False
chkStepForward.Checked = False
chkFullDataFile.Checked = bFullPlay
chkDataFileSaveBinary.Enabled = Not bRecord
chkRecord.Enabled = bRecordReady
chkPlay.Enabled = bLoaded
chkPause.Enabled = bLoaded
chkReverse.Enabled = bLoaded
If bLoaded = True And nDataIndex > 1 Then
chkStepBack.Enabled = bLoaded
Else
chkStepBack.Enabled = False
End If
If bLoaded = True And nDataIndex < UBound(rawData) Then
chkStepForward.Enabled = bLoaded
Else
chkStepForward.Enabled = False
End If
chkFullDataFile.Enabled = bLoaded
If bRecord = True Then
chkRecord.Image = My.Resources.AvionicsInstrumentsControlsRessources.StopRed
ToolTip1.SetToolTip(chkRecord, GetResString(, "Stop Recording"))
Else
chkRecord.Image = My.Resources.AvionicsInstrumentsControlsRessources.Record
ToolTip1.SetToolTip(chkRecord, GetResString(, "Record"))
End If
cmdViewFile.Enabled = bLoaded
TrackBar1.Enabled = bLoaded
bButtonStateLocked = False
End Sub
Private Sub FormClosing(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles Me.Closing
Me.Dispose()
End Sub
Private Sub frmMain_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
If bInstruments(e_Instruments.e_Instruments_3DModel) = True Then
_3DMesh1.UpdateModel(GetPitch(nPitch * n3DPitchRollOffset), GetRoll(nRoll * n3DPitchRollOffset), GetYaw(nYaw + n3DHeadingOffset), True, sModelName, GetRootPath() & "3D Models\")
'System.Diagnostics.Debug.Print("Actvated " & Now)
End If
End Sub
Private Sub frmMain_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Disposed
Try
bShutdown = True
tmrSearch.Enabled = False
tmrComPort.Enabled = False
tmrJoystick.Enabled = False
tmrPlayback.Enabled = False
If chkVarioenable.Checked = True Then
oVario.StopSound()
End If
tmrTracking.Enabled = False
If Not sOutputFile Is Nothing Then
sOutputFile.Close()
sOutputFile = Nothing
End If
If Not SocketServer Is Nothing Then
SocketServer.CloseAll()
End If
If serialPortIn.IsOpen = True Then
serialPortIn.Close()
End If
IsProcessRunning("HK_Tiny", True)
Catch e2 As Exception
End Try
End Sub
Public Sub SetupWebBroswer()
Select Case eMapSelection
Case e_MapSelection.e_MapSelection_GoogleEarth
WebBrowser1.DocumentText = Replace(My.Resources.GoogleResources.pluginhost.ToString, "<GoogleEarthKey>", sGoogleEarthKey)
Case e_MapSelection.e_MapSelection_GoogleMaps
WebBrowser1.DocumentText = My.Resources.GoogleResources.Maps.ToString
Case e_MapSelection.e_MapSelection_None
webDocument = Nothing
WebBrowser1.DocumentText = ""
WebBrowser1.ObjectForScripting = Nothing
WebBrowser1.Visible = False
End Select
If eMapSelection <> e_MapSelection.e_MapSelection_None Then
webDocument = WebBrowser1.Document
WebBrowser1.ObjectForScripting = Me
WebBrowser1.Visible = True
'While WebBrowser1.ReadyState <> 4
'Application.DoEvents()
'System.Threading.Thread.Sleep(20)
'End While
If eMapSelection = e_MapSelection.e_MapSelection_GoogleMaps Then
'webDocument.GetElementById("lockDragDrop").SetAttribute("value", "Locked")
End If
End If
End Sub
Public Sub JSInitSuccessCallback_(ByVal pluginInstance As Object)
m_ge = pluginInstance
'WebBrowser1.Invoke(New MyDelegate(AddressOf buildPlaneModel))
bGoogleLoaded = True
bGoogleFailed = False
cmdConnect.Enabled = True
cboOutputFiles.Enabled = True
chkViewChaseCam.Checked = True
LoadGEFeatures()
End Sub
Public Sub JSInitErrorCallback_(ByVal errorObj As Object)
Debug.Print(errorObj.ToString())
If errorObj.ToString() = "ERR_API_KEY" Then
webDocument = Nothing
WebBrowser1.Dispose()
WebBrowser1.ObjectForScripting = Nothing
eMapSelection = e_MapSelection.e_MapSelection_None
End If
End Sub
Public Sub JSGoogleLoadFail_()
bGoogleLoaded = False
bGoogleFailed = True
cmdConnect.Enabled = True
cboOutputFiles.Enabled = True
SetMapMode()
End Sub
Public Sub JSClick_(ByVal index As String)
Dim nIndex As Integer
Dim sTemp As String
Dim firstVisibleRow As Integer
Dim lastVisibleRow As Integer
bLockMissionCenter = True
sTemp = index.Substring(0, InStrRev(index, ".") - 1)
If sTemp.Substring(Len(sTemp) - 1) = "H" Then
nIndex = 0
Else
nIndex = Convert.ToInt32(sTemp.Substring(Len(sTemp) - 2))
End If
dgMission.Rows(nIndex).Selected = True
firstVisibleRow = dgMission.HitTest(dgMission.RowTemplate.Height, dgMission.Columns(0).Width).RowIndex
lastVisibleRow = firstVisibleRow + dgMission.DisplayedRowCount(False)
If nIndex < firstVisibleRow Or nIndex > lastVisibleRow Then
dgMission.FirstDisplayedScrollingRowIndex = nIndex
End If
bLockMissionCenter = False
End Sub
Public Sub JSHomeAlt_(ByVal altitude As Single, ByVal offset As Integer)
lblMissionHomeAlt.Text = "Home Alt:" & ConvertDistance(altitude.ToString("0.00"), e_DistanceFormat.e_DistanceFormat_Meters, eDistanceUnits) '& ",Offset:" & offset
End Sub
'Public Sub JSGoogleLicenseFail_()
' Debug.Print("Failed")
' 'WebBrowser1.Stop()
'End Sub
Public Sub AddWaypoint(ByVal latitude As String, ByVal longitude As String, ByVal altitude As String, Optional ByVal speed As Single = -1, Optional ByVal trigger As String = g_DefaultAttoTrigger, Optional ByVal commandValue As Integer = -1, Optional ByVal otherValue As String = "")
Dim nIndex As Integer
'Dim sTemp As String
Dim nCount As Integer
Dim bPrevValue As Boolean
'If tabInstrumentView.SelectedIndex = 4 Then
bPrevValue = bLockMissionCenter
bLockMissionCenter = True
nWPCount = nWPCount + 1
RedimWaypointArray(nWPCount)
If chkMissionInsert.Checked = True And dgMission.SelectedRows.Count > 0 Then
nIndex = dgMission.SelectedRows(0).Index
For nCount = nWPCount - 1 To nIndex Step -1
SwapArrayGroup(nCount, nCount + 1)
Next
Else
nIndex = nWPCount
End If
'If nConfigDevice = e_ConfigDevice.e_ConfigDevice_AttoPilot Or nConfigDevice = e_ConfigDevice.e_ConfigDevice_Generic Then
If latitude <> "" Then
aWPLat(nIndex) = Convert.ToDouble(latitude).ToString(sConfigFormatString)
End If
If longitude <> "" Then
aWPLon(nIndex) = Convert.ToDouble(longitude).ToString(sConfigFormatString)
End If
If altitude <> "" Then
aWPAlt(nIndex) = altitude.ToString
End If
'ElseIf nConfigDevice = e_ConfigDevice.e_ConfigDevice_MAVlink Then
'aWPLat(nIndex) = latitude
'aWPLon(nIndex) = longitude
'aWPAlt(nIndex) = altitude
'End If
aWPTrigger(nIndex) = trigger
If speed = -1 Then
aWPSpeed(nIndex) = txtMissionAttoDefaultSpeed.Text
Else
aWPSpeed(nIndex) = speed
End If
If commandValue <> -1 Then
aWPCommand(nIndex) = commandValue
Else
aWPCommand(nIndex) = 16
End If
aWPOther(nIndex) = otherValue
nNewWaypoint = nIndex
LoadMissionGrid(nIndex)
UpdateMissionGE(nIndex)
bLockMissionCenter = bPrevValue
'End If
End Sub
Public Sub JSDoubleClick_(ByVal latitude As String, ByVal longitude As String)
Dim aOutput() As Byte
Dim nGuidedAlt As Single
If nConfigDevice <> e_ConfigDevice.e_ConfigDevice_MAVlink Or bMavLinkGuided = False Then
AddWaypoint(latitude, longitude, Convert.ToSingle(txtMissionDefaultAlt.Text), txtMissionAttoDefaultSpeed.Text, g_DefaultAttoTrigger)
chkViewNoTracking.Checked = True
chkViewNoTracking_CheckedChanged(Nothing, Nothing)
bLockMissionCenter = False
If nWPCount >= nNewWaypoint Then
'CenterAndTilt(nWaypoint, 0)
' 'UpdateMissionGE(nWaypoint, , 0)
End If
Else
aOutput = New Byte() {85, 36, 0, g_GCS_System_ID, g_GCS_Component_ID, 39, nConfigVehicle, 1}
aOutput = ConCatArray(aOutput, ConvertIntegerToMavlinkByte(1))
'If chkMissionMavlinkAltOffset.Visible = True Then
' If chkMissionMavlinkAltOffset.Checked = True Then
' aOutput = ConCatArray(aOutput, New Byte() {0})
' Else
aOutput = ConCatArray(aOutput, New Byte() {3})
'End If
' Else
'aOutput = ConCatArray(aOutput, New Byte() {0})
' End If
aOutput = ConCatArray(aOutput, New Byte() {17, 2, 1})
aOutput = ConCatArray(aOutput, New Byte() {0, 0, 0, 0})
aOutput = ConCatArray(aOutput, New Byte() {0, 0, 0, 0})
aOutput = ConCatArray(aOutput, New Byte() {0, 0, 0, 0})
aOutput = ConCatArray(aOutput, New Byte() {0, 0, 0, 0})
aOutput = ConCatArray(aOutput, ConvertSingleToMavlinkByte(latitude)) 'Lat
aOutput = ConCatArray(aOutput, ConvertSingleToMavlinkByte(longitude)) 'Long
If IsNumeric(txtControlMavlinkGuidedAlt.Text) = False Then
nGuidedAlt = 200
Else
nGuidedAlt = Convert.ToSingle(txtControlMavlinkGuidedAlt.Text)
End If
aOutput = ConCatArray(aOutput, ConvertSingleToMavlinkByte(nGuidedAlt)) 'Alt
SendMavLink(aOutput, "Guided Command")
Debug.Print("Sent Guided Command Alt=" & nGuidedAlt)
webDocument.InvokeScript("setGuidedDest", New Object() {latitude, longitude})
End If
End Sub
Public Sub JSDragDrop_(ByVal iconString As String, ByVal latitude As String, ByVal longitude As String, ByVal altitude As Single)
Dim nIndex As Integer
Dim sTemp As String
Dim bPrevValue As Boolean
bPrevValue = bLockMissionCenter
bLockMissionCenter = True
sTemp = iconString.Substring(0, InStrRev(iconString, ".") - 1)
If sTemp.Substring(Len(sTemp) - 1) = "H" Then
nIndex = 0
Else
nIndex = Convert.ToInt32(sTemp.Substring(Len(sTemp) - 2))
End If
aWPLat(nIndex) = Convert.ToDouble(latitude).ToString(sConfigFormatString)
aWPLon(nIndex) = Convert.ToDouble(longitude).ToString(sConfigFormatString)
'aWPAlt(nIndex) = Convert.ToDouble(altitude).ToString("0.00")
If dgMission.RowCount > nIndex Then
If tabInstrumentView.SelectedIndex = 4 Then
LoadMissionGrid(nIndex)
UpdateMissionGE(nIndex, , 0)
Else
LoadMissionGrid()
UpdateMissionGE()
End If
End If
lblMissionHomeAlt.Text = "Home Alt:" & ConvertDistance(altitude.ToString("0.00"), e_DistanceFormat.e_DistanceFormat_Meters, eDistanceUnits) '& ",Offset:" & offset
bLockMissionCenter = bPrevValue
End Sub
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim nCount As Integer
Dim nTop As Long
Dim nLeft As Long
Dim nWidth As Long
Dim nHeight As Long
Dim nSplitter As Long
'Dim aLanguages() As String
oActiveDevices = New cActiveDevices
oActiveDevices.Initialize()
sLanguageFile = GetRegSetting(sRootRegistry & "\Settings", "Language File", "Default")
serialPortIn.Encoding = System.Text.Encoding.GetEncoding(28591)
'serialPortIn.Encoding = System.Text.Encoding.Default
'serialPortIn.Encoding = System.Text.Encoding.GetEncoding(1252)
Try
'Call SaveRegSetting("TypeLib\{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}\1.1\0\win32", "", Environment.GetEnvironmentVariable("WINDIR") & "\system32\ieframe.dll", Microsoft.Win32.RegistryHive.ClassesRoot)
'Call SaveRegSetting("TypeLib\{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}\1.1\0\win32", "", "", Microsoft.Win32.RegistryHive.ClassesRoot)
Call SaveRegSetting("Software\Microsoft\Windows\CurrentVersion\Internet Settings\Cache", "Persistent", 1, Microsoft.Win32.RegistryHive.CurrentUser, Microsoft.Win32.RegistryValueKind.DWord)
Catch
End Try
Me.Visible = False
LoadSettings()
ResetForm()
bStartup = True
frmAbout.bIsSplash = True
frmAbout.Show()
nTimeZoneOffset = DateDiff(DateInterval.Hour, Now, Now.ToUniversalTime)
If Screen.PrimaryScreen.Bounds.Height = 600 And Screen.PrimaryScreen.Bounds.Width = 1024 Then
nWidth = GetRegSetting(sRootRegistry & "\Settings", "Form Width", 900)
nHeight = GetRegSetting(sRootRegistry & "\Settings", "Form Height", 550)
nTop = GetRegSetting(sRootRegistry & "\Settings", "Form Top", 0)
nLeft = GetRegSetting(sRootRegistry & "\Settings", "Form Left", 0)
nSplitter = GetRegSetting(sRootRegistry & "\Settings", "Splitter Location 0", 497)
Else
nWidth = GetRegSetting(sRootRegistry & "\Settings", "Form Width", 1100)
nHeight = GetRegSetting(sRootRegistry & "\Settings", "Form Height", 675)
nTop = GetRegSetting(sRootRegistry & "\Settings", "Form Top", Screen.PrimaryScreen.WorkingArea.Height / 2 - nHeight / 2)
nLeft = GetRegSetting(sRootRegistry & "\Settings", "Form Left", Screen.PrimaryScreen.WorkingArea.Width / 2 - nWidth / 2)
nSplitter = GetRegSetting(sRootRegistry & "\Settings", "Splitter Location 0", 590)
End If
bUTCTime = GetRegSetting(sRootRegistry & "\Settings", "UTC Time", False)
If nWidth > Screen.PrimaryScreen.WorkingArea.Width Then
nWidth = Screen.PrimaryScreen.WorkingArea.Width
End If
If nHeight > Screen.PrimaryScreen.WorkingArea.Height Then
nHeight = Screen.PrimaryScreen.WorkingArea.Width
End If
SplitContainer1.Panel1MinSize = 320
LaunchTinyWeb()
If Screen.PrimaryScreen.Bounds.Height = 600 And Screen.PrimaryScreen.Bounds.Width = 1024 Then
eSelectedInstrument = GetRegSetting(sRootRegistry & "\Settings", "Selected Instrument", e_Instruments.e_Instruments_3DModel)
Else
eSelectedInstrument = GetRegSetting(sRootRegistry & "\Settings", "Selected Instrument", e_Instruments.e_Instruments_None)
End If
sSelectedCamera1 = GetRegSetting(sRootRegistry & "\Settings", "Selected Camera 1", "")
sSelectedCamera2 = GetRegSetting(sRootRegistry & "\Settings", "Selected Camera 2", "")
frmAbout.UpdateStatus(GetResString(, "Building_Map_Files"), 10)
'If Dir(GetRootPath() & "Maps.html") = "" Then
' Dim sFileContents As String = HK_GCS.My.Resources.GoogleResources.Maps.ToString
' Dim fs As New FileStream(GetRootPath() & "Maps.html", FileMode.Create, FileAccess.Write)
' Dim sMapsFile As StreamWriter = New StreamWriter(fs)
' sMapsFile.WriteLine(sFileContents)
' sMapsFile.Close()
'End If
If Dir(GetRootPath() & "Missions", FileAttribute.Directory) = "" Then
MkDir(GetRootPath() & "Missions")
End If
Try
InitServoCombos()
cboServo1.SelectedIndex = GetRegSetting(sRootRegistry & "\Settings\Servo", "1", 1)
cboServo2.SelectedIndex = GetRegSetting(sRootRegistry & "\Settings\Servo", "2", 2)
cboServo3.SelectedIndex = GetRegSetting(sRootRegistry & "\Settings\Servo", "3", 3)
cboServo4.SelectedIndex = GetRegSetting(sRootRegistry & "\Settings\Servo", "4", 4)
cboServo5.SelectedIndex = GetRegSetting(sRootRegistry & "\Settings\Servo", "5", 9)
cboServo6.SelectedIndex = GetRegSetting(sRootRegistry & "\Settings\Servo", "6", 10)
cboServo7.SelectedIndex = GetRegSetting(sRootRegistry & "\Settings\Servo", "7", 11)
cboServo8.SelectedIndex = GetRegSetting(sRootRegistry & "\Settings\Servo", "8", 12)
cboSensors1.SelectedIndex = GetRegSetting(sRootRegistry & "\Settings\Sensor", "1", 17)
cboSensors2.SelectedIndex = GetRegSetting(sRootRegistry & "\Settings\Sensor", "2", 18)
cboSensors3.SelectedIndex = GetRegSetting(sRootRegistry & "\Settings\Sensor", "3", 19)
cboSensors4.SelectedIndex = GetRegSetting(sRootRegistry & "\Settings\Sensor", "4", 20)
cboSensors5.SelectedIndex = GetRegSetting(sRootRegistry & "\Settings\Sensor", "5", 21)
cboSensors6.SelectedIndex = GetRegSetting(sRootRegistry & "\Settings\Sensor", "6", 22)
cboSensors7.SelectedIndex = GetRegSetting(sRootRegistry & "\Settings\Sensor", "7", 0)
cboSensors8.SelectedIndex = GetRegSetting(sRootRegistry & "\Settings\Sensor", "8", 0)
Catch
End Try
Control.CheckForIllegalCrossThreadCalls = False
txtOutputFolder.Text = GetRegSetting(sRootRegistry & "\Settings", "OutputFolder", GetRootPath)
LoadOutputFiles()
Dim i As Integer
frmAbout.UpdateStatus(GetResString(, "Setting_Up_Comboboxes"), 20)
Dim names As String()
names = System.Enum.GetNames(GetType(GeneralMidiInstruments))
With cboVarioInstruments
.Items.Clear()
For nCount = 0 To names.Length - 1
.Items.Add(New cValueDesc(nCount, names(nCount)))
Next nCount
For i = 0 To .Items.Count - 1
If CType(.Items(i), cValueDesc).Value = nVarioInstrument Then
.SelectedIndex = i ' CType(.Items(i), cValueDesc).Description
Exit For
End If
Next
If .SelectedIndex < 0 Then
.SelectedIndex = 0
End If
End With
'LoadSettings()
If eMapSelection = e_MapSelection.e_MapSelection_None Then
SetMapMode()
Else
frmAbout.UpdateStatus(GetResString(, "Setting_Up_Webbrowser"), 30)
SetupWebBroswer()
End If
cboAttitude.Items.Add(GetResString(, "None"))
cboGPS.Items.Add(GetResString(, "None"))
cboWaypoint.Items.Add(GetResString(, "None"))
cboHertzTracking.Items.Add(GetResString(, "None"))
For i = 1 To 20
cboAttitude.Items.Add(i & " Hz")
If i <= 10 Then
cboGPS.Items.Add(i & " Hz")
cboWaypoint.Items.Add(i & " Hz")
End If
If i <= 5 Then
cboHertzTracking.Items.Add(i & " Hz")
End If
Next
cboAttitude.SelectedIndex = Convert.ToInt32(GetRegSetting(sRootRegistry & "\Settings", "Attitude Hz", "5"))
cboGPS.SelectedIndex = Convert.ToInt32(GetRegSetting(sRootRegistry & "\Settings", "GPS Hz", "2"))
cboWaypoint.SelectedIndex = Convert.ToInt32(GetRegSetting(sRootRegistry & "\Settings", "Waypoint Hz", "2"))
If Convert.ToInt32(GetRegSetting(sRootRegistry & "\Settings\Tracking", "Hz", "5")) > 5 Then
cboHertzTracking.SelectedIndex = 5
Else
cboHertzTracking.SelectedIndex = Convert.ToInt32(GetRegSetting(sRootRegistry & "\Settings\Tracking", "Hz", "5"))
End If
With cboCommandLineDelim
.Items.Add(GetResString(, "No_line_ending"))
.Items.Add(GetResString(, "Line Feed"))
.Items.Add(GetResString(, "Carriage Return"))
.Items.Add(GetResString(, "Line Feed Carriage Return"))
.SelectedIndex = GetRegSetting(sRootRegistry & "\Settings", "Command Line Delim", "2")
nCommandLineDelim = .SelectedIndex
End With
With cboConfigDevice
.Items.Add(New cValueDesc(e_ConfigDevice.e_ConfigDevice_Generic, "Generic"))
.Items.Add(New cValueDesc(e_ConfigDevice.e_ConfigDevice_AttoPilot, "AttoPilot"))
.Items.Add(New cValueDesc(e_ConfigDevice.e_ConfigDevice_MAVlink, "ArduPilot Mega (MAVlink)"))
.Items.Add(New cValueDesc(e_ConfigDevice.e_ConfigDevice_Gluonpilot, "Gluonpilot"))
If bIsAdmin = True Then
.Items.Add(New cValueDesc(e_ConfigDevice.e_ConfigDevice_FY21AP, "FY21AP II"))
End If
For i = 0 To .Items.Count - 1
If CType(.Items(i), cValueDesc).Value = nConfigDevice Then
.SelectedIndex = i ' CType(.Items(i), cValueDesc).Description
Exit For
End If
Next
End With
With cboJoystickOutput
.Items.Add("None")
.Items.Add("AttoPilot")
.Items.Add("UavDevBoard")
.Items.Add("Millswood Eng.")
.Items.Add("ArduPilot Mega")
'.Items.Add("Pololu")
.SelectedIndex = nJoystickOutput
End With
For i = 0 To 255
cboConfigVehicle.Items.Add(i)
Next
cboConfigVehicle.SelectedIndex = nConfigVehicle
With cboOutputTypeTracking
.Items.Add(New cValueDesc(0, "ArduTracker"))
.Items.Add(New cValueDesc(1, "Heading"))
.Items.Add(New cValueDesc(2, "LatLong"))
.Items.Add(New cValueDesc(3, "ArduStation"))
.Items.Add(New cValueDesc(4, "Melih"))
.Items.Add(New cValueDesc(5, "Pololu"))
.Items.Add(New cValueDesc(6, "MiniSSC"))
For i = 0 To .Items.Count - 1
If CType(.Items(i), cValueDesc).Value = nTrackingOutputType Then
.SelectedIndex = i ' CType(.Items(i), cValueDesc).Description
Exit For
End If
Next
End With
With cboTrackingSet
.Items.Clear()
For nCount = 0 To 359
.Items.Add(nCount)
Next
'.Items.Add("N")
'.Items.Add("NE")
'.Items.Add("E")
'.Items.Add("SE")
'.Items.Add("S")
'.Items.Add("SW")
'.Items.Add("W")
'.Items.Add("NW")
.SelectedIndex = 0
End With
frmAbout.UpdateStatus(GetResString(, "Loading Settings"), 40)
LoadComboEntries(cboCommandLineCommand)
LoadMissions()
tbarModelScale.Value = GetRegSetting(sRootRegistry & "\Settings", "Model Scale", "10")
chkCommandLineAutoScroll.Checked = GetRegSetting(sRootRegistry & "\Settings", "Command Line Auto Scroll", True)
'UpdateLineColor()
'bWaypointExtrude = GetRegSetting(sRootRegistry & "\Settings", "WP Extrude", True)
'chkWaypointExtrude.Checked = bWaypointExtrude
'SetupWebBroswer()
frmAbout.UpdateStatus(GetResString(, "Loading_COM_Ports"), 50)
LoadComPorts()
SetPlayerState(e_PlayerState.e_PlayerState_None)
For nCount = LBound(baudRates) To UBound(baudRates)
cboBaudRate.Items.Add(baudRates(nCount))
cboBaudRateTracking.Items.Add(baudRates(nCount))
If GetRegSetting(sRootRegistry & "\Settings", "Baud Rate", "38400") = baudRates(nCount) Then
cboBaudRate.SelectedIndex = nCount
End If
If GetRegSetting(sRootRegistry & "\Settings\Tracking", "Baud Rate", "38400") = baudRates(nCount) Then
cboBaudRateTracking.SelectedIndex = nCount
End If
Next
If cboBaudRate.SelectedIndex = -1 Then
cboBaudRate.SelectedIndex = 3
End If
If cboBaudRateTracking.SelectedIndex = -1 Then
cboBaudRateTracking.SelectedIndex = 3
End If
txtSocket.Text = GetRegSetting(sRootRegistry & "\Settings", "Socket Port", "localhost:30300")
lblGPSLock.Text = ""
lblSatellites.Text = ""
lblHDOP.Text = ""
lblAmperage.Text = ""
lblBattery.Text = ""
lblWaypoint.Text = ""
lblDistance.Text = ""
lblMode.Text = ""
lblThrottle.Text = ""
lblLatitude.Text = ""
lblLongitude.Text = ""
lblTargetAlt.Text = ""
lblDataPoints.Text = ""
lblRunTime.Text = ""
nDataPoints = 1
sMode = ""
sModeNumber = ""
SplitContainer1.SplitterDistance = nSplitter
If Screen.PrimaryScreen.Bounds.Height = 600 And Screen.PrimaryScreen.Bounds.Width = 1024 Then
Me.WindowState = GetRegSetting(sRootRegistry & "\Settings", "Form WindowState", FormWindowState.Maximized)
Else
Me.WindowState = GetRegSetting(sRootRegistry & "\Settings", "Form WindowState", FormWindowState.Normal)
End If
If Me.WindowState = FormWindowState.Normal Then
Me.Width = nWidth
Me.Height = nHeight
Me.Left = nLeft
Me.Top = nTop
End If
bStartup = False