/// <summary> /// Set the heading based off the NMEA 2 data. This will get the NMEA 2 data and /// get the heading value from GPHDT or GPRMC sentences. It will set the heading /// to this value. /// </summary> /// <param name="ensemble">Ensemble to set the value.</param> private static void HeadingSourceNmea2(ref DataSet.Ensemble ensemble) { double heading = 0.0; // Check if NMEA 2 data exist if (ensemble.IsNmea2DataAvail) { // Create a NMEA dataset to decode the data DataSet.NmeaDataSet nmea2 = new DataSet.NmeaDataSet(ensemble.Nmea2Data); // GPHDT if (nmea2.IsGphdtAvail()) { heading = nmea2.GPHDT.Heading.DecimalDegrees; } // GPRMC else if (nmea2.IsGprmcAvail()) { heading = nmea2.GPRMC.Bearing.DecimalDegrees; } } // Set the heading SetHeading(ref ensemble, (float)heading); }
/// <summary> /// Decode the group into a line with the ensemble number /// and the rest is the GPS data. Create a NmeaDataSet which /// will decode the GPS data and create the dataset. /// </summary> /// <param name="group">GPS data per ensemble.</param> /// <param name="project">Project to add the data to.</param> private void DecodeGroup(string group, Project project) { // Verify the first line contains the ensemble number string[] lines = group.Split('\n'); // Verify data was found if (lines.Length > 0) { // Verify first line //if(lines[0].Contains('#')) //{ // Get the ensemble number int ensNum = GetEnsNum(lines[0]); // Ensembles will always be greater than 0 if (ensNum > 0) { string gpsData = ""; // Get the GPS data // Start aver the first line for (int x = 1; x < lines.Length; x++) { gpsData += lines[x]; } // Create the dataset DataSet.NmeaDataSet nds = new DataSet.NmeaDataSet(gpsData); // Add the dataset to the ensemble in the project project.UpdateNmeaDataSet(nds, ensNum); } //} } }
/// <summary> /// Initialize the object. /// </summary> /// <param name="nmea">RTI NMEA data.</param> public Pd0NmeaData(DataSet.NmeaDataSet nmea) : base(ID_LSB, ID_MSB, Pd0ID.Pd0Types.NmeaData) { NmeaStrings = new List <string>(); DecodeRtiEnsemble(nmea); }
/// <summary> /// Convert the RTI Amplitude data set to the PD0 Echo Intensity data type. /// </summary> /// <param name="nmeaDS">RTI Amplitude data set.</param> public void DecodeRtiEnsemble(DataSet.NmeaDataSet nmeaDS) { NmeaStrings = nmeaDS.NmeaStrings; GPGGA = nmeaDS.GPGGA; GPGLL = nmeaDS.GPGLL; GPGSA = nmeaDS.GPGSA; GPGSV = nmeaDS.GPGSV; GPHDT = nmeaDS.GPHDT; GPRMC = nmeaDS.GPRMC; GPVTG = nmeaDS.GPVTG; PGRMF = nmeaDS.PGRMF; }
public void TestJson() { // Generate an Ensemble DataSet.Ensemble ensemble = EnsembleHelper.GenerateEnsemble(30); // Modify the data string nmeaData = "$HEHDT,274.67,T*1F$HEROT,-32.6,A*31$GPGGA,155339.00,3245.44007,N,11719.83271,W,2,09,0.9,-1.1,M,-33.3,M,5.0,0138*50$GPVTG,277.26,T,265.15,M,2.62,N,4.86,K,D*29$GPZDA,155339.00,08,12,2011,00,00*67$GPGSV,3,1,09,02,75,182,50,04,56,053,51,05,08,167,42,09,50,241,48*75$GPGSV,3,2,09,10,24,111,46,12,45,322,47,17,17,063,45,25,15,313,44*71$GPGSV,3,3,09,28,05,121,36,,,,,,,,,,,,*48"; ensemble.AddNmeaData(nmeaData); Assert.IsNotNull(ensemble, "Adcp Data was not properly created."); Assert.IsTrue(ensemble.IsNmeaAvail, "Nmea Dataset not created."); Assert.IsTrue(ensemble.NmeaData.IsGpggaAvail(), "GGA message not parsed correctly."); Assert.IsTrue(ensemble.NmeaData.IsGpvtgAvail(), "VTG message not parsed correctly."); Assert.IsTrue(ensemble.NmeaData.IsGpgsvAvail(), "GSV message not parsed correctly."); Assert.IsFalse(ensemble.NmeaData.IsGpgllAvail(), "GLL message should not have been found."); Assert.IsFalse(ensemble.NmeaData.IsGpgsaAvail(), "GSA message should not have been found."); Assert.IsFalse(ensemble.NmeaData.IsGprmcAvail(), "RMC message should not have been found."); Assert.IsFalse(ensemble.NmeaData.IsPgrmfAvail(), "PGRMF message should not have been found."); Assert.AreEqual(new DotSpatial.Positioning.Latitude("32 45.44007").DecimalDegrees, ensemble.NmeaData.GPGGA.Position.Latitude.DecimalDegrees, 0.0001, "Latitude is not correct"); Assert.AreEqual(new DotSpatial.Positioning.Latitude("-117 19.83271").DecimalDegrees, ensemble.NmeaData.GPGGA.Position.Longitude.DecimalDegrees, 0.0001, "Longitude is not correct"); Assert.AreEqual(DotSpatial.Positioning.FixQuality.DifferentialGpsFix, ensemble.NmeaData.GPGGA.FixQuality, "Fix Quality is not correct"); Assert.AreEqual(9, ensemble.NmeaData.GPGGA.FixedSatelliteCount, "Number of fixed satellites is incorrect."); Assert.AreEqual(new DotSpatial.Positioning.Distance(-1.1, DotSpatial.Positioning.DistanceUnit.Meters).Value, ensemble.NmeaData.GPGGA.Altitude.Value, 0.00001, "Altitude is not correct"); Assert.AreEqual(new DotSpatial.Positioning.Azimuth(277.26), ensemble.NmeaData.GPVTG.Bearing, "True Track Made Good Bearing not correct."); Assert.AreEqual(new DotSpatial.Positioning.Speed(2.62, DotSpatial.Positioning.SpeedUnit.Knots), ensemble.NmeaData.GPVTG.Speed, "Speed is not correct."); string encoded = Newtonsoft.Json.JsonConvert.SerializeObject(ensemble.NmeaData); // Serialize object to JSON DataSet.NmeaDataSet decoded = Newtonsoft.Json.JsonConvert.DeserializeObject <DataSet.NmeaDataSet>(encoded); // Deserialize the JSON // Verify the values are the same Assert.IsTrue(decoded.IsGpggaAvail(), "GGA message not parsed correctly."); Assert.IsTrue(decoded.IsGpvtgAvail(), "VTG message not parsed correctly."); Assert.IsTrue(decoded.IsGpgsvAvail(), "GSV message not parsed correctly."); Assert.IsFalse(decoded.IsGpgllAvail(), "GLL message should not have been found."); Assert.IsFalse(decoded.IsGpgsaAvail(), "GSA message should not have been found."); Assert.IsFalse(decoded.IsGprmcAvail(), "RMC message should not have been found."); Assert.IsFalse(decoded.IsPgrmfAvail(), "PGRMF message should not have been found."); Assert.AreEqual(new DotSpatial.Positioning.Latitude("32 45.44007").DecimalDegrees, decoded.GPGGA.Position.Latitude.DecimalDegrees, 0.0001, "Latitude is not correct"); Assert.AreEqual(new DotSpatial.Positioning.Latitude("-117 19.83271").DecimalDegrees, decoded.GPGGA.Position.Longitude.DecimalDegrees, 0.0001, "Longitude is not correct"); Assert.AreEqual(DotSpatial.Positioning.FixQuality.DifferentialGpsFix, decoded.GPGGA.FixQuality, "Fix Quality is not correct"); Assert.AreEqual(9, decoded.GPGGA.FixedSatelliteCount, "Number of fixed satellites is incorrect."); Assert.AreEqual(new DotSpatial.Positioning.Distance(-1.1, DotSpatial.Positioning.DistanceUnit.Meters).Value, decoded.GPGGA.Altitude.Value, 0.00001, "Altitude is not correct"); Assert.AreEqual(new DotSpatial.Positioning.Azimuth(277.26), decoded.GPVTG.Bearing, "True Track Made Good Bearing not correct."); Assert.AreEqual(new DotSpatial.Positioning.Speed(2.62, DotSpatial.Positioning.SpeedUnit.Knots), decoded.GPVTG.Speed, "Speed is not correct."); }
/// <summary> /// Set the heading based off the ADCP GPS data. This will get the ADCP GPS data and /// get the heading value from GPHDT or GPRMC sentences. It will set the heading /// to this value. /// </summary> /// <param name="ensemble">Ensemble to set the value.</param> private static void HeadingSourceAdcpGps(ref DataSet.Ensemble ensemble) { double heading = 0.0; // Check if GPS 1 data exist if (ensemble.IsAdcpGpsDataAvail) { // Create a NMEA dataset to decode the data DataSet.NmeaDataSet adcpGps = new DataSet.NmeaDataSet(ensemble.AdcpGpsData); // GPHDT if (adcpGps.IsGphdtAvail()) { heading = adcpGps.GPHDT.Heading.DecimalDegrees; } // GPRMC else if (adcpGps.IsGprmcAvail()) { heading = adcpGps.GPRMC.Bearing.DecimalDegrees; } } else if (ensemble.IsNmeaAvail) { // GPHDT if (ensemble.NmeaData.IsGphdtAvail()) { heading = ensemble.NmeaData.GPHDT.Heading.DecimalDegrees; } // GPRMC else if (ensemble.NmeaData.IsGprmcAvail()) { heading = ensemble.NmeaData.GPRMC.Bearing.DecimalDegrees; } } // Set the heading SetHeading(ref ensemble, (float)heading); }
public void TestTiming() { // Generate an Ensemble DataSet.Ensemble ensemble = EnsembleHelper.GenerateEnsemble(30); string nmeaData = "$HEHDT,274.67,T*1F$HEROT,-32.6,A*31$GPGGA,155339.00,3245.44007,N,11719.83271,W,2,09,0.9,-1.1,M,-33.3,M,5.0,0138*50$GPVTG,277.26,T,265.15,M,2.62,N,4.86,K,D*29$GPZDA,155339.00,08,12,2011,00,00*67$GPGSV,3,1,09,02,75,182,50,04,56,053,51,05,08,167,42,09,50,241,48*75$GPGSV,3,2,09,10,24,111,46,12,45,322,47,17,17,063,45,25,15,313,44*71$GPGSV,3,3,09,28,05,121,36,,,,,,,,,,,,*48"; ensemble.AddNmeaData(nmeaData); Stopwatch watch = new Stopwatch(); // Test Serialize() watch = new Stopwatch(); watch.Start(); for (int x = 0; x < 1000; x++) { string encoded = Newtonsoft.Json.JsonConvert.SerializeObject(ensemble.NmeaData); } watch.Stop(); long resultSerialize = watch.ElapsedMilliseconds; // Test Deserialize() string encodedd = Newtonsoft.Json.JsonConvert.SerializeObject(ensemble.NmeaData); watch = new Stopwatch(); watch.Start(); for (int x = 0; x < 1000; x++) { DataSet.NmeaDataSet decoded = Newtonsoft.Json.JsonConvert.DeserializeObject <DataSet.NmeaDataSet>(encodedd); } watch.Stop(); long resultDeserialize = watch.ElapsedMilliseconds; Debug.WriteLine(String.Format("Serialize:{0} Deserialize:{1}", resultSerialize, resultDeserialize)); Debug.WriteLine("Complete"); }
/// <summary> /// Set the heading based off the NMEA 2 data. This will get the NMEA 2 data and /// get the heading value from GPHDT or GPRMC sentences. It will set the heading /// to this value. /// </summary> /// <param name="ensemble">Ensemble to set the value.</param> private static void HeadingSourceNmea2(ref DataSet.Ensemble ensemble) { double heading = 0.0; // Check if NMEA 2 data exist if (ensemble.IsNmea2DataAvail) { // Create a NMEA dataset to decode the data DataSet.NmeaDataSet nmea2 = new DataSet.NmeaDataSet(ensemble.Nmea2Data); // GPHDT if (nmea2.IsGphdtAvail()) { heading = nmea2.GPHDT.Heading.DecimalDegrees; } // GPRMC else if (nmea2.IsGprmcAvail()) { heading = nmea2.GPRMC.Bearing.DecimalDegrees; } } // Set the heading SetHeading(ref ensemble, (float)heading); }
/// <summary> /// Set the heading based off the ADCP GPS data. This will get the ADCP GPS data and /// get the heading value from GPHDT or GPRMC sentences. It will set the heading /// to this value. /// </summary> /// <param name="ensemble">Ensemble to set the value.</param> private static void HeadingSourceAdcpGps(ref DataSet.Ensemble ensemble) { double heading = 0.0; // Check if GPS 1 data exist if (ensemble.IsAdcpGpsDataAvail) { // Create a NMEA dataset to decode the data DataSet.NmeaDataSet adcpGps = new DataSet.NmeaDataSet(ensemble.AdcpGpsData); // GPHDT if (adcpGps.IsGphdtAvail()) { heading = adcpGps.GPHDT.Heading.DecimalDegrees; } // GPRMC else if (adcpGps.IsGprmcAvail()) { heading = adcpGps.GPRMC.Bearing.DecimalDegrees; } } // Set the heading SetHeading(ref ensemble, (float)heading); }