Пример #1
0
        private async Task <CommandProcessingResult> ExecuteSendWaypointsCommandAsync(DeserializableCommand deserializableCommand)
        {
            var command = deserializableCommand.Command;

            try
            {
                dynamic parameters = WireCommandSchemaHelper.GetParameters(command);
                if (parameters != null)
                {
                    string waypointString = ReflectionHelper.GetNamedPropertyValue(
                        parameters,
                        "data",
                        usesCaseSensitivePropertyNameMatch: true,
                        exceptionThrownIfNoMatch: true);
                    if (!string.IsNullOrEmpty(waypointString))
                    {
                        JArray waypointArray = JArray.Parse(waypointString);
                        if (waypointArray != null && waypointArray.Count > 0)
                        {
                            var wayPoints = new List <GeoCoordinate>();
                            foreach (var wayPoint in waypointArray)
                            {
                                if (double.TryParse(wayPoint[0].ToString(), out var lat) &&
                                    double.TryParse(wayPoint[1].ToString(), out var lon))
                                {
                                    var wayPointObject = new GeoCoordinate(lat, lon);
                                    wayPoints.Add(wayPointObject);
                                }
                            }

                            if (wayPoints.Count > 0)
                            {
                                await this.wayPointNavigator.StartWayPointNavigationAsync(wayPoints);
                            }

                            return(CommandProcessingResult.Success);
                        }
                    }
                }

                return(CommandProcessingResult.CannotComplete);
            }
            catch (Exception)
            {
                return(CommandProcessingResult.RetryLater);
            }
        }
Пример #2
0
        private async Task <CommandProcessingResult> HandleCommandAsync(DeserializableCommand deserializableCommand)
        {
            var notifyEventArgs = new NotifyUIEventArgs()
            {
                NotificationType = NotificationType.Console,
                Data             = $"Received cloud command: {deserializableCommand.CommandName}"
            };

            this.NotifyUIEvent(notifyEventArgs);

            if (deserializableCommand.CommandName == "DemoRun")
            {
                return(await this.ExecuteDemoCommandAsync(deserializableCommand));
            }
            else if (deserializableCommand.CommandName == "SendWaypoints")
            {
                return(await this.ExecuteSendWaypointsCommandAsync(deserializableCommand));
            }
            else if (deserializableCommand.CommandName == "SetLights")
            {
                return(await this.ExecuteSetLightsCommandAsync(deserializableCommand));
            }
            else if (deserializableCommand.CommandName == "SetCamera")
            {
                return(await this.ExecuteSetCameraCommandAsync(deserializableCommand));
            }
            else if (deserializableCommand.CommandName == "SendBuzzer")
            {
                return(await this.ExecuteSendBuzzerCommandAsync());
            }
            else if (deserializableCommand.CommandName == "EmergencyStop")
            {
                return(await this.ExecuteEmergencyStopCommandAsync());
            }
            else if (deserializableCommand.CommandName == "StartTelemetry")
            {
                return(this.ExecuteStartStopTelemetryCommandAsync(true));
            }
            else if (deserializableCommand.CommandName == "StopTelemetry")
            {
                return(this.ExecuteStartStopTelemetryCommandAsync(false));
            }
            else if (deserializableCommand.CommandName == "MoveVehicle")
            {
                return(await this.ExecuteMoveVehicleCommandAsync(deserializableCommand));
            }
            else if (deserializableCommand.CommandName == "MoveCamera")
            {
                return(await this.ExecuteMoveCameraCommandAsync(deserializableCommand));
            }
            else
            {
                notifyEventArgs = new NotifyUIEventArgs()
                {
                    NotificationType = NotificationType.Console,
                    Data             = $"Command not registered in the system: {deserializableCommand.CommandName}"
                };

                this.NotifyUIEvent(notifyEventArgs);
            }

            return(CommandProcessingResult.CannotComplete);
        }