Exemple #1
0
        public bool TakeOff()
        {
            if (!enabled)
            {
                return(false);
            }
            if (droneClient.IsActive && !droneClient.IsFlying)
            {
                Logger.WriteLine("TakeOff");

                if (detectFlyStatusTimer != null)
                {
                    detectFlyStatusTimer.Stop();
                }
                detectFlyStatusTimer          = new DispatcherTimer();
                detectFlyStatusTimer.Interval = TimeSpan.FromMilliseconds(200);
                detectFlyStatusTimer.Tick    += (object sender, EventArgs e) => {
                    if (droneClient.IsFlying)
                    {
                        if (OnFlyStopStart != null)
                        {
                            OnFlyStopStart(true);
                        }
                        detectFlyStatusTimer.Stop();
                    }
                };
                detectFlyStatusTimer.Start();

                droneClient.TakeOff();
                // commandTimer.Start();
                return(true);
            }
            return(false);
        }
Exemple #2
0
        /// <summary>
        /// Updates availability based on a clean response from the car's OBD system, as well as a PID number where this information should be stored.
        /// </summary>
        /// <param name="supportedSensors"></param>
        private void updateAvailability(string supportedSensors)
        {
            Logger.WriteLine("Updating availability PID to " + supportedSensors);

            // If this PID is an 'availability' PID, it should have a 'start' number of the first PID available here.
            ulong u_startPID = (ulong)this.firstPID;
            ulong u_endPID   = u_startPID + 31;

            UInt64 nHex = UInt64.Parse(supportedSensors, NumberStyles.HexNumber);

            for (ulong currentPID_absolute = u_startPID; currentPID_absolute <= u_endPID; currentPID_absolute++)
            {
                ulong currentPID_relative = u_endPID - currentPID_absolute;
                ulong currentPID_bit      = (ulong)Math.Pow(2, currentPID_relative);

                var result = this.PIDSensors.Where(sensor => ((ulong)sensor.PID == currentPID_absolute));
                if ((nHex & currentPID_bit) == currentPID_bit && result.Count() == 1)
                {
                    Logger.WriteLine("Setting PID " + currentPID_absolute + "(0x" + currentPID_absolute.ToString("x") + " available");

                    result.First().isAvailable = true;
                }
                else if (result.Count() == 1)
                {
                    Logger.WriteLine("Setting PID " + currentPID_absolute + "(0x" + currentPID_absolute.ToString("x") + " unavailable");

                    result.First().isAvailable = false;
                }
            }
        }
Exemple #3
0
        public void StartRecording()
        {
            if (!SettingsModel.Instance.PathRecorder)
            {
                return;
            }
            isPaused        = false;
            pausedTime      = 0;
            missionDateTime = DateTime.Now;
            missionName     = MissionManager.MakeMissionName(missionDateTime);
            missionTitle    = MissionManager.MakeMissionTitle(missionDateTime);
            Logger.WriteLine("Start mission: " + missionName);
            ticksStarted = missionDateTime.Ticks;
            activities.Clear();
            navigationCommands.Clear();
            missionDoc  = new XDocument();
            rootElement = new XElement("flight");
            missionDoc.Add(rootElement);
            rootElement.Add(new XElement("common",
                                         new XElement("datetime", missionDateTime),
                                         new XElement("latitude", 0),
                                         new XElement("longitude", 0)));
            activitiesElement = new XElement("activities");
            rootElement.Add(activitiesElement);

            TriggerMessage("Flight recording started");
        }
Exemple #4
0
 public void Disconnect()
 {
     if (!enabled)
     {
         return;
     }
     Logger.WriteLine("Drone.Disconnect()");
     droneClient.Close();
 }
Exemple #5
0
 public bool Emergency()
 {
     Logger.WriteLine("Emergency");
     if (droneClient.IsActive)
     {
         droneClient.Emergency();
         return(true);
     }
     return(false);
 }
Exemple #6
0
        public async Task <bool> Connect()
        {
            if (!enabled)
            {
                return(false);
            }
            Logger.WriteLine("Drone.Connect()");
            bool connected = await droneClient.ConnectAsync();

            return(connected);
        }
Exemple #7
0
 // Code to execute when the application is closing (eg, user hit Back)
 // This code will not execute when the application is deactivated
 private void Application_Closing(object sender, ClosingEventArgs e)
 {
     using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
     {
         using (IsolatedStorageFileStream fs = storage.CreateFile(LogFile))
         {
             using (StreamWriter writer = new StreamWriter(fs))
             {
                 Logger.Save(writer);
             }
         }
     }
 }
        // Code to execute on Unhandled Exceptions
        private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
        {
            Logger.WriteLine(e.ExceptionObject);

            SaveLog();
            e.Handled = true;

            if (Debugger.IsAttached)
            {
                // An unhandled exception has occurred; break into the debugger
                Debugger.Break();
            }
        }
Exemple #9
0
        private Drone()
        {
            Logger.WriteLine("DroneClient()");
            if (!enabled)
            {
                return;
            }
            droneClient = DroneClient.Instance;
            droneClient.NavigationDataViewModel.PropertyChanged += NavigationDataViewModel_PropertyChanged;
            droneClient.Messages.CollectionChanged += Messages_CollectionChanged;

            // commandTimer.Interval = TimeSpan.FromMilliseconds(50);
            // commandTimer.Tick += OnCommandTimerTick;
        }
Exemple #10
0
        /// <summary>
        /// Constructor for the Application object.
        /// </summary>
        public App()
        {
            using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (storage.FileExists(LogFile))
                {
                    storage.DeleteFile(LogFile);
                    //using (IsolatedStorageFileStream fs = storage.OpenFile(LogFile, FileMode.Open))
                    //{
                    //    using (StreamReader reader = new StreamReader(fs))
                    //    {
                    //        Logger.Load(reader);
                    //    }
                    //}
                }
            }

            Logger.WriteLine("Start");
            Logger.WriteLine("Newline is: " + ReplaceString.StringLiteral(Environment.NewLine));

            // Global handler for uncaught exceptions.
            UnhandledException += Application_UnhandledException;

            // Standard Silverlight initialization
            InitializeComponent();

            // Phone-specific initialization
            InitializePhoneApplication();

            // Show graphics profiling information while debugging.
            if (System.Diagnostics.Debugger.IsAttached)
            {
                // Display the current frame rate counters.
                Application.Current.Host.Settings.EnableFrameRateCounter = true;

                // Show the areas of the app that are being redrawn in each frame.
                //Application.Current.Host.Settings.EnableRedrawRegions = true;

                // Enable non-production analysis visualization mode,
                // which shows areas of a page that are handed off to GPU with a colored overlay.
                //Application.Current.Host.Settings.EnableCacheVisualization = true;

                // Disable the application idle detection by setting the UserIdleDetectionMode property of the
                // application's PhoneApplicationService object to Disabled.
                // Caution:- Use this under debug mode only. Application that disables user idle detection will continue to run
                // and consume battery power when the user is not using the phone.
                PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled;
            }
        }
        private void SaveLog()
        {
            string logFile = String.Format("{0:yyyyMMdd_HHmmss}.log", DateTime.Now);

            using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
            {
                using (IsolatedStorageFileStream fs = storage.CreateFile(logFile))
                {
                    using (StreamWriter writer = new StreamWriter(fs))
                    {
                        Logger.Save(writer);
                    }
                }
            }
        }
Exemple #12
0
        public void LoadMissions(ViewModel viewModel)
        {
            IsolatedStorageFile isoFile = IsolatedStorageFile.GetUserStoreForApplication();

            viewModel.MissionItems.Clear();
            foreach (string fileName in isoFile.GetFileNames())
            {
                string ext = Path.GetExtension(fileName);
                if (@".xml".Equals(ext) && !String.Empty.Equals(Path.GetFileNameWithoutExtension(fileName)))
                {
                    IsolatedStorageFileStream xmlFileStream = isoFile.OpenFile(fileName, FileMode.Open);
                    XDocument missionDoc = XDocument.Load(xmlFileStream);
                    xmlFileStream.Close();
                    XElement    commonElement   = missionDoc.Descendants("common").First();
                    XElement    dateTimeElement = commonElement.Descendants("datetime").First();
                    DateTime    dateTime        = DateTime.Parse(dateTimeElement.Value);
                    MissionItem missionItem     = new MissionItem(MakeMissionName(dateTime));
                    missionItem.When = dateTime;
                    Logger.WriteLine("MissionManager.LoadMissions: Loaded " + missionItem.Name);
                    viewModel.MissionItems.Add(missionItem);
                }
            }
        }
Exemple #13
0
 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     base.OnNavigatedTo(e);
     logContents.Text = Logger.GetStoredLog();
 }