-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathLogReader.cs
60 lines (50 loc) · 2.03 KB
/
LogReader.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
using System.Collections.Generic;
using System.IO;
namespace WtLogging
{
public static class LogReader
{
public static List<string> IdToName = new List<string>();
public static Dictionary<string, List<float>> LogTable = new Dictionary<string, List<float>>();
public static string CraftName = "";
public static int LogEntries = 0;
public static void ReadLog(string filename)
{
IdToName.Clear();
LogTable.Clear();
CraftName = "";
LogEntries = 0;
using (var fs = new FileStream(filename, FileMode.Open, FileAccess.Read))
using (var reader = new BinaryReader(fs))
{
var logProtocolVersion = reader.ReadInt32();
if (logProtocolVersion != LoggingProperties.LogProtocolVersion)
throw new InvalidDataException("This log data is not supported by this version of LogView!");
CraftName = reader.ReadString();
var headerLen = reader.ReadInt32();
for (var i = 0; i < headerLen; ++i)
{
var paramName = reader.ReadString();
IdToName.Add(paramName);
LogTable[paramName] = new List<float>();
}
while (fs.Position < fs.Length)
{
var recordLen = reader.ReadInt32();
foreach (var item in LogTable)
{
item.Value.Add(float.NaN);
}
for (var i = 0; i < recordLen; ++i)
{
var paramId = reader.ReadByte();
var paramVal = reader.ReadSingle();
var paramName = IdToName[paramId];
LogTable[paramName][LogEntries] = paramVal;
}
LogEntries++;
}
}
}
}
}