public void TelloCommandObservation_Insert_Read()
        {
            using (var repo = CreateRepository())
            {
                Assert.IsTrue(repo.CreateCatalog <Session>());
                Assert.IsTrue(repo.CreateCatalog <ObservationGroup>());
                Assert.IsTrue(repo.CreateCatalog <ResponseObservation>());

                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 request = new TelloRequest(Commands.Takeoff);
                var ok      = "ok";
                var okBytes = Encoding.UTF8.GetBytes(ok);
                IResponse <string> response = new TelloResponse(request, okBytes, TimeSpan.FromSeconds(1));

                var observation = new ResponseObservation(group, response);
                Assert.AreEqual(1, repo.Insert(observation));

                observation = repo.Read <ResponseObservation>(1);
                Assert.IsNotNull(observation);
                Assert.AreEqual(1, observation.Id);
                Assert.AreEqual(1, observation.GroupId);
                Assert.AreEqual(request.Timestamp, observation.TimeInitiated);
                Assert.AreEqual(Commands.Takeoff, observation.Command.Rule.Command);
                Assert.AreEqual("ok", observation.Response);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Implements the Observer.OnNext method. Receives the next response from the message controller.
        /// </summary>
        /// <param name="response">IResponse<string></string>.</param>
        public override void OnNext(IResponse <string> response)
        {
            try
            {
                response = new TelloResponse(response);
                var command = (Command)response.Request.Data;

                if (response.Success)
                {
                    this.HandleSuccessResponse(response, command);
                }
                else
                {
                    this.OnError(new TelloException($"{command} returned message '{response.Message}' at {response.Timestamp.ToString("o")} after {response.TimeTaken.TotalMilliseconds}ms", response.Exception));
                }

                this.ResponseReceived?.Invoke(this, new ResponseReceivedArgs(response as TelloResponse));
            }
            catch (Exception ex)
            {
                this.OnError(new TelloException(ex.Message, ex));
            }
        }
Ejemplo n.º 3
0
        public override void OnNext(IResponse <string> response)
        {
            try
            {
                response = new TelloResponse(response);
                var command = (Command)response.Request.Data;

                if (response.Success)
                {
                    if (response.Message != Responses.Error.ToString().ToLowerInvariant())
                    {
                        switch (command.Rule.Response)
                        {
                        case Responses.Ok:
                            if (response.Message == Responses.Ok.ToString().ToLowerInvariant())
                            {
                                this.HandleOk(response, command);
                            }
                            else
                            {
                                throw new TelloException($"'{command}' expecting response '{Responses.Ok.ToString().ToLowerInvariant()}' returned message '{response.Message}' at {response.Timestamp.ToString("o")} after {response.TimeTaken.TotalMilliseconds}ms");
                            }

                            break;

                        case Responses.Speed:
                            this.InterogativeState.Speed = Int32.Parse(response.Message);
                            break;

                        case Responses.Battery:
                            this.InterogativeState.Battery = Int32.Parse(response.Message);
                            break;

                        case Responses.Time:
                            this.InterogativeState.Time = Int32.Parse(response.Message);
                            break;

                        case Responses.WIFISnr:
                            this.InterogativeState.WIFISnr = response.Message;
                            break;

                        case Responses.SdkVersion:
                            this.InterogativeState.SdkVersion = response.Message;
                            break;

                        case Responses.SerialNumber:
                            this.InterogativeState.SerialNumber = response.Message;
                            break;

                        case Responses.None:
                        default:
                            break;
                        }
                    }
                    else
                    {
                        throw new TelloException($"{command} returned message '{response.Message}' at {response.Timestamp.ToString("o")} after {response.TimeTaken.TotalMilliseconds}ms");
                    }
                }
                else
                {
                    this.OnError(new TelloException($"{command} returned message '{response.Message}' at {response.Timestamp.ToString("o")} after {response.TimeTaken.TotalMilliseconds}ms", response.Exception));
                }

                this.ResponseReceived?.Invoke(this, new ResponseReceivedArgs(response as TelloResponse));
            }
            catch (Exception ex)
            {
                this.OnError(new TelloException(ex.Message, ex));
            }
        }
Ejemplo n.º 4
0
 public ResponseReceivedArgs(TelloResponse response)
 {
     this.Response = response ?? throw new ArgumentNullException(nameof(response));
 }