private void GPSA_BurstReceived(NmeaBurst b) { if (UseMyPos || _init) { double x = 0, y = 0; if (b._longDir == EastWest.West) x = b._longitude * -1; else x = b._longitude; if (b._latDir == NorthSouth.South) y = b._latitude * -1; else y = b._latitude; TtUtils.LatLontoUTM(y, x, _CurrMeta.Zone, out _UtmYFrom, out _UtmXFrom); this.GuiInvoke(() => { txtFromX.Text = UtmXFrom.ToString("F5").Truncate(12); txtFromY.Text = UtmYFrom.ToString("F5").Truncate(12); }); Altitude = TtUtils.ConvertDistance(b._altitude, UomDistance.FeetTenths, TtUtils.UnitToUomDistance(b._alt_unit)); MagDec = b._magVar; this.GuiInvoke(() => { Calculate(); }); if (_navigating) { fpm = calculateFeetPerMin(); this.GuiInvoke(() => { navCtrl.UpdateLocation(new DoublePoint(_UtmXFrom, _UtmYFrom)); navCtrl.FeetPerMin = fpm; }); } _LastPos = new DoublePoint(UtmXFrom, UtmYFrom); } }
/// <summary> /// Parses an RMC sentence which has the following format: /// RMC,225446,A,4916.45,N,12311.12,W,000.5,054.7,191194,020.3,E*68 /// </summary> /// <param name="tokens">Tokens from the NMEA string in order </param> /// <param name="newNmeaBurst">NmeaBurst to add the data to </param> private void ParseRMC(String[] tokens, ref NmeaBurst toFill) { try { if (tokens[1] != string.Empty) { if (tokens[1].Length > 6) tokens[1] = tokens[1].Substring(0, 6); toFill._time = DateTime.ParseExact(tokens[1], "HHmmss", System.Globalization.CultureInfo.CurrentCulture); } if (tokens[3].IsDouble()) toFill._RMC_latitude = Convert.ToDouble(tokens[3]); if (tokens[4] != String.Empty) toFill._RMC_latDir = CoordConvert.ConvertNorthSouth(tokens[4]);// (NorthSouth)Enum.Parse(typeof(NorthSouth), tokens[4], true); if (tokens[5].IsDouble()) toFill._RMC_longitude = Convert.ToDouble(tokens[5]); if (tokens[6] != String.Empty) toFill._RMC_longDir = CoordConvert.ConvertEastWest(tokens[6]);// (EastWest)Enum.Parse(typeof(EastWest), tokens[6], true); if (tokens[7].IsDouble()) toFill._track_angle = Convert.ToDouble(tokens[7]); if (tokens[8].IsDouble()) toFill._speed = Convert.ToDouble(tokens[8]); if (tokens[9] != String.Empty) { if (tokens[9].Length > 6) tokens[9] = tokens[9].Substring(0, 6); toFill._date = DateTime.ParseExact(tokens[9], "ddMMyy", System.Globalization.CultureInfo.CurrentCulture); } if (tokens[10].IsDouble()) toFill._magVar = Convert.ToDouble(tokens[10]); if (tokens[11] != String.Empty) toFill._magVarDir = CoordConvert.ConvertEastWest(tokens[11]);// (EastWest)Enum.Parse(typeof(EastWest), tokens[11], true); toFill.bRMC = true; } catch { toFill.BadData(); } }
/// <summary> /// Create a burst object out of the NMEA string /// </summary> /// <param name="sentence">the text string sentence</param> /// <returns>NmeaBurst containing the string information or null if invalid</returns> private bool ParseSentence(string sentence, ref NmeaBurst toFill) { OnStringReceived(sentence); bool? isValid = IsValidSentence(sentence); if (isValid != true) { if (InvalidStringFound != null && !_cancelled && !ignoreFirst) { ignoreFirst = false; InvalidStringFound(); } return false; } OnValidStringReceived(sentence); string[] tokens = sentence.Split(','); string sType = tokens[0].Substring(3); tokens[tokens.Length - 1] = tokens[tokens.Length - 1].Substring(0, tokens[tokens.Length - 1].IndexOf('*')); NmeaString type = (NmeaString)Enum.Parse(typeof(NmeaString), sType, true); try { if (ParsingFunctions[type] != null) ParsingFunctions[type].DynamicInvoke(tokens, toFill); } catch (KeyNotFoundException e) { throw new GpsAccessException("Function to handle burst type " + type.ToString() + " is missing.", e); } catch (Exception ex) { TtUtils.WriteError(ex.Message, "GpsAccess:ParseSentence", ex.StackTrace); return false; } return true; }
private void ParseGSA(String[] tokens, ref NmeaBurst toFill) { try { StringBuilder sb = new StringBuilder(); if (tokens[2].IsInteger()) toFill._fix = Convert.ToInt32(tokens[2]); for (int i = 3; i < 15; i++) { if (tokens[i] != "") sb.Append(tokens[i] + '_'); } toFill._fixed_PRNs = sb.ToString(); toFill._fixed_PRNs.TrimEnd('_'); if (tokens[15].IsDouble()) toFill._PDOP = Convert.ToDouble(tokens[15]); if (tokens[16].IsDouble()) toFill._HDOP = Convert.ToDouble(tokens[16]); if (tokens[16].IsDouble()) toFill._VDOP = Convert.ToDouble(tokens[17]); toFill.bGSA = true; } catch { toFill.BadData(); } }
/// <summary> /// Parses a GSV sentence /// </summary> /// <param name="tokens">String tokens from the NMEA sentence</param> /// <param name="toFill">NmeaBurst to put the sentence data into</param> private void ParseGSV(String[] tokens, ref NmeaBurst toFill) { try { if (tokens[1] != String.Empty && toFill.totalGSV < 0) { if (tokens[1].IsInteger()) toFill.totalGSV = Convert.ToInt32(tokens[1]); if (tokens[3].IsInteger()) toFill._num_of_sat = Convert.ToInt32(tokens[3]); } for (int i = 4; i < tokens.Length - 4; i += 4) { Satellite s = new Satellite(); if (tokens[i] != String.Empty) s.ID = tokens[i]; if (tokens[i + 1].IsDouble()) s.Elevation = Convert.ToDouble(tokens[i + 1]); if (tokens[i + 2].IsDouble()) s.Azimuth = Convert.ToDouble(tokens[i + 2]); if (tokens[i + 3].IsDouble()) s.SNR = Convert.ToDouble(tokens[i + 3]); toFill.AddSatalite(s); } toFill.countGSV++; //if all GSV sentences parsed mark as GSV completed if (toFill.countGSV >= toFill.totalGSV) toFill.bGSV = true; } catch { toFill.BadData(); } }
private void GPSA_BurstReceived(NmeaBurst data) { if (calcBursts) { data.CalcRealZone(); if(data.IsValid) bursts.Add(data); if (bursts.Count > 4) { double mag = 0; int zone = 0; foreach (NmeaBurst b in bursts) { mag += b._magVar; zone = b._utm_zone; } mag /= bursts.Count; this.GuiInvoke(() => { Current.magDec = mag; Current.Zone = zone; txtZone.Text = zone.ToString(); txtMagDec.Text = mag.ToString(); TtUtils.HideWaitCursor(); }); Changed(); Values.GPSA.BurstReceived -= GPSA_BurstReceived; DelInit = false; TtUtils.HideWaitCursor(); if (!Values.Settings.DeviceOptions.KeepGpsOn) { Values.GPSA.CloseGps(); } calcBursts = false; } } }
private void ParseGGA(String[] tokens, ref NmeaBurst toFill) { try { if (tokens[2].IsDouble()) toFill._GGA_latitude = Convert.ToDouble(tokens[2]); if (tokens[3] != String.Empty) toFill._GGA_latDir = CoordConvert.ConvertNorthSouth(tokens[3]);// (NorthSouth)Enum.Parse(typeof(NorthSouth), tokens[3], true); if (tokens[4].IsDouble()) toFill._GGA_longitude = Convert.ToDouble(tokens[4]); if (tokens[5] != String.Empty) toFill._GGA_longDir = CoordConvert.ConvertEastWest(tokens[5]);// (EastWest)Enum.Parse(typeof(EastWest), tokens[5], true); if (tokens[6].IsInteger()) toFill._fix_quality = Convert.ToInt32(tokens[6]); if (tokens[7].IsInteger()) toFill._num_of_used_sat = Convert.ToInt32(tokens[7]); if (tokens[8].IsDouble()) toFill._horiz_dilution_position = Convert.ToDouble(tokens[8]); if (tokens[9].IsDouble()) toFill._altitude = Convert.ToDouble(tokens[9]); if (tokens[10] != String.Empty) toFill._alt_unit = TtUtils.ConvertUnit(tokens[10]);// (Unit)Enum.Parse(typeof(Unit), tokens[10], true); if (tokens[11].IsDouble()) toFill._geoid_height = Convert.ToDouble(tokens[11]); if (tokens[12] != String.Empty) toFill._geoid_unit = TtUtils.ConvertUnit(tokens[12]);// (Unit)Enum.Parse(typeof(Unit), tokens[12], true); toFill.bGGA = true; } catch { toFill.BadData(); } }
private void InsertUpgradeNmeaBurst(NmeaBurst burst, SQLiteTransaction trans) { StringBuilder queryBeginning = new StringBuilder(); StringBuilder queryEnd = new StringBuilder(); queryBeginning.AppendFormat("INSERT INTO {0} (", TwoTrailsSchema.TtnmeaSchema.TableName); queryEnd.Append("("); //CN queryBeginning.AppendFormat("{0},", TwoTrailsSchema.TtnmeaSchema.CN); queryEnd.AppendFormat("'{0}',", Guid.NewGuid().ToString()); //Point CN queryBeginning.AppendFormat("{0},", TwoTrailsSchema.TtnmeaSchema.PointCN); queryEnd.AppendFormat("'{0}',", burst._PointCN); //Used in Point queryBeginning.AppendFormat("{0},", TwoTrailsSchema.TtnmeaSchema.Used); if (burst._Used) queryEnd.AppendFormat("'{0}',", 1); else queryEnd.AppendFormat("'{0}',", 0); //DateTime queryBeginning.AppendFormat("{0},", TwoTrailsSchema.TtnmeaSchema.DateTimeZulu); queryEnd.AppendFormat("'{0}',", burst._datetime.ToString()); //Longitude queryBeginning.AppendFormat("{0},", TwoTrailsSchema.TtnmeaSchema.Longitude); queryEnd.AppendFormat("'{0}',", burst._longitude); //Latitude queryBeginning.AppendFormat("{0},", TwoTrailsSchema.TtnmeaSchema.Latitude); queryEnd.AppendFormat("'{0}',", burst._latitude); //Latitude Direction queryBeginning.AppendFormat("{0},", TwoTrailsSchema.TtnmeaSchema.LatDir); queryEnd.AppendFormat("'{0}',", burst._latDir.ToString()); //Longitude Direction queryBeginning.AppendFormat("{0},", TwoTrailsSchema.TtnmeaSchema.LonDir); queryEnd.AppendFormat("'{0}',", burst._longDir.ToString()); //Magnetitc Variation queryBeginning.AppendFormat("{0},", TwoTrailsSchema.TtnmeaSchema.MagVar); queryEnd.AppendFormat("'{0}',", burst._magVar); //Magnetitc Variation Direction queryBeginning.AppendFormat("{0},", TwoTrailsSchema.TtnmeaSchema.MagDir); queryEnd.AppendFormat("'{0}',", burst._magVarDir.ToString()); //UTM Zone queryBeginning.AppendFormat("{0},", TwoTrailsSchema.TtnmeaSchema.UtmZone); queryEnd.AppendFormat("'{0}',", burst._utm_zone); //UTM X queryBeginning.AppendFormat("{0},", TwoTrailsSchema.TtnmeaSchema.UtmX); queryEnd.AppendFormat("'{0}',", burst._X); //UTM Y queryBeginning.AppendFormat("{0},", TwoTrailsSchema.TtnmeaSchema.UtmY); queryEnd.AppendFormat("'{0}',", burst._Y); //Altitude queryBeginning.AppendFormat("{0},", TwoTrailsSchema.TtnmeaSchema.Altitude); queryEnd.AppendFormat("'{0}',", burst._altitude); //Altitude Unit Type queryBeginning.AppendFormat("{0},", TwoTrailsSchema.TtnmeaSchema.AltUnit); queryEnd.AppendFormat("'{0}',", burst._alt_unit.ToString()); //Fix Quality queryBeginning.AppendFormat("{0},", TwoTrailsSchema.TtnmeaSchema.FixQuality); queryEnd.AppendFormat("'{0}',", burst._fix_quality); //Altitude Fix Type queryBeginning.AppendFormat("{0},", TwoTrailsSchema.TtnmeaSchema.Mode); queryEnd.AppendFormat("'{0}',", burst._fix); //PDOP queryBeginning.AppendFormat("{0},", TwoTrailsSchema.TtnmeaSchema.PDOP); queryEnd.AppendFormat("'{0}',", burst._PDOP); //HDOP queryBeginning.AppendFormat("{0},", TwoTrailsSchema.TtnmeaSchema.HDOP); queryEnd.AppendFormat("'{0}',", burst._HDOP); //VDOP queryBeginning.AppendFormat("{0},", TwoTrailsSchema.TtnmeaSchema.VDOP); queryEnd.AppendFormat("'{0}',", burst._VDOP); //PRNs queryBeginning.AppendFormat("{0},", TwoTrailsSchema.TtnmeaSchema.PRNS); queryEnd.AppendFormat("'{0}',", burst._fixed_PRNs); //Horizontal Dilution of Position queryBeginning.AppendFormat("{0},", TwoTrailsSchema.TtnmeaSchema.HDo_Position); queryEnd.AppendFormat("'{0}',", burst._horiz_dilution_position); //HAE queryBeginning.AppendFormat("{0},", TwoTrailsSchema.TtnmeaSchema.HAE); queryEnd.AppendFormat("'{0}',", burst._geoid_height); //HAE queryBeginning.AppendFormat("{0},", TwoTrailsSchema.TtnmeaSchema.HAE_Unit); queryEnd.AppendFormat("'{0}',", burst._geoid_unit); //Speed queryBeginning.AppendFormat("{0},", TwoTrailsSchema.TtnmeaSchema.Speed); queryEnd.AppendFormat("'{0}',", burst._speed); //HAE queryBeginning.AppendFormat("{0},", TwoTrailsSchema.TtnmeaSchema.Track_Angle); queryEnd.AppendFormat("'{0}',", burst._track_angle); //Satellite Count queryBeginning.AppendFormat("{0},", TwoTrailsSchema.TtnmeaSchema.SatelliteCount); queryEnd.AppendFormat("'{0}',", burst._num_of_sat); //Satellite Used queryBeginning.AppendFormat("{0},", TwoTrailsSchema.TtnmeaSchema.SatelliteUsed); queryEnd.AppendFormat("'{0}',", burst._num_of_used_sat); #region Satellites List<Satellite> sats = burst.GetSatellites(); string satID = "", satElev = "", satAz = "", satSRN = ""; for (int i = 0; i < sats.Count; i++) { switch (i) { case 0: { satID = TwoTrailsSchema.TtnmeaSchema.PRN1ID; satElev = TwoTrailsSchema.TtnmeaSchema.PRN1Elev; satAz = TwoTrailsSchema.TtnmeaSchema.PRN1Az; satSRN = TwoTrailsSchema.TtnmeaSchema.PRN1SRN; break; } case 1: { satID = TwoTrailsSchema.TtnmeaSchema.PRN2ID; satElev = TwoTrailsSchema.TtnmeaSchema.PRN2Elev; satAz = TwoTrailsSchema.TtnmeaSchema.PRN2Az; satSRN = TwoTrailsSchema.TtnmeaSchema.PRN2SRN; break; } case 2: { satID = TwoTrailsSchema.TtnmeaSchema.PRN3ID; satElev = TwoTrailsSchema.TtnmeaSchema.PRN3Elev; satAz = TwoTrailsSchema.TtnmeaSchema.PRN3Az; satSRN = TwoTrailsSchema.TtnmeaSchema.PRN3SRN; break; } case 3: { satID = TwoTrailsSchema.TtnmeaSchema.PRN4ID; satElev = TwoTrailsSchema.TtnmeaSchema.PRN4Elev; satAz = TwoTrailsSchema.TtnmeaSchema.PRN4Az; satSRN = TwoTrailsSchema.TtnmeaSchema.PRN4SRN; break; } case 4: { satID = TwoTrailsSchema.TtnmeaSchema.PRN5ID; satElev = TwoTrailsSchema.TtnmeaSchema.PRN5Elev; satAz = TwoTrailsSchema.TtnmeaSchema.PRN5Az; satSRN = TwoTrailsSchema.TtnmeaSchema.PRN5SRN; break; } case 5: { satID = TwoTrailsSchema.TtnmeaSchema.PRN6ID; satElev = TwoTrailsSchema.TtnmeaSchema.PRN6Elev; satAz = TwoTrailsSchema.TtnmeaSchema.PRN6Az; satSRN = TwoTrailsSchema.TtnmeaSchema.PRN6SRN; break; } case 6: { satID = TwoTrailsSchema.TtnmeaSchema.PRN7ID; satElev = TwoTrailsSchema.TtnmeaSchema.PRN7Elev; satAz = TwoTrailsSchema.TtnmeaSchema.PRN7Az; satSRN = TwoTrailsSchema.TtnmeaSchema.PRN7SRN; break; } case 7: { satID = TwoTrailsSchema.TtnmeaSchema.PRN8ID; satElev = TwoTrailsSchema.TtnmeaSchema.PRN8Elev; satAz = TwoTrailsSchema.TtnmeaSchema.PRN8Az; satSRN = TwoTrailsSchema.TtnmeaSchema.PRN8SRN; break; } case 8: { satID = TwoTrailsSchema.TtnmeaSchema.PRN9ID; satElev = TwoTrailsSchema.TtnmeaSchema.PRN9Elev; satAz = TwoTrailsSchema.TtnmeaSchema.PRN9Az; satSRN = TwoTrailsSchema.TtnmeaSchema.PRN9SRN; break; } case 9: { satID = TwoTrailsSchema.TtnmeaSchema.PRN10ID; satElev = TwoTrailsSchema.TtnmeaSchema.PRN10Elev; satAz = TwoTrailsSchema.TtnmeaSchema.PRN10Az; satSRN = TwoTrailsSchema.TtnmeaSchema.PRN10SRN; break; } case 10: { satID = TwoTrailsSchema.TtnmeaSchema.PRN11ID; satElev = TwoTrailsSchema.TtnmeaSchema.PRN11Elev; satAz = TwoTrailsSchema.TtnmeaSchema.PRN11Az; satSRN = TwoTrailsSchema.TtnmeaSchema.PRN11SRN; break; } case 11: { satID = TwoTrailsSchema.TtnmeaSchema.PRN12ID; satElev = TwoTrailsSchema.TtnmeaSchema.PRN12Elev; satAz = TwoTrailsSchema.TtnmeaSchema.PRN12Az; satSRN = TwoTrailsSchema.TtnmeaSchema.PRN12SRN; break; } } //Satellite Info queryBeginning.AppendFormat("{0},", satID); queryEnd.AppendFormat("'{0}',", sats[i].ID); queryBeginning.AppendFormat("{0},", satElev); queryEnd.AppendFormat("'{0}',", sats[i].Elevation); queryBeginning.AppendFormat("{0},", satAz); queryEnd.AppendFormat("'{0}',", sats[i].Azimuth); queryBeginning.AppendFormat("{0},", satSRN); queryEnd.AppendFormat("'{0}',", sats[i].SNR); } #endregion queryBeginning.Remove(queryBeginning.Length - 1, 1); queryEnd.Remove(queryEnd.Length - 1, 1); queryBeginning.Append(") values "); queryEnd.Append(");"); queryBeginning.AppendFormat(" {0}", queryEnd.ToString()); SQLiteCommand update = _dbConnection.CreateCommand(); try { if (trans != null) update.Transaction = trans; update.CommandText = queryBeginning.ToString(); update.ExecuteNonQuery(); } catch (Exception ex) { TtUtils.WriteError(ex.Message, "DataAccessUpgrader:SaveNmeaBurst", ex.StackTrace); } finally { update.Dispose(); } }
//GPS Connection and Read private void GpsWorker(object o) { _UseFile = false; NmeaBurst burst = new NmeaBurst(); _bursts = 0; try { #region File if (!Port.ToLower().Contains("com")) { _UseFile = true; GpsFile = Port; try { try { sr = new StreamReader(GpsFile); FileOpen = true; } catch(Exception ex) { TtUtils.WriteError(ex.Message, String.Format("GpsAccess:GpsWorker:OpenFile [{0}]", GpsFile), ex.StackTrace); Error = GpsErrorType.FileOpenError; if (GpsError != null) GpsError(); Cancel(); return; } if (sr.Peek() < 1) { Error = GpsErrorType.FileNull; if (GpsError != null) GpsError(); Cancel(); return; } while (true) { if (_cancelled) { Cancel(); return; } try { sentence = sr.ReadLine(); if (sentence == null) { sr.Close(); FileOpen = false; sr = new StreamReader(GpsFile); FileOpen = true; sentence = sr.ReadLine(); } sentence = sentence.Trim(); } catch (Exception ex) { TtUtils.WriteError(ex.Message, "GpsAccess:GpsWorker:Readline", ex.StackTrace); Error = GpsErrorType.FileReadError; if (GpsError != null) GpsError(); Cancel(); return; } //create new burst if no burst or prev burst was completed if (burst == null || burst.complete) { burst = new NmeaBurst(); } ParseSentence(sentence, ref burst); //if all lines are parsed mark as complete if (burst != null) { if (burst.bGGA && burst.bGSA && burst.bGSV && burst.bRMC) burst.Complete(); } //trigger complete burst completed #region Trigger NmeaBurstReceived Event if (burst != null && !_cancelled && burst.complete) { _bursts++; try { OnBurstReceived(burst); } catch (Exception ex) { TtUtils.WriteError(ex.Message, "GpsAccess:GpsWorker:BurstReceived:Delegate", ex.StackTrace); Error = GpsErrorType.BurstDelegateError; if (GpsError != null) GpsError(); Cancel(); return; } Thread.Sleep(1000); } #endregion } } catch (IOException ioEx) { TtUtils.WriteError(ioEx.Message, "GpsAccess:GpsWorker(IO)", ioEx.StackTrace); Error = GpsErrorType.UnknownFileError; if (GpsError != null) GpsError(); Cancel(); } catch (Exception ex) { TtUtils.WriteError(ex.Message, "GpsAccess:GpsWorker", ex.StackTrace); Error = GpsErrorType.UnknownError; if (GpsError != null) GpsError(); Cancel(); } } #endregion #region GpsDevice else { _port = new SerialPort(Port, Rate); _port.Parity = Parity.None; _port.StopBits = StopBits.One; _port.DataBits = 8; _port.Handshake = Handshake.None; _port.ReadTimeout = Values.Settings.DeviceOptions.GpsTimeout; _port.Open(); ignoreFirst = true; //ignore first GPS string (bad data) #region Trigger Event //Trigger Event if (GpsStarted != null) { GpsStarted(); } #endregion if (_test) { sentence = _port.ReadLine().TrimEx(); _test = false; } else { sentence = SyncGps().TrimEx(); } while (true) { //create new burst if no burst or prev burst was completed if (burst == null || burst.complete) { burst = new NmeaBurst(); } ParseSentence(sentence, ref burst); if(burst != null) { if (burst.bGGA && burst.bGSA && burst.bGSV && burst.bRMC) burst.Complete(); #region Trigger NmeaBurstReceived Event if (burst.complete && BurstReceived != null && !_cancelled) { _bursts++; try { if (burst.IsValidNmea) { OnBurstReceived(burst); } else { burst.drop = true; OnBurstReceived(burst); burst = null; } } catch (Exception ex) { TtUtils.WriteError(ex.Message, "GpsAccess:BurstReceived:Delegate", ex.StackTrace); } } #endregion } if (_cancelled) { Cancel(); return; } sentence = _port.ReadLine().TrimEx(); } } } #endregion #region Catch Exceptions catch (TimeoutException toEx) { Error = GpsErrorType.GpsTimeout; TtUtils.WriteError(toEx.Message, "GpsAccess", toEx.StackTrace); #region trigger ComTimeout event if (ComTimeout != null) ComTimeout(); #endregion CloseGpsPort(); } catch(System.IO.IOException ioEx) { Error = GpsErrorType.ComNotExist; TtUtils.WriteError(ioEx.Message, "GpsAccess", ioEx.StackTrace); #region trigger Error event if (GpsError != null) GpsError(); #endregion CloseGpsPort(); } catch (Exception ex) { Error = GpsErrorType.UnknownError; TtUtils.WriteError(ex.Message, "GpsAccess", ex.StackTrace); #region trigger Error event if (GpsError != null) GpsError(); #endregion CloseGpsPort(); } #endregion }
protected void UpdateNmeaBurst(NmeaBurst burst, string pointCN, SQLiteTransaction trans) { StringBuilder query = new StringBuilder(); query.AppendFormat("Update {0} set ", TwoTrailsSchema.TtnmeaSchema.TableName); //Point CN query.AppendFormat("{0} = '{1}', ", TwoTrailsSchema.TtnmeaSchema.PointCN, pointCN); //Used query.AppendFormat("{0} = '{1}', ", TwoTrailsSchema.TtnmeaSchema.Used, (burst._Used)?(1):(0)); //DateTime query.AppendFormat("{0} = '{1}', ", TwoTrailsSchema.TtnmeaSchema.DateTimeZulu, burst._datetime.ToString()); //Longitude query.AppendFormat("{0} = '{1}', ", TwoTrailsSchema.TtnmeaSchema.Longitude, burst._longitude); //Latitude query.AppendFormat("{0} = '{1}', ", TwoTrailsSchema.TtnmeaSchema.Latitude, burst._latitude); //Latitude Direction query.AppendFormat("{0} = '{1}', ", TwoTrailsSchema.TtnmeaSchema.LatDir, burst._latDir.ToString()); //Longitude Direction query.AppendFormat("{0} = '{1}', ", TwoTrailsSchema.TtnmeaSchema.LonDir, burst._longDir.ToString()); //Magnetitc Variation query.AppendFormat("{0} = '{1}', ", TwoTrailsSchema.TtnmeaSchema.MagVar, burst._magVar); //Magnetitc Variation Direction query.AppendFormat("{0} = '{1}', ", TwoTrailsSchema.TtnmeaSchema.MagDir, burst._magVarDir.ToString()); //UTM Zone query.AppendFormat("{0} = '{1}', ", TwoTrailsSchema.TtnmeaSchema.UtmZone, burst._utm_zone); //UTM X query.AppendFormat("{0} = '{1}', ", TwoTrailsSchema.TtnmeaSchema.UtmX, burst._X); //UTM Y query.AppendFormat("{0} = '{1}', ", TwoTrailsSchema.TtnmeaSchema.UtmY, burst._Y); //Altitude query.AppendFormat("{0} = '{1}', ", TwoTrailsSchema.TtnmeaSchema.Altitude, burst._altitude); //Altitude Unit Type query.AppendFormat("{0} = '{1}', ", TwoTrailsSchema.TtnmeaSchema.AltUnit, burst._alt_unit.ToString()); //Fix Quality query.AppendFormat("{0} = '{1}', ", TwoTrailsSchema.TtnmeaSchema.FixQuality, burst._fix_quality); //Altitude Fix Type query.AppendFormat("{0} = '{1}', ", TwoTrailsSchema.TtnmeaSchema.Mode, burst._fix); //PDOP query.AppendFormat("{0} = '{1}', ", TwoTrailsSchema.TtnmeaSchema.PDOP, burst._PDOP); //HDOP query.AppendFormat("{0} = '{1}', ", TwoTrailsSchema.TtnmeaSchema.HDOP, burst._HDOP); //VDOP query.AppendFormat("{0} = '{1}', ", TwoTrailsSchema.TtnmeaSchema.VDOP, burst._VDOP); //PRNs query.AppendFormat("{0} = '{1}', ", TwoTrailsSchema.TtnmeaSchema.PRNS, burst._fixed_PRNs); //Horizontal Dilution of Position query.AppendFormat("{0} = '{1}', ", TwoTrailsSchema.TtnmeaSchema.HDo_Position, burst._horiz_dilution_position); //HAE query.AppendFormat("{0} = '{1}', ", TwoTrailsSchema.TtnmeaSchema.HAE, burst._geoid_height); //HAE query.AppendFormat("{0} = '{1}', ", TwoTrailsSchema.TtnmeaSchema.HAE_Unit, burst._geoid_unit); //Speed query.AppendFormat("{0} = '{1}', ", TwoTrailsSchema.TtnmeaSchema.Speed, burst._speed); //Angle query.AppendFormat("{0} = '{1}', ", TwoTrailsSchema.TtnmeaSchema.Track_Angle, burst._track_angle); //Satellite Count query.AppendFormat("{0} = '{1}', ", TwoTrailsSchema.TtnmeaSchema.SatelliteCount, burst._num_of_sat); //Satellite Used query.AppendFormat("{0} = '{1}', ", TwoTrailsSchema.TtnmeaSchema.SatelliteUsed, burst._num_of_used_sat); #region Satellites List<Satellite> sats = burst.GetSatellites(); string satID = "", satElev = "", satAz = "", satSRN = ""; for (int i = 0; i < sats.Count; i++) { switch (i) { case 0: { satID = TwoTrailsSchema.TtnmeaSchema.PRN1ID; satElev = TwoTrailsSchema.TtnmeaSchema.PRN1Elev; satAz = TwoTrailsSchema.TtnmeaSchema.PRN1Az; satSRN = TwoTrailsSchema.TtnmeaSchema.PRN1SRN; break; } case 1: { satID = TwoTrailsSchema.TtnmeaSchema.PRN2ID; satElev = TwoTrailsSchema.TtnmeaSchema.PRN2Elev; satAz = TwoTrailsSchema.TtnmeaSchema.PRN2Az; satSRN = TwoTrailsSchema.TtnmeaSchema.PRN2SRN; break; } case 2: { satID = TwoTrailsSchema.TtnmeaSchema.PRN3ID; satElev = TwoTrailsSchema.TtnmeaSchema.PRN3Elev; satAz = TwoTrailsSchema.TtnmeaSchema.PRN3Az; satSRN = TwoTrailsSchema.TtnmeaSchema.PRN3SRN; break; } case 3: { satID = TwoTrailsSchema.TtnmeaSchema.PRN4ID; satElev = TwoTrailsSchema.TtnmeaSchema.PRN4Elev; satAz = TwoTrailsSchema.TtnmeaSchema.PRN4Az; satSRN = TwoTrailsSchema.TtnmeaSchema.PRN4SRN; break; } case 4: { satID = TwoTrailsSchema.TtnmeaSchema.PRN5ID; satElev = TwoTrailsSchema.TtnmeaSchema.PRN5Elev; satAz = TwoTrailsSchema.TtnmeaSchema.PRN5Az; satSRN = TwoTrailsSchema.TtnmeaSchema.PRN5SRN; break; } case 5: { satID = TwoTrailsSchema.TtnmeaSchema.PRN6ID; satElev = TwoTrailsSchema.TtnmeaSchema.PRN6Elev; satAz = TwoTrailsSchema.TtnmeaSchema.PRN6Az; satSRN = TwoTrailsSchema.TtnmeaSchema.PRN6SRN; break; } case 6: { satID = TwoTrailsSchema.TtnmeaSchema.PRN7ID; satElev = TwoTrailsSchema.TtnmeaSchema.PRN7Elev; satAz = TwoTrailsSchema.TtnmeaSchema.PRN7Az; satSRN = TwoTrailsSchema.TtnmeaSchema.PRN7SRN; break; } case 7: { satID = TwoTrailsSchema.TtnmeaSchema.PRN8ID; satElev = TwoTrailsSchema.TtnmeaSchema.PRN8Elev; satAz = TwoTrailsSchema.TtnmeaSchema.PRN8Az; satSRN = TwoTrailsSchema.TtnmeaSchema.PRN8SRN; break; } case 8: { satID = TwoTrailsSchema.TtnmeaSchema.PRN9ID; satElev = TwoTrailsSchema.TtnmeaSchema.PRN9Elev; satAz = TwoTrailsSchema.TtnmeaSchema.PRN9Az; satSRN = TwoTrailsSchema.TtnmeaSchema.PRN9SRN; break; } case 9: { satID = TwoTrailsSchema.TtnmeaSchema.PRN10ID; satElev = TwoTrailsSchema.TtnmeaSchema.PRN10Elev; satAz = TwoTrailsSchema.TtnmeaSchema.PRN10Az; satSRN = TwoTrailsSchema.TtnmeaSchema.PRN10SRN; break; } case 10: { satID = TwoTrailsSchema.TtnmeaSchema.PRN11ID; satElev = TwoTrailsSchema.TtnmeaSchema.PRN11Elev; satAz = TwoTrailsSchema.TtnmeaSchema.PRN11Az; satSRN = TwoTrailsSchema.TtnmeaSchema.PRN11SRN; break; } case 11: { satID = TwoTrailsSchema.TtnmeaSchema.PRN12ID; satElev = TwoTrailsSchema.TtnmeaSchema.PRN12Elev; satAz = TwoTrailsSchema.TtnmeaSchema.PRN12Az; satSRN = TwoTrailsSchema.TtnmeaSchema.PRN12SRN; break; } } //Satellite Info query.AppendFormat("{0} = '{1}', ", satID, sats[i].ID); query.AppendFormat("{0} = '{1}', ", satElev, sats[i].Elevation); query.AppendFormat("{0} = '{1}', ", satAz, sats[i].Azimuth); query.AppendFormat("{0} = '{1}'{2} ", satSRN, sats[i].SNR, i == sats.Count - 1 ? "" : ","); } #endregion query.AppendFormat("where {0} = '{1}'", TwoTrailsSchema.SharedSchema.CN, burst._CN); SQLiteCommand update = _dbConnection.CreateCommand(); try { if (trans != null) update.Transaction = trans; update.CommandText = query.ToString(); update.ExecuteNonQuery(); } catch (Exception ex) { TtUtils.WriteError(ex.Message, "DataAccessLayer:UpdateNmeaBurst"); } finally { update.Dispose(); } }
private List<NmeaBurst> GetUpgradeNmeaBursts() { StringBuilder query = new StringBuilder(); query.AppendFormat(@"SELECT {0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}, {11}, {12}, {13}, {14}, {15}, {16}, {17}, {18}, {19}, {20}, {21}, {22}, {23}, {24}, {25}, {26}, {27}, {28}, {29}, {30}, {31}, {32}, {33}, {34}, {35}, {36}, {37}, {38}, {39}, {40}, {41}, {42}, {43}, {44}, {45}, {46}, {47}, {48}, {49}, {50}, {51}, {52}, {53}, {54}, {55}, {56}, {57}, {58}, {59}, {60}, {61}, {62}, {63}, {64}, {65}, {66}, {67}, {68}, {69}, {70}, {71}, {72}, {73}, {74}, {75} from {76}", #region Values TwoTrailsSchema.SharedSchema.CN, //0 TwoTrailsSchema.TtnmeaSchema.PointCN, TwoTrailsSchema.TtnmeaSchema.Used, TwoTrailsSchema.TtnmeaSchema.DateTimeZulu, TwoTrailsSchema.TtnmeaSchema.Longitude, TwoTrailsSchema.TtnmeaSchema.Latitude, //5 TwoTrailsSchema.TtnmeaSchema.LatDir, TwoTrailsSchema.TtnmeaSchema.LonDir, TwoTrailsSchema.TtnmeaSchema.MagVar, TwoTrailsSchema.TtnmeaSchema.MagDir, TwoTrailsSchema.TtnmeaSchema.UtmZone, //10 TwoTrailsSchema.TtnmeaSchema.UtmX, TwoTrailsSchema.TtnmeaSchema.UtmY, TwoTrailsSchema.TtnmeaSchema.Altitude, TwoTrailsSchema.TtnmeaSchema.AltUnit, TwoTrailsSchema.TtnmeaSchema.FixQuality, //15 TwoTrailsSchema.TtnmeaSchema.Mode, TwoTrailsSchema.TtnmeaSchema.PDOP, TwoTrailsSchema.TtnmeaSchema.HDOP, TwoTrailsSchema.TtnmeaSchema.VDOP, TwoTrailsSchema.TtnmeaSchema.PRNS, //20 TwoTrailsSchema.TtnmeaSchema.HDo_Position, TwoTrailsSchema.TtnmeaSchema.HAE, TwoTrailsSchema.TtnmeaSchema.HAE_Unit, TwoTrailsSchema.TtnmeaSchema.Speed, TwoTrailsSchema.TtnmeaSchema.Track_Angle, TwoTrailsSchema.TtnmeaSchema.SatelliteCount, TwoTrailsSchema.TtnmeaSchema.SatelliteUsed, //27 TwoTrailsSchema.TtnmeaSchema.PRN1ID, //28 TwoTrailsSchema.TtnmeaSchema.PRN1Elev, TwoTrailsSchema.TtnmeaSchema.PRN1Az, TwoTrailsSchema.TtnmeaSchema.PRN1SRN, TwoTrailsSchema.TtnmeaSchema.PRN2ID, //32 TwoTrailsSchema.TtnmeaSchema.PRN2Elev, TwoTrailsSchema.TtnmeaSchema.PRN2Az, TwoTrailsSchema.TtnmeaSchema.PRN2SRN, TwoTrailsSchema.TtnmeaSchema.PRN3ID, //36 TwoTrailsSchema.TtnmeaSchema.PRN3Elev, TwoTrailsSchema.TtnmeaSchema.PRN3Az, TwoTrailsSchema.TtnmeaSchema.PRN3SRN, TwoTrailsSchema.TtnmeaSchema.PRN4ID, //40 TwoTrailsSchema.TtnmeaSchema.PRN4Elev, TwoTrailsSchema.TtnmeaSchema.PRN4Az, TwoTrailsSchema.TtnmeaSchema.PRN4SRN, TwoTrailsSchema.TtnmeaSchema.PRN5ID, //44 TwoTrailsSchema.TtnmeaSchema.PRN5Elev, TwoTrailsSchema.TtnmeaSchema.PRN5Az, TwoTrailsSchema.TtnmeaSchema.PRN5SRN, TwoTrailsSchema.TtnmeaSchema.PRN6ID, //48 TwoTrailsSchema.TtnmeaSchema.PRN6Elev, TwoTrailsSchema.TtnmeaSchema.PRN6Az, TwoTrailsSchema.TtnmeaSchema.PRN6SRN, TwoTrailsSchema.TtnmeaSchema.PRN7ID, //52 TwoTrailsSchema.TtnmeaSchema.PRN7Elev, TwoTrailsSchema.TtnmeaSchema.PRN7Az, TwoTrailsSchema.TtnmeaSchema.PRN7SRN, TwoTrailsSchema.TtnmeaSchema.PRN8ID, //56 TwoTrailsSchema.TtnmeaSchema.PRN8Elev, TwoTrailsSchema.TtnmeaSchema.PRN8Az, TwoTrailsSchema.TtnmeaSchema.PRN8SRN, TwoTrailsSchema.TtnmeaSchema.PRN9ID, //60 TwoTrailsSchema.TtnmeaSchema.PRN9Elev, TwoTrailsSchema.TtnmeaSchema.PRN9Az, TwoTrailsSchema.TtnmeaSchema.PRN9SRN, TwoTrailsSchema.TtnmeaSchema.PRN10ID, //64 TwoTrailsSchema.TtnmeaSchema.PRN10Elev, TwoTrailsSchema.TtnmeaSchema.PRN10Az, TwoTrailsSchema.TtnmeaSchema.PRN10SRN, TwoTrailsSchema.TtnmeaSchema.PRN11ID, //68 TwoTrailsSchema.TtnmeaSchema.PRN11Elev, TwoTrailsSchema.TtnmeaSchema.PRN11Az, TwoTrailsSchema.TtnmeaSchema.PRN11SRN, TwoTrailsSchema.TtnmeaSchema.PRN12ID, //72 TwoTrailsSchema.TtnmeaSchema.PRN12Elev, TwoTrailsSchema.TtnmeaSchema.PRN12Az, TwoTrailsSchema.TtnmeaSchema.PRN12SRN, //75 TwoTrailsSchema.TtnmeaSchema.TableName); //76 #endregion List<NmeaBurst> Bursts = new List<NmeaBurst>(); SQLiteCommand cmd = _dbConnection.CreateCommand(); try { cmd.CommandText = query.ToString(); NmeaBurst burst = new NmeaBurst(); SQLiteDataReader reader = cmd.ExecuteReader(); #region Reader while (reader.Read()) { if (!reader.IsDBNull(0)) burst._CN = reader.GetString(0); if (!reader.IsDBNull(1)) burst._PointCN = reader.GetString(1); if (!reader.IsDBNull(2)) burst._Used = reader.GetBoolean(2); if (!reader.IsDBNull(3)) burst._datetime = DateTime.Parse(reader.GetString(3)); if (!reader.IsDBNull(4)) burst._longitude = reader.GetDouble(4); if (!reader.IsDBNull(5)) burst._latitude = reader.GetDouble(5); if (!reader.IsDBNull(6)) burst._latDir = (NorthSouth)Enum.Parse(typeof(NorthSouth), reader.GetString(6), true); if (!reader.IsDBNull(7)) burst._longDir = (EastWest)Enum.Parse(typeof(EastWest), reader.GetString(7), true); if (!reader.IsDBNull(8)) burst._magVar = reader.GetDouble(8); if (!reader.IsDBNull(9)) burst._magVarDir = (EastWest)Enum.Parse(typeof(EastWest), reader.GetString(9), true); if (!reader.IsDBNull(10)) burst._utm_zone = reader.GetInt32(10); if (!reader.IsDBNull(11)) burst._X = reader.GetDouble(11); if (!reader.IsDBNull(12)) burst._Y = reader.GetDouble(12); if (!reader.IsDBNull(13)) { burst._altitude = reader.GetDouble(13); burst._Z = burst._altitude; } if (!reader.IsDBNull(14)) burst._alt_unit = (Unit)Enum.Parse(typeof(Unit), reader.GetString(14), true); if (!reader.IsDBNull(15)) burst._fix_quality = reader.GetInt32(15); if (!reader.IsDBNull(16)) burst._fix = reader.GetInt32(16); if (!reader.IsDBNull(17)) burst._PDOP = reader.GetDouble(17); if (!reader.IsDBNull(18)) burst._HDOP = reader.GetDouble(18); if (!reader.IsDBNull(19)) burst._VDOP = reader.GetDouble(19); if (!reader.IsDBNull(20)) burst._fixed_PRNs = reader.GetString(20); if (!reader.IsDBNull(21)) burst._horiz_dilution_position = reader.GetDouble(21); if (!reader.IsDBNull(22)) burst._geoid_height = reader.GetDouble(22); if (!reader.IsDBNull(23)) burst._geoid_unit = (Unit)Enum.Parse(typeof(Unit), reader.GetString(23), true); if (!reader.IsDBNull(24)) burst._speed = reader.GetDouble(24); if (!reader.IsDBNull(25)) burst._track_angle = reader.GetDouble(25); if (!reader.IsDBNull(26)) burst._num_of_sat = reader.GetInt32(26); if (!reader.IsDBNull(27)) burst._num_of_used_sat = reader.GetInt32(27); for (int i = 28; i < 76; i += 4) { Satellite sat = new Satellite(); if (!reader.IsDBNull(i)) sat.ID = reader.GetString(i); if (!reader.IsDBNull(i + 1)) sat.Elevation = reader.GetDouble(i + 1); if (!reader.IsDBNull(i + 2)) sat.Azimuth = reader.GetDouble(i + 2); if (!reader.IsDBNull(i + 3)) sat.SNR = reader.GetDouble(i + 3); burst.AddSatalite(sat); } Bursts.Add(burst); burst = new NmeaBurst(); } #endregion } catch (Exception ex) { TtUtils.WriteError(ex.Message, "DataAccessUpgrader:GetNmeaBursts", ex.StackTrace); } finally { cmd.Dispose(); } return Bursts; }
public void SaveNmeaBurst(NmeaBurst burst, string pointCN) { SQLiteTransaction trans = _dbConnection.BeginTransaction(); try { SaveNmeaBurst(burst, pointCN, trans); trans.Commit(); } catch (Exception ex) { TtUtils.WriteError(ex.Message, "DataAccessLayer:SaveNmeaBurst"); } finally { trans.Dispose(); } }
private void gpsReceivingData(NmeaBurst b) { Display(b); }
private void Display(NmeaBurst b) { if (RangeOn) { UtmRangeX.Add(b._X); UtmRangeY.Add(b._Y); CalculateUtmRange(); } lblAlt.Text = b._altitude.ToString(); if (b._magVar >= 0) lblDec.Text = "+" + b._magVar.ToString(); else lblDec.Text = b._magVar.ToString(); lblPdop.Text = b._PDOP.ToString(); lblHdop.Text = b._HDOP.ToString(); lblSat.Text = b._num_of_used_sat.ToString(); if (b._fix_quality == 2) lblDiff.Text = "Yes"; else lblDiff.Text = "No"; lblUtmRangeX.Text = UTMX.ToString("F2").Truncate(6); lblUtmRangeY.Text = UTMY.ToString("F2").Truncate(6); lblLat.Text = b._latitude.ToString().Truncate(7); lblLon.Text = b._longitude.ToString().Truncate(7); lblUTMX.Text = b._X.ToString().Truncate(11); lblUTMY.Text = b._Y.ToString().Truncate(11); switch (b._fix_quality) { case 1: lblGpsStatus.Text = "GPS"; break; case 2: lblGpsStatus.Text = "D-GPS"; break; case 3: lblGpsStatus.Text = "PPS"; break; case 4: lblGpsStatus.Text = "RTK"; break; case 5: lblGpsStatus.Text = "F-RTK"; break; case 6: lblGpsStatus.Text = "EST"; break; case 7: lblGpsStatus.Text = "MAN"; break; case 8: lblGpsStatus.Text = "Simulation"; break; default: lblGpsStatus.Text = "No Fix"; break; } string gpsString = String.Empty; if (b._fix_quality != 3) { switch (b._fix) { case 2: gpsString = "GPS-2D"; break; case 3: gpsString = "GPS-3D"; break; default: gpsString = "GPS-UNKOWN"; break; } if (b._fix_quality == 2) gpsString = gpsString + "-DIFF"; lblGpsFix.Text = gpsString; } else { lblGpsFix.Text = "GPS-PPS"; } }
private void CreateWalkPoint(NmeaBurst b) { try { if (WalkGroup == null) { WalkGroup = new TtGroup(); WalkGroup.SetGroupName(String.Format("Walk_{0}", WalkGroup.CN.Truncate(8)), null); DAL.InsertGroup(WalkGroup); } if (CurrentPoint != null) { DAL.InsertPoint(CurrentPoint); DAL.SaveNmeaBurst(CurrentNmea, CurrentPoint.CN); LastPoint = CurrentPoint; btnOk.GuiInvoke(() => { btnOk.Enabled = true; }); } } catch (Exception ex) { TtUtils.WriteError(ex.Message, "WalkFormLogic:CreateWalkPoint-Save Current Point", ex.StackTrace); } LastNmea = CurrentNmea; CurrentNmea = b; if (SetupPoint()) { try { CurrentPoint.UnAdjX = b._X; CurrentPoint.UnAdjY = b._Y; CurrentPoint.UnAdjZ = b._Z; //CurrentPoint.X = b._X; //CurrentPoint.Y = b._Y; //CurrentPoint.Z = b._Z; CurrentPoint.Time = DateTime.Now; CurrentPoint.MetaDefCN = _currmeta.CN; CurrentPoint.RMSEr = Values.Settings.DeviceOptions.MIN_POINT_ACCURACY; b._Used = true; if (_sound) { try { player.Play(); } catch { } } new Thread(()=> { if(TtUtils.PointHasValue(CurrentPoint) || !Values.Settings.ProjectOptions.DropZero) DrawSavePointIcon(); else CurrentPoint = LastPoint; }).Start(); } catch (Exception ex) { TtUtils.WriteError(ex.Message, "WalkFormLogic:CreateWalkPoint", ex.StackTrace); } } }
private void OnBurstReceived(NmeaBurst burst) { if (LogToFile && sw != null) { sw.WriteLine(burst.ToString()); } if (BurstReceived != null) BurstReceived(burst); }
private void GPSA_BurstReceived(NmeaBurst b) { if (checkMeta && b.IsValid) { if (b.CalcRealZone() != currentZone) { MessageBox.Show("The current UTM zone does not match the set metadata zone.", "Zone mismatch", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); } checkMeta = false; } if (logging) { logged++; NmeaData.Add(b); } recieved++; this.GuiInvoke(() => { lblRecieved.Text = recieved.ToString(); lblLogged.Text = logged.ToString(); }); }
bool filterFix(NmeaBurst burst, int filter) { //no fix if (filter == 0) return true; if (burst._fix == 3 && burst._fix_quality >= filter) { return true; } //if (burst._fix == 3 && // (burst._fix_quality >= filter || // (filter == 4 && burst._fix_quality == 5) || // (filter == 5 && burst._fix_quality == 4))) //{ // return true; //} return false; }