Ejemplo n.º 1
0
 public bool IsInSoftBoundary(GPSPoint Point)
 {
     return(SoftBoundaryPolygon.InPolygon(Point));
 }
Ejemplo n.º 2
0
 public Double GetDistanceTo(GPSPoint Point)
 {
     return(BoundaryPolygon.GetDistanceTo(Point));
 }
        public bool ProcessDroneData()
        {
            GPSPoint ThisPosition = new GPSPoint((float)_FlightMapData.Latitude, (float)_FlightMapData.Longitude);

            LastUpdatedOn = DateTime.Now;

            if (_LastFlightMapData != null)
            {
                //Fix sudden change in heading
                Double ChangeInHeading = (Double)_LastFlightMapData.Heading - (Double)_FlightMapData.Heading;
                if (ChangeInHeading > 20 || ChangeInHeading < -20)
                {
                    if (_LastFlightMapData.Heading > 340 && _FlightMapData.Heading < 10)
                    {
                        //then we leave it to rotate
                    }
                    else
                    {
                        _FlightMapData.Heading = _LastFlightMapData.Heading + (ChangeInHeading > 0 ? 1 : -1) * 20;
                        if (_FlightMapData.Heading > 360)
                        {
                            _FlightMapData.Heading = _FlightMapData.Heading - 360;
                        }
                        if (_FlightMapData.Heading < 0)
                        {
                            _FlightMapData.Heading = -1 * _FlightMapData.Heading;
                        }
                    }
                }

                if (_FlightMapData.Altitude >= _MinFieldValue || _FlightMapData.Speed >= _MinFieldValue)
                {
                    DateTime StartTime = (DateTime)(_LastFlightMapData.ReadTime);
                    DateTime EndTime   = (DateTime)(_FlightMapData.ReadTime);
                    _TotalFlightTime += (Decimal)Math.Abs(EndTime.Subtract(StartTime).TotalSeconds);

                    //Distance between Last point and this point
                    GPSPoint LastLocation = new GPSPoint((float)_LastFlightMapData.Latitude, (float)_LastFlightMapData.Longitude);
                    _FlightMapData.PointDistance = (Decimal)GPSCalc.GetDistance(ThisPosition, LastLocation);
                    _TotalDistance += (Decimal)_FlightMapData.PointDistance;
                }
            }

            SatelliteSummary.AddTo((Double)_FlightMapData.Satellites);
            SpeedSummary.AddTo((Double)_FlightMapData.Speed);
            AltitudeSummary.AddTo((Double)_FlightMapData.Altitude);

            _FlightMapData.TotalFlightTime = _TotalFlightTime;
            _FlightMapData.Distance        = _TotalDistance;

            _FlightMapData.avg_Altitude   = (Decimal)AltitudeSummary.Avg;
            _FlightMapData.Max_Altitude   = (Decimal)AltitudeSummary.Max;
            _FlightMapData.Min_Altitude   = (Decimal)AltitudeSummary.Min;
            _FlightMapData.Avg_Satellites = (Decimal)SatelliteSummary.Avg;
            _FlightMapData.Max_Satellites = (Decimal)SatelliteSummary.Max;
            _FlightMapData.Min_Satellites = (Decimal)SatelliteSummary.Min;
            _FlightMapData.Avg_Speed      = (Decimal)SpeedSummary.Avg;
            _FlightMapData.Max_Speed      = (Decimal)SpeedSummary.Max;
            _FlightMapData.Min_Speed      = (Decimal)SpeedSummary.Min;


            _DroneFlight.Longitude         = _FlightMapData.Longitude;
            _DroneFlight.Latitude          = _FlightMapData.Latitude;
            _ExtDroneFlight.Altitude       = (Double)_FlightMapData.Altitude;
            _ExtDroneFlight.LastFlightDate = _ReadTime;

            //Save the last point for the reference
            _LastFlightMapData = Cloner <FlightMapData> .Clone(_FlightMapData);

            return(true);
        }
        public async Task <bool> GenerateAlerts()
        {
            bool _InBoundary        = true;
            bool _InSoftBoundary    = true;
            bool _IsInAltitudeLimit = true;

            GPSPoint       ThisPosition = new GPSPoint((float)_FlightMapData.Latitude, (float)_FlightMapData.Longitude);
            FlightApproval Approval     = GetApproval(ThisPosition);

            if (Approval != null)
            {
                _Approval = Approval;
                _DroneFlight.ApprovalID = _Approval.ApprovalId;

                _InBoundary        = _Approval.IsInBoundary(ThisPosition);
                _InSoftBoundary    = Approval.IsInSoftBoundary(ThisPosition);
                _IsInAltitudeLimit = Approval.IsInAltitudeLimit((Decimal)_FlightMapData.Altitude);
            }
            else
            {
                _Approval       = GetClosesetApproval(ThisPosition);
                _InBoundary     = false;
                _InSoftBoundary = false;
                //If approval found on close by, take that
                //if not, maximum to 40 meter
                _IsInAltitudeLimit = _Approval != null?
                                     _Approval.IsInAltitudeLimit((Decimal)_FlightMapData.Altitude) :
                                         (_FlightMapData.Altitude <= 40M);
            }

            if (!_InSoftBoundary && !IsAlertedSoftBoundary)
            {
                //Outside the Soft Boundary, Generate alert
                var ThisAlert = new Alert(_ExtDroneFlight);
                ThisAlert.Generate("Boundary", "Critical");
                await ThisAlert.Save();

                IsAlertedSoftBoundary = true;
            }
            else if (_InSoftBoundary)
            {
                IsAlertedSoftBoundary = false;
            }

            if (!_InBoundary && !IsAlertedBoundary)
            {
                //Outside the Boundary, generate alert
                var ThisAlert = new Alert(_ExtDroneFlight);
                ThisAlert.Generate("Boundary", "High");
                await ThisAlert.Save();

                IsAlertedBoundary = true;
            }
            else if (_InBoundary)
            {
                IsAlertedBoundary = false;
            }

            if (!_IsInAltitudeLimit && !IsAlertedAltitudeLimit)
            {
                //Generate Alert for Altitude breach
                var ThisAlert = new Alert(_ExtDroneFlight);
                ThisAlert.Generate("Altitude", "Critical");
                await ThisAlert.Save();

                IsAlertedAltitudeLimit = true;
            }
            else if (_IsInAltitudeLimit)
            {
                IsAlertedAltitudeLimit = false;
            }

            //Save the current status
            _DroneFlight.ApprovalID        = _Approval == null ? 0 : _Approval.ApprovalId;
            _DroneFlight.IsFlightOutside   = IsAlertedBoundary;
            _DroneFlight.IsFlightSoftFence = IsAlertedSoftBoundary ? 1 : 0;
            _DroneFlight.HigherLimit       = IsAlertedAltitudeLimit ? 1 : 0;

            _FlightMapData.IsOutSide   = !_InBoundary;
            _FlightMapData.IsSoftFence = (_InSoftBoundary ? 0 : 1);

            return(true);
        }
Ejemplo n.º 5
0
 public Double GetDistanceTo(GPSPoint Point)
 {
     return(Point.GetDistanceTo(Points[0]));
 }