Exemple #1
0
 private void UpdateButtons()
 {
     UiDispatcher.RunOnUIThread(() =>
     {
         ShowMapButton.Visibility = Visibility.Visible;
     });
 }
Exemple #2
0
        private void DiffBaseline(TestModel model)
        {
            string path = model.Path;

            model.Baseline = FindBaseline(path);
            string newBaseLine = System.IO.Path.Combine(model.Path, settings.ErrorLogName);
            string oldBaseLine = System.IO.Path.Combine(model.Baseline, settings.BaselineName);

            if (File.Exists(newBaseLine) && !File.Exists(oldBaseLine))
            {
                MessageBox.Show(this, model.Path + "\n\nThis test baseline cannot be fixed because it was not supposed to pass.", "Unexpected Baseline", MessageBoxButton.OK, MessageBoxImage.Error);
                FailedTestList.SelectedIndex++;
                return;
            }
            else if (!File.Exists(newBaseLine) && File.Exists(oldBaseLine))
            {
                MessageBox.Show(this, model.Path + "\n\nThis test baseline cannot be fixed because the test couldn't run.", "Missing Baseline", MessageBoxButton.OK, MessageBoxImage.Error);
                FailedTestList.SelectedIndex++;
                return;
            }


            Task.Run(() =>
            {
                string args     = string.Format("\"{0}\" \"{1}\"", newBaseLine, oldBaseLine);
                Process windiff = Process.Start(new ProcessStartInfo(settings.WindiffPath, args));
                windiff.WaitForExit();
                UiDispatcher.RunOnUIThread(() =>
                {
                    PromptUser(model);
                });
            });
        }
Exemple #3
0
        void Backup(bool shutdown)
        {
            ConsoleTextBox.Document.Blocks.Clear();
            this._errors = new ErrorLog();
            this.cancel  = new CancellationTokenSource();
            Task.Run(() =>
            {
                try
                {
                    backup.Run(this._log, this._errors, cancel);
                }
                catch (Exception ex)
                {
                    backup.Error    = ex.Message;
                    backup.Running  = false;
                    backup.Complete = true;
                    this._log.WriteLine(ex.Message);
                }
                if (shutdown)
                {
                    backup.Shutdown();
                    UiDispatcher.RunOnUIThread(ShowCancelShutdown);
                }

                UiDispatcher.RunOnUIThread(OnBackupComplete);
            });
        }
Exemple #4
0
        private async Task LoadJSonFile(string file)
        {
            try
            {
                UiDispatcher.RunOnUIThread(() =>
                {
                    SystemConsole.Show();
                });
                AppendMessage("Loading " + file);
                ShowStatus("Loading " + file);

                JSonDataLog data = new JSonDataLog();
                await data.Load(file, progress);

                //logs.Add(data);
                ShowSchema();

                LoadFlights(data);
            }
            catch (Exception ex)
            {
                AppendMessage("### Error loading json file: " + ex.Message);
            }
            ShowStatus("Done Loading " + file);
            UpdateButtons();
        }
Exemple #5
0
        private async Task LoadMavlinkFile(string file)
        {
            try
            {
                UiDispatcher.RunOnUIThread(() =>
                {
                    SystemConsole.Show();
                });
                AppendMessage("Loading " + file);
                ShowStatus("Loading " + file);

                MavlinkLog data = new MavlinkLog();
                await data.Load(file, progress);

                logs.Add(data);
                ShowSchema();

                Debug.WriteLine(data.StartTime.ToString());
                LoadFlights(data);

                // remember successfully loaded log file.
                Settings settings = await((App)App.Current).LoadSettings();
                settings.LastLogFile = file;
                await settings.SaveAsync();
            }
            catch (Exception ex)
            {
                AppendMessage("### Error loading log: " + ex.Message);
            }
            ShowStatus("Done Loading " + file);
            UpdateButtons();
        }
Exemple #6
0
        bool HandleUnhandledException(object exceptionObject)
        {
            Exception ex      = exceptionObject as Exception;
            string    message = null;
            string    details = null;

            if (ex == null && exceptionObject != null)
            {
                message = exceptionObject.GetType().FullName;
                details = exceptionObject.ToString();
            }
            else
            {
                message = ex.Message;
                details = ex.ToString();
            }

            try
            {
                UiDispatcher.RunOnUIThread(() =>
                {
                    MessageBoxEx.Show(message, "Unhandled Exception", details, MessageBoxButton.OK, MessageBoxImage.Error);
                });
                return(true);
            }
            catch (Exception)
            {
                // hmmm, if we can't show the dialog then perhaps this is some sort of stack overflow.
                // save the details to a file, terminate the process and
            }
            return(false);
        }
Exemple #7
0
        private void ShowSchema()
        {
            UiDispatcher.RunOnUIThread(() =>
            {
                LogItemSchema schema = null;

                // todo: compute combined schema for selected logs, but for now just show the first one.
                if (this.currentFlightLog != null)
                {
                    schema = currentFlightLog.Schema;
                }
                else if (this.logs.Count > 0)
                {
                    schema = this.logs[0].Schema;
                }
                if (schema == null || schema.ChildItems == null || schema.ChildItems.Count == 0)
                {
                    CategoryList.ItemsSource = null;
                }
                else
                {
                    // todo: compute combined schema for selected logs, but for now just show the first one.
                    List <LogItemSchema> list = new List <Model.LogItemSchema>(schema.ChildItems);
                    list.Sort((a, b) => { return(string.Compare(a.Name, b.Name, StringComparison.OrdinalIgnoreCase)); });
                    CategoryList.ItemsSource = list;
                }
            });
        }
Exemple #8
0
 private void ShowStatus(string message)
 {
     UiDispatcher.RunOnUIThread(() =>
     {
         StatusText.Text = message;
     });
 }
Exemple #9
0
        private void LoadFlights(IDataLog data)
        {
            UiDispatcher.RunOnUIThread(() =>
            {
                // add flights
                Flight entireLog = new Flight()
                {
                    Name      = "Log " + logs.Count,
                    StartTime = data.StartTime,
                    Duration  = data.Duration
                };
                allFlights.Add(entireLog);

                foreach (var flight in data.GetFlights())
                {
                    flight.Name = "Flight " + allFlights.Count;
                    allFlights.Add(flight);
                    AppendMessage("Motor started at {0} and ran for {1} ", flight.StartTime, flight.Duration);
                }

                if (myMap.Visibility == Visibility.Visible)
                {
                    ShowMap();
                }
            });
        }
 private void FiterEventTextChanged(string filter)
 {
     if (FilterValueChanged != null)
     {
         UiDispatcher.RunOnUIThread(() =>
         {
             this.FilterValueChanged(this, filter);
         });
     }
 }
Exemple #11
0
        private async Task LoadMavlinkFile(string file)
        {
            try
            {
                UiDispatcher.RunOnUIThread(() =>
                {
                    SystemConsole.Show();
                });
                AppendMessage("Loading " + file);
                ShowStatus("Loading " + file);

                MavlinkLog data = new MavlinkLog();
                await data.Load(file, progress);

                logs.Add(data);
                ShowSchema();

                Debug.WriteLine(data.StartTime.ToString());

                UiDispatcher.RunOnUIThread(() =>
                {
                    foreach (var flight in data.GetFlights())
                    {
                        flight.Name = "Flight " + allFlights.Count;
                        allFlights.Add(flight);
                        AppendMessage("Motor started at {0} and ran for {1} ", flight.StartTime, flight.Duration);
                    }

                    if (myMap.Visibility == Visibility.Visible)
                    {
                        ShowMap();
                    }

                    foreach (var text in data.GetStatusMessages())
                    {
                        SystemConsole.Write(text + "\n");
                    }

                    ShowTotalFlightTime();
                });



                // remember successfully loaded log file.
                Settings settings = await((App)App.Current).LoadSettings();
                settings.LastLogFile = file;
                await settings.SaveAsync();
            }
            catch (Exception ex)
            {
                AppendMessage("### Error loading log: " + ex.Message);
            }
            ShowStatus("Done Loading " + file);
            UpdateButtons();
        }
Exemple #12
0
        private async Task LoadBinaryFile(string file)
        {
            try
            {
                UiDispatcher.RunOnUIThread(() =>
                {
                    SystemConsole.Show();
                });
                AppendMessage("Loading " + file);
                ShowStatus("Loading " + file);

                Px4DataLog data = new Px4DataLog();
                await data.Load(file, progress);

                logs.Add(data);
                ShowSchema();

                UiDispatcher.RunOnUIThread(() =>
                {
                    // add flights
                    Flight entireLog = new Flight()
                    {
                        Name      = "Log " + logs.Count,
                        StartTime = data.StartTime,
                        Duration  = data.Duration
                    };
                    allFlights.Add(entireLog);

                    foreach (var flight in data.GetFlights())
                    {
                        flight.Name = "Flight " + allFlights.Count;
                        allFlights.Add(flight);
                        AppendMessage("Motor started at {0} and ran for {1} ", flight.StartTime, flight.Duration);
                    }

                    if (myMap.Visibility == Visibility.Visible)
                    {
                        ShowMap();
                    }

                    ShowTotalFlightTime();
                });

                // remember successfully loaded log file.
                Settings settings = await((App)App.Current).LoadSettings();
                settings.LastLogFile = file;
                await settings.SaveAsync();
            }
            catch (Exception ex)
            {
                AppendMessage("### Error loading log: " + ex.Message);
            }
            ShowStatus("Done Loading " + file);
            UpdateButtons();
        }
Exemple #13
0
        private void OpenAudioFile(string fileName)
        {
            this.isRecording = true;
            string wavFile = null;

            this.samples = new List <float>();
            if (System.IO.Path.GetExtension(fileName).ToLowerInvariant() == ".wav")
            {
                wavFile = fileName;
            }
            else
            {
                // then we'll load the audio and convert it to a wav file.
                wavFile = GetNextWavFileName();
            }

            try
            {
                this.recording = new AudioRecording(fileName, wavFile, (s, sample) =>
                {
                    // handle PCM data on background thread
                    UiDispatcher.RunOnUIThread(new Action(() =>
                    {
                        if (sample.Error != null)
                        {
                            ShowStatus(sample.Error);
                            StopRecording();
                        }
                        else
                        {
                            if (this.isRecording)
                            {
                                CollectSamples(sample);
                            }
                            if (sample.Closed)
                            {
                                StopRecording();
                            }
                            else
                            {
                                this.recording.ReadNextFrame();
                            }
                        }
                    }));
                });
            }
            catch (Exception ex)
            {
                ShowStatus(ex.Message);
            }
            SetButtonState();
        }
Exemple #14
0
 private void AppendMessage(string message, params object[] args)
 {
     UiDispatcher.RunOnUIThread(() =>
     {
         if (args == null || args.Length == 0)
         {
             SystemConsole.Write(message + "\n");
         }
         else
         {
             SystemConsole.Write(string.Format(message, args) + "\n");
         }
     });
 }
Exemple #15
0
 private void OnFlightSelected(object sender, SelectionChangedEventArgs e)
 {
     UiDispatcher.RunOnUIThread(() =>
     {
         if (myMap.Visibility == Visibility.Visible)
         {
             ShowMap();
         }
         else
         {
             // todo: show sensor data pruned to this flight time...
             foreach (LogItemSchema item in CategoryList.SelectedItems)
             {
                 if (item.ChildItems == null || item.ChildItems.Count == 0)
                 {
                     GraphItem(item);
                 }
             }
         }
     });
 }
Exemple #16
0
 void OnDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
 {
     if (handlingException)
     {
         e.Handled = false;
     }
     else
     {
         handlingException = true;
         UiDispatcher.RunOnUIThread(new Action(() =>
         {
             try
             {
                 e.Handled = HandleUnhandledException(e.Exception);
             }
             catch (Exception)
             {
             }
             handlingException = false;
         }));
     }
 }
        private void FetchNextHole(mavlink_log_data_t?downloaded)
        {
            bool next = false;

            if (downloaded == null)
            {
                next = true;
            }
            else
            {
                holeCount += downloaded.Value.count;
                if (holeCount == hole.Item2)
                {
                    // done!, get the next one.
                    next = true;
                }
            }
            if (next && holes.Count > 0)
            {
                holeCount = 0;
                hole      = holes[0];
                holes.RemoveAt(0);
                Debug.WriteLine("Filling hole at {0}, size {1}", hole.Item1, hole.Item2);
                RequestLogData(selectedEntry.id, hole.Item1, hole.Item2);
                if (!verifying)
                {
                    verifying = true;
                    UiDispatcher.RunOnUIThread(() =>
                    {
                        DownloadStatus.Text = "verifying...";
                    });
                }
            }
            else
            {
                // we should be done, the CheckDone will fine out for sure after we resort the data and check for holes again...
            }
        }
        private void OnMessageReceived(object sender, MavLinkMessage e)
        {
            if (e.MsgId == MAVLINK_MSG_ID.LOG_ENTRY)
            {
                if (e.TypedPayload is mavlink_log_entry_t)
                {
                    List <LogEntryModel> list  = new List <LogEntryModel>();
                    mavlink_log_entry_t  entry = (mavlink_log_entry_t)e.TypedPayload;
                    UiDispatcher.RunOnUIThread(() =>
                    {
                        logList.Add(new LogEntryModel(entry));
                        delayedActions.CancelDelayedAction("GetList");
                    });
                }
            }
            else if (e.MsgId == MAVLINK_MSG_ID.LOG_DATA)
            {
                if (e.TypedPayload is mavlink_log_data_t)
                {
                    var logdata = (mavlink_log_data_t)e.TypedPayload;
                    if (logdata.id == selectedEntry.id)
                    {
                        lock (data)
                        {
                            lastChunkTime    = Environment.TickCount;
                            totalDownloaded += logdata.count;
                            data.Add(logdata);
                        }

                        if (holes.Count > 0)
                        {
                            FetchNextHole(logdata);
                        }
                    }
                }
            }
        }
Exemple #19
0
        private void OnRecord(object sender, RoutedEventArgs e)
        {
            this.samples     = new List <float>();
            this.isRecording = true;
            string filename = GetNextWavFileName();

            try
            {
                this.recording = this.selectedDevice.StartRecording(filename, (s, sample) =>
                {
                    // handle PCM data on background thread
                    //
                    UiDispatcher.RunOnUIThread(new Action(() =>
                    {
                        if (this.isRecording)
                        {
                            CollectSamples(sample);
                        }
                        if (sample.Error != null)
                        {
                            ShowStatus(sample.Error);
                        }
                        else if (!sample.Closed)
                        {
                            // keep pumping no matter what so we don't get any buffering on next recording.
                            this.recording.ReadNextFrame();
                        }
                    }));
                });
            }
            catch (Exception ex)
            {
                ShowStatus(ex.Message);
            }
            SetButtonState();
        }
        private void CheckDone()
        {
            if (checking)
            {
                return;
            }
            checking = true;
            try
            {
                bool foundHole = false;
                uint pos       = 0;
                var  holes     = new List <Tuple <uint, uint> >();

                lock (data)
                {
                    // sort packets in order of ofs.
                    data.Sort((a, b) => { return((int)a.ofs - (int)b.ofs); });

                    foreach (var e in data.ToArray())
                    {
                        if (e.ofs < pos)
                        {
                            // duplicate?
                            data.Remove(e);
                        }
                        else if (e.ofs != pos)
                        {
                            // we have a hole!!
                            foundHole = true;
                            holes.Add(new Tuple <uint, uint>(pos, e.ofs - pos));
                            pos = e.ofs + e.count;
                        }
                        else
                        {
                            pos += e.count;
                        }
                    }
                }

                if (!foundHole)
                {
                    if (selectedEntry.size <= totalDownloaded)
                    {
                        // ok, we're done!
                        Debug.WriteLine("Log is complete!");
                        if (!complete)
                        {
                            complete = true;
                            UiDispatcher.RunOnUIThread(() =>
                            {
                                StopProgress();
                                OnSaveLog();
                            });
                        }
                    }
                }
                else
                {
                    this.holes = holes;
                    FetchNextHole(null);
                }
            }
            finally
            {
                checking = false;
            }
        }
Exemple #21
0
        private void OnMavlinkMessageReceived(object sender, MavLinkMessage e)
        {
            if (currentFlightLog != null && !pauseRecording)
            {
                currentFlightLog.AddMessage(e);
            }

            switch (e.MsgId)
            {
            case MAVLink.MAVLINK_MSG_ID.ATTITUDE_QUATERNION:
            {
                var payload = (MAVLink.mavlink_attitude_quaternion_t)e.TypedPayload;
                var q       = new System.Windows.Media.Media3D.Quaternion(payload.q1, payload.q2, payload.q3, payload.q4);
                UiDispatcher.RunOnUIThread(() =>
                    {
                        //ModelViewer.ModelAttitude = initialAttitude * q;
                    });
                break;
            }

            case MAVLink.MAVLINK_MSG_ID.ATTITUDE:
            {
                var        payload = (MAVLink.mavlink_attitude_t)e.TypedPayload;
                Quaternion y       = new Quaternion(new Vector3D(0, 0, 1), -payload.yaw * 180 / Math.PI);
                Quaternion x       = new Quaternion(new Vector3D(1, 0, 0), payload.pitch * 180 / Math.PI);
                Quaternion z       = new Quaternion(new Vector3D(0, 1, 0), payload.roll * 180 / Math.PI);
                UiDispatcher.RunOnUIThread(() =>
                    {
                        ModelViewer.ModelAttitude = initialAttitude * (y * x * z);
                    });
                break;
            }

            case MAVLink.MAVLINK_MSG_ID.HIL_STATE_QUATERNION:
            {
                var        payload = (MAVLink.mavlink_hil_state_quaternion_t)e.TypedPayload;
                Quaternion q       = new Quaternion(payload.attitude_quaternion[0],
                                                    payload.attitude_quaternion[1],
                                                    payload.attitude_quaternion[2],
                                                    payload.attitude_quaternion[3]);
                UiDispatcher.RunOnUIThread(() =>
                    {
                        ModelViewer.ModelAttitude = initialAttitude * q;
                    });
                break;
            }

            case MAVLink.MAVLINK_MSG_ID.GLOBAL_POSITION_INT:
            {
                var payload = (MAVLink.mavlink_global_position_int_t)e.TypedPayload;
                UiDispatcher.RunOnUIThread(() =>
                    {
                        MapLocation((double)payload.lat / 1e7, (double)payload.lon / 1e7);
                    });
                break;
            }

            case MAVLink.MAVLINK_MSG_ID.SERIAL_CONTROL:
            {
                var ctrl = (MAVLink.mavlink_serial_control_t)e.TypedPayload;
                if (ctrl.count > 0)
                {
                    string text = System.Text.Encoding.ASCII.GetString(ctrl.data, 0, ctrl.count);
                    UiDispatcher.RunOnUIThread(() =>
                        {
                            SystemConsole.Write(text);
                        });
                }
                break;
            }

            case MAVLink.MAVLINK_MSG_ID.DATA_TRANSMISSION_HANDSHAKE:
                if (showImageStream)
                {
                    var p = (MAVLink.mavlink_data_transmission_handshake_t)e.TypedPayload;
                    incoming_image.size           = p.size;
                    incoming_image.packets        = p.packets;
                    incoming_image.payload        = p.payload;
                    incoming_image.quality        = p.jpg_quality;
                    incoming_image.type           = p.type;
                    incoming_image.width          = p.width;
                    incoming_image.height         = p.height;
                    incoming_image.start          = Environment.TickCount;
                    incoming_image.packetsArrived = 0;
                    incoming_image.data           = new byte[incoming_image.size];
                }
                break;

            case MAVLink.MAVLINK_MSG_ID.ENCAPSULATED_DATA:
                if (showImageStream)
                {
                    var img = (MAVLink.mavlink_encapsulated_data_t)e.TypedPayload;

                    int  seq = img.seqnr;
                    uint pos = (uint)seq * (uint)incoming_image.payload;

                    // Check if we have a valid transaction
                    if (incoming_image.packets == 0 || incoming_image.size == 0)
                    {
                        // not expecting an image?
                        incoming_image.packetsArrived = 0;
                        break;
                    }

                    uint available = (uint)incoming_image.payload;
                    if (pos + available > incoming_image.size)
                    {
                        available = incoming_image.size - pos;
                    }
                    Array.Copy(img.data, 0, incoming_image.data, pos, available);

                    progress.ShowProgress(0, incoming_image.size, pos + available);

                    ++incoming_image.packetsArrived;
                    //Debug.WriteLine("packet {0} of {1}, position {2} of {3}", incoming_image.packetsArrived, incoming_image.packets,
                    //    pos + available, incoming_image.size);

                    // emit signal if all packets arrived
                    if (pos + available >= incoming_image.size)
                    {
                        // Restart state machine
                        incoming_image.packets        = 0;
                        incoming_image.packetsArrived = 0;
                        byte[] saved = incoming_image.data;
                        incoming_image.data = null;

                        UiDispatcher.RunOnUIThread(() =>
                        {
                            progress.ShowProgress(0, 0, 0);
                            ShowImage(saved);
                        });
                    }
                }
                break;
            }
        }