diff --git a/src/SharpBladeFlightAnalyzer/Controls/LogPageControl.xaml.cs b/src/SharpBladeFlightAnalyzer/Controls/LogPageControl.xaml.cs index 984e0fd..29e8e32 100644 --- a/src/SharpBladeFlightAnalyzer/Controls/LogPageControl.xaml.cs +++ b/src/SharpBladeFlightAnalyzer/Controls/LogPageControl.xaml.cs @@ -259,7 +259,8 @@ private void exportAcmiBtn_Click(object sender, RoutedEventArgs e) } DataField[] posData = new DataField[3]; DataField[] attData = new DataField[3]; - int id = logFile.FormatList["vehicle_global_position"].SubscribedID[0]; + //int id = logFile.FormatList["vehicle_global_position"].SubscribedID[0]; + int id = logFile.FormatList["vehicle_gps_position"].SubscribedID[0]; posData[0] = logFile.MessageDict[id].FieldDict["lon"]; posData[1] = logFile.MessageDict[id].FieldDict["lat"]; posData[2] = logFile.MessageDict[id].FieldDict["alt"]; @@ -288,7 +289,8 @@ private void exportAcmiBtn_Click(object sender, RoutedEventArgs e) var posTimes = posData[0].Timestamps; var attTimes = attData[0].Timestamps; sw.WriteLine("#{0}", Math.Min(posTimes[0], attTimes[0])); - sw.WriteLine("101,T={0}|{1}|{2}", posData[0].Values[0], posData[1].Values[0], posData[2].Values[0]); + //sw.WriteLine("101,T={0}|{1}|{2}", posData[0].Values[0], posData[1].Values[0], posData[2].Values[0]); + sw.WriteLine("101,T={0}|{1}|{2}", posData[0].Values[0]/1E7, posData[1].Values[0] / 1E7, posData[2].Values[0] / 1E3); hdg = attData[2].Values[0] * 57.29577951; while (pospos < posTimes.Count || attpos < attTimes.Count) { @@ -317,7 +319,7 @@ private void exportAcmiBtn_Click(object sender, RoutedEventArgs e) //Update pos sw.WriteLine("#" + posTimes[pospos].ToString()); - sw.WriteLine("101,T={0}|{1}|{2}|{3}|{4}|{5}", posData[0].Values[pospos], posData[1].Values[pospos], posData[2].Values[pospos], attFilter[0] * 57.29577951, attFilter[1] * 57.29577951, hdg); + sw.WriteLine("101,T={0}|{1}|{2}|{3}|{4}|{5}", posData[0].Values[pospos] / 1E7, posData[1].Values[pospos] / 1E7, posData[2].Values[pospos] / 1E3, attFilter[0] * 57.29577951, attFilter[1] * 57.29577951, hdg); pospos++; } else diff --git a/src/SharpBladeFlightAnalyzer/LoadViewModel.cs b/src/SharpBladeFlightAnalyzer/LoadViewModel.cs index dd9f76b..9b4b2d4 100644 --- a/src/SharpBladeFlightAnalyzer/LoadViewModel.cs +++ b/src/SharpBladeFlightAnalyzer/LoadViewModel.cs @@ -18,6 +18,8 @@ public class LoadViewModel : INotifyPropertyChanged Visibility visibility; + bool loadFailed; + public double MaxProgress { @@ -47,5 +49,7 @@ public Visibility Visibility PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Visibility")); } } + + public bool LoadFailed { get => loadFailed; set => loadFailed = value; } } } diff --git a/src/SharpBladeFlightAnalyzer/MainWindow.xaml.cs b/src/SharpBladeFlightAnalyzer/MainWindow.xaml.cs index 086bc0f..76cef3c 100644 --- a/src/SharpBladeFlightAnalyzer/MainWindow.xaml.cs +++ b/src/SharpBladeFlightAnalyzer/MainWindow.xaml.cs @@ -216,30 +216,28 @@ private void Window_Drop(object sender, DragEventArgs e) return; if(e.Data.GetDataPresent(DataFormats.FileDrop)) { - string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); - - startLoadFile(files[0]); - + string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); + startLoadFile(files[0]); } } - private void loadFile(string path) - { - ULogFile f = new ULogFile(); - if (f.Load(path, fieldConfigs)) - { - LogPageControl lpc = new LogPageControl(f, this); - lpc.addFieldBtn.Click += AddFieldBtn_Click; - TabPage page = new TabPage(); - page.Header = f.File.Name; + //private void loadFile(string path) + //{ + // ULogFile f = new ULogFile(); + // if (f.Load(path, fieldConfigs)) + // { + // LogPageControl lpc = new LogPageControl(f, this); + // lpc.addFieldBtn.Click += AddFieldBtn_Click; + // TabPage page = new TabPage(); + // page.Header = f.File.Name; - page.Content = lpc; - page.DisposableContent = f; - mainTabControl.Items.Insert(mainTabControl.Items.Count - 1, page); - mainTabControl.SelectedIndex = mainTabControl.Items.Count - 2; - currentPage = lpc; - } - } + // page.Content = lpc; + // page.DisposableContent = f; + // mainTabControl.Items.Insert(mainTabControl.Items.Count - 1, page); + // mainTabControl.SelectedIndex = mainTabControl.Items.Count - 2; + // currentPage = lpc; + // } + //} private void startLoadFile(string path) { @@ -249,20 +247,31 @@ private void startLoadFile(string path) Thread uiThread = new Thread(new ParameterizedThreadStart(updateUI)); uiThread.IsBackground = true; uiThread.Start(path); - } private void updateUI(object o) { string path = (string)o; + lvm.LoadFailed = false; Thread loadThread= new Thread(new ParameterizedThreadStart(loadingFile)); loadThread.IsBackground = true; - lvm.CurrProgress = 0; - lvm.Visibility = Visibility.Visible; + lvm.CurrProgress = 0; ULogFile f = new ULogFile(); loadThread.Start(new Tuple(f, path)); - Thread.Sleep(20); + while(f.TotalSize<0) + { + Thread.Sleep(20); + if(lvm.LoadFailed) + { + Dispatcher.Invoke(() => ShowMessageBox("无法打开文件")); + + isloading = false; + return; + } + } + lvm.MaxProgress = f.TotalSize; + lvm.Visibility = Visibility.Visible; while (true) { lvm.CurrProgress = f.CurrPos; @@ -292,6 +301,8 @@ private void loadingFile(object o) Tuple args = (Tuple)o; ULogFile f = args.Item1; bool res = f.Load(args.Item2, fieldConfigs); + if (res == false) + lvm.LoadFailed = true; } private void Window_Loaded(object sender, RoutedEventArgs e) diff --git a/src/SharpBladeFlightAnalyzer/ULogFile.cs b/src/SharpBladeFlightAnalyzer/ULogFile.cs index 2bcb897..b1cd223 100644 --- a/src/SharpBladeFlightAnalyzer/ULogFile.cs +++ b/src/SharpBladeFlightAnalyzer/ULogFile.cs @@ -13,6 +13,7 @@ public class ULogFile :IDisposable { private static Dictionary typeSize; public static DateTime UnixStartTime = new DateTime(1970, 1, 1, 0, 0, 0, 0); + const string AllMsgTypes = "BFIMPQARDLCSO"; UInt64 timestamp; byte version; @@ -103,7 +104,7 @@ public FileInfo File public List MessageList { get => messageList; set => messageList = value; } public Dictionary FormatList { get => formatList; set => formatList = value; } public Dictionary MessageDict { get => messageDict; set => messageDict = value; } - public long TotalSize { get => reader.BaseStream.Length; } + public long TotalSize { get => reader == null ? -1 : reader.BaseStream.Length; } public long CurrPos { get => currLoadPos; } public bool ReadCompleted { get => readCompleted; set => readCompleted = value; } @@ -122,8 +123,16 @@ public ULogFile() public bool Load(string path, Dictionary fieldConfigs) { - file = new FileInfo(path); - reader = new BinaryReader(new FileStream(path, FileMode.Open)); + file = new FileInfo(path); + try + { + reader = new BinaryReader(new FileStream(path,FileMode.Open,FileAccess.Read)); + } + catch + { + return false; + } + byte[] buff = reader.ReadBytes(8); if (buff[0] != 0x55) return false; @@ -224,6 +233,7 @@ private bool readMessage() { if (reader.BaseStream.Length - reader.BaseStream.Position < 3) return false; + long pos = reader.BaseStream.Position; ushort size = reader.ReadUInt16(); byte msgtype = reader.ReadByte(); if (reader.BaseStream.Length - reader.BaseStream.Position < size) @@ -275,11 +285,30 @@ private bool readMessage() case 79://O res = readDropoutMark(size); break; + default: - Debug.WriteLine("Unknow message type:{0},at {1}, size {2}.", msgtype, reader.BaseStream.Position,size); + if (msgtype == 0 && size==0) + { + int blanklen = 0; + while (reader.BaseStream.Position != reader.BaseStream.Length) + { + byte b = reader.ReadByte(); + if (b == 0) + blanklen++; + else + break; + } + Debug.WriteLine("Suspected blank data:at {0}, len {1}.", pos, blanklen); + } + Debug.WriteLine("Unknow message type:{0},at {1}, size {2}.", msgtype, pos, size); byte[] tmp= reader.ReadBytes(size); res = false; errmsg = "未知日志消息类型:" + msgtype.ToString(); + Debug.WriteLine("Try to find the next package."); + if (!findNextData()) + { + errmsg = "文件末端损坏"; + } break; } @@ -301,6 +330,48 @@ private bool readMessage() return res; } + + private bool checkData(int thrd) + { + long posbackup = reader.BaseStream.Position; + + for(int i=0;i