/// <summary> /// Initializes the NMEA Geographic position, Latitude and Longitude and parses an NMEA sentence /// </summary> /// <param name="NMEAsentence"></param> public GPGLL(string NMEAsentence) { try { //Split into an array of strings. string[] split = NMEAsentence.Split(new Char[] { ',' }); try { _position = new Coordinate(GPSHandler.GPSToDecimalDegrees(split[3], split[4]), GPSHandler.GPSToDecimalDegrees(split[1], split[2])); } catch { _position = null; } try { _timeOfSolution = new TimeSpan(int.Parse(split[5].Substring(0, 2)), int.Parse(split[5].Substring(2, 2)), int.Parse(split[5].Substring(4))); } catch { _timeOfSolution = null; // TimeSpan.Zero; } _dataValid = (split[6] == "A"); } catch { } }
public LoginPage() { this.InitializeComponent(); gpsHandler = new GPSHandler(); MyMapLoginScreen.ColorScheme = MapColorScheme.Dark; this.Loaded += page_Loaded; }
public NTRIPClient(IPEndPoint Server, GPSHandler gpsHandler) { //Initialization... gps = gpsHandler; BroadCaster = Server; //InitializeSocket(); }
void Start() { if (Instance == null) { Instance = this; StartCoroutine(StartLocationService()); } }
public MainForm() { InitializeComponent(); GPS = new GPSHandler(); //Initialize GPS handler GPS.TimeOut = 5; //Set timeout to 5 seconds GPS.NewGPSFix += GPSEventHandler; //Hook up GPS data events to a handler frmGpsSettings = new FrmGpsSettings(); }
private async void page_Loaded(object sender, RoutedEventArgs args) { //Init map mapController = new MapController(MyMap); gpsHandler = new GPSHandler(); InitGPS(); mapController.InitMap(); await mapController.GetJsonBuildings(); drawGeofences(); }
/// <summary> /// Initializes the NMEA Estimated Position Error and parses an NMEA sentence /// </summary> /// <param name="NMEAsentence"></param> public GPRME(string NMEAsentence) { try { //Split into an array of strings. string[] split = NMEAsentence.Split(new Char[] { ',' }); GPSHandler.dblTryParse(split[1], out _estHorisontalError); GPSHandler.dblTryParse(split[3], out _estVerticalError); GPSHandler.dblTryParse(split[5], out _estSphericalError); } catch { } }
public MainForm() { InitializeComponent(); GPS = new GPSHandler(this); //Initialize GPS handler GPS.TimeOut = 5; //Set timeout to 5 seconds GPS.NewGPSFix += new GPSHandler.NewGPSFixHandler(this.GPSEventHandler); //Hook up GPS data events to a handler frmGpsSettings = new FrmGpsSettings(); frmNtripSettings = new FrmNTRIPSettings(); ntrip = null; ntripStarted = false; Coms = new List <SerialPort>(); }
/// <summary> /// Adds a GPGSV sentence, and parses it. /// </summary> /// <param name="NMEAsentence">NMEA string</param> /// <returns>Returns true if this is the last message in GSV nmea sentences</returns> public bool AddSentence(string NMEAsentence) { bool lastmsg = false; try { //Split into an array of strings. string[] split = NMEAsentence.Split(new Char[] { ',' }); int satsInView = GPSHandler.intTryParse(split[3]); int msgCount = GPSHandler.intTryParse(split[1]); //Number of GPGSV messages int msgno = GPSHandler.intTryParse(split[2]); //Current messagenumber if (msgCount < msgno || msgno < 1) //check for invalid data (could be zero if parse failed) { return(false); } if (msgno == 1) { _satellites.Clear(); //First message. Let's clear the satellite list firstMessageParsed = true; } else if (!firstMessageParsed) //If we haven't received the first GSV message, return { return(false); } lastmsg = (msgCount == msgno); //Is this the last GSV message in the GSV messages? int satsInMsg; if (!lastmsg) { satsInMsg = 4; //If this isn't the last message, the message will hold info for 4 satellites } else { satsInMsg = satsInView - 4 * (msgno - 1); //calculate number of satellites in last message } for (int i = 0; i < satsInMsg; i++) { Satellite sat = new Satellite(); sat.PRN = split[i * 4 + 4]; sat.Elevation = Convert.ToByte(split[i * 4 + 5]); sat.Azimuth = Convert.ToInt16(split[i * 4 + 6]); Byte.TryParse(split[i * 4 + 7], out sat.SNR); //sat.SNR = Convert.ToByte(split[i * 4 + 7]); _satellites.Add(sat); } } catch { } return(lastmsg); }
/// <summary> /// Begins the listening for messages, and signals from the signal app /// </summary> public void StartListening() { SubscribeGeneralMessage(Gestures.UP); SubscribeGeneralMessage(Gestures.DOWN); SubscribeGeneralMessage(Gestures.LEFT); SubscribeGeneralMessage(Gestures.RIGHT); IMusicManager musicManager = new SpotifyManager(); actionHandler.RegisterMusicManager(musicManager); MessagingCenter.Subscribe <SettingsViewModel>(this, Gestures.SPOTIFY, async message => { if (!actionHandler.HasAuthenticatedMusicManager) { MessagingCenter.Subscribe <SpotifyLoginMessage>(this, "LoginSuccess", message => { if (!actionHandler.HasAuthenticatedMusicManager) { actionHandler.UpdateMusicManagerAuthentication(true); MessagingCenter.Send(new SpotifyLoginMessage("RegistrationSuccess", message.HasPremium), "RegistrationSuccess"); } }); await musicManager.Init(); } }); MessagingCenter.Subscribe <DNDPermissionMessage>(this, "DNDAdded", message => { if (!notificationManager.IsNotificationPolicyAccessGranted) { Intent intent = new Intent(Android.Provider.Settings.ActionNotificationPolicyAccessSettings); StartActivity(intent); } else { MessagingCenter.Send(new DNDPermissionMessage(), "DNDGranted"); } }); MessagingCenter.Subscribe <string>(this, "GPSRoute", async message => { GPSManager gpsManager = new GPSManager(); GPSHandler handler = new GPSHandler(); GPSSetting setting = await handler.GetSetting(); Rootobject root = await gpsManager.GetDirectionsAsync(setting.Destination, setting.Mode); if (root.status.Equals("NOT_FOUND")) { MessagingCenter.Send <string>("", "Unsuccessful"); return; } MessagingCenter.Send <string, Rootobject>("", "GetRoute", root); }); }
/// <summary> /// GPS DOP and active satellites and parses an NMEA sentence /// </summary> /// <param name="NMEAsentence"></param> public GPGSA(string NMEAsentence) { _pRNInSolution = new List <string>(); try { if (NMEAsentence.IndexOf('*') > 0) { NMEAsentence = NMEAsentence.Substring(0, NMEAsentence.IndexOf('*')); } //Split into an array of strings. string[] split = NMEAsentence.Split(new Char[] { ',' }); if (split[1].Length > 0) { _mode = split[1][0]; } else { _mode = ' '; } if (split[2].Length > 0) { switch (split[2]) { case "2": _fixMode = GSAFixModeEnum._2D; break; case "3": _fixMode = GSAFixModeEnum._3D; break; default: _fixMode = GSAFixModeEnum.FixNotAvailable; break; } } _pRNInSolution.Clear(); for (int i = 0; i <= 11; i++) { if (split[i + 3] != "") { _pRNInSolution.Add(split[i + 3]); } } GPSHandler.dblTryParse(split[15], out _pdop); GPSHandler.dblTryParse(split[16], out _hdop); GPSHandler.dblTryParse(split[17], out _vdop); } catch { } }
public static NTRIPCaster ParseFromString(string line) { string[] strData = line.Trim().Split(';'); NTRIPCaster data = new NTRIPCaster(); data.Host = new System.Net.IPEndPoint(System.Net.Dns.GetHostEntry(strData[1]).AddressList[0], int.Parse(strData[2])); //data.Host = new System.Net.IPEndPoint(System.Net.IPAddress.Parse(strData[1]),int.Parse(strData[2])); data.Identifier = strData[3]; data.Operator = strData[4]; data.NMEA = (strData[5] == "1"); data.Country = strData[6]; GPSHandler.dblTryParse(strData[7], out data.Latitude); GPSHandler.dblTryParse(strData[8], out data.Longitude); if (strData.Length > 9) { data.FallbackHost = strData[9]; } return(data); }
/// <summary> /// Initializes the NMEA Global Positioning System Fix Data and parses an NMEA sentence /// </summary> /// <param name="NMEAsentence"></param> public GPGGA(string NMEAsentence) { try { if (NMEAsentence.IndexOf('*') > 0) { NMEAsentence = NMEAsentence.Substring(0, NMEAsentence.IndexOf('*')); } //Split into an array of strings. string[] split = NMEAsentence.Split(new Char[] { ',' }); if (split[1].Length >= 6) { TimeSpan t = new TimeSpan(GPSHandler.intTryParse(split[1].Substring(0, 2)), GPSHandler.intTryParse(split[1].Substring(2, 2)), GPSHandler.intTryParse(split[1].Substring(4, 2))); DateTime nowutc = DateTime.UtcNow; nowutc = nowutc.Add(-nowutc.TimeOfDay); _timeOfFix = nowutc.Add(t); } _position = new Coordinate(GPSHandler.GPSToDecimalDegrees(split[4], split[5]), GPSHandler.GPSToDecimalDegrees(split[2], split[3])); if (split[6] == "1") { _fixQuality = FixQualityEnum.GPS; } else if (split[6] == "2") { _fixQuality = FixQualityEnum.DGPS; } else { _fixQuality = FixQualityEnum.Invalid; } _noOfSats = Convert.ToByte(split[7]); GPSHandler.dblTryParse(split[8], out _dilution); GPSHandler.dblTryParse(split[9], out _altitude); _altitudeUnits = split[10][0]; GPSHandler.dblTryParse(split[11], out _heightOfGeoid); GPSHandler.intTryParse(split[13], out _dGPSUpdate); _dGPSStationID = split[14]; } catch { } }
/// <summary> /// Initializes the NMEA Recommended minimum specific GPS/Transit data and parses an NMEA sentence /// </summary> /// <param name="NMEAsentence"></param> public GPRMC(string NMEAsentence) { try { //Split into an array of strings. string[] split = NMEAsentence.Split(new Char[] { ',' }); //Extract date/time try { string[] DateTimeFormats = { "ddMMyyHHmmss", "ddMMyy", "ddMMyyHHmmss.FFFFFF" }; if (split[9].Length >= 6) //Require at least the date to be present { string time = split[9] + split[1]; // +" 0"; _timeOfFix = DateTime.ParseExact(time, DateTimeFormats, GPSHandler.NumberFormatEnUs, System.Globalization.DateTimeStyles.AssumeUniversal); } else { _timeOfFix = new DateTime(); } } catch { _timeOfFix = new DateTime(); } if (split[2] == "A") { _status = StatusEnum.OK; } else { _status = StatusEnum.Warning; } _position = new Coordinate(GPSHandler.GPSToDecimalDegrees(split[5], split[6]), GPSHandler.GPSToDecimalDegrees(split[3], split[4])); GPSHandler.dblTryParse(split[7], out _speed); GPSHandler.dblTryParse(split[8], out _course); GPSHandler.dblTryParse(split[10], out _magneticVariation); } catch { } }
public NTRIPClient(IPEndPoint Server, string strUserName, string strPassword, GPSHandler gpsHandler) : this(Server, gpsHandler) { _username = strUserName; _password = strPassword; //InitializeSocket(); }
public GpsDevice(HierachyItem owner) { GPS = new GPSHandler(); //Initialize GPS handler GPS.TimeOut = 5; //Set timeout to 5 seconds GPS.NewGPSFix += new GPSHandler.NewGPSFixHandler(this.GPSEventHandler); //Hook up GPS data events to a handle values = new MonitoredDictionary <string, UAVSingleParameter>(owner); if (!values.ContainsKey("lbRMCPosition")) { values.Add(new UAVParameter("lbRMCPosition", GPS.GPRMC.Position, null, null, urate)); } if (!values.ContainsKey("lbRMCPositionLongitude")) { values.Add(new UAVParameter("lbRMCPositionLongitude", 0, null, null, urate)); } if (!values.ContainsKey("lbRMCPositionLatitude")) { values.Add(new UAVParameter("lbRMCPositionLatitude", 0, null, null, urate)); } if (!values.ContainsKey("lbRMCPositionUTM")) { values.Add(new UAVParameter("lbRMCPositionUTM", 0, null, null, urate)); } if (!values.ContainsKey("lbRMCCourse")) { values.Add(new UAVParameter("lbRMCCourse", 0, null, null, urate)); } if (!values.ContainsKey("lbRMCSpeed")) { values.Add(new UAVParameter("lbRMCSpeed", 0, null, null, urate)); } if (!values.ContainsKey("lbRMCTimeOfFix")) { values.Add(new UAVParameter("lbRMCTimeOfFix", 0, null, null, urate)); } if (!values.ContainsKey("lbRMCMagneticVariation")) { values.Add(new UAVParameter("lbRMCMagneticVariation", 0, null, null, urate)); } if (!values.ContainsKey("lbGGAPosition")) { values.Add(new UAVParameter("lbGGAPosition", 0, null, null, urate)); } if (!values.ContainsKey("lbGGATimeOfFix")) { values.Add(new UAVParameter("lbGGATimeOfFix", 0, null, null, urate)); } if (!values.ContainsKey("lbGGAFixQuality")) { values.Add(new UAVParameter("lbGGAFixQuality", 0, null, null, urate)); } if (!values.ContainsKey("lbGGANoOfSats")) { values.Add(new UAVParameter("lbGGANoOfSats", 0, null, null, urate)); } if (!values.ContainsKey("lbGGAAltitude")) { values.Add(new UAVParameter("lbGGAAltitude", 0, null, null, urate)); } if (!values.ContainsKey("lbGGAAltitudeUnit")) { values.Add(new UAVParameter("lbGGAAltitudeUnit", 0, null, null, urate)); } if (!values.ContainsKey("lbGGAHDOP")) { values.Add(new UAVParameter("lbGGAHDOP", 0, null, null, urate)); } if (!values.ContainsKey("lbGGAGeoidHeight")) { values.Add(new UAVParameter("lbGGAGeoidHeight", 0, null, null, urate)); } if (!values.ContainsKey("lbGGADGPSupdate")) { values.Add(new UAVParameter("lbGGADGPSupdate", 0, null, null, urate)); } if (!values.ContainsKey("lbGGADGPSID")) { values.Add(new UAVParameter("lbGGADGPSID", 0, null, null, urate)); } if (!values.ContainsKey("lbGLLPosition")) { values.Add(new UAVParameter("lbGLLPosition", 0, null, null, urate)); } if (!values.ContainsKey("lbGLLTimeOfSolution")) { values.Add(new UAVParameter("lbGLLTimeOfSolution", 0, null, null, urate)); } if (!values.ContainsKey("lbGLLDataValid")) { values.Add(new UAVParameter("lbGLLDataValid", 0, null, null, urate)); } if (!values.ContainsKey("lbGSAMode")) { values.Add(new UAVParameter("lbGSAMode", 0, null, null, urate)); } if (!values.ContainsKey("lbGLLPosition")) { values.Add(new UAVParameter("lbGLLPosition", 0, null, null, urate)); } if (!values.ContainsKey("lbGSAFixMode")) { values.Add(new UAVParameter("lbGSAFixMode", 0, null, null, urate)); } if (!values.ContainsKey("lbGSAPRNs")) { values.Add(new UAVParameter("lbGSAPRNs", 0, null, null, urate)); } if (!values.ContainsKey("lbGSAPDOP")) { values.Add(new UAVParameter("lbGSAPDOP", 0, null, null, urate)); } if (!values.ContainsKey("lbGSAHDOP")) { values.Add(new UAVParameter("lbGSAHDOP", 0, null, null, urate)); } if (!values.ContainsKey("lbGSAVDOP")) { values.Add(new UAVParameter("lbGSAVDOP", 0, null, null, urate)); } if (!values.ContainsKey("lbRMEHorError")) { values.Add(new UAVParameter("lbRMEHorError", 0, null, null, urate)); } if (!values.ContainsKey("lbRMEVerError")) { values.Add(new UAVParameter("lbRMEVerError", 0, null, null, urate)); } if (!values.ContainsKey("lbRMESphericalError")) { values.Add(new UAVParameter("lbRMESphericalError", 0, null, null, urate)); } if (!values.ContainsKey("lbRMEVerError")) { values.Add(new UAVParameter("lbRMEVerError", 0, null, null, urate)); } if (!values.ContainsKey("lbRMEVerError")) { values.Add(new UAVParameter("lbRMEVerError", 0, null, null, urate)); } }
/// <summary> /// Responds to sentence events from GPS receiver /// </summary> private void GPSEventHandler(object sender, GPSHandler.GPSEventArgs e) { tbRawLog.Text += e.Sentence + "\r\n"; if (tbRawLog.Text.Length > 20 * 1024 * 1024) //20Kb maximum - prevents crash { tbRawLog.Text = tbRawLog.Text.Substring(10 * 1024 * 1024); } tbRawLog.ScrollToCaret(); //Scroll to bottom switch (e.TypeOfEvent) { case GPSEventType.GPRMC: //Recommended minimum specific GPS/Transit data if (GPS.HasGPSFix) //Is a GPS fix available? { //lbRMCPosition.Text = GPS.GPRMC.Position.ToString("#.000000"); lbRMCPosition.Text = GPS.GPRMC.Position.ToString("DMS"); double[] utmpos = TransformToUTM(GPS.GPRMC.Position); lbRMCPositionUTM.Text = utmpos[0].ToString("#.0N ") + utmpos[0].ToString("#.0E") + " (Zone: " + utmpos[2] + ")"; lbRMCCourse.Text = GPS.GPRMC.Course.ToString(); lbRMCSpeed.Text = GPS.GPRMC.Speed.ToString() + " mph"; lbRMCTimeOfFix.Text = GPS.GPRMC.TimeOfFix.ToString("F"); lbRMCMagneticVariation.Text = GPS.GPRMC.MagneticVariation.ToString(); } else { statusBar1.Text = "No fix"; lbRMCCourse.Text = "N/A"; lbRMCSpeed.Text = "N/A"; lbRMCTimeOfFix.Text = GPS.GPRMC.TimeOfFix.ToString(); } break; case GPSEventType.GPGGA: //Global Positioning System Fix Data if(GPS.GPGGA.Position!=null) lbGGAPosition.Text = GPS.GPGGA.Position.ToString("DM"); else lbGGAPosition.Text = ""; lbGGATimeOfFix.Text = GPS.GPGGA.TimeOfFix.Hour.ToString() + ":" + GPS.GPGGA.TimeOfFix.Minute.ToString() + ":" + GPS.GPGGA.TimeOfFix.Second.ToString(); lbGGAFixQuality.Text = GPS.GPGGA.FixQuality.ToString(); lbGGANoOfSats.Text = GPS.GPGGA.NoOfSats.ToString(); lbGGAAltitude.Text = GPS.GPGGA.Altitude.ToString() + " " + GPS.GPGGA.AltitudeUnits; lbGGAHDOP.Text = GPS.GPGGA.Dilution.ToString(); lbGGAGeoidHeight.Text = GPS.GPGGA.HeightOfGeoid.ToString(); lbGGADGPSupdate.Text = GPS.GPGGA.DGPSUpdate.ToString(); lbGGADGPSID.Text = GPS.GPGGA.DGPSStationID; break; case GPSEventType.GPGLL: //Geographic position, Latitude and Longitude lbGLLPosition.Text = GPS.GPGLL.Position.ToString(); lbGLLTimeOfSolution.Text = (GPS.GPGLL.TimeOfSolution.HasValue ? GPS.GPGLL.TimeOfSolution.Value.Hours.ToString() + ":" + GPS.GPGLL.TimeOfSolution.Value.Minutes.ToString() + ":" + GPS.GPGLL.TimeOfSolution.Value.Seconds.ToString() : ""); lbGLLDataValid.Text = GPS.GPGLL.DataValid.ToString(); break; case GPSEventType.GPGSA: //GPS DOP and active satellites if (GPS.GPGSA.Mode == 'A') lbGSAMode.Text = "Auto"; else if (GPS.GPGSA.Mode == 'M') lbGSAMode.Text = "Manual"; else lbGSAMode.Text = ""; lbGSAFixMode.Text = GPS.GPGSA.FixMode.ToString(); lbGSAPRNs.Text = ""; if(GPS.GPGSA.PRNInSolution.Count>0) foreach (string prn in GPS.GPGSA.PRNInSolution) lbGSAPRNs.Text += prn + " "; else lbGSAPRNs.Text += "none"; lbGSAPDOP.Text = GPS.GPGSA.PDOP.ToString() + " (" + DOPtoWord(GPS.GPGSA.PDOP) +")"; lbGSAHDOP.Text = GPS.GPGSA.HDOP.ToString() + " (" + DOPtoWord(GPS.GPGSA.HDOP) + ")"; lbGSAVDOP.Text = GPS.GPGSA.VDOP.ToString() + " (" + DOPtoWord(GPS.GPGSA.VDOP) + ")"; break; case GPSEventType.GPGSV: //Satellites in view if (NMEAtabs.TabPages[NMEAtabs.SelectedIndex].Text == "GPGSV") //Only update this tab when it is active DrawGSV(); break; case GPSEventType.PGRME: //Garmin proprietary sentences. lbRMEHorError.Text = GPS.PGRME.EstHorisontalError.ToString(); lbRMEVerError.Text = GPS.PGRME.EstVerticalError.ToString(); lbRMESphericalError.Text = GPS.PGRME.EstSphericalError.ToString(); break; case GPSEventType.TimeOut: //Serialport timeout. statusBar1.Text = "Serialport timeout"; /*notification1.Caption = "GPS Serialport timeout"; notification1.InitialDuration = 5; notification1.Text = "Check your settings and connection"; notification1.Critical = false; notification1.Visible = true; */ break; } }