-
Notifications
You must be signed in to change notification settings - Fork 1
/
BlackBoxAnalyser.cs
342 lines (305 loc) · 11.9 KB
/
BlackBoxAnalyser.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using ZedGraph;
using System.Xml;
namespace JCFLIGHTGCS
{
public partial class BlackBoxAnalyser : Form
{
int ColumnCount = 0;
DataTable DataTableCSV = new DataTable();
PointPairList List1 = new PointPairList();
PointPairList List2 = new PointPairList();
PointPairList List3 = new PointPairList();
PointPairList List4 = new PointPairList();
PointPairList List5 = new PointPairList();
int Graphs = 0;
public BlackBoxAnalyser()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
OpenFileDialog OpenFileDialogInstance = new OpenFileDialog();
OpenFileDialogInstance.InitialDirectory = Directory.GetCurrentDirectory() + "\\Caixa Preta";
OpenFileDialogInstance.Filter = "Log Files|*.log";
OpenFileDialogInstance.FilterIndex = 2;
OpenFileDialogInstance.RestoreDirectory = true;
OpenFileDialogInstance.InitialDirectory = Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + "logs";
CreateChart(zg1);
if (OpenFileDialogInstance.ShowDialog() == DialogResult.OK)
{
try
{
Stream stream = File.Open(OpenFileDialogInstance.FileName, FileMode.Open);
PopulateDataTableFromUploadedFile(stream);
stream.Close();
dataGridView1.DataSource = DataTableCSV;
}
catch (Exception)
{
MessageBox.Show("Falha ao ler o arquivo");
}
foreach (DataGridViewColumn column in dataGridView1.Columns)
{
column.SortMode = DataGridViewColumnSortMode.NotSortable;
}
int a = 1;
foreach (DataGridViewRow row in dataGridView1.Rows)
{
row.HeaderCell.Value = a.ToString();
a++;
}
}
else
{
this.Close();
return;
}
}
private void PopulateDataTableFromUploadedFile(System.IO.Stream strm)
{
System.IO.StreamReader srdr = new System.IO.StreamReader(strm);
String strLine = String.Empty;
Int32 iLineCount = 0;
do
{
strLine = srdr.ReadLine();
if (strLine == null)
{
break;
}
if (0 == iLineCount++)
{
DataTableCSV = new DataTable("CSVTable");
}
this.AddDataRowToTable(strLine, DataTableCSV);
} while (true);
}
private DataRow AddDataRowToTable(String strCSVLine, DataTable dataTable)
{
String[] strVals = strCSVLine.Split(new char[] { ',' });
Int32 iTotalNumberOfValues = strVals.Length;
if (iTotalNumberOfValues > ColumnCount)
{
Int32 iDiff = iTotalNumberOfValues - ColumnCount;
for (Int32 i = 0; i < iDiff; i++)
{
String strColumnName = String.Format("{0}", (ColumnCount + i));
dataTable.Columns.Add(strColumnName, Type.GetType("System.String"));
}
ColumnCount = iTotalNumberOfValues;
}
int idx = 0;
DataRow drow = dataTable.NewRow();
foreach (String strVal in strVals)
{
String strColumnName = String.Format("{0}", idx++);
drow[strColumnName] = strVal.Trim();
}
dataTable.Rows.Add(drow);
return drow;
}
private void dataGridView1_RowEnter(object sender, DataGridViewCellEventArgs e)
{
try
{
int a = 0;
foreach (DataGridViewColumn col in dataGridView1.Columns)
{
col.HeaderText = a.ToString();
a++;
}
}
catch { }
try
{
string option = dataGridView1[0, e.RowIndex].EditedFormattedValue.ToString();
using (XmlReader reader = XmlReader.Create("BlackBoxFields.xml"))
{
reader.Read();
reader.ReadStartElement("LOGFORMAT");
reader.ReadToFollowing("JCFLIGHT");
reader.ReadToFollowing(option);
dataGridView1.Columns[0].HeaderText = "";
XmlReader inner = reader.ReadSubtree();
inner.MoveToElement();
int a = 1;
while (inner.Read())
{
inner.MoveToElement();
if (inner.IsStartElement())
{
if (inner.Name.StartsWith("F"))
{
dataGridView1.Columns[a].HeaderText = inner.ReadString();
a++;
}
}
}
for (; a < dataGridView1.Columns.Count; a++)
{
dataGridView1.Columns[a].HeaderText = "";
}
}
}
catch
{
}
}
public void CreateChart(ZedGraphControl zgc)
{
GraphPane myPane = zgc.GraphPane;
myPane.Title.Text = "";
myPane.XAxis.Title.Text = "Horário";
myPane.YAxis.Title.Text = "Valor";
myPane.XAxis.Type = AxisType.Date;
myPane.XAxis.Scale.Format = "HH:mm:ss.fff";
LineItem myCurve;
myCurve = myPane.AddCurve("NULL", List1, Color.Red, SymbolType.None);
myCurve = myPane.AddCurve("NULL", List2, Color.LightGreen, SymbolType.None);
myCurve = myPane.AddCurve("NULL", List3, Color.LightBlue, SymbolType.None);
myCurve = myPane.AddCurve("NULL", List4, Color.Pink, SymbolType.None);
myCurve = myPane.AddCurve("NULL", List5, Color.Yellow, SymbolType.None);
myPane.XAxis.MajorGrid.IsVisible = true;
myPane.YAxis.Scale.FontSpec.FontColor = Color.White;
myPane.YAxis.Title.FontSpec.FontColor = Color.White;
myPane.YAxis.MajorTic.IsOpposite = false;
myPane.YAxis.MinorTic.IsOpposite = false;
myPane.YAxis.MajorGrid.IsZeroLine = true;
myPane.YAxis.Scale.Align = AlignP.Inside;
myPane.Chart.Fill = new Fill(Color.DimGray, Color.DarkGray, 45.0f);
myPane.Fill = new Fill(Color.DimGray, Color.DimGray, 45.0f);
myPane.Legend.Fill = new Fill(Color.DimGray, Color.DimGray, 0);
myPane.Legend.FontSpec.FontColor = Color.White;
foreach (ZedGraph.LineItem li in myPane.CurveList)
{
li.Line.Width = 2;
}
myPane.XAxis.MajorTic.Color = Color.White;
myPane.XAxis.MinorTic.Color = Color.White;
myPane.YAxis.MajorTic.Color = Color.White;
myPane.YAxis.MinorTic.Color = Color.White;
myPane.XAxis.MajorGrid.Color = Color.White;
myPane.YAxis.MajorGrid.Color = Color.White;
myPane.YAxis.Scale.FontSpec.FontColor = Color.White;
myPane.YAxis.Title.FontSpec.FontColor = Color.White;
myPane.XAxis.Scale.FontSpec.FontColor = Color.White;
myPane.XAxis.Title.FontSpec.FontColor = Color.White;
myPane.Legend.Fill = new ZedGraph.Fill(Color.FromArgb(0x85, 0x84, 0x83));
myPane.Legend.Position = LegendPos.TopCenter;
try
{
zg1.AxisChange();
}
catch { }
}
private void Graphit_Click(object sender, EventArgs e)
{
if (dataGridView1.RowCount == 0 || dataGridView1.ColumnCount == 0)
{
MessageBox.Show("Arquivo invalido!");
return;
}
GraphPane myPane = zg1.GraphPane;
int col = dataGridView1.CurrentCell.ColumnIndex;
int row = dataGridView1.CurrentCell.RowIndex;
string type = dataGridView1[0, row].Value.ToString();
double a = 0;
if (col == 0)
{
return;
}
int error = 0;
foreach (DataGridViewRow datarow in dataGridView1.Rows)
{
DateTime dt;
try
{
dt = Convert.ToDateTime(datarow.Cells[1].Value.ToString());
}
catch
{
dt = Convert.ToDateTime("00:00:00.000");
}
double timestamp = dt.ToOADate();
if (datarow.Cells[0].Value.ToString() == type)
{
try
{
double value = double.Parse(datarow.Cells[col].Value.ToString(), new System.Globalization.CultureInfo("en-US"));
if (Graphs == 0)
{
zg1.GraphPane.CurveList[0].Label.Text = dataGridView1.Columns[col].HeaderText;
List1.Add(timestamp, value);
}
else if (Graphs == 1)
{
zg1.GraphPane.CurveList[1].Label.Text = dataGridView1.Columns[col].HeaderText;
List2.Add(timestamp, value);
}
else if (Graphs == 2)
{
zg1.GraphPane.CurveList[2].Label.Text = dataGridView1.Columns[col].HeaderText;
List3.Add(timestamp, value);
}
else if (Graphs == 3)
{
zg1.GraphPane.CurveList[3].Label.Text = dataGridView1.Columns[col].HeaderText;
List4.Add(timestamp, value);
}
else if (Graphs == 4)
{
zg1.GraphPane.CurveList[4].Label.Text = dataGridView1.Columns[col].HeaderText;
List5.Add(timestamp, value);
}
else
{
MessageBox.Show("Número maximo de componentes ao plotter atingido!");
break;
}
}
catch
{
error++;
if (error >= 500)
{
MessageBox.Show("Caixa-Preta Falhou!"); break;
}
}
}
a++;
}
try
{
zg1.AxisChange();
}
catch { }
zg1.ZoomOutAll(zg1.GraphPane);
zg1.Invalidate();
Graphs++;
}
private void BUT_cleargraph_Click(object sender, EventArgs e)
{
Graphs = 0;
foreach (LineItem line in zg1.GraphPane.CurveList)
{
line.Clear();
line.Label.Text = "NULL";
}
zg1.Invalidate();
}
private void BUT_loadlog_Click(object sender, EventArgs e)
{
ColumnCount = 0;
zg1.GraphPane.CurveList.Clear();
Form1_Load(sender, e);
}
}
}