Пример #1
0
        public void GpsRawDataServiceAction(GpsRawDataService obj)
        {
            if (Vehicles != null)
            {
                var vehicle = Vehicles.FirstOrDefault(v => v.ID == obj.VehicleId) as GuiQuadVehicle;

                if (vehicle != null)
                {
                    vehicle.Latitude              = obj.Latitude;
                    vehicle.Longitude             = obj.Longitude;
                    vehicle.Altitude              = obj.Altitude;
                    vehicle.QuadStatus.GpsStatus  = obj.GpsStatus;
                    vehicle.QuadStatus.Satellites = obj.Satellites;
                    vehicle.QuadStatus.Hdop       = obj.Hdop;

                    if (obj.HomeAltitude == 0 && obj.HomeLatitude == 0 && obj.HomeLongitude == 0)
                    {
                        vehicle.HomePosition = null;
                    }

                    if (vehicle.HomePosition == null)
                    {
                        vehicle.HomePosition = new MavlinkWaypoint
                        {
                            Latitude  = obj.HomeLatitude,
                            Longitude = obj.HomeLongitude,
                            Altitude  = obj.HomeAltitude
                        };
                    }
                }
            }
        }
        public async void DeleteVehicle(string vehicleId)
        {
            if (BaseView != null && BaseView.CheckInternetConnection())
            {
                Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, true));
                var result = await mApiService.DeleteVehicle(mCacheService.CurrentUser.UserId, vehicleId);

                if (result)
                {
                    //Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, result.Result));
                    Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, result ? "Success" : "Error"));
                    if (result)
                    {
                        var vehicle = mCacheService.UserVehicles.FirstOrDefault(x => x.VehicleId.Equals(vehicleId));
                        if (vehicle != null)
                        {
                            mCacheService.UserVehicles.Remove(vehicle);
                            //save to local database
                            BlobCache.UserAccount.InsertObject <List <Vehicle> >(mCacheService.CurrentUser.UserId, mCacheService.UserVehicles);
                        }

                        var vehicleVM = Vehicles.FirstOrDefault(x => x.Vehicle.VehicleId == vehicleId);
                        if (vehicle != null)
                        {
                            Vehicles.Remove(vehicleVM);
                        }
                    }
                }
                Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, false));
            }
            else
            {
                Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, SharedTextSource.GetText("TurnOnInternetText")));
            }
        }
Пример #3
0
        public void SystemStatusServiceAction(SystemStatusService obj)
        {
            if (Vehicles != null)
            {
                var vehicle = Vehicles.FirstOrDefault(v => v.ID == obj.VehicleId) as GuiQuadVehicle ??
                              AddVehicle(obj.VehicleId);

                vehicle.SetArm(obj.Armed);
                vehicle.SetMode(obj.Mode);

                vehicle.QuadStatus.BatteryVoltage       = obj.BatteryVoltage;
                vehicle.QuadStatus.BatteryRemaining     = obj.BatteryRemaining;
                vehicle.QuadStatus.BatteryCurrent       = obj.BatteryCurrent;
                vehicle.QuadStatus.Landed               = obj.Landed;
                vehicle.QuadStatus.Failsafe             = obj.Failsafe;
                vehicle.QuadStatus.ErrorQuad.Gps        = obj.Gps;
                vehicle.QuadStatus.ErrorQuad.Gyro       = obj.Gyro;
                vehicle.QuadStatus.ErrorQuad.Accel      = obj.Accel;
                vehicle.QuadStatus.ErrorQuad.Compass    = obj.Compass;
                vehicle.QuadStatus.ErrorQuad.Baro       = obj.Baro;
                vehicle.QuadStatus.ErrorQuad.OptFlow    = obj.OptFlow;
                vehicle.QuadStatus.ErrorQuad.Rc         = obj.Rc;
                vehicle.QuadStatus.ErrorQuad.Battery    = obj.Battery;
                vehicle.QuadStatus.ErrorQuad.Hdop       = obj.Hdop;
                vehicle.QuadStatus.ErrorQuad.Satellites = obj.Satellites;
            }
        }
Пример #4
0
        public void GlobalPositionServiceAction(GlobalPositionService obj)
        {
            if (Vehicles != null)
            {
                var vehicle = Vehicles.FirstOrDefault(v => v.ID == obj.VehicleId) as GuiQuadVehicle;
                if (vehicle != null)
                {
                    vehicle.Latitude  = obj.Latitude;
                    vehicle.Longitude = obj.Longitude;
                    vehicle.Altitude  = obj.Altitude;
                    vehicle.QuadStatus.AltitudeAboveGround = obj.AltitudeAboveGround;
                    var x = vehicle.Longitude;
                    var y = vehicle.Latitude;
                    vehicle.MapEntity.Latitude  = vehicle.Latitude;
                    vehicle.MapEntity.Longitude = vehicle.Longitude;
                    vehicle.MapEntity.Altitude  = vehicle.Altitude;

                    //Utils.Utils.ConvertMercatorToGeo(ref x, ref y);

                    vehicle.MapEntity.XLocation = x;
                    vehicle.MapEntity.YLocation = y;
                    //Messenger.Default.Send(new VehicleSelected { VehicleId = obj.VehicleId });
                }
            }
        }
Пример #5
0
        public void SetHomePosition(long idx, Waypoint homeWaypoint)
        {
            var vehicle = Vehicles.FirstOrDefault(v => v.ID == idx) as GuiQuadVehicle;

            if (vehicle != null)
            {
                vehicle.HomePosition = homeWaypoint;
            }
        }
Пример #6
0
        public void SetActivateMission(long idx, bool isActivateMission)
        {
            var vehicle = Vehicles.FirstOrDefault(v => v.ID == idx) as GuiQuadVehicle;

            if (vehicle != null)
            {
                vehicle.IsActivateMission = true;
            }
        }
Пример #7
0
        public Race RemoveVehicleBy(Guid vehicleId)
        {
            if (Status == RaceStatusType.Running)
                throw new Exception("Vehicle cannot be removed from the race while the race is running.");

            var vehicleToRemove = Vehicles.FirstOrDefault(vehicle => vehicle.Id.Equals(vehicleId));
            Vehicles.Remove(vehicleToRemove);

            return this;
        }
Пример #8
0
        public Race UpdateVehicleInfo(UpsertVehicle vehicle)
        {
            if (Status == RaceStatusType.Running)
                throw new Exception("Cannot update vehicle info while the race is running.");
            if (Vehicles.Any(v => v.TeamName.Equals(vehicle.TeamName)))
                throw new Exception($"Team name '{vehicle.TeamName}' is already taken.");

            Vehicles.FirstOrDefault(v => v.Id.Equals(vehicle.Id)).UpdateInfo(vehicle);

            return this;
        }
Пример #9
0
        public void SetHudData(HudDataService hudData)
        {
            var vehicle = Vehicles.FirstOrDefault(v => v.ID == hudData.VehicleId) as GuiQuadVehicle;

            if (vehicle != null)
            {
                vehicle.QuadStatus.GroundSpeed = hudData.GroundSpeed;
                vehicle.QuadStatus.AirSpeed    = hudData.AirSpeed;
                vehicle.QuadStatus.Climb       = hudData.Climb;
            }
        }
Пример #10
0
        public void JoystickInStatusAction(JoystickInStatusService obj)
        {
            var vehicle = Vehicles.FirstOrDefault(v => v.ID == obj.VehicleId) as GuiQuadVehicle;

            if (vehicle != null)
            {
                vehicle.JoystickIn.Roll     = obj.Chan1Raw;
                vehicle.JoystickIn.Pitch    = obj.Chan2Raw;
                vehicle.JoystickIn.Throttle = obj.Chan3Raw;
                vehicle.JoystickIn.Rudder   = obj.Chan4Raw;
            }
        }
Пример #11
0
 public void AttitudeServiseAction(AttitudeServise obj)
 {
     if (Vehicles != null)
     {
         var vehicle = Vehicles.FirstOrDefault(v => v.ID == obj.VehicleId) as GuiQuadVehicle;
         if (vehicle != null)
         {
             vehicle.Heading           = obj.Heading;
             vehicle.Pitch             = obj.Pitch;
             vehicle.Roll              = obj.Roll;
             vehicle.MapEntity.Heading = vehicle.Heading;
         }
     }
 }
Пример #12
0
        public void ReadMission(long idx, byte sysid, byte compid, ObservableCollection <Waypoint> waypoints)
        {
            Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
            {
                var vehicle = Vehicles.FirstOrDefault(v => v.ID == idx) as GuiQuadVehicle;
                if (vehicle != null)
                {
                    //vehicle.Tasks.Clear();
                    var taskId         = ServiceLocator.Current.GetInstance <IMissionSource>().GenerateTaskId();
                    var mavlinkTaskNav = new MavlinkTaskNav("Task" + taskId, taskId)
                    {
                        NavPath = waypoints
                    };
                    ServiceLocator.Current.GetInstance <IMissionSource>().AddTask(mavlinkTaskNav);
                    vehicle.Tasks.Add(mavlinkTaskNav);
                    vehicle.MissionID = mavlinkTaskNav.TaskID;
                    var convertPoint  = new ObservableCollection <Waypoint>();

                    foreach (MavlinkWaypoint point in mavlinkTaskNav.NavPath)
                    {
                        if (point.Command == (decimal)MMAVLink.MAVLink.MAV_CMD.WAYPOINT)
                        {
                            var x = point.Latitude;
                            var y = point.Longitude;
                            //Utils.Utils.ConvertMercatorToGeo(ref y, ref x);
                            convertPoint.Add(new MavlinkWaypoint
                            {
                                Latitude  = x,
                                Longitude = y,
                                Altitude  = point.Altitude,
                                Id        = point.Id,
                                Command   = point.Command,
                                Param1    = point.Param1,
                                Param2    = point.Param2,
                                Param3    = point.Param3,
                                Param4    = point.Param4,
                            });
                        }
                    }
                    var newShape = new Shape(mavlinkTaskNav.TaskID, convertPoint)
                    {
                        Symbol = (LineSymbol)Application.Current.FindResource("LineSymbol")
                    };
                    ServiceLocator.Current.GetInstance <IMap>().AddShape(newShape);
                }
            }));
        }
Пример #13
0
        public void VehicleStatusServiceAction(VehicleStatusService obj)
        {
            if (Vehicles != null)
            {
                var vehicle = Vehicles.FirstOrDefault(v => v.ID == obj.VehicleId) as GuiQuadVehicle;

                if (vehicle != null)
                {
                    vehicle.SetArm(obj.Armed);
                    vehicle.SetMode(obj.Mode);
                    vehicle.QuadStatus.Failsafe = obj.Failsafe;
                    vehicle.QuadStatus.Landed   = obj.Landed;
                    //vehicle.QuadStatus.LinqQuality = obj.LinqQuality;
                    vehicle.QuadStatus.TickCount = obj.TickCount;
                    //Messenger.Default.Send(new VehicleSelected { Vehicle = vehicle });
                }
            }
        }
Пример #14
0
 void FindVehiclesCompleted(object sender, FindVehiclesCompletedEventArgs e)
 {
     if (e.Error == null)
     {
         Vehicles        = e.Result;
         SelectedVehicle = Vehicles.FirstOrDefault(c => c.ID == Work.VehicleID);
     }
     else
     {
         ErrorProvider.ShowError(e.Error, Navigator);
     }
     dataClient.FindVehiclesCompleted -= FindVehiclesCompleted;
     if (busyCount == 0)
     {
         Busy = false;
     }
     else
     {
         busyCount--;
     }
 }
Пример #15
0
 public VehicleStatistics VehicleStatisticsBy(Guid vehicleId)
 {
     return Vehicles.FirstOrDefault(v => v.Id.Equals(vehicleId)).VehicleStatistics();
 }