forked from ArduPilot/MissionPlanner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScan.cs
115 lines (94 loc) · 4.5 KB
/
Scan.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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using ICSharpCode.SharpZipLib.Core;
using ICSharpCode.SharpZipLib.Zip;
namespace MissionPlanner.Log
{
public class Scan
{
public static void ScanAccel()
{
string[] files = Directory.GetFiles(MainV2.LogDir, "*.tlog", SearchOption.AllDirectories);
List<string> badfiles = new List<string>();
foreach (var file in files)
{
bool board = false;
Console.WriteLine(file);
MAVLinkInterface mavi = new MAVLinkInterface();
using (mavi.logplaybackfile = new BinaryReader(File.OpenRead(file)))
{
mavi.logreadmode = true;
try
{
while (mavi.logplaybackfile.BaseStream.Position < mavi.logplaybackfile.BaseStream.Length)
{
byte[] packet = mavi.readPacket();
if (packet.Length == 0)
break;
var objectds = mavi.DebugPacket(packet, false);
if (objectds is MAVLink.mavlink_param_value_t)
{
MAVLink.mavlink_param_value_t param = (MAVLink.mavlink_param_value_t)objectds;
if (ASCIIEncoding.ASCII.GetString(param.param_id).Contains("INS_PRODUCT_ID"))
{
if (param.param_value == 0 || param.param_value == 5)
{
board = true;
}
else
{
break;
}
}
}
if (objectds is MAVLink.mavlink_raw_imu_t)
{
MAVLink.mavlink_raw_imu_t rawimu = (MAVLink.mavlink_raw_imu_t)objectds;
if (board && Math.Abs(rawimu.xacc) > 2000 && Math.Abs(rawimu.yacc) > 2000 && Math.Abs(rawimu.zacc) > 2000)
{
//CustomMessageBox.Show("Bad Log " + file);
badfiles.Add(file);
break;
}
}
}
}
catch { }
}
}
if (badfiles.Count > 0)
{
FileStream fs = File.Open(MainV2.LogDir + Path.DirectorySeparatorChar + "SearchResults.zip", FileMode.Create);
ZipOutputStream zipStream = new ZipOutputStream(fs);
zipStream.SetLevel(9); //0-9, 9 being the highest level of compression
zipStream.UseZip64 = UseZip64.Off; // older zipfile
foreach (var file in badfiles)
{
// entry 2
string entryName = ZipEntry.CleanName(Path.GetFileName(file)); // Removes drive from name and fixes slash direction
ZipEntry newEntry = new ZipEntry(entryName);
newEntry.DateTime = DateTime.Now;
zipStream.PutNextEntry(newEntry);
// Zip the file in buffered chunks
// the "using" will close the stream even if an exception occurs
byte[] buffer = new byte[4096];
using (FileStream streamReader = File.OpenRead(file))
{
StreamUtils.Copy(streamReader, zipStream, buffer);
}
zipStream.CloseEntry();
}
zipStream.IsStreamOwner = true; // Makes the Close also Close the underlying stream
zipStream.Close();
CustomMessageBox.Show("Added " + badfiles.Count + " logs to " + MainV2.LogDir + Path.DirectorySeparatorChar + "SearchResults.zip\n Please send this file to Craig Elder <[email protected]>");
}
else
{
CustomMessageBox.Show("No Bad Logs Found");
}
}
}
}