-
Notifications
You must be signed in to change notification settings - Fork 1
/
GCSSettings.cs
128 lines (109 loc) · 5.15 KB
/
GCSSettings.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO.Ports;
using System.Xml;
using System.IO;
using System.Reflection;
using System.Windows.Forms;
namespace JCFLIGHTGCS
{
class GCSSettings
{
public static int GCSFrequency = 15;
public static int GCSRate = 66;
public static int GCSSpeech = 0;
public static int GCSRebootBoard = 0;
public static int GCSAutoWP = 0;
public static int GCSTrackLength = 200;
public static int GCSAirPorts = 1;
public static int GCSTrackSize = 5;
public static void Save_To_XML(string FileName)
{
XmlTextWriter XMLWrite = new XmlTextWriter(FileName, null);
XMLWrite.Formatting = Formatting.Indented;
XMLWrite.Indentation = 4;
XMLWrite.WriteStartDocument();
XMLWrite.WriteStartElement("GCSPARAMETERS");
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
XMLWrite.WriteStartElement("GCSFrequency Valor = \"" + GCSFrequency + "\""); XMLWrite.WriteEndElement();
XMLWrite.WriteStartElement("GCSRate Valor = \"" + GCSRate + "\""); XMLWrite.WriteEndElement();
XMLWrite.WriteStartElement("GCSSpeech Valor = \"" + GCSSpeech + "\""); XMLWrite.WriteEndElement();
XMLWrite.WriteStartElement("GCSRebootBoard Valor = \"" + GCSRebootBoard + "\""); XMLWrite.WriteEndElement();
XMLWrite.WriteStartElement("GCSAutoWP Valor = \"" + GCSAutoWP + "\""); XMLWrite.WriteEndElement();
XMLWrite.WriteStartElement("GCSTrackLength Valor = \"" + GCSTrackLength + "\""); XMLWrite.WriteEndElement();
XMLWrite.WriteStartElement("GCSAirPorts Valor = \"" + GCSAirPorts + "\""); XMLWrite.WriteEndElement();
XMLWrite.WriteStartElement("GCSTrackSize Valor = \"" + GCSTrackSize + "\""); XMLWrite.WriteEndElement();
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
XMLWrite.WriteEndElement();
XMLWrite.WriteEndDocument();
XMLWrite.Close();
}
public static bool Read_From_XML(string FileName)
{
XmlTextReader XMLReader;
if (!File.Exists(FileName))
{
return false;
}
XMLReader = new XmlTextReader(FileName);
try
{
while (XMLReader.Read())
{
switch (XMLReader.NodeType)
{
case XmlNodeType.Element:
if (String.Compare(XMLReader.Name, "GCSRate", true) == 0 && XMLReader.HasAttributes)
{
GCSRate = Convert.ToByte(XMLReader.GetAttribute("Valor"));
}
if (String.Compare(XMLReader.Name, "GCSFrequency", true) == 0 && XMLReader.HasAttributes)
{
GCSFrequency = Convert.ToByte(XMLReader.GetAttribute("Valor"));
}
if (String.Compare(XMLReader.Name, "GCSSpeech", true) == 0 && XMLReader.HasAttributes)
{
GCSSpeech = Convert.ToByte(XMLReader.GetAttribute("Valor"));
}
if (String.Compare(XMLReader.Name, "GCSRebootBoard", true) == 0 && XMLReader.HasAttributes)
{
GCSRebootBoard = Convert.ToByte(XMLReader.GetAttribute("Valor"));
}
if (String.Compare(XMLReader.Name, "GCSAutoWP", true) == 0 && XMLReader.HasAttributes)
{
GCSAutoWP = Convert.ToByte(XMLReader.GetAttribute("Valor"));
}
if (String.Compare(XMLReader.Name, "GCSTrackLength", true) == 0 && XMLReader.HasAttributes)
{
GCSTrackLength = Convert.ToInt32(XMLReader.GetAttribute("Valor"));
}
if (String.Compare(XMLReader.Name, "GCSAirPorts", true) == 0 && XMLReader.HasAttributes)
{
GCSAirPorts = Convert.ToByte(XMLReader.GetAttribute("Valor"));
}
if (String.Compare(XMLReader.Name, "GCSTrackSize", true) == 0 && XMLReader.HasAttributes)
{
GCSTrackSize = Convert.ToByte(XMLReader.GetAttribute("Valor"));
}
break;
}
}
}
catch
{
return false;
}
finally
{
if (XMLReader != null)
{
XMLReader.Close();
}
}
return true;
}
}
}