Exemplo n.º 1
0
        public GpsController()
        {
            _nmea = new NmeaParser();
            MyGpsData = new GpsData();

            //Set timeout for 45 sec.
            MaxTimeout = 90;
            _waitHandles = new WaitHandle[] { _terminate, };
            #if DEBUG
            _nmea.Validate = false;
            #endif
        }
Exemplo n.º 2
0
        public GpsController()
        {
            _nmea     = new NmeaParser();
            MyGpsData = new GpsData();

            //Set timeout for 45 sec.
            MaxTimeout   = 90;
            _waitHandles = new WaitHandle[] { _terminate, };
            #if DEBUG
            _nmea.Validate = false;
            #endif
        }
Exemplo n.º 3
0
        public static Waypoint ConvertNetworkDataToWaypoint(NetworkData data, GpsData gpsData)
        {
            Waypoint outpoint = new Waypoint();

            outpoint.Latitude = gpsData.Latitude;
            outpoint.Longitude = gpsData.Longitude;

            outpoint.Elevation = gpsData.Altitude;
            outpoint.Time = string.Format("{0}-{1}-{2}T{3}:{4}:{5}.{6}Z",
                                          new object[]
                                              {
                                                  gpsData.SatelliteTime.Year,
                                                  gpsData.SatelliteTime.Month.ToString("D2"),
                                                  gpsData.SatelliteTime.Day.ToString("D2"),
                                                  gpsData.SatelliteTime.Hour.ToString("D2"),
                                                  gpsData.SatelliteTime.Minute.ToString("D2"),
                                                  gpsData.SatelliteTime.Second,
                                                  gpsData.SatelliteTime.Millisecond
                                              });

            outpoint.GeoidHeight = gpsData.GeoidSeperation;
            //The SSID must be cleaned
            outpoint.Name = XmlHelper.CleanString(data.Ssid) + " [" + data.MyMacAddress + "]";

            outpoint.Cmt = gpsData.Speed.ToString(CultureInfo.InvariantCulture.NumberFormat);

            //outpoint.Description = string.Format(
            //    "{0}\r\n[{1}]\r\nRSSI: {2} dB\r\nQuality: {3}%\r\nChannel {4}\r\nSpeed (kph): {5}\r\n{6}",
            //    new object[]
            //        {
            //            XmlHelper.CleanString(data.Ssid), data.MyMacAddress.ToString(), data.Rssi, data.SignalQuality,
            //            data.Channel, gpsData.Speed,
            //            gpsData.SatelliteTime.ToString()
            //        });

            outpoint.Fix = gpsData.FixType;
            outpoint.SatCount = gpsData.SatellitesUsed;
            outpoint.Hdop = gpsData.Hdop;
            outpoint.Vdop = gpsData.Vdop;
            outpoint.Pdop = gpsData.Pdop;

            outpoint.Extensions.MacAddress = data.MyMacAddress.ToString();
            outpoint.Extensions.Ssid = XmlHelper.CleanString(data.Ssid);
            outpoint.Extensions.Rssi = data.Rssi;
            outpoint.Extensions.Channel = data.Channel;
            outpoint.Extensions.Privacy = data.Privacy;
            outpoint.Extensions.SignalQuality = data.SignalQuality;
            outpoint.Extensions.NetworkType = data.NetworkType;
            outpoint.Extensions.Rates = data.SupportedRates;

            return outpoint;
        }
Exemplo n.º 4
0
        /*
        public void AppendEntry(NetworkData[] aps, GpsData gpsData)
        {
            if(_doc == null) return;
            if(aps.Length < 1) return;

            XmlElement newE = null;
            XmlElement ne;

            foreach (NetworkData ap in aps)
            {

                //Ignore anything -100 (or below?)
                if(ap.Rssi <= -100) continue;

                newE = _doc.CreateElement("wpt");

                //Set lat and lon as attributes
                newE.SetAttribute("lat", gpsData.Latitude.ToString(CultureInfo.InvariantCulture.NumberFormat));
                newE.SetAttribute("lon", gpsData.Longitude.ToString(CultureInfo.InvariantCulture.NumberFormat));

                ne = _doc.CreateElement("ele");
                ne.AppendChild(_doc.CreateTextNode(gpsData.Altitude.ToString(CultureInfo.InvariantCulture.NumberFormat)));
                newE.AppendChild(ne);

                ne = _doc.CreateElement("time");
                ne.AppendChild(
                    _doc.CreateTextNode(string.Format("{0}-{1}-{2}T{3}:{4}:{5}.{6}Z",
                                                      new object[]
                                                          {
                                                              gpsData.SatelliteTime.Year,
                                                              gpsData.SatelliteTime.Month.ToString("D2"),
                                                              gpsData.SatelliteTime.Day.ToString("D2"),
                                                              gpsData.SatelliteTime.Hour.ToString("D2"),
                                                              gpsData.SatelliteTime.Minute.ToString("D2"),
                                                              gpsData.SatelliteTime.Second,
                                                              gpsData.SatelliteTime.Millisecond
                                                          })));
                newE.AppendChild(ne);

                //ne = _doc.CreateElement("time");
                //ne.AppendChild(_doc.CreateTextNode(""));
                //newE.AppendChild(ne);

                ne = _doc.CreateElement("geoidheight");
                ne.AppendChild(_doc.CreateTextNode(gpsData.GeoidSeperation.ToString(CultureInfo.InvariantCulture.NumberFormat)));
                newE.AppendChild(ne);

                ne = _doc.CreateElement("name");
                ne.AppendChild(_doc.CreateTextNode(XmlHelper.CleanString(ap.Ssid) + " [" + ap.MyMacAddress + "]"));
                newE.AppendChild(ne);

                ne = _doc.CreateElement("cmt");
                ne.AppendChild(_doc.CreateTextNode(gpsData.Speed.ToString(CultureInfo.InvariantCulture.NumberFormat)));
                newE.AppendChild(ne);

                ne = _doc.CreateElement("desc");
                ne.AppendChild(_doc.CreateTextNode(
                                   string.Format(
                                       "{0}\r\n[{1}]\r\nRSSI: {2} dB\r\nQuality: {3}%\r\nChannel {4}\r\nSpeed (kph): {5}\r\n{6}",
                                       new object[]
                                           {
                                               XmlHelper.CleanString(ap.Ssid), ap.MyMacAddress.ToString(), ap.Rssi, ap.SignalQuality,
                                               ap.Channel, gpsData.Speed,
                                               gpsData.SatelliteTime.ToString()
                                           })));
                newE.AppendChild(ne);

                ne = _doc.CreateElement("fix");
                ne.AppendChild(_doc.CreateTextNode(gpsData.FixType));
                newE.AppendChild(ne);

                ne = _doc.CreateElement("sat");
                ne.AppendChild(_doc.CreateTextNode(gpsData.SatCount.ToString()));
                newE.AppendChild(ne);

                ne = _doc.CreateElement("hdop");
                ne.AppendChild(_doc.CreateTextNode(gpsData.HDOP.ToString(CultureInfo.InvariantCulture.NumberFormat)));
                newE.AppendChild(ne);

                ne = _doc.CreateElement("vdop");
                ne.AppendChild(_doc.CreateTextNode(gpsData.VDOP.ToString(CultureInfo.InvariantCulture.NumberFormat)));
                newE.AppendChild(ne);

                ne = _doc.CreateElement("pdop");
                ne.AppendChild(_doc.CreateTextNode(gpsData.PDOP.ToString(CultureInfo.InvariantCulture.NumberFormat)));
                newE.AppendChild(ne);

                //Extensions = ap data
                ne = _doc.CreateElement("extensions");

                XmlElement ext = _doc.CreateElement("MAC");
                ext.AppendChild(_doc.CreateTextNode(ap.MyMacAddress.ToString()));
                ne.AppendChild(ext);

                ext = _doc.CreateElement("SSID");
                ext.AppendChild(_doc.CreateTextNode(XmlHelper.CleanString(ap.Ssid)));
                ne.AppendChild(ext);

                ext = _doc.CreateElement("RSSI");
                ext.AppendChild(_doc.CreateTextNode(ap.Rssi.ToString()));
                ne.AppendChild(ext);

                ext = _doc.CreateElement("ChannelID");
                ext.AppendChild(_doc.CreateTextNode(ap.Channel.ToString()));
                ne.AppendChild(ext);

                ext = _doc.CreateElement("Security");
                ext.AppendChild(_doc.CreateTextNode(ap.Security));
                ne.AppendChild(ext);

                ext = _doc.CreateElement("signalQuality");
                ext.AppendChild(_doc.CreateTextNode(ap.SignalQuality.ToString()));
                ne.AppendChild(ext);

                ext = _doc.CreateElement("networkType");
                ext.AppendChild(_doc.CreateTextNode(ap.NetworkType));
                ne.AppendChild(ext);

                ext = _doc.CreateElement("rates");
                ext.AppendChild(_doc.CreateTextNode(ap.SupportedRates));
                ne.AppendChild(ext);

                newE.AppendChild(ne);

                _doc.GetElementsByTagName("gpx").Item(0).AppendChild(newE);
            }

            //Auto save if it's enabled and had been long enough
            if(AutoSave && (DateTime.Now - _lastSaveTime >= AutoSaveInterval || _lastSaveTime == DateTime.MinValue))
            {
                SaveLogFile();
                _lastSaveTime = DateTime.Now;
            }
        }
        */
        public void AppendEntry(NetworkData[] data, GpsData gpsData)
        {
            if (data.Length < 1) return;

            lock (_data)
            {
                foreach (NetworkData nd in data)
                {
                    _data.Add(GpxIO.ConvertNetworkDataToWaypoint(nd, gpsData));
                }
            }

            //Auto save if it's enabled and had been long enough
            if (AutoSave && (DateTime.Now - _lastSaveTime >= AutoSaveInterval || _lastSaveTime == DateTime.MinValue))
            {
                SaveLogFile();
                _lastSaveTime = DateTime.Now;
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Clones and then adds data to this AP
        /// </summary>
        /// <param name="data">The data to add</param>
        /// <param name="gpsData">The GPS data to go with</param>
        public void AddData(NetworkData data, GpsData gpsData)
        {
            if (data == null) throw new ArgumentNullException("data");
            if (gpsData == null) throw new ArgumentNullException("gpsData");

            NetworkData nd2 = (NetworkData)data.Clone();

            lock (MyNetworkDataCollection)
            {
                //Check if the RSSI had been consistently stronger and stronger than the strongest reading before updating the GPS data
                //This means if this reading and the last reading are both higher than 2 readings ago, update the GPS data
                if ((MyNetworkDataCollection.Count > 1 && nd2.Rssi > MyNetworkDataCollection.Max(nd => nd.Rssi) &&
                     (nd2.Rssi > MyNetworkDataCollection[MyNetworkDataCollection.Count - 2].Rssi &&
                      MyNetworkDataCollection[MyNetworkDataCollection.Count - 1].Rssi >
                      MyNetworkDataCollection[MyNetworkDataCollection.Count - 2].Rssi)) ||
                    (nd2.Rssi > -100 && GpsData.SatelliteTime == DateTime.MinValue))
                {
                    //Update GPS data
                    GpsData = gpsData;
                }
                //Add the data
                MyNetworkDataCollection.Add(nd2);
            }
            Timestamp = nd2.MyTimestamp;
            LastSeenTimestamp = nd2.MyTimestamp;

            //Remove old data, if any
            DeleteOldData(Timestamp - TimeSpan.FromMinutes(8));
        }
 public ScanCompleteEventArgs(NetworkData[] data, GpsData gpsData)
 {
     Data = data;
     GpsData = gpsData;
 }
Exemplo n.º 7
0
        /// <summary>
        /// Adds data to the cache, and filler(-100 rssi) data if the AP isn't in the data
        /// </summary>
        /// <param name="data"></param>
        /// <param name="gpsData"></param>
        public void AddData(NetworkData[] data, GpsData gpsData)
        {
            if (data == null || data.Length < 1) return;

            //Keep a tally of the APs that weren't here.
            List<MacAddress> missing = new List<MacAddress>();
            missing.AddRange(_cache.Keys);

            lock (_cache)
            {
                //Loop through all supplied data and add or update accesspoints
                foreach (NetworkData n2 in data)
                {
                    //Check if the cache contains this AP already
                    if (_cache.ContainsKey(n2.MyMacAddress))
                    {
                        //It does, update it!
                        GetAccessPointByMacAddress(n2.MyMacAddress).AddData(n2, gpsData);
                        //The AP was here, remove it from the missing list
                        missing.Remove(n2.MyMacAddress);
                    }
                    else
                    {
                        //nope, never heard of it. Add it!
                        _cache.Add(n2.MyMacAddress, new AccessPoint(n2)
                                                        {
                                                            MyColor = Utilities.GetColor(),
                                                            Vendor = _av.GetVendor(n2.MyMacAddress),
                                                            GpsData = gpsData
                                                        });

                    }
                }
            }

            //Add filler data for all absent APs
            foreach (MacAddress mac in missing)
            {
                GetAccessPointByMacAddress(mac).AddFiller(
                    DateTime.FromFileTime(data.Max(nd => nd.MyTimestamp.ToFileTime())));
            }
        }
Exemplo n.º 8
0
 private void OnScanComplete(IEnumerable<NetworkData> data, GpsData gpsData)
 {
     if (ScanComplete != null)
     {
         ScanComplete(this, new ScanCompleteEventArgs(data.ToArray(), gpsData));
     }
 }
Exemplo n.º 9
0
 private void OnScanComplete(NetworkData[] data,GpsData gpsData)
 {
     if (ScanComplete != null) ScanComplete(this, new ScanCompleteEventArgs(data, gpsData));
 }