public void BeaconReceived(NearbyBluetoothTag Sender, int RSSI)
        {
            /*
             * RssiMeasure rssi = distanceMeasureHelper.GetRSSI(RSSI);
             * double distance = rssi.DistanceAverage;
             *
             * RssiMeasure avgrssi = distanceMeasureHelper.GetRSSI(AverageRSSI);
             * double avgdistance = avgrssi.DistanceAverage;
             */
            double distance    = distcalc.GetDistanceByRSSI(RSSI);
            double avgdistance = distcalc.GetDistanceByRSSI(Sender.AverageRSSI);

            Sender.SetAveragePredictedDistance(avgdistance);

            foreach (BluetoothTagDisplay tag in tags)
            {
                if (tag.MAC.Equals(Sender.MAC))
                {
                    tag.BeaconSent(RSSI, distance, Sender.AverageRSSI, avgdistance);
                }
            }

            LocationResult location = PredictPosition();

            mainWindow.Dispatcher.Invoke((Action)(() =>
            {
                DrawSimulatedPosition(location);
            }));
        }
        protected override LocationResult CalculateCommonPoint(List<NearbyBluetoothTag> Distances, LocationResult LastLocation)
        {
            List<NearbyBluetoothTag> leastDistances = CalculateClosestDistances(Distances, 3);

            List<Intersection> intersectionPoints = GetIntersections(leastDistances); // ebben lesznek két-két kör metszéspontjai

            return new LocationResult(commonPointStrategy.CommonPointOfIntersections(intersectionPoints), Precision.ThreeOrMoreTag);
        }
 private LocationResult PredictPosition()
 {
     // Amíg a pozíciót számoljuk, ne lehessen megváltoztatni az average értékeket!
     lock (nearbyTags)
     {
         CommonPointStrategy cps        = new ClosestPointsStrategy(); //InspectAllPointsStrategy ez mégsem jó
         CalculatorStrategy  calculator = new AverageClosestDistanceLocationCalculator(cps);
         LocationResult      location   = calculator.CalculateLocation(nearbyTags, null);
         return(location);
     }
 }
        protected override LocationResult CalculateCommonPoint(List<NearbyBluetoothTag> Distances, LocationResult LastLocation)
        {
            List<NearbyBluetoothTag> leastDistances = CalculateClosestDistances(Distances, 3);

            // TODO: javítás: kivédeni a pontatlan, torzított eseteket úgy, hogy minden esetben legyen metszéspont! 
            ForceAllIntersections(leastDistances);
            // Innen már mindenhol biztosan lesz metszéspont

            List<Intersection> intersectionPoints = GetIntersections(leastDistances); // ebben lesznek két-két kör metszéspontjai
            intersectionPoints.RemoveAll(intersect => intersect.Points == null || intersect.Points.Count == 0);

            return new LocationResult(commonPointStrategy.CommonPointOfIntersections(intersectionPoints), Precision.ThreeOrMoreTag);
        }
        public LocationResult CalculateLocation(List<NearbyBluetoothTag> NearbyDistances, LocationResult LastLocation)
        {
            List<NearbyBluetoothTag> Distances = NearbyDistances.ToList<NearbyBluetoothTag>();
            Distances.RemoveAll(tag => tag.AverageRSSI == 0.0);
            if (Distances.Count == 0) return new LocationResult(new Point(-1, -1), Precision.NoTag);
            if (Distances.Count == 1) return new LocationResult(Distances[0].Origo, Precision.OneTag, Distances[0].AveragePredictedDistanceFromTag); // 1 vagy semennyi kör esetén nem tudunk pozíciót meghatározni

            if (Distances.Count == 2) // 2 kör esetén a metszet két pontja közti felezőpont kell
            {
                ForceAllIntersections(Distances);
                Intersection points = Intersection.CalculateIntersection(Distances[0].Origo, Distances[0].AveragePredictedDistanceFromTag, Distances[1].Origo, Distances[1].AveragePredictedDistanceFromTag);
                return new LocationResult(LocationCalculator.Midpoint(points.Points[0], points.Points[1]), Precision.TwoTag, LocationCalculator.Distance(points.Points[0], points.Points[1]) / 2);
            }

            return CalculateCommonPoint(Distances, LastLocation);
        }
        protected override LocationResult CalculateCommonPoint(List<NearbyBluetoothTag> Distances, LocationResult LastLocation)
        {
            List<Point> adjacentPoints = new List<Point>(); // ebben lesznek az egyes metszetek legközelebbi pontjai után kiválogatott szomszédos pontok

            // kiszámoljuk minden kör, minden másik körhöz mért metszéspontját
            List<Intersection> intersectionPoints = GetIntersections(Distances); // ebben lesznek két-két kör metszéspontjai
           
            // eddig jó
            for (int i = 0; i < intersectionPoints.Count; i++)
            {
                for (int j = i + 1; j < intersectionPoints.Count; j++)
                {
                    if (i == j) continue;
                    adjacentPoints.Add(LocationCalculator.ClosestPoint(intersectionPoints[i], intersectionPoints[j]));
                }
            }

            return new LocationResult(LocationCalculator.PointAverage(adjacentPoints), Precision.ThreeOrMoreTag);
        }
        private void DrawSimulatedPosition(LocationResult Position)
        {
            if (Position.Precision != Precision.NoTag)
            {
                switch (Position.Precision)
                {
                case Precision.OneTag: simDev.SetSimulationDisplay(Precision.OneTag, Position.SimulatedLocation, Position.Radius); break;

                case Precision.TwoTag: simDev.SetSimulationDisplay(Precision.TwoTag, Position.SimulatedLocation, Position.Radius); break;

                case Precision.ThreeOrMoreTag: simDev.SetSimulationDisplay(Precision.ThreeOrMoreTag, Position.SimulatedLocation); break;
                }
                Point simulatedDevicePos = Position.SimulatedLocation;
                simDev.MoveDevice(simulatedDevicePos);
            }
            else
            {
                simDev.SetSimulationDisplay(Precision.NoTag, new Point(-1, -1));
            }
        }
 protected abstract LocationResult CalculateCommonPoint(List <NearbyBluetoothTag> Distances, LocationResult LastLocation);
        public LocationResult CalculateLocation(List <NearbyBluetoothTag> NearbyDistances, LocationResult LastLocation)
        {
            List <NearbyBluetoothTag> Distances = NearbyDistances.ToList <NearbyBluetoothTag>();

            Distances.RemoveAll(tag => tag.AverageRSSI == 0.0);
            if (Distances.Count == 0)
            {
                return(new LocationResult(new Point(-1, -1), Precision.NoTag));
            }
            if (Distances.Count == 1)
            {
                return(new LocationResult(Distances[0].Origo, Precision.OneTag, Distances[0].AveragePredictedDistanceFromTag)); // 1 vagy semennyi kör esetén nem tudunk pozíciót meghatározni
            }
            if (Distances.Count == 2)                                                                                           // 2 kör esetén a metszet két pontja közti felezőpont kell
            {
                ForceAllIntersections(Distances);
                Intersection points = Intersection.CalculateIntersection(Distances[0].Origo, Distances[0].AveragePredictedDistanceFromTag, Distances[1].Origo, Distances[1].AveragePredictedDistanceFromTag);
                return(new LocationResult(LocationCalculator.Midpoint(points.Points[0], points.Points[1]), Precision.TwoTag, LocationCalculator.Distance(points.Points[0], points.Points[1]) / 2));
            }

            return(CalculateCommonPoint(Distances, LastLocation));
        }
        protected override LocationResult CalculateCommonPoint(List <NearbyBluetoothTag> Distances, LocationResult LastLocation)
        {
            List <NearbyBluetoothTag> leastDistances = CalculateClosestDistances(Distances, 3);

            List <Intersection> intersectionPoints = GetIntersections(leastDistances); // ebben lesznek két-két kör metszéspontjai

            return(new LocationResult(commonPointStrategy.CommonPointOfIntersections(intersectionPoints), Precision.ThreeOrMoreTag));
        }
 private void DrawSimulatedPosition(LocationResult Position)
 {
     if (Position.Precision != Precision.NoTag)
     {
         switch (Position.Precision)
         {
             case Precision.OneTag: simDev.SetSimulationDisplay(Precision.OneTag, Position.SimulatedLocation, Position.Radius); break;
             case Precision.TwoTag: simDev.SetSimulationDisplay(Precision.TwoTag, Position.SimulatedLocation, Position.Radius); break;
             case Precision.ThreeOrMoreTag: simDev.SetSimulationDisplay(Precision.ThreeOrMoreTag, Position.SimulatedLocation); break;
         }
         Point simulatedDevicePos = Position.SimulatedLocation;
         simDev.MoveDevice(simulatedDevicePos);
     }
     else simDev.SetSimulationDisplay(Precision.NoTag, new Point(-1, -1));
 }
 protected abstract LocationResult CalculateCommonPoint(List<NearbyBluetoothTag> Distances, LocationResult LastLocation);
 /// <summary>
 /// Három, vagy több körnek számolja ki azt a pontját, amelyik ponton az összes kör metszi egymást
 /// </summary>
 /// <param name="OrigoPoints">A körök középpontjai</param>
 /// <param name="Radiuses">A körök sugarai</param>
 /// <param name="CalculatorStrategy">Különféle stratégiák megadásával különféle módokon lehet pozíciót számolni</param>
 /// <returns>Azt a pontot adja vissza, ahol az összes kör metszi egymást</returns>
 public static LocationResult CalculateCommonPoint(List<NearbyBluetoothTag> Distances, LocationResult LastLocation, CalculatorStrategy CalculatorStrategy)
 {
     return CalculatorStrategy.CalculateLocation(Distances, LastLocation);
 }
Beispiel #14
0
 /// <summary>
 /// Három, vagy több körnek számolja ki azt a pontját, amelyik ponton az összes kör metszi egymást
 /// </summary>
 /// <param name="OrigoPoints">A körök középpontjai</param>
 /// <param name="Radiuses">A körök sugarai</param>
 /// <param name="CalculatorStrategy">Különféle stratégiák megadásával különféle módokon lehet pozíciót számolni</param>
 /// <returns>Azt a pontot adja vissza, ahol az összes kör metszi egymást</returns>
 public static LocationResult CalculateCommonPoint(List <NearbyBluetoothTag> Distances, LocationResult LastLocation, CalculatorStrategy CalculatorStrategy)
 {
     return(CalculatorStrategy.CalculateLocation(Distances, LastLocation));
 }
        protected override LocationResult CalculateCommonPoint(List <NearbyBluetoothTag> Distances, LocationResult LastLocation)
        {
            List <NearbyBluetoothTag> leastDistances = CalculateClosestDistances(Distances, 3);

            // TODO: javítás: kivédeni a pontatlan, torzított eseteket úgy, hogy minden esetben legyen metszéspont!
            ForceAllIntersections(leastDistances);
            // Innen már mindenhol biztosan lesz metszéspont

            List <Intersection> intersectionPoints = GetIntersections(leastDistances); // ebben lesznek két-két kör metszéspontjai

            intersectionPoints.RemoveAll(intersect => intersect.Points == null || intersect.Points.Count == 0);

            return(new LocationResult(commonPointStrategy.CommonPointOfIntersections(intersectionPoints), Precision.ThreeOrMoreTag));
        }
Beispiel #16
0
        protected override LocationResult CalculateCommonPoint(List <NearbyBluetoothTag> Distances, LocationResult LastLocation)
        {
            List <Point> adjacentPoints = new List <Point>(); // ebben lesznek az egyes metszetek legközelebbi pontjai után kiválogatott szomszédos pontok

            // kiszámoljuk minden kör, minden másik körhöz mért metszéspontját
            List <Intersection> intersectionPoints = GetIntersections(Distances); // ebben lesznek két-két kör metszéspontjai

            // eddig jó
            for (int i = 0; i < intersectionPoints.Count; i++)
            {
                for (int j = i + 1; j < intersectionPoints.Count; j++)
                {
                    if (i == j)
                    {
                        continue;
                    }
                    adjacentPoints.Add(LocationCalculator.ClosestPoint(intersectionPoints[i], intersectionPoints[j]));
                }
            }

            return(new LocationResult(LocationCalculator.PointAverage(adjacentPoints), Precision.ThreeOrMoreTag));
        }