-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
MainV2.cs
4836 lines (4179 loc) · 189 KB
/
MainV2.cs
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
#if !LIB
extern alias Drawing;
#endif
using GMap.NET.WindowsForms;
using log4net;
using MissionPlanner.ArduPilot;
using MissionPlanner.Comms;
using MissionPlanner.Controls;
using MissionPlanner.GCSViews.ConfigurationView;
using MissionPlanner.Log;
using MissionPlanner.Maps;
using MissionPlanner.Utilities;
using MissionPlanner.Warnings;
using SkiaSharp;
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
using System.Globalization;
using System.IO;
using System.Net.Sockets;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using MissionPlanner.ArduPilot.Mavlink;
using MissionPlanner.Utilities.HW;
using Transitions;
using System.Linq;
using MissionPlanner.Joystick;
using System.Net;
using Newtonsoft.Json;
using MissionPlanner;
using Flurl.Util;
using Org.BouncyCastle.Bcpg;
using log4net.Repository.Hierarchy;
using System.Numerics;
using System.Runtime.Remoting.Metadata.W3cXsd2001;
using static MAVLink;
using DroneCAN;
namespace MissionPlanner
{
public partial class MainV2 : Form
{
private static readonly ILog log =
LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public static menuicons displayicons; //do not initialize to allow update of custom icons
public static string running_directory = Settings.GetRunningDirectory();
public abstract class menuicons
{
public abstract Image fd { get; }
public abstract Image fp { get; }
public abstract Image initsetup { get; }
public abstract Image config_tuning { get; }
public abstract Image sim { get; }
public abstract Image terminal { get; }
public abstract Image help { get; }
public abstract Image donate { get; }
public abstract Image connect { get; }
public abstract Image disconnect { get; }
public abstract Image bg { get; }
public abstract Image wizard { get; }
}
public class burntkermitmenuicons : menuicons
{
public override Image fd
{
get
{
if (File.Exists($"{running_directory}light_flightdata_icon.png"))
return Image.FromFile($"{running_directory}light_flightdata_icon.png");
else
return global::MissionPlanner.Properties.Resources.light_flightdata_icon;
}
}
public override Image fp
{
get
{
if (File.Exists($"{running_directory}light_flightplan_icon.png"))
return Image.FromFile($"{running_directory}light_flightplan_icon.png");
else
return global::MissionPlanner.Properties.Resources.light_flightplan_icon;
}
}
public override Image initsetup
{
get
{
if (File.Exists($"{running_directory}light_initialsetup_icon.png"))
return Image.FromFile($"{running_directory}light_initialsetup_icon.png");
else
return global::MissionPlanner.Properties.Resources.light_initialsetup_icon;
}
}
public override Image config_tuning
{
get
{
if (File.Exists($"{running_directory}light_tuningconfig_icon.png"))
return Image.FromFile($"{running_directory}light_tuningconfig_icon.png");
else
return global::MissionPlanner.Properties.Resources.light_tuningconfig_icon;
}
}
public override Image sim
{
get
{
if (File.Exists($"{running_directory}light_simulation_icon.png"))
return Image.FromFile($"{running_directory}light_simulation_icon.png");
else
return global::MissionPlanner.Properties.Resources.light_simulation_icon;
}
}
public override Image terminal
{
get
{
if (File.Exists($"{running_directory}light_terminal_icon.png"))
return Image.FromFile($"{running_directory}light_terminal_icon.png");
else
return global::MissionPlanner.Properties.Resources.light_terminal_icon;
}
}
public override Image help
{
get
{
if (File.Exists($"{running_directory}light_help_icon.png"))
return Image.FromFile($"{running_directory}light_help_icon.png");
else
return global::MissionPlanner.Properties.Resources.light_help_icon;
}
}
public override Image donate
{
get
{
if (File.Exists($"{running_directory}light_donate_icon.png"))
return Image.FromFile($"{running_directory}light_donate_icon.png");
else
return global::MissionPlanner.Properties.Resources.donate;
}
}
public override Image connect
{
get
{
if (File.Exists($"{running_directory}light_connect_icon.png"))
return Image.FromFile($"{running_directory}light_connect_icon.png");
else
return global::MissionPlanner.Properties.Resources.light_connect_icon;
}
}
public override Image disconnect
{
get
{
if (File.Exists($"{running_directory}light_disconnect_icon.png"))
return Image.FromFile($"{running_directory}light_disconnect_icon.png");
else
return global::MissionPlanner.Properties.Resources.light_disconnect_icon;
}
}
public override Image bg
{
get
{
if (File.Exists($"{running_directory}light_icon_background.png"))
return Image.FromFile($"{running_directory}light_icon_background.png");
else
return global::MissionPlanner.Properties.Resources.bgdark;
}
}
public override Image wizard
{
get
{
if (File.Exists($"{running_directory}light_wizard_icon.png"))
return Image.FromFile($"{running_directory}light_wizard_icon.png");
else
return global::MissionPlanner.Properties.Resources.wizardicon;
}
}
}
public class highcontrastmenuicons : menuicons
{
private string running_directory = Settings.GetRunningDirectory();
public override Image fd
{
get
{
if (File.Exists($"{running_directory}dark_flightdata_icon.png"))
return Image.FromFile($"{running_directory}dark_flightdata_icon.png");
else
return global::MissionPlanner.Properties.Resources.dark_flightdata_icon;
}
}
public override Image fp
{
get
{
if (File.Exists($"{running_directory}dark_flightplan_icon.png"))
return Image.FromFile($"{running_directory}dark_flightplan_icon.png");
else
return global::MissionPlanner.Properties.Resources.dark_flightplan_icon;
}
}
public override Image initsetup
{
get
{
if (File.Exists($"{running_directory}dark_initialsetup_icon.png"))
return Image.FromFile($"{running_directory}dark_initialsetup_icon.png");
else
return global::MissionPlanner.Properties.Resources.dark_initialsetup_icon;
}
}
public override Image config_tuning
{
get
{
if (File.Exists($"{running_directory}dark_tuningconfig_icon.png"))
return Image.FromFile($"{running_directory}dark_tuningconfig_icon.png");
else
return global::MissionPlanner.Properties.Resources.dark_tuningconfig_icon;
}
}
public override Image sim
{
get
{
if (File.Exists($"{running_directory}dark_simulation_icon.png"))
return Image.FromFile($"{running_directory}dark_simulation_icon.png");
else
return global::MissionPlanner.Properties.Resources.dark_simulation_icon;
}
}
public override Image terminal
{
get
{
if (File.Exists($"{running_directory}dark_terminal_icon.png"))
return Image.FromFile($"{running_directory}dark_terminal_icon.png");
else
return global::MissionPlanner.Properties.Resources.dark_terminal_icon;
}
}
public override Image help
{
get
{
if (File.Exists($"{running_directory}dark_help_icon.png"))
return Image.FromFile($"{running_directory}dark_help_icon.png");
else
return global::MissionPlanner.Properties.Resources.dark_help_icon;
}
}
public override Image donate
{
get
{
if (File.Exists($"{running_directory}dark_donate_icon.png"))
return Image.FromFile($"{running_directory}dark_donate_icon.png");
else
return global::MissionPlanner.Properties.Resources.donate;
}
}
public override Image connect
{
get
{
if (File.Exists($"{running_directory}dark_connect_icon.png"))
return Image.FromFile($"{running_directory}dark_connect_icon.png");
else
return global::MissionPlanner.Properties.Resources.dark_connect_icon;
}
}
public override Image disconnect
{
get
{
if (File.Exists($"{running_directory}dark_disconnect_icon.png"))
return Image.FromFile($"{running_directory}dark_disconnect_icon.png");
else
return global::MissionPlanner.Properties.Resources.dark_disconnect_icon;
}
}
public override Image bg
{
get
{
if (File.Exists($"{running_directory}dark_icon_background.png"))
return Image.FromFile($"{running_directory}dark_icon_background.png");
else
return null;
}
}
public override Image wizard
{
get
{
if (File.Exists($"{running_directory}dark_wizard_icon.png"))
return Image.FromFile($"{running_directory}dark_wizard_icon.png");
else
return global::MissionPlanner.Properties.Resources.wizardicon;
}
}
}
Controls.MainSwitcher MyView;
private static DisplayView _displayConfiguration = File.Exists(DisplayViewExtensions.custompath)
? new DisplayView().Custom()
: new DisplayView().Advanced();
public static event EventHandler LayoutChanged;
public static DisplayView DisplayConfiguration
{
get { return _displayConfiguration; }
set
{
_displayConfiguration = value;
Settings.Instance["displayview"] = _displayConfiguration.ConvertToString();
LayoutChanged?.Invoke(null, EventArgs.Empty);
}
}
public static bool ShowAirports { get; set; }
public static bool ShowTFR { get; set; }
private Utilities.adsb _adsb;
public bool EnableADSB
{
get { return _adsb != null; }
set
{
if (value == true)
{
_adsb = new Utilities.adsb();
if (Settings.Instance["adsbserver"] != null)
Utilities.adsb.server = Settings.Instance["adsbserver"];
if (Settings.Instance["adsbport"] != null)
Utilities.adsb.serverport = int.Parse(Settings.Instance["adsbport"].ToString());
}
else
{
Utilities.adsb.Stop();
_adsb = null;
}
}
}
//public static event EventHandler LayoutChanged;
/// <summary>
/// Active Comport interface
/// </summary>
public static MAVLinkInterface comPort
{
get { return _comPort; }
set
{
if (_comPort == value)
return;
_comPort = value;
if (instance == null)
return;
_comPort.MavChanged -= instance.comPort_MavChanged;
_comPort.MavChanged += instance.comPort_MavChanged;
instance.comPort_MavChanged(null, null);
}
}
static MAVLinkInterface _comPort = new MAVLinkInterface();
/// <summary>
/// passive comports
/// </summary>
public static List<MAVLinkInterface> Comports = new List<MAVLinkInterface>();
public delegate void WMDeviceChangeEventHandler(WM_DEVICECHANGE_enum cause);
public event WMDeviceChangeEventHandler DeviceChanged;
/// <summary>
/// other planes in the area from adsb
/// </summary>
public object adsblock = new object();
public ConcurrentDictionary<string, adsb.PointLatLngAltHdg> adsbPlanes =
new ConcurrentDictionary<string, adsb.PointLatLngAltHdg>();
public static string titlebar;
/// <summary>
/// Comport name
/// </summary>
public static string comPortName = "";
public static int comPortBaud = 57600;
/// <summary>
/// mono detection
/// </summary>
public static bool MONO = false;
public bool UseCachedParams { get; set; } = false;
public static bool Android { get; set; }
public static bool IOS { get; set; }
public static bool OSX { get; set; }
/// <summary>
/// speech engine enable
/// </summary>
public static bool speechEnable
{
get { return speechEngine == null ? false : speechEngine.speechEnable; }
set
{
if (speechEngine != null) speechEngine.speechEnable = value;
}
}
public static bool speech_armed_only = false;
public static bool speechEnabled()
{
if (speechEngine == null)
return false;
if (!speechEnable) {
return false;
}
if (speech_armed_only) {
return MainV2.comPort.MAV.cs.armed;
}
return true;
}
/// <summary>
/// spech engine static class
/// </summary>
public static ISpeech speechEngine { get; set; }
/// <summary>
/// joystick static class
/// </summary>
public static Joystick.JoystickBase joystick { get; set; }
/// <summary>
/// track last joystick packet sent. used to control rate
/// </summary>
DateTime lastjoystick = DateTime.Now;
/// <summary>
/// determine if we are running sitl
/// </summary>
public static bool sitl
{
get
{
if (MissionPlanner.GCSViews.SITL.SITLSEND == null) return false;
if (MissionPlanner.GCSViews.SITL.SITLSEND.Client.Connected) return true;
return false;
}
}
/// <summary>
/// hud background image grabber from a video stream - not realy that efficent. ie no hardware overlays etc.
/// </summary>
public static WebCamService.Capture cam { get; set; }
/// <summary>
/// used for custom autoconnect for predefined endpoints
/// </summary>
public List<AutoConnect.ConnectionInfo> ExtraConnectionList { get; } = new List<AutoConnect.ConnectionInfo>();
/// <summary>
/// used for dynamic custom port types
/// </summary>
public Dictionary<Regex, Func<string, string, ICommsSerial>> CustomPortList { get; } = new Dictionary<Regex, Func<string, string, ICommsSerial>>();
/// <summary>
/// controls the main serial reader thread
/// </summary>
bool serialThread = false;
bool pluginthreadrun = false;
bool joystickthreadrun = false;
bool adsbThread = false;
Thread httpthread;
Thread pluginthread;
/// <summary>
/// track the last heartbeat sent
/// </summary>
private DateTime heatbeatSend = DateTime.UtcNow;
/// <summary>
/// track the last ads-b send time
/// </summary>
private DateTime adsbSend = DateTime.Now;
/// <summary>
/// track the adsb plane index we're round-robin sending
/// starts at -1 because it'll get incremented before sending
/// </summary>
private int adsbIndex = -1;
/// <summary>
/// used to call anything as needed.
/// </summary>
public static MainV2 instance = null;
public static bool isHerelink = false;
public static MainSwitcher View;
/// <summary>
/// store the time we first connect UTC
/// </summary>
DateTime connecttime = DateTime.UtcNow;
/// <summary>
/// no data repeat interval UTC
/// </summary>
DateTime nodatawarning = DateTime.UtcNow;
/// <summary>
/// update the connect button UTC
/// </summary>
DateTime connectButtonUpdate = DateTime.UtcNow;
/// <summary>
/// declared here if i want a "single" instance of the form
/// ie configuration gets reloaded on every click
/// </summary>
public GCSViews.FlightData FlightData;
public GCSViews.FlightPlanner FlightPlanner;
GCSViews.SITL Simulation;
private Form connectionStatsForm;
private ConnectionStats _connectionStats;
/// <summary>
/// This 'Control' is the toolstrip control that holds the comport combo, baudrate combo etc
/// Otiginally seperate controls, each hosted in a toolstip sqaure, combined into this custom
/// control for layout reasons.
/// </summary>
public static ConnectionControl _connectionControl;
public static bool TerminalTheming = true;
public void updateLayout(object sender, EventArgs e)
{
MenuSimulation.Visible = DisplayConfiguration.displaySimulation;
MenuHelp.Visible = DisplayConfiguration.displayHelp;
MissionPlanner.Controls.BackstageView.BackstageView.Advanced = DisplayConfiguration.isAdvancedMode;
// force autohide on
if (DisplayConfiguration.autoHideMenuForce)
{
AutoHideMenu(true);
Settings.Instance["menu_autohide"] = true.ToString();
autoHideToolStripMenuItem.Visible = false;
}
else if (Settings.Instance.GetBoolean("menu_autohide"))
{
AutoHideMenu(Settings.Instance.GetBoolean("menu_autohide"));
Settings.Instance["menu_autohide"] = Settings.Instance.GetBoolean("menu_autohide").ToString();
}
//Flight data page
if (MainV2.instance.FlightData != null)
{
//hide menu items
MainV2.instance.FlightData.updateDisplayView();
}
if (MainV2.instance.FlightPlanner != null)
{
//hide menu items
MainV2.instance.FlightPlanner.updateDisplayView();
}
}
public MainV2()
{
log.Info("Mainv2 ctor");
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
// create one here - but override on load
Settings.Instance["guid"] = Guid.NewGuid().ToString();
//Check for -config argument, and if it is an xml extension filename then use that for config
if (Program.args.Length > 0 && Program.args.Contains("-config"))
{
var cmds = ProcessCommandLine(Program
.args); //This will be called later as well, but we need it here and now
if (cmds.ContainsKey("config") &&
(cmds["config"] != null) &&
(String.Compare(Path.GetExtension(cmds["config"]), ".xml", true) == 0))
{
Settings.FileName = cmds["config"];
}
}
// load config
LoadConfig();
// force language to be loaded
L10N.GetConfigLang();
ShowAirports = true;
// setup adsb
Utilities.adsb.ApplicationVersion = System.Windows.Forms.Application.ProductVersion;
Utilities.adsb.UpdatePlanePosition += adsb_UpdatePlanePosition;
MAVLinkInterface.UpdateADSBPlanePosition += adsb_UpdatePlanePosition;
MAVLinkInterface.UpdateADSBCollision += (sender, tuple) =>
{
lock (adsblock)
{
if (MainV2.instance.adsbPlanes.ContainsKey(tuple.id))
{
// update existing
((adsb.PointLatLngAltHdg) instance.adsbPlanes[tuple.id]).ThreatLevel = tuple.threat_level;
}
}
};
MAVLinkInterface.gcssysid = (byte) Settings.Instance.GetByte("gcsid", MAVLinkInterface.gcssysid);
Form splash = Program.Splash;
splash?.Refresh();
Application.DoEvents();
instance = this;
MyView = new MainSwitcher(this);
View = MyView;
if (Settings.Instance.ContainsKey("language") && !string.IsNullOrEmpty(Settings.Instance["language"]))
{
changelanguage(CultureInfoEx.GetCultureInfo(Settings.Instance["language"]));
}
InitializeComponent();
//Init Theme table and load BurntKermit as a default
ThemeManager.thmColor = new ThemeColorTable(); //Init colortable
ThemeManager.thmColor.InitColors(); //This fills up the table with BurntKermit defaults.
ThemeManager.thmColor
.SetTheme(); //Set the colors, this need to handle the case when not all colors are defined in the theme file
if (Settings.Instance["theme"] == null)
{
if (File.Exists($"{running_directory}custom.mpsystheme"))
Settings.Instance["theme"] = "custom.mpsystheme";
else
Settings.Instance["theme"] = "BurntKermit.mpsystheme";
}
ThemeManager.LoadTheme(Settings.Instance["theme"]);
Utilities.ThemeManager.ApplyThemeTo(this);
// define default basestream
comPort.BaseStream = new SerialPort();
comPort.BaseStream.BaudRate = 57600;
_connectionControl = toolStripConnectionControl.ConnectionControl;
_connectionControl.CMB_baudrate.TextChanged += this.CMB_baudrate_TextChanged;
_connectionControl.CMB_serialport.SelectedIndexChanged += this.CMB_serialport_SelectedIndexChanged;
_connectionControl.CMB_serialport.Click += this.CMB_serialport_Click;
_connectionControl.cmb_sysid.Click += cmb_sysid_Click;
_connectionControl.ShowLinkStats += (sender, e) => ShowConnectionStatsForm();
srtm.datadirectory = $"{Settings.GetDataDirectory()}srtm";
var t = Type.GetType("Mono.Runtime");
MONO = (t != null);
try
{
if (speechEngine == null)
speechEngine = new Speech();
MAVLinkInterface.Speech = speechEngine;
CurrentState.Speech = speechEngine;
}
catch
{
}
// proxy loader - dll load now instead of on config form load
new Transition(new TransitionType_EaseInEaseOut(2000));
PopulateSerialportList();
if (_connectionControl.CMB_serialport.Items.Count > 0)
{
_connectionControl.CMB_baudrate.SelectedIndex = 8;
_connectionControl.CMB_serialport.SelectedIndex = 0;
}
// ** Done
splash?.Refresh();
Application.DoEvents();
// load last saved connection settings
string temp = Settings.Instance.ComPort;
if (!string.IsNullOrEmpty(temp))
{
_connectionControl.CMB_serialport.SelectedIndex = _connectionControl.CMB_serialport.FindString(temp);
if (_connectionControl.CMB_serialport.SelectedIndex == -1)
{
_connectionControl.CMB_serialport.Text = temp; // allows ports that dont exist - yet
}
comPort.BaseStream.PortName = temp;
comPortName = temp;
}
string temp2 = Settings.Instance.BaudRate;
if (!string.IsNullOrEmpty(temp2))
{
var idx = _connectionControl.CMB_baudrate.FindString(temp2);
if (idx == -1)
{
_connectionControl.CMB_baudrate.Text = temp2;
}
else
{
_connectionControl.CMB_baudrate.SelectedIndex = idx;
}
comPortBaud = int.Parse(temp2);
}
MissionPlanner.Utilities.Tracking.cid = new Guid(Settings.Instance["guid"].ToString());
if (splash != null)
{
this.Text = splash?.Text;
titlebar = splash?.Text;
}
if (!MONO) // windows only
{
if (Settings.Instance["showconsole"] != null && Settings.Instance["showconsole"].ToString() == "True")
{
}
else
{
NativeMethods.ShowWindow(NativeMethods.GetConsoleWindow(), NativeMethods.SW_HIDE);
}
// prevent system from sleeping while mp open
var previousExecutionState =
NativeMethods.SetThreadExecutionState(
NativeMethods.ES_CONTINUOUS | NativeMethods.ES_SYSTEM_REQUIRED);
}
ChangeUnits();
if (Settings.Instance["showairports"] != null)
{
MainV2.ShowAirports = bool.Parse(Settings.Instance["showairports"]);
}
// set default
ShowTFR = true;
// load saved
if (Settings.Instance["showtfr"] != null)
{
MainV2.ShowTFR = Settings.Instance.GetBoolean("showtfr", ShowTFR);
}
if (Settings.Instance["enableadsb"] != null)
{
MainV2.instance.EnableADSB = Settings.Instance.GetBoolean("enableadsb");
}
try
{
log.Debug(Process.GetCurrentProcess().Modules.ToJSON());
}
catch
{
}
try
{
log.Info("Create FD");
FlightData = new GCSViews.FlightData();
log.Info("Create FP");
FlightPlanner = new GCSViews.FlightPlanner();
//Configuration = new GCSViews.ConfigurationView.Setup();
log.Info("Create SIM");
Simulation = new GCSViews.SITL();
//Firmware = new GCSViews.Firmware();
//Terminal = new GCSViews.Terminal();
FlightData.Width = MyView.Width;
FlightPlanner.Width = MyView.Width;
Simulation.Width = MyView.Width;
}
catch (ArgumentException e)
{
//http://www.microsoft.com/en-us/download/details.aspx?id=16083
//System.ArgumentException: Font 'Arial' does not support style 'Regular'.
log.Fatal(e);
CustomMessageBox.Show($"{e}\n\n Font Issues? Please install this http://www.microsoft.com/en-us/download/details.aspx?id=16083");
//splash.Close();
//this.Close();
Application.Exit();
}
catch (Exception e)
{
log.Fatal(e);
CustomMessageBox.Show($"A Major error has occured : {e}");
Application.Exit();
}
//set first instance display configuration
if (DisplayConfiguration == null)
{
DisplayConfiguration = DisplayConfiguration.Advanced();
}
// load old config
if (Settings.Instance["advancedview"] != null)
{
if (Settings.Instance.GetBoolean("advancedview") == true)
{
DisplayConfiguration = new DisplayView().Advanced();
}
// remove old config
Settings.Instance.Remove("advancedview");
} //// load this before the other screens get loaded
if (Settings.Instance["displayview"] != null)
{
try
{
DisplayConfiguration = Settings.Instance.GetDisplayView("displayview");
//Force new view in case of saved view in config.xml
DisplayConfiguration.displayAdvancedParams = false;
DisplayConfiguration.displayStandardParams = false;
DisplayConfiguration.displayFullParamList = true;
}
catch
{
DisplayConfiguration = DisplayConfiguration.Advanced();
}
}
LayoutChanged += updateLayout;
LayoutChanged(null, EventArgs.Empty);
if (Settings.Instance["CHK_GDIPlus"] != null)
GCSViews.FlightData.myhud.opengl = !bool.Parse(Settings.Instance["CHK_GDIPlus"].ToString());
if (Settings.Instance["CHK_hudshow"] != null)
GCSViews.FlightData.myhud.hudon = bool.Parse(Settings.Instance["CHK_hudshow"].ToString());
try
{
if (Settings.Instance["MainLocX"] != null && Settings.Instance["MainLocY"] != null)
{
this.StartPosition = FormStartPosition.Manual;
Point startpos = new Point(Settings.Instance.GetInt32("MainLocX"),
Settings.Instance.GetInt32("MainLocY"));
// fix common bug which happens when user removes a monitor, the app shows up
// offscreen and it is very hard to move it onscreen. Also happens with
// remote desktop a lot. So this only restores position if the position
// is visible.
foreach (Screen s in Screen.AllScreens)
{
if (s.WorkingArea.Contains(startpos))
{
this.Location = startpos;
break;
}
}
}
if (Settings.Instance["MainMaximised"] != null)
{
this.WindowState =
(FormWindowState) Enum.Parse(typeof(FormWindowState), Settings.Instance["MainMaximised"]);
// dont allow minimised start state
if (this.WindowState == FormWindowState.Minimized)
{
this.WindowState = FormWindowState.Normal;
this.Location = new Point(100, 100);
}
}
if (Settings.Instance["MainHeight"] != null)
this.Height = Settings.Instance.GetInt32("MainHeight");
if (Settings.Instance["MainWidth"] != null)
this.Width = Settings.Instance.GetInt32("MainWidth");
// set presaved default telem rates
if (Settings.Instance["CMB_rateattitude"] != null)
CurrentState.rateattitudebackup = Settings.Instance.GetInt32("CMB_rateattitude");
if (Settings.Instance["CMB_rateposition"] != null)
CurrentState.ratepositionbackup = Settings.Instance.GetInt32("CMB_rateposition");
if (Settings.Instance["CMB_ratestatus"] != null)
CurrentState.ratestatusbackup = Settings.Instance.GetInt32("CMB_ratestatus");
if (Settings.Instance["CMB_raterc"] != null)
CurrentState.ratercbackup = Settings.Instance.GetInt32("CMB_raterc");
if (Settings.Instance["CMB_ratesensors"] != null)
CurrentState.ratesensorsbackup = Settings.Instance.GetInt32("CMB_ratesensors");
//Load customfield names from config
for (short i = 0; i < 20; i++)
{
var fieldname = "customfield" + i.ToString();
if (Settings.Instance.ContainsKey(fieldname))
CurrentState.custom_field_names.Add(fieldname, Settings.Instance[fieldname].ToUpper());
}
// make sure rates propogate
MainV2.comPort.MAV.cs.ResetInternals();
if (Settings.Instance["speechenable"] != null)
MainV2.speechEnable = Settings.Instance.GetBoolean("speechenable");
if (Settings.Instance["analyticsoptout"] != null)
MissionPlanner.Utilities.Tracking.OptOut = Settings.Instance.GetBoolean("analyticsoptout");
try
{
if (Settings.Instance["TXT_homelat"] != null)
MainV2.comPort.MAV.cs.PlannedHomeLocation.Lat = Settings.Instance.GetDouble("TXT_homelat");
if (Settings.Instance["TXT_homelng"] != null)
MainV2.comPort.MAV.cs.PlannedHomeLocation.Lng = Settings.Instance.GetDouble("TXT_homelng");