/// <summary> /// Get the latest data from the NMEA buffer /// and create a string. /// Then record the NMEA data and add it to /// the ensemble. /// </summary> /// <param name="adcpData">Ensemble data.</param> /// <returns>Binary data.</returns> private byte[] GetNmeaData(ref DataSet.Ensemble adcpData) { // Byte array of the binary data List <byte> byteList = new List <byte>(); string nmeaData = GetNmeaBuffer(); if (nmeaData.Length > 0) { // Add the NMEA data to the dataset adcpData.AddNmeaData(nmeaData.ToString()); // Create byte array for all the NMEA data accumulated // Record the NMEA data to the file // Get the NMEA data from the dataset to ensure valid NMEA messages for (int x = 0; x < adcpData.NmeaData.NmeaStrings.Count; x++) { string nmeaStr = adcpData.NmeaData.NmeaStrings[x] + NMEA_END; byte[] nmeaBA = System.Text.Encoding.ASCII.GetBytes(nmeaStr); byteList.AddRange(nmeaBA); } } // Return the binary data return(byteList.ToArray()); }
public void TestConstructorFull() { //string gga = "$GPGGA,155339.00,3245.44007,N,11719.83271,W,2,09,0.9,-1.1,M,-33.3,M,5.0,0138*50"; //string vtg = "$GPVTG,277.26,T,265.15,M,2.62,N,4.86,K,D*29"; //string hehdt = "$HEHDT,274.67,T*1F"; //string herot = "$HEROT,-32.6,A*31"; //string zda = "$GPZDA,155339.00,08,12,2011,00,00*67"; //string gsv = "$GPGSV,3,1,09,02,75,182,50,04,56,053,51,05,08,167,42,09,50,241,48*75"; 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"; DataSet.Ensemble adcpData = new DataSet.Ensemble(); adcpData.AddNmeaData(nmeaData); Assert.IsNotNull(adcpData, "Adcp Data was not properly created."); Assert.IsTrue(adcpData.IsNmeaAvail, "Nmea Dataset not created."); Assert.IsTrue(adcpData.NmeaData.IsGpggaAvail(), "GGA message not parsed correctly."); Assert.IsTrue(adcpData.NmeaData.IsGpvtgAvail(), "VTG message not parsed correctly."); Assert.IsTrue(adcpData.NmeaData.IsGpgsvAvail(), "GSV message not parsed correctly."); Assert.IsFalse(adcpData.NmeaData.IsGpgllAvail(), "GLL message should not have been found."); Assert.IsFalse(adcpData.NmeaData.IsGpgsaAvail(), "GSA message should not have been found."); Assert.IsFalse(adcpData.NmeaData.IsGprmcAvail(), "RMC message should not have been found."); Assert.IsFalse(adcpData.NmeaData.IsPgrmfAvail(), "PGRMF message should not have been found."); Assert.AreEqual(new DotSpatial.Positioning.Latitude("32 45.44007").DecimalDegrees, adcpData.NmeaData.GPGGA.Position.Latitude.DecimalDegrees, 0.0001, "Latitude is not correct"); Assert.AreEqual(new DotSpatial.Positioning.Latitude("-117 19.83271").DecimalDegrees, adcpData.NmeaData.GPGGA.Position.Longitude.DecimalDegrees, 0.0001, "Longitude is not correct"); Assert.AreEqual(DotSpatial.Positioning.FixQuality.DifferentialGpsFix, adcpData.NmeaData.GPGGA.FixQuality, "Fix Quality is not correct"); Assert.AreEqual(9, adcpData.NmeaData.GPGGA.FixedSatelliteCount, "Number of fixed satellites is incorrect."); Assert.AreEqual(new DotSpatial.Positioning.Distance(-1.1, DotSpatial.Positioning.DistanceUnit.Meters).Value, adcpData.NmeaData.GPGGA.Altitude.Value, 0.00001, "Altitude is not correct"); Assert.AreEqual(new DotSpatial.Positioning.Azimuth(277.26), adcpData.NmeaData.GPVTG.Bearing, "True Track Made Good Bearing not correct."); Assert.AreEqual(new DotSpatial.Positioning.Speed(2.62, DotSpatial.Positioning.SpeedUnit.Knots), adcpData.NmeaData.GPVTG.Speed, "Speed is not correct."); }
/// <summary> /// Create the data set using PRTI01. Then add PRTI02 to the /// dataset. Then send the dataset. /// </summary> /// <param name="prti01">PRTI01 Sentence.</param> /// <param name="prti02">PRTI02 Sentence.</param> /// <param name="prti03">PRTI03 Sentence.</param> /// <param name="prti30">PRTI30 Sentence.</param> /// <param name="prti31">PRTI31 Sentence.</param> /// <param name="nmeaBuffer">NMEA buffer.</param> /// <returns>Created ensemble.</returns> private DataSet.Ensemble CreateEnsemble(Prti01Sentence prti01, Prti02Sentence prti02, Prti03Sentence prti03 = null, Prti30Sentence prti30 = null, Prti31Sentence prti31 = null, List <string> nmeaBuffer = null) { // Create the dataset DataSet.Ensemble ensemble = CreateDataSet(prti01); if (prti02 != null) { ensemble.AddAdditionalBottomTrackData(prti02); } if (prti03 != null) { ensemble.AddAdditionalBottomTrackData(prti03); } if (prti30 != null) { ensemble.AddAdditionalAncillaryData(prti30); ensemble.AddAdditionalBottomTrackData(prti30); // Setup the serial number if (ensemble.IsEnsembleAvail) { // Remove the temp serial number subsystem ensemble.EnsembleData.SysSerialNumber.RemoveSubsystem(SerialNumber.DVL_Subsystem); // Add the actual subsystem ensemble.EnsembleData.SysSerialNumber.AddSubsystem(prti30.SubsystemConfig.SubSystem); } } if (prti31 != null) { ensemble.AddAdditionalAncillaryData(prti31); ensemble.AddAdditionalBottomTrackData(prti31); // Setup the serial number if (ensemble.IsEnsembleAvail) { // Remove the temp serial number subsystem ensemble.EnsembleData.SysSerialNumber.RemoveSubsystem(SerialNumber.DVL_Subsystem); // Add the actual subsystem ensemble.EnsembleData.SysSerialNumber.AddSubsystem(prti30.SubsystemConfig.SubSystem); } } if (nmeaBuffer != null) { StringBuilder sb = new StringBuilder(); foreach (var nmea in nmeaBuffer) { sb.Append(nmea); } ensemble.AddNmeaData(sb.ToString()); } return(ensemble); }
/// <summary> /// Add Nmea data set. /// </summary> /// <param name="ensemble">Ensemble to add the dataset.</param> public static void AddNmea(ref DataSet.Ensemble ensemble) { ensemble.AddNmeaData(DataSet.Ensemble.DATATYPE_BYTE, DataSet.EarthWaterMassDataSet.NUM_DATA_ELEMENTS, // Num elements (Bins) DataSet.Ensemble.DEFAULT_NUM_BEAMS_BEAM, // Num Beams DataSet.Ensemble.DEFAULT_IMAG, // Image DataSet.Ensemble.DEFAULT_NAME_LENGTH, // Name length DataSet.Ensemble.NmeaID); // Name (Dataset ID) }
public void TestConstructorCompleteString() { string nmeaData = "$GPGGA,,,,,,0,,,,M,,M,,*66"; DataSet.Ensemble adcpData = new DataSet.Ensemble(); adcpData.AddNmeaData(nmeaData); Assert.IsNotNull(adcpData, "Adcp Data was not properly created."); Assert.IsTrue(adcpData.IsNmeaAvail, "Nmea Dataset not created."); Assert.IsTrue(adcpData.NmeaData.IsGpggaAvail(), "GGA message not parsed correctly."); Assert.IsFalse(adcpData.NmeaData.IsGpvtgAvail(), "VTG message not parsed correctly."); }
public void TestConstructorNmea() { string nmeaData = "$GPGSV,3,3,11,30,22,145,,31,68,063,,32,62,336,,,,,*40$HEHDT,,T*01$HEROT,,V*12$GPGGA,,,,,,0,,,,M,,M,,*66$GPVTG,,T,,M,,N,,K,N*2C$GPZDA,025735.78,20,12,2011,00,00*6C$GPGSV,3,1,11,01,49,269,,11,36,239,,14,23,056,,16,04,164,*70$GPGSV,3,2,11,20,37,315,,22,16,118,,23,18,269,,25,07,046,*71$GPGSV,3,3,11,30,22,145,,31,68,063,,32,62,336,,,,,*40$HEHDT,,T*01$HEROT,,V*12$GPGGA,,,,,,0,,,,M,,M,,*66$GPVTG,,T,,M,,N,,K,N*2C$GPZDA,025736.78,20,12,2011,00,00*6F$GPGSV,3,1,11,01,49,269,,11,36,239,,14,23,056,,16,04,164,*70$GPGSV,3,2,11,20,37,315,,22,16,118,,23,18,269,,25,07,046,*71$GPGSV,3,3,11,30,22,145,,31,68,063,,32,62,336,,,,,*40$HEHDT,,T*01$HEROT,,V*12$GPGGA,,,,,,0,,,,M,,M,,*66$GPVTG,,T,,M,,N,,K,N*2C$GPZDA,025737.78,20,12,2011,00,00*6E$GPGSV,3,1,11,01,49,269,,11,36,239,,14,23,056,,16,04,164,*70$GPGSV,3,2,11,20,37,315,,22,16,118,,23,18,269,,25,07,046,*71$GPGSV,3,3,11,30,22,145,,31,68,063,,32,62,336,,,,,*40$HEHDT,,T*01$HEROT,,V*12$GPGGA,,,,,,0,,,,M,,M,,*66"; DataSet.Ensemble adcpData = new DataSet.Ensemble(); adcpData.AddNmeaData(nmeaData); Assert.IsNotNull(adcpData, "Adcp Data was not properly created."); Assert.IsTrue(adcpData.IsNmeaAvail, "Nmea Dataset not created."); Assert.IsTrue(adcpData.NmeaData.IsGpggaAvail(), "GGA message not parsed correctly."); Assert.IsTrue(adcpData.NmeaData.IsGpvtgAvail(), "VTG message not parsed correctly."); Assert.AreEqual(DotSpatial.Positioning.Position.Invalid, adcpData.NmeaData.GPGGA.Position, "Position not invalid"); Assert.AreEqual(DotSpatial.Positioning.Latitude.Invalid, adcpData.NmeaData.GPGGA.Position.Latitude, "Latitude not invalid"); Assert.AreEqual(DotSpatial.Positioning.Longitude.Invalid, adcpData.NmeaData.GPGGA.Position.Longitude, "Longitude not invalid."); Assert.AreEqual(DotSpatial.Positioning.Distance.Invalid, adcpData.NmeaData.GPGGA.Altitude, "Altitude not invalid"); }
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> /// Add NMEA data to the ensemble. /// </summary> /// <param name="adcpData">DataSet to add NMEA data.</param> private void MergeNmeaDataSet(ref DataSet.Ensemble adcpData) { // Copy the data from the buffer // This will take a current cout of the buffer. // Then create a string of the buffer and remove // the item from the buffer at the same time. StringBuilder nmeaData = new StringBuilder(); // Copy the buffer so it can be unlocked LinkedList <string> bufferCopy; lock (_nmeaBufferLock) { // Copy the buffer then clear it bufferCopy = new LinkedList <string>(_nmeaBuffer); _nmeaBuffer.Clear(); } // Create a string of all the buffered data for (int x = 0; x < bufferCopy.Count; x++) { nmeaData.Append(bufferCopy.First.Value); // Remove the data bufferCopy.RemoveFirst(); } // Check if NMEA data already exsit, if it does, combine the data if (adcpData.IsNmeaAvail) { // Merge the NMEA data with the new nmea data adcpData.NmeaData.MergeNmeaData(nmeaData.ToString()); } else { // Add the NMEA data to the dataset adcpData.AddNmeaData(nmeaData.ToString()); } }
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"); }