forked from ArduPilot/MissionPlanner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDashWare.cs
86 lines (74 loc) · 2.84 KB
/
DashWare.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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MissionPlanner.Utilities;
namespace MissionPlanner.Utilities
{
public class DashWare
{
public static void Create(string filein, string fileout, List<string> fmtList = null)
{
using (StreamReader tr = new StreamReader(filein))
using (DFLogBuffer logdata = new DFLogBuffer(tr.BaseStream))
{
List<string> colList = new List<string>();
Dictionary<string, int> colStart = new Dictionary<string, int>();
colStart.Add("GLOBAL", colList.Count);
colList.Add("GLOBAL_TimeMS");
foreach (var logformatValue in logdata.dflog.logformat.Values)
{
if(fmtList != null && !fmtList.Contains(logformatValue.Name))
continue;
colStart.Add(logformatValue.Name, colList.Count);
foreach (var field in logformatValue.FieldNames)
{
colList.Add(logformatValue.Name + "_" + field);
}
}
using (StreamWriter sr = new StreamWriter(fileout))
{
// header
var nCols = 0;
foreach (var item in colList)
{
nCols++;
sr.Write(item + ",");
}
sr.WriteLine();
// lines
foreach (var dfitem in logdata.GetEnumeratorType(colStart.Keys.ToArray()))
{
if (dfitem.msgtype == "FMT")
continue;
var idx = 0;
StringBuilder sb = new StringBuilder();
sb.Append(dfitem.timems);
idx++;
sb.Append(',');
var start = colStart[dfitem.msgtype];
while (idx < start)
{
idx++;
sb.Append(',');
}
foreach (var item in dfitem.items.Skip(1))
{
sb.Append(item?.Trim());
idx++;
sb.Append(',');
}
while (idx < nCols)
{
idx++;
sb.Append(',');
}
sr.WriteLine(sb);
}
}
}
}
}
}