/// <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(); }
/// <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()); } }
/// <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) }