public static string tlogToCSV(string filepath)
{
CurrentState.SpeedUnit = "m/s";
CurrentState.DistanceUnit = "m";
MAVLinkInterface proto = new MAVLinkInterface();
OpenFileDialog openFileDialog1 = new OpenFileDialog();
string LogFilePath;
openFileDialog1.FileName = filepath;
foreach (string logfile in openFileDialog1.FileNames)
{
using (MAVLinkInterface mine = new MAVLinkInterface())
{
try
{
mine.logplaybackfile = new BinaryReader(File.Open(logfile, FileMode.Open, FileAccess.Read, FileShare.Read));
}
catch (Exception ex) { log.Debug(ex.ToString()); }
mine.logreadmode = true;
mine.MAV.packets.Initialize(); // clear
StreamWriter sw = new StreamWriter(Path.GetDirectoryName(logfile) + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(logfile) + ".csv");
while (mine.logplaybackfile.BaseStream.Position < mine.logplaybackfile.BaseStream.Length)
{
byte[] packet = mine.readPacket();
string text = "";
mine.DebugPacket(packet, ref text, true, ",");
sw.Write(mine.lastlogread.ToString("yyyy-MM-ddTHH:mm:ss.fff") + "," + text);
}
sw.Close();
mine.logreadmode = false;
mine.logplaybackfile.Close();
mine.logplaybackfile = null;
LogFilePath = (Path.GetDirectoryName(logfile) + Path.DirectorySeparatorChar + (Path.GetFileNameWithoutExtension(logfile) + ".csv"));
return LogFilePath;
}
}
return null;
}