Esempio n. 1
0
 /// <summary>
 /// Receive binary data from the ADCP serial port.
 /// Then pass the binary data to the codec to decode the
 /// data into ensembles.
 ///
 /// The data could be binary or dvl data.
 /// The data will go to both codec and
 /// if the codec can process the data it will.
 /// </summary>
 /// <param name="data">Data to decode.</param>
 public void ReceiveAdcpSerialData(byte[] data)
 {
     if (_adcpCodec != null)
     {
         // Add incoming data to codec
         _adcpCodec.AddIncomingData(data);
     }
 }
        /// <summary>
        /// Ensemble data to add to the codec.
        /// </summary>
        /// <param name="data">Ensemble data.</param>
        /// <returns>Negative number indicates an error.</returns>
        public int AddData(byte[] data, EnsembleSource source)
        {
            // Add data to codec, set flags for data to decode
            _codec.AddIncomingData(data,
                                   _options.IsRTB,
                                   _options.IsRTD,
                                   _options.IsPD0,
                                   _options.IsPD6_13,
                                   _options.IsPD4_5);

            log.Debug(string.Format("Add data to codec: Source: {0}  Count: {1} IsRTB: {2}  IsRTD: {3}  IsPD0 {4}  IsPD6_13: {5}  IsPD4_5: {6}", source, data.Length, _options.IsRTB, _options.IsRTD, _options.IsPD0, _options.IsPD6_13, _options.IsPD4_5));

            return(data.Length);
        }
Esempio n. 3
0
        /// <summary>
        /// Find the ensembles in the file.
        /// This will move through the file and
        /// all the ensembles from the file.
        /// </summary>
        /// <param name="file">File to get the ensembles.</param>
        public void FindEnsembles(string file)
        {
            try
            {
                // Open the file
                if (File.Exists(file))
                {
                    //Set the file name
                    FileInfo finfo = new FileInfo(file);
                    Name = finfo.Name;

                    using (var fileStream = new FileStream(file, FileMode.Open, FileAccess.Read))
                    {
                        _fileSize = fileStream.Length;

                        // Read in the data from file
                        byte[] buffer = new byte[1024 * 100];
                        int    count  = 0;
                        while ((count = fileStream.Read(buffer, 0, buffer.Length)) > 0)
                        {
                            // Add the data to the codec
                            _adcpCodec.AddIncomingData(buffer);

                            // Set the offset
                            _fileOffset += count;
                        }

                        fileStream.Close();
                        fileStream.Dispose();
                    }


                    // Block until awoken when all the data is decoded
                    // Or wait 30 seconds for a timeout.
                    _eventWaitDecode.WaitOne(30000);
                }
            }
            catch (Exception e)
            {
                log.Error("Error reading the file.", e);

                // Set the block to not wait any longer for data
                _eventWaitDecode.Set();
            }
        }