Example #1
0
        /// <summary>
        /// Receive decoded data from the PD0 codec.  This will be
        /// the latest data decoded.  It will include the complete
        /// binary array of the data and the ensemble object.
        /// </summary>
        /// <param name="binaryEnsemble">Binary data of the ensemble.</param>
        /// <param name="ensemble">Ensemble object.</param>
        void _pd0Codec_ProcessDataEvent(byte[] binaryEnsemble, PD0 ensemble)
        {
            // Convert to a RTI ensemble
            DataSet.Ensemble rtiEns = new DataSet.Ensemble(ensemble);
            DataSet.VelocityVectorHelper.CreateVelocityVector(ref rtiEns);

            // Generate a subsystem so that multiple configurations can be seprated
            // PD0 does not contain the CEPO index or CEPO Configuraiton Index
            if (rtiEns.IsEnsembleAvail)
            {
                rtiEns.EnsembleData.SubsystemConfig = _pd0SubsystemGen.GenSubsystem(rtiEns);
            }

            if (ProcessDataEvent != null)
            {
                // Pass the data to the subscribers
                ProcessDataEvent(binaryEnsemble, rtiEns, CodecEnum.PD0);
            }

            _pd0Counter++;

            // Check which buffers to clear
            //CheckCodecBuffers(CodecEnum.PD0);
        }
Example #2
0
        /// <summary>
        /// Find the entire ensemble in the file.  This will look for the start location.
        /// Decode the payload size and checksum.  If they are good, then generate an
        /// ensemble from the data.  Add the data to the list and return it.
        /// </summary>
        /// <param name="ensStart">List of all the ensembles.</param>
        /// <param name="file">File to look for the ensembles.</param>
        /// <returns>List of all the ensembles in the file.</returns>
        protected List <DataSet.EnsemblePackage> FindCompleteEnsembles(List <int> ensStart, string file)
        {
            var list = new List <DataSet.EnsemblePackage>();

            using (var fileStream = new FileStream(file, FileMode.Open, FileAccess.Read))
            {
                foreach (var start in ensStart)
                {
                    try
                    {
                        var buffer = new byte[DataSet.Ensemble.ENSEMBLE_HEADER_LEN];                                //Buffer is byte array of size 32. In Binary codec, buffer is byte array of size 32, containing 32 bytes from file

                        // Move the start location and read in the header
                        fileStream.Seek(start, SeekOrigin.Begin);
                        if (fileStream.Read(buffer, 0, buffer.Length) >= DataSet.Ensemble.ENSEMBLE_HEADER_LEN)      // Always true, buffer always size of variable, this loads in bytes to Buffer, however
                        {
                            // Get the payload size
                            int payloadSize = MathHelper.LsbMsbInt(buffer[2], buffer[3]) + PD0.CHECKSUM_NUM_BYTE;   //When referencing positions in buffer, uses "start" Which implies it is looking for the position in the actual file. (Error?)

                            // Get the ensemble size
                            int ensSize = MathHelper.LsbMsbInt(buffer[2], buffer[3]) + PD0.CHECKSUM_NUM_BYTE;       // Same equation as payload size, but the LsbMsbInt Might change buffer itself?

                            // Sanity check
                            if (ensSize > DataSet.Ensemble.ENSEMBLE_HEADER_LEN)
                            {
                                // Get the entire ensemble
                                var rawEns = new byte[ensSize];
                                fileStream.Seek(start, SeekOrigin.Begin);
                                fileStream.Read(rawEns, 0, rawEns.Length);

                                // Check the checksum
                                ushort calculatedChecksum = PD0.CalculateChecksum(rawEns, ensSize - PD0.CHECKSUM_NUM_BYTE);
                                ushort ensembleChecksum   = MathHelper.LsbMsbUShort(rawEns[rawEns.Length - 2], rawEns[rawEns.Length - 1]);

                                if (calculatedChecksum == ensembleChecksum)
                                {
                                    // Pass event that a good ensemble was found
                                    if (GoodEnsembleEvent != null)
                                    {
                                        GoodEnsembleEvent();
                                    }

                                    //Pd0Codec _pd0Codec = new Pd0Codec();
                                    //PD0 pd0 = _pd0Codec.DecodePd0Data(rawEns);
                                    PD0 pd0Ensemble      = new PD0(rawEns);
                                    DataSet.Ensemble ens = new DataSet.Ensemble(pd0Ensemble);
                                    ens.FileName = file;

                                    // Generate a subsystem so that multiple configurations can be seprated
                                    // PD0 does not contain the CEPO index or CEPO Configuraiton Index
                                    if (ens.IsEnsembleAvail)
                                    {
                                        ens.EnsembleData.SubsystemConfig = _pd0SubsystemGen.GenSubsystem(ens);
                                    }


                                    // Package the data
                                    var ensPak = new DataSet.EnsemblePackage();
                                    ensPak.Ensemble       = ens;
                                    ensPak.RawEnsemble    = rawEns;
                                    ensPak.OrigDataFormat = AdcpCodec.CodecEnum.PD0;
                                    list.Add(ensPak);
                                }
                                else
                                {
                                    // Pass event that a good ensemble was found
                                    if (BadEnsembleEvent != null)
                                    {
                                        BadEnsembleEvent();
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        log.Error("Error looking for an ensemble. Loc: " + start, e);
                    }
                }
            }

            return(list);
        }