Beispiel #1
0
        /// <summary>
        /// method is used to create a sector at a specified position. This sector and all it's access points will be saved in a
        /// large SortedDictionary type. Be aware of the possibly long pause !
        /// </summary>
        /// <param name="sector">int</param>
        /// <param name="client">WlanClient</param>
        /// <param name="xSector">int</param>
        /// <param name="ySector">int</param>
        public virtual bool createSectorAtPosition(int sector, int xSector, int ySector, WlanClient client)
        {
            //Console.WriteLine("X: ");
            int x = xSector;

            //Console.WriteLine("Y: ");
            int y = ySector;

            Sector tempSector = new Sector(x, y, sector);

            Wlan.WlanBssEntry[] bsses = client.Interfaces[0].GetNetworkBssList();

            double rssi = 0;

            Dictionary <string, RssiCalcHelper> calcList = new Dictionary <string, RssiCalcHelper>();

            for (int i = 0; i < this.mapCreationCount; i++)
            {
                foreach (Wlan.WlanBssEntry bss in bsses)
                {
                    rssi = bss.rssi;
                    string bssid = Converter.getBssid(bss);

                    if (rssi > this.minimumRangeRssi || this.minimumRangeRssi == 0)
                    {
                        // drop 1st measuring
                        if (i != 0)
                        {
                            if (!calcList.ContainsKey(bssid))
                            {
                                calcList.Add(bssid, new RssiCalcHelper(rssi));
                            }
                            else if (calcList.ContainsKey(bssid))
                            {
                                RssiCalcHelper tempHelper = calcList[bssid];
                                calcList.Remove(bssid);

                                tempHelper.addRssi(rssi);
                                calcList.Add(bssid, tempHelper);
                            }

                            Console.WriteLine("AP: bssid=" + bssid + " rssi=" + rssi + " x=" + x + " y=" + y + " added to list");
                        }
                        else
                        {
                            Console.WriteLine("1st measurement dropped!");
                        }
                    }
                }

                Thread.Sleep(this.scanPause);
                bsses = client.Interfaces[0].GetNetworkBssList();
                client.Interfaces[0].Scan();

                Console.WriteLine("");
            }

            foreach (KeyValuePair <string, RssiCalcHelper> keyValPair in calcList)
            {
                string         bssid          = keyValPair.Key;
                RssiCalcHelper tempRssiHelper = keyValPair.Value;
                double         averageRssi    = tempRssiHelper.getAverageRssi();

                tempSector.addAccessPointToSector(bssid, averageRssi);
                Console.WriteLine("Saved Middle value for: " + bssid + " rssi= " + averageRssi);
            }

            accessPointsMap.Add(sector, tempSector);
            Console.WriteLine("Sector " + sector + " saved at position x=" + x + " y=" + y);

            return(true);
        }
Beispiel #2
0
        /// <summary>
        /// method is used to calculate the position of the wifi adapter (client). Be aware of the possibly long break!
        /// </summary>
        /// <param name="client">WlanClient</param>
        /// <returns>Position</returns>
        public virtual Position findPosition(WlanClient client)
        {
            LinkedList <BlindMeasurement> measured = new LinkedList <BlindMeasurement>();

            Dictionary <string, RssiCalcHelper> calcList = new Dictionary <string, RssiCalcHelper>();

            Wlan.WlanBssEntry[] bsses = client.Interfaces[0].GetNetworkBssList();

            int rssi = 0;

            for (int i = 0; i < this.findPositionCount; i++)
            {
                foreach (Wlan.WlanBssEntry bss in bsses)
                {
                    rssi = bss.rssi;    // signal strength
                    string bssid = Converter.getBssid(bss);

                    if (rssi > this.minimumRangeRssi || this.minimumRangeRssi == 0)
                    {
                        if (i != 0)
                        {
                            if (!calcList.ContainsKey(bssid))
                            {
                                calcList.Add(bssid, new RssiCalcHelper(rssi));
                            }
                            else if (calcList.ContainsKey(bssid))
                            {
                                RssiCalcHelper tempHelper = calcList[bssid];
                                calcList.Remove(bssid);

                                tempHelper.addRssi(rssi);
                                calcList.Add(bssid, tempHelper);
                            }

                            Console.WriteLine("Measurement - AP: bssid=" + bssid + " rssi=" + rssi);
                        }
                        else
                        {
                            Console.WriteLine("1st measurement dropped!");
                        }
                    }
                }

                Console.WriteLine("");

                Thread.Sleep(this.scanPause);
                bsses = client.Interfaces[0].GetNetworkBssList();
                client.Interfaces[0].Scan();
            }

            foreach (KeyValuePair <string, RssiCalcHelper> keyValPair in calcList)
            {
                string         bssid              = keyValPair.Key;
                RssiCalcHelper tempRssiHelper     = keyValPair.Value;
                double         averageRssi        = tempRssiHelper.getAverageRssi();
                double         averageFluctuation = tempRssiHelper.getAverageFluctuation();

                measured.AddLast(new BlindMeasurement(bssid, averageRssi, averageFluctuation));
                Console.WriteLine("Saved Middle value for: " + bssid + " rssi= " + averageRssi + " fluctuation= " + averageFluctuation);
            }

            List <SectorDifference> results = new List <SectorDifference>();

            int counterMap = 0;

            foreach (KeyValuePair <int, Sector> keyValPair in this.accessPointsMap)
            {
                int    sector     = keyValPair.Key;
                Sector tempSector = keyValPair.Value;

                Console.WriteLine("Sector: " + sector);

                int counter = 0;

                Dictionary <string, AccessPoint> tempApMap = tempSector.getAccessPoints();

                double result = 0;

                foreach (BlindMeasurement apData in measured)
                {
                    char[]   delimiter = new char[] { '|' };
                    string[] splitted  = apData.getBssid().Split(delimiter, StringSplitOptions.RemoveEmptyEntries);
                    apData.setBssid(splitted[0]);

                    if (tempApMap.ContainsKey(apData.getBssid()))
                    {
                        AccessPoint apTemp = tempApMap[apData.getBssid()];

                        double tempResult = Math.Abs(apTemp.getRssi() - apData.getRssi());

                        if (
                            (this.standardError == false && tempResult <= apData.getAverageFluctuation()) ||
                            (this.standardError == true && tempResult <= this.errorBuffer)
                            )
                        {
                            tempResult = 0;
                        }

                        result += tempResult;

                        Console.WriteLine("Result: bssid=" + apData.getBssid() + " map " + apTemp.getRssi() + " measured " + apData.getRssi() + " DIF: " + tempResult);
                        counter++;
                    }
                }
                counterMap++;

                double average = 0;

                if (counter == 0)
                {
                    Console.WriteLine("");
                }
                else
                {
                    average = result / counter;

                    Console.WriteLine("calculated range " + result + "/" + counter + " = " + average);
                    results.Add(new SectorDifference(tempSector.getX(), tempSector.getY(), average));
                }
            }

            Console.WriteLine("Results: ");

            results.Sort(delegate(SectorDifference s1, SectorDifference s2)
            {
                return(s1.getRssi().CompareTo(s2.getRssi()));
            });

            Position tempPos = printFinalResult(results);

            Thread.Sleep(this.scanPause);
            return(tempPos);
        }