Example #1
0
 public void TestInitialise()
 {
     _context   = new TelloCommanderDbContextFactory().CreateDbContext(null);
     _monitor   = new MockDroneStatusMonitor();
     _collector = new TelemetryCollector(_context, _monitor);
     _monitor.Listen(0);
 }
Example #2
0
        /// <summary>
        /// Connect to the drone then repeatedly prompt for and send commands
        /// </summary>
        /// <param name="enableStatusMonitor"></param>
        public void Run(bool enableStatusMonitor = true)
        {
            char[]                  separators = { ' ' };
            TelemetryCollector      collector  = null;
            TelloCommanderDbContext context    = null;

            try
            {
                Connect();

                if (enableStatusMonitor)
                {
                    _monitor.Listen(DroneStatusMonitor.DefaultTelloStatusPort);
                }

                Console.WriteLine();
                Console.WriteLine("You are connected to the Tello in API mode");

                bool haveCommand;
                do
                {
                    Console.WriteLine();
                    Console.Write("Enter command or hit ENTER to quit : ");
                    string command = Console.ReadLine();

                    haveCommand = !string.IsNullOrEmpty(command);
                    if (haveCommand)
                    {
                        Console.WriteLine($"Command : {command}");

                        try
                        {
                            string[] words = command.Trim().Split(separators, StringSplitOptions.RemoveEmptyEntries);
                            switch (words[0])
                            {
                            case "?":
                                ReportDroneStatus();
                                LastResponse = "ok";
                                break;

                            case "startcapture":
                                int.TryParse(words[2], out int intervalMilliseconds);
                                _monitor.StartCapture(words[1], intervalMilliseconds);
                                LastResponse = "ok";
                                break;

                            case "stopcapture":
                                _monitor.StopCapture();
                                LastResponse = "ok";
                                break;

                            case "startdbcapture":
                                int.TryParse(words[3], out int collectionInterval);
                                string[] filters = (words.Length > 4) ? words[4].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries) : null;
                                context   = new TelloCommanderDbContextFactory().CreateDbContext(null);
                                collector = new TelemetryCollector(context, _monitor);
                                collector.Start(words[1], words[2], collectionInterval, filters);
                                LastResponse = "ok";
                                break;

                            case "stopdbcapture":
                                if (collector != null)
                                {
                                    collector.Stop();
                                    context.Dispose();
                                    collector = null;
                                }
                                LastResponse = "ok";
                                break;

                            default:
                                RunCommand(command);
                                break;
                            }

                            Console.WriteLine($"Response: {LastResponse}");
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine($"Error : {ex.Message}");
                        }
                    }
                }while (haveCommand);

                _monitor.Stop();
                Disconnect();
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error Connecting: {ex.Message}");
            }
        }