예제 #1
0
        public Core(ILogger <Core> logger, TelloClient client, TelloStateServer stateServer, FFmpeg ffmpeg)
        {
            this.logger      = logger;
            this.client      = client;
            this.stateServer = stateServer;
            this.ffmpeg      = ffmpeg;

            stateServer.OnState     += (s) => telloState = s;
            stateServer.OnException += (ex) => logger.LogError(ex, "stateServer.OnException");
        }
예제 #2
0
 public override void OnNext(IEnvelope message)
 {
     try
     {
         State = new TelloState(Encoding.UTF8.GetString(message.Data), message.Timestamp, _position);
         StateChanged?.Invoke(this, new StateChangedArgs(State));
     }
     catch (Exception ex)
     {
         OnError(ex);
     }
 }
예제 #3
0
        public static void GenerateCsv(string file, List <TelloState> states)
        {
            if (!file.EndsWith(".csv"))
            {
                file += ".csv";
            }
            var lines = states.Select(state => state.GetCsvDataRow()).ToList();

            lines.Insert(0, TelloState.GetCsvHeaderRow());
            var csvFile = File.Create(file);

            csvFile.Close();
            File.WriteAllLines(file, lines);
        }
예제 #4
0
        private async void ListenTask()
        {
            while (true)
            {
                try
                {
                    var result = await udpServer.ReceiveAsync();

                    var data = Encoding.ASCII.GetString(result.Buffer);
                    OnStateRaw?.Invoke(data);
                    OnState?.Invoke(TelloState.FromString(data));
                }
                catch (Exception ex)
                {
                    OnException?.Invoke(ex);
                }
            }
        }
        public void AirSpeed_Insert_Read()
        {
            using (var repo = CreateRepository())
            {
                Assert.IsTrue(repo.CreateCatalog <Session>());
                Assert.IsTrue(repo.CreateCatalog <ObservationGroup>());
                Assert.IsTrue(repo.CreateCatalog <AirSpeedObservation>());

                var start   = DateTime.UtcNow;
                var session = repo.NewEntity <Session>(start, TimeSpan.FromSeconds(1));
                Assert.IsNotNull(session);
                Assert.AreEqual(1, session.Id);
                Assert.AreEqual(start, session.StartTime);
                Assert.AreEqual(1000, session.Duration.TotalMilliseconds);

                var group = repo.NewEntity <ObservationGroup>(session, start);
                Assert.IsNotNull(group);
                Assert.AreEqual(1, group.Id);
                Assert.AreEqual(start, group.Timestamp);

                group = repo.Read <ObservationGroup>(1);
                Assert.IsNotNull(group);
                Assert.AreEqual(1, group.Id);
                Assert.AreEqual(start, group.Timestamp);

                var stateString = "mid:-1;x:0;y:0;z:0;mpry:0,0,0;pitch:1;roll:2;yaw:3;vgx:4;vgy:5;vgz:6;templ:7;temph:8;tof:9;h:10;bat:11;baro:12.13;time:14;agx:15.16;agy:17.18;agz:19.20;";
                var state       = new TelloState(stateString);

                var observation = new AirSpeedObservation(group, state);
                Assert.AreEqual(1, repo.Insert(observation));

                observation = repo.Read <AirSpeedObservation>(1);
                Assert.IsNotNull(observation);
                Assert.AreEqual(1, observation.Id);
                Assert.AreEqual(state.Timestamp, observation.Timestamp);
                Assert.AreEqual(1, observation.GroupId);
                Assert.AreEqual(15.16, observation.AccelerationX);
                Assert.AreEqual(17.18, observation.AccelerationY);
                Assert.AreEqual(19.20, observation.AccelerationZ);
                Assert.AreEqual(4, observation.SpeedX);
                Assert.AreEqual(5, observation.SpeedY);
                Assert.AreEqual(6, observation.SpeedZ);
            }
        }
        public void PositionObservation_Insert_Read()
        {
            using (var repo = this.CreateRepository())
            {
                Assert.IsTrue(repo.CreateCatalog <Session>());
                Assert.IsTrue(repo.CreateCatalog <ObservationGroup>());
                Assert.IsTrue(repo.CreateCatalog <PositionObservation>());

                var start   = DateTime.UtcNow;
                var session = repo.NewEntity <Session>(start, TimeSpan.FromSeconds(1));
                Assert.IsNotNull(session);
                Assert.AreEqual(1, session.Id);
                Assert.AreEqual(start, session.StartTime);
                Assert.AreEqual(1000, session.Duration.TotalMilliseconds);

                var group = repo.NewEntity <ObservationGroup>(session, start);
                Assert.IsNotNull(group);
                Assert.AreEqual(1, group.Id);
                Assert.AreEqual(start, group.Timestamp);

                group = repo.Read <ObservationGroup>(1);
                Assert.IsNotNull(group);
                Assert.AreEqual(1, group.Id);
                Assert.AreEqual(start, group.Timestamp);

                var stateString = "mid:-1;x:0;y:0;z:0;mpry:0,0,0;pitch:1;roll:2;yaw:3;vgx:4;vgy:5;vgz:6;templ:7;temph:8;tof:9;h:10;bat:11;baro:12.13;time:14;agx:15.16;agy:17.18;agz:19.20;";
                var state       = new TelloState(stateString);

                var observation = new PositionObservation(group, state);
                Assert.AreEqual(1, repo.Insert(observation));

                observation = repo.Read <PositionObservation>(1);
                Assert.IsNotNull(observation);
                Assert.AreEqual(1, observation.Id);
                Assert.AreEqual(state.Timestamp, observation.Timestamp);
                Assert.AreEqual(1, observation.GroupId);
                Assert.AreEqual(10, observation.AltitudeAGLInCm);
                Assert.AreEqual(12.13, observation.BarometricPressueInCm);
                Assert.AreEqual(0, observation.Heading);
                Assert.AreEqual(0, observation.X);
                Assert.AreEqual(0, observation.Y);
            }
        }
        public void Battery_Insert_Read()
        {
            using (var repo = this.CreateRepository())
            {
                Assert.IsTrue(repo.CreateCatalog <Session>());
                Assert.IsTrue(repo.CreateCatalog <ObservationGroup>());
                Assert.IsTrue(repo.CreateCatalog <BatteryObservation>());

                var start   = DateTime.UtcNow;
                var session = repo.NewEntity <Session>(start, TimeSpan.FromSeconds(1));
                Assert.IsNotNull(session);
                Assert.AreEqual(1, session.Id);
                Assert.AreEqual(start, session.StartTime);
                Assert.AreEqual(1000, session.Duration.TotalMilliseconds);

                var group = repo.NewEntity <ObservationGroup>(session, start);
                Assert.IsNotNull(group);
                Assert.AreEqual(1, group.Id);
                Assert.AreEqual(start, group.Timestamp);

                group = repo.Read <ObservationGroup>(1);
                Assert.IsNotNull(group);
                Assert.AreEqual(1, group.Id);
                Assert.AreEqual(start, group.Timestamp);

                var stateString = "mid:-1;x:0;y:0;z:0;mpry:0,0,0;pitch:1;roll:2;yaw:3;vgx:4;vgy:5;vgz:6;templ:7;temph:8;tof:9;h:10;bat:11;baro:12.13;time:14;agx:15.16;agy:17.18;agz:19.20;";
                var state       = new TelloState(stateString);

                var observation = new BatteryObservation(group, state);
                Assert.AreEqual(1, repo.Insert(observation));

                observation = repo.Read <BatteryObservation>(1);
                Assert.IsNotNull(observation);
                Assert.AreEqual(1, observation.Id);
                Assert.AreEqual(state.Timestamp, observation.Timestamp);
                Assert.AreEqual(1, observation.GroupId);
                Assert.AreEqual(11, observation.PercentRemaining);
                Assert.AreEqual(8, observation.TemperatureHighC);
                Assert.AreEqual(7, observation.TemperatureLowC);
            }
        }