Example #1
0
        /// <summary>
        /// loads a virtual access point map. you have to supply the type of the file and the name. possibles types are:
        ///
        /// - json (TODO: read file and interpret)
        /// 
        /// </summary>
        /// <param name="type">string</param>
        /// <param name="mapName">string</param>
        /// <returns>SortedDictionary</returns>
        public virtual SortedDictionary<int, Sector> loadMap(string type, string mapName)
        {
            SortedDictionary<int, Sector> apMap = new SortedDictionary<int, Sector>();

            Dictionary<string, AccessPoint> apList = new Dictionary<string, AccessPoint>();
            Sector tempSector = new Sector();

            if (type.Equals("xml"))
            {
                // xpath
                XPathNavigator nav;
                XPathDocument docNav;
                XPathNodeIterator NodeIter;
                String strExpression;

                docNav = new XPathDocument(mapName);
                Console.WriteLine("reading " + mapName);

                nav = docNav.CreateNavigator();

                // read map
                strExpression = "//map/sector/*";
                NodeIter = nav.Select(strExpression);

                int counter = 0;
                while (NodeIter.MoveNext())
                {
                    if (counter == 0)
                    {
                        Console.WriteLine("number: " + NodeIter.Current.Value);
                        tempSector.setSectorId(int.Parse(NodeIter.Current.Value));
                        this.xmlCountSector++;
                    }
                    else if (counter == 1)
                    {
                        Console.WriteLine("x: " + NodeIter.Current.Value);
                        tempSector.setX(int.Parse(NodeIter.Current.Value));
                    }
                    else if (counter == 2)
                    {
                        Console.WriteLine("y: " + NodeIter.Current.Value);
                        tempSector.setY(int.Parse(NodeIter.Current.Value));
                    }
                    else
                    {
                        if (NodeIter.Current.Value.Equals("stop"))
                        {
                            tempSector.setAccessPointList(apList);

                            Console.WriteLine("counter = " + counter);

                            apMap.Add(tempSector.getSectorId(), tempSector);
                            counter = 0;

                            // reset temp dicitionary
                            apList = null;
                            apList = new Dictionary<string, AccessPoint>();

                            Console.WriteLine("sector saved");
                        }
                        else
                        {
                           Console.WriteLine("accesspoint: " + NodeIter.Current.Value);
                           string[] splitted = NodeIter.Current.Value.Split('|');

                           Console.WriteLine("split0: " + splitted[0]);
                           Console.WriteLine("split1: " + splitted[1]);

                           AccessPoint tempAp = new AccessPoint(splitted[0], double.Parse(splitted[1]));

                           apList.Add(splitted[0], tempAp);

                           this.xmlCountAps++;
                        }
                    }

                    if(!NodeIter.Current.Value.Equals("stop"))
                        counter++;
                }

                Console.WriteLine("finished reading");

                if (apMap.Count == 0)
                    Console.WriteLine("ap map while xml loading is empty!");

                return apMap;
            }
            else if (type.Equals("json"))
            {
                Console.WriteLine("json file loading ... ");
                // MAKE ME WORK
                return null;
            }
            else
            {
                Console.WriteLine("only 'xml' or 'json' files could be read!");
                return null;
            }
        }
Example #2
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;
        }