public void ReadGprmcWithNmeaReader() { using (MemoryStream mStrm = new MemoryStream(Encoding.ASCII.GetBytes("$GPRMC,220516.000,A,5133.8200,N,00042.2400,W,173.8,231.8,130604,4.2,W*67"))) { NmeaReader nr = new NmeaReader(mStrm); NmeaSentence ns = nr.ReadTypedSentence(); GprmcSentence sentence = ns as GprmcSentence; Assert.AreNotEqual(null, sentence); if (sentence == null) { return; } Assert.AreEqual("$GPRMC,220516.000,A,5133.8200,N,00042.2400,W,173.8,231.8,130604,4.2,W*67", sentence.Sentence); Latitude l = new Latitude(51, 33.82, LatitudeHemisphere.North); Longitude l2 = new Longitude(0, 42.24, LongitudeHemisphere.West); Position p = new Position(l, l2); DateTime date = new DateTime(2004, 06, 13, 22, 05, 16, DateTimeKind.Utc); Speed s = new Speed(173.8, SpeedUnit.Knots); Azimuth a = new Azimuth(231.8); Longitude mv = new Longitude(4.2, LongitudeHemisphere.West); Assert.AreEqual(FixStatus.Fix, sentence.FixStatus); Assert.AreEqual(l, sentence.Position.Latitude); Assert.AreEqual(l2, sentence.Position.Longitude); Assert.AreEqual(s, sentence.Speed); Assert.AreEqual(a, sentence.Bearing); Assert.AreEqual(mv, sentence.MagneticVariation); Assert.AreEqual(date, sentence.UtcDateTime); } }
/// <summary> /// Set any possible values for the given NMEA data. /// It will continue to replace /// the values so the last value is used as the final value. /// </summary> /// <param name="sentence">NMEA sentence containing data.</param> private void SetValues(NmeaSentence sentence) { /* * NMEA specification states that the first two letters of * a sentence may change. For example, for "$GPGSV" there may be variations such as * "$__GSV" where the first two letters change. As a result, we need only test the last three * characters. */ try { if (sentence.CommandWord.EndsWith("GGA", StringComparison.Ordinal)) { // Yes. Convert it using the fast pre-parseed constructor GPGGA = new GpggaSentence(sentence.Sentence); // Set the Lat and Lon and time } if (sentence.CommandWord.EndsWith("VTG", StringComparison.Ordinal)) { // Yes. Convert it using the fast pre-parseed constructor GPVTG = new GpvtgSentence(sentence.Sentence); } if (sentence.CommandWord.EndsWith("RMC", StringComparison.Ordinal)) { // Yes. Convert it using the fast pre-parseed constructor GPRMC = new GprmcSentence(sentence.Sentence); } if (sentence.CommandWord.EndsWith("RMF", StringComparison.Ordinal)) { // Yes. Convert it using the fast pre-parseed constructor PGRMF = new PgrmfSentence(sentence.Sentence); } if (sentence.CommandWord.EndsWith("GLL", StringComparison.Ordinal)) { // Yes. Convert it using the fast pre-parseed constructor GPGLL = new GpgllSentence(sentence.Sentence); } if (sentence.CommandWord.EndsWith("GSV", StringComparison.Ordinal)) { // Yes. Convert it using the fast pre-parseed constructor GPGSV = new GpgsvSentence(sentence.Sentence); } if (sentence.CommandWord.EndsWith("GSA", StringComparison.Ordinal)) { // Yes. Convert it using the fast pre-parseed constructor GPGSA = new GpgsaSentence(sentence.Sentence); } if (sentence.CommandWord.EndsWith("HDT", StringComparison.Ordinal)) { // Yes. Convert it using the fast pre-parseed constructor GPHDT = new GphdtSentence(sentence.Sentence); } } catch (Exception e) { log.Error("Error decoding a NMEA sentance.", e); } }
public void GprmcSentenceFromObjects() { Latitude l = new Latitude(51, 33.82, LatitudeHemisphere.North); Longitude l2 = new Longitude(0, 42.24, LongitudeHemisphere.West); Position p = new Position(l, l2); DateTime date = new DateTime(2004, 06, 13, 22, 05, 16, DateTimeKind.Utc); Speed s = new Speed(173.8, SpeedUnit.Knots); Azimuth a = new Azimuth(231.8); Longitude mv = new Longitude(4.2, LongitudeHemisphere.West); GprmcSentence sentence = new GprmcSentence(date, true, p, s, a, mv); Assert.AreEqual("$GPRMC,220516.000,A,5133.8200,N,00042.2400,W,173.8,231.8,130604,4.2,W*67", sentence.Sentence); Assert.AreEqual(FixStatus.Fix, sentence.FixStatus); Assert.AreEqual(l, sentence.Position.Latitude); Assert.AreEqual(l2, sentence.Position.Longitude); Assert.AreEqual(s, sentence.Speed); Assert.AreEqual(a, sentence.Bearing); Assert.AreEqual(mv, sentence.MagneticVariation); Assert.AreEqual(date, sentence.UtcDateTime); }
public void GprmcSentenceFromString() { GprmcSentence sentence = new GprmcSentence("$GPRMC,194530.000,A,3051.8007,N,10035.9989,W,1.49,111.67,310714,,,A*74"); Assert.AreEqual("$GPRMC,194530.000,A,3051.8007,N,10035.9989,W,1.49,111.67,310714,,,A*74", sentence.Sentence); Assert.AreEqual(FixStatus.Fix, sentence.FixStatus); Latitude l = new Latitude(30, 51.8007, LatitudeHemisphere.North); Assert.AreEqual(l, sentence.Position.Latitude); Longitude l2 = new Longitude(100, 35.9989, LongitudeHemisphere.West); Assert.AreEqual(l2, sentence.Position.Longitude); Assert.AreEqual(new Speed(1.49, SpeedUnit.Knots), sentence.Speed); Assert.AreEqual(111.67, sentence.Bearing.DecimalDegrees); Assert.AreEqual(Longitude.Invalid, sentence.MagneticVariation); DateTime date = new DateTime(2014, 07, 31, 19, 45, 30, DateTimeKind.Utc); Assert.AreEqual(date, sentence.UtcDateTime); }
/// <summary> /// Set any possible values for the given NMEA data. /// It will continue to replace /// the values so the last value is used as the final value. /// </summary> /// <param name="sentence">NMEA sentence containing data.</param> private void SetValues(NmeaSentence sentence) { /* * NMEA specification states that the first two letters of * a sentence may change. For example, for "$GPGSV" there may be variations such as * "$__GSV" where the first two letters change. As a result, we need only test the last three * characters. */ if (sentence.CommandWord.EndsWith("GGA", StringComparison.Ordinal)) { // Yes. Convert it using the fast pre-parseed constructor GPGGA = new GpggaSentence(sentence.Sentence); // Set the Lat and Lon and time } if (sentence.CommandWord.EndsWith("VTG", StringComparison.Ordinal)) { // Yes. Convert it using the fast pre-parseed constructor GPVTG = new GpvtgSentence(sentence.Sentence); } if (sentence.CommandWord.EndsWith("RMC", StringComparison.Ordinal)) { // Yes. Convert it using the fast pre-parseed constructor GPRMC = new GprmcSentence(sentence.Sentence); } if (sentence.CommandWord.EndsWith("RMF", StringComparison.Ordinal)) { // Yes. Convert it using the fast pre-parseed constructor PGRMF = new PgrmfSentence(sentence.Sentence); } if (sentence.CommandWord.EndsWith("GLL", StringComparison.Ordinal)) { // Yes. Convert it using the fast pre-parseed constructor GPGLL = new GpgllSentence(sentence.Sentence); } if (sentence.CommandWord.EndsWith("GSV", StringComparison.Ordinal)) { // Yes. Convert it using the fast pre-parseed constructor GPGSV = new GpgsvSentence(sentence.Sentence); } if (sentence.CommandWord.EndsWith("GSA", StringComparison.Ordinal)) { // Yes. Convert it using the fast pre-parseed constructor GPGSA = new GpgsaSentence(sentence.Sentence); } if (sentence.CommandWord.EndsWith("HDT", StringComparison.Ordinal)) { // Yes. Convert it using the fast pre-parseed constructor GPHDT = new GphdtSentence(sentence.Sentence); } }