/// <summary> /// Process the incoming data. This will screen and average the data. /// </summary> /// <param name="data">Data to display.</param> /// <param name="origDataFormat">Originial Format of the data.</param> private void ProcessEnsemble(DataSet.Ensemble data, AdcpCodec.CodecEnum origDataFormat) { // Distribute the dataset to all subscribers if (data != null) { // Publish the ensemble before it is screened and averaged _events.PublishOnBackgroundThread(new EnsembleRawEvent(data.Clone(), EnsembleSource.Playback, EnsembleType.Single, origDataFormat)); // Make a copy of the ensemble to pass to all the views DataSet.Ensemble newEnsemble = data.Clone(); // Lock the ensemble lock (newEnsemble.SyncRoot) { // Vessel Mount Options VesselMountScreen(ref newEnsemble); // Screen the data _screenDataVM.ScreenData(ref newEnsemble, origDataFormat); // Average the data _averagingVM.AverageEnsemble(newEnsemble); // Create and Ensembl event EnsembleEvent ensEvent = new EnsembleEvent(newEnsemble, EnsembleSource.Playback); // Publish the ensemble after screening and averging the data _events.PublishOnBackgroundThread(ensEvent); // Display the ensemble _pm.DisplayEnsemble(ensEvent); } } }
/// <summary> /// Initialize the event. /// </summary> /// <param name="ensemble">Ensemble to send in event.</param> /// <param name="source">Source of the ensemble.</param> /// <param name="type">Type of ensemble: single or averaged. Default is SINGLE.</param> /// <param name="origDataFormat">Original data forma.</param> public EnsembleRawEvent(DataSet.Ensemble ensemble, EnsembleSource source, EnsembleType type = EnsembleType.Single, AdcpCodec.CodecEnum origDataFormat = AdcpCodec.CodecEnum.Binary) { Ensemble = ensemble; Source = source; Type = type; OrigDataFormat = origDataFormat; }
/// <summary> /// Look for the view model for the screen options. /// Then pass the ensemble to the VM to be screened. /// </summary> /// <param name="ensemble">Ensemble to screen.</param> /// <param name="origDataFormat">Original Data format.</param> public void ScreenData(ref DataSet.Ensemble ensemble, AdcpCodec.CodecEnum origDataFormat) { if (ensemble != null) { try { // Find the VM that matches the configuration foreach (ScreenDataViewModel vm in ScreenDataVMList) { // Do not rescreen the averaged data // it already has been screen if (vm.Config == ensemble.EnsembleData.SubsystemConfig && vm.Config.Source != EnsembleSource.LTA && vm.Config.Source != EnsembleSource.STA) { // Screen the data based off the options in the VM vm.ScreenEnsemble(ref ensemble, origDataFormat); } } } catch (Exception e) { // Ususually an exception occurs here at startup when // all the VMs are being created. log.Error("Error screening the data.", e); } } }
/// <summary> /// Process all the ensembles in batches. This will ensure that not all the data is read /// in at one time. /// </summary> /// <param name="index">Index in the total ensemble list.</param> /// <param name="batch_size">Batch size.</param> /// <param name="origDataFormat">Format of the data.</param> private void ProcessEnsembleBatch(long index, uint batch_size, AdcpCodec.CodecEnum origDataFormat) { // Get all the data from the files Cache <long, DataSet.Ensemble> data = _pm.SelectedProject.GetEnsembles(index, batch_size); // Store the new screened data Cache <long, DataSet.Ensemble> screenData = new Cache <long, DataSet.Ensemble>(batch_size); // Screen all the data for (int x = 0; x < data.Count(); x++) { // Make a copy of the ensemble to pass to all the views DataSet.Ensemble newEnsemble = data.IndexValue(x).Clone(); lock (newEnsemble.SyncRoot) { // Vessel Mount Options VesselMountScreen(ref newEnsemble); // Screen the data _screenDataVM.ScreenData(ref newEnsemble, origDataFormat); // Add the screened ensemble to the list screenData.Add(data.IndexKey(x), newEnsemble); } } // Publish all the ensembles //_events.PublishOnBackgroundThread(new BulkEnsembleEvent(screenData, EnsembleSource.Playback)); _pm.DisplayEnsembleBulk(new BulkEnsembleEvent(screenData, EnsembleSource.Playback)); }
/// <summary> /// Initialize the values. /// </summary> public PlaybackArgs() { Index = 0; TotalEnsembles = 0; Ensemble = null; OrigDataFormat = AdcpCodec.CodecEnum.Binary; }
/// <summary> /// Add the ensemble to the dictionary. The ensemble will then /// be available to playback. /// </summary> /// <param name="ensembleRaw"></param> /// <param name="ensemble"></param> /// <param name="origDataFormat">Originl Data format.</param> public void AddEnsemble(byte[] ensembleRaw, DataSet.Ensemble ensemble, AdcpCodec.CodecEnum origDataFormat) { // ********** // Moved this to eventhandler // Not needed when reading in the entire file // ********** // Copy the data //var ens = ensemble.Clone(); //byte[] raw = new byte[ensembleRaw.Length]; //Buffer.BlockCopy(ensembleRaw, 0, raw, 0, ensembleRaw.Length); // Create the velocity vectors for the ensemble DataSet.VelocityVectorHelper.CreateVelocityVector(ref ensemble); if (ensemble.IsEnsembleAvail) { // Store the found ensemble to the dictionary if (!_ensembleDict.ContainsKey(ensemble.EnsembleData.EnsembleNumber)) { _ensembleDict.Add(ensemble.EnsembleData.EnsembleNumber, new EnsembleData(ensembleRaw, ensemble, origDataFormat)); // Find the first ensemble number if (_firstEnsNum == 0 || _firstEnsNum > ensemble.EnsembleData.EnsembleNumber) { _firstEnsNum = ensemble.EnsembleData.EnsembleNumber; } // Find the last ensemble number if (_lastEnsNum < ensemble.EnsembleData.EnsembleNumber) { _lastEnsNum = ensemble.EnsembleData.EnsembleNumber; } } else { if (!_ensembleDict.ContainsKey(_lastEnsNum + ensemble.EnsembleData.EnsembleNumber)) { // Create a new ensemble number key based off the last ensemble and add 1 _ensembleDict.Add(_lastEnsNum + ensemble.EnsembleData.EnsembleNumber, new EnsembleData(ensembleRaw, ensemble, origDataFormat)); } else { // Generate the key from the datetime _ensembleDict.Add((int)DateTime.Now.Ticks, new EnsembleData(ensembleRaw, ensemble, origDataFormat)); } } } // Set total number of ensembles // Subtract because 0 based TotalEnsembles = _ensembleDict.Count() - 1; }
/// <summary> /// Receive the ensemble and decode it to output the data. /// </summary> /// <param name="ens">Ensemble.</param> /// <param name="origDataFormat">Original Data format.</param> public void ReceiveEnsemble(DataSet.Ensemble ens, AdcpCodec.CodecEnum origDataFormat) { // Set the buffer size to display data // To much data will make the system run slower int dataOutputMax = 5000; // If the HeadingOffset is set or // If they want to retransform the data or // They are replacing the heading with GPS heading, // The data needs to be retransformed to use the new heading. // Retransform the data with the new heading // Apply HDT heading if requried and available // This will also apply the heading offset if (_options.IsRetransformData || _options.IsUseGpsHeading || _options.HeadingOffset != 0) { // Retransform the Profile datas Transform.ProfileTransform(ref ens, origDataFormat, 0.25f, _options.SelectedHeadingSource, _options.HeadingOffset); // Retransform the Bottom Track data // This will also create the ship data Transform.BottomTrackTransform(ref ens, origDataFormat, 0.90f, 10.0f, _options.SelectedHeadingSource, _options.HeadingOffset); // WaterMass transform data // This will also create the ship data if (ens.IsInstrumentWaterMassAvail) { Transform.WaterMassTransform(ref ens, origDataFormat, 0.90f, 10.0f, _options.SelectedHeadingSource, _options.HeadingOffset, _options.ShipXdcrOffset); } } // Remove the ship speed RemoveShipSpeed(ref ens); // Encode the data string output = EncodeVelocity(ens); // Display data DataOutput += output; // Send data to serial port SendDataToSerial(output); // Write data to file if turned on WriteData(output); // Keep the Buffer to a set limit if (DataOutput.Length > dataOutputMax) { DataOutput = DataOutput.Substring(DataOutput.Length - dataOutputMax); } }
/// <summary> /// Process the ensembles. Look for new subsystem configurations with each ensemble. /// </summary> /// <param name="ensemble"></param> /// <param name="source"></param> /// <param name="dataFormat"></param> /// <returns></returns> public void ProcessEnsemble(Ensemble ensemble, EnsembleSource source, AdcpCodec.CodecEnum dataFormat) { if (ensemble != null && ensemble.IsEnsembleAvail) { // Create subsystem config ViewSubsystemConfig config = new ViewSubsystemConfig(ensemble.EnsembleData.SubsystemConfig, source); // Check if the config exist already if (!_dictSsConfig.ContainsKey(config)) { // Create the viewmodel for each subsystem config/source found DashboardSubsystemConfigViewModel vm = new DashboardSubsystemConfigViewModel(config); // Add the vm to the list _dictSsConfig.Add(config, vm); // Add to the list of subsystems Application.Current.Dispatcher.Invoke((System.Action) delegate { SsConfigList.Add(vm); }); log.Debug(string.Format("Add configuration {0}", config.Config.DescString())); // Select the last config add SelectedSsConfigIndex = SsConfigList.Count(); // Pass the ensemble to the viewmodel vm.ProcessEnsemble(ensemble, source); //return config; } else { // Viewmodel already exist, so send the ensemble //DashboardSubsystemConfigViewModel vm = null; //if (_dictSsConfig.TryGetValue(config, out vm)) //{ // vm.ProcessEnsemble(ensemble, source); //} //return config; } } // Not a valid ensemble //return null; }
/// <summary> /// Display all the data from the project. /// </summary> private void DisplayAllData() { // Stop playback if it is playing back StopTimer(); lock (_playbackIndexLock) { PlaybackIndex = DEFAULT_PLAYBACK_INDEX; } if (_pm.IsPlaybackSelected) { IsLoading = true; // Get all the ensembles from the project Cache <long, DataSet.Ensemble> data = _pm.SelectedPlayback.GetAllEnsembles(); AdcpCodec.CodecEnum origDataFormat = _pm.SelectedPlayback.GetOrigDataFormat(); int numEns = _pm.SelectedProject.GetNumberOfEnsembles(); // We will process in batches of 100 int batches = numEns / 100; int remainder = numEns % 100; long index = 1; uint BATCH_SIZE = 100; // Process all the ensembles for (int x = 0; x < batches; x++) { // Process an ensemble batch ProcessEnsembleBatch(index, BATCH_SIZE, origDataFormat); index += BATCH_SIZE; Debug.WriteLine("PlaybackVeiwModel Batch Number: " + index); } // Process the remainder of the ensembles not a multiple of 100 ProcessEnsembleBatch(index, (uint)remainder, origDataFormat); // Set new Total ensembles _TotalEnsembles = (long)data.Count(); this.NotifyOfPropertyChange(() => this.TotalEnsembles); IsLoading = false; } }
/// <summary> /// Screen the ensemble. Then pass it along to the average layer. /// </summary> /// <param name="data">Raw binary Ensemble.</param> /// <param name="ensemble">Ensemble object.</param> /// <param name="source">Source of the ensemble.</param> /// <param name="dataFormat">Format of the ensemble.</param> /// <returns>Negative number indicates an error.</returns> public int ScreenEnsemble(byte[] data, Ensemble ensemble, EnsembleSource source, AdcpCodec.CodecEnum dataFormat) { // Fill in for missing data if only Bottom Track is turned on FillInMissingWpData(ref ensemble); // Screen for bad heading ScreenData.ScreenBadHeading.Screen(ref ensemble, _prevHeading); SetPreviousHeading(ensemble); // Force 3 Beam Solution if (_Options.IsForce3BeamSolution) { ScreenData.ScreenForce3BeamSolution.Force3BeamSolution(ref ensemble, _Options.Force3BeamSolutionBeam, dataFormat); } // Force 3 Beam Bottom Track solution if (_Options.IsForceBt3BeamSolution) { ScreenData.ScreenForce3BeamSolution.Force3BottomTrackBeamSolution(ref ensemble, _Options.ForceBt3BeamSolutionBeam, dataFormat); } // Retransform the data if (_Options.IsRetransformData) { // PD0 has a different cooridiate matrix // And the beams are in different positions Transform.ProfileTransform(ref ensemble, dataFormat, _Options.RetransformWpCorrThresh, _Options.RetransformHeadingSource, _Options.RetransformHeadingOffset); Transform.BottomTrackTransform(ref ensemble, dataFormat, _Options.RetransformBtCorrThresh, _Options.RetransformBtSnrThresh, _Options.RetransformHeadingSource, _Options.RetransformHeadingOffset); // WaterMass transform data // This will also create the ship data if (ensemble.IsInstrumentWaterMassAvail) { Transform.WaterMassTransform(ref ensemble, dataFormat, _Options.RetransformBtCorrThresh, _Options.RetransformBtSnrThresh, _Options.RetransformHeadingSource, _Options.RetransformHeadingOffset, 0.0f); } } // Mark Bad Below Bottom if (_Options.IsMarkBadBelowBottom) { ScreenData.ScreenMarkBadBelowBottom.Screen(ref ensemble, _prevBtRange); } // Remove Ship Speed if (_Options.IsRemoveShipSpeed) { ScreenData.RemoveShipSpeed.RemoveVelocity(ref ensemble, _prevBtEast, _prevBtNorth, _prevBtVert, _Options.IsRemoveShipSpeedBottomTrack, _Options.IsRemoveShipSpeedGps, _Options.RemoveShipSpeedHeadingOffset); ScreenData.RemoveShipSpeed.RemoveVelocityInstrument(ref ensemble, _prevShipSpeedX, _prevShipSpeedY, _prevShipSpeedZ, _Options.IsRemoveShipSpeedBottomTrack, _Options.IsRemoveShipSpeedGps, _Options.RemoveShipSpeedHeadingOffset); ScreenData.RemoveShipSpeed.RemoveVelocityShip(ref ensemble, _prevShipSpeedTransverse, _prevShipSpeedLongitudinal, _prevShipSpeedNormal, _Options.IsRemoveShipSpeedBottomTrack, _Options.IsRemoveShipSpeedGps, _Options.RemoveShipSpeedHeadingOffset); // Create the new velocity vectors based off the new data DataSet.VelocityVectorHelper.CreateVelocityVector(ref ensemble); } // Record the previous ship speed values SetPreviousShipSpeed(ensemble); // Pass the ensemble to the Processed Ensemble Layer foreach (var vm in IoC.GetAllInstances(typeof(IProcessEnsLayer))) { ((IRecordEnsLayer)vm).RecordEnsemble(data, ensemble, EnsembleSource.Serial, dataFormat); } return(0); }
/// <summary> /// Process the ensemble. /// Cause a blink. /// </summary> /// <param name="ensemble"></param> /// <param name="source"></param> /// <param name="dataFormat"></param> /// <returns></returns> public void ProcessEnsemble(Ensemble ensemble, EnsembleSource source, AdcpCodec.CodecEnum dataFormat) { // Cause a blink }
/// <summary> /// Screen the ensembles based off the options selected. /// The original data format is needed because the Re-Transform will be done /// different for PD0 data. /// </summary> /// <param name="ensemble">Ensemble to screen.</param> /// <param name="origDataFormat">Original Data format.</param> public void ScreenEnsemble(ref DataSet.Ensemble ensemble, AdcpCodec.CodecEnum origDataFormat) { // Fill in for missing data if only Bottom Track is turned on FillInMissingWpData(ref ensemble); // Screen for bad heading ScreenData.ScreenBadHeading.Screen(ref ensemble, _prevHeading); SetPreviousHeading(ensemble); // Force 3 Beam Solution if (_Options.IsForce3BeamSolution) { ScreenData.ScreenForce3BeamSolution.Force3BeamSolution(ref ensemble, _Options.ForceBeamBad, origDataFormat); } // Force 3 Beam Bottom Track solution if (_Options.IsForce3BottomTrackBeamSolution) { ScreenData.ScreenForce3BeamSolution.Force3BottomTrackBeamSolution(ref ensemble, _Options.ForceBottomTrackBeamBad, origDataFormat); } // Retransform the data if (_Options.IsRetransformData) { // PD0 has a different cooridiate matrix // And the beams are in different positions Transform.ProfileTransform(ref ensemble, origDataFormat, _Options.WpCorrThresh, _Options.RetransformHeadingSource, _Options.RetransformHeadingOffset); Transform.BottomTrackTransform(ref ensemble, origDataFormat, _Options.BtCorrThresh, _Options.BtSnrThresh, _Options.RetransformHeadingSource, _Options.RetransformHeadingOffset); // WaterMass transform data // This will also create the ship data if (ensemble.IsInstrumentWaterMassAvail) { Transform.WaterMassTransform(ref ensemble, origDataFormat, _Options.BtCorrThresh, _Options.BtSnrThresh, _Options.RetransformHeadingSource, _Options.RetransformHeadingOffset, 0.0f); } } // Mark Bad Below Bottom if (_Options.IsMarkBadBelowBottom || _Options.IsMarkBadBelowBottomAmplitude || _Options.IsMarkBadBelowBottomCorrelation) { ScreenData.ScreenMarkBadBelowBottom.Screen(ref ensemble, _prevBtRange, _Options.IsMarkBadBelowBottom, _Options.IsMarkBadBelowBottomAmplitude, _Options.IsMarkBadBelowBottomCorrelation); } // Mark Bad Above Surface if (_Options.IsMarkBadAboveSurface || _Options.IsMarkBadAboveSurfaceAmplitude || _Options.IsMarkBadAboveSurfaceCorrelation) { ScreenData.ScreenMarkBadAboveSurface.Screen(ref ensemble, _prevRangeTrackRange, _Options.IsMarkBadAboveSurface, _Options.IsMarkBadAboveSurfaceAmplitude, _Options.IsMarkBadAboveSurfaceCorrelation); } // Remove Ship Speed if (_Options.IsRemoveShipSpeed) { ScreenData.RemoveShipSpeed.RemoveVelocity(ref ensemble, _prevBtEast, _prevBtNorth, _prevBtVert, _Options.CanUseBottomTrackVel, _Options.CanUseGpsVel, _Options.GpsHeadingOffset); ScreenData.RemoveShipSpeed.RemoveVelocityInstrument(ref ensemble, _prevShipSpeedX, _prevShipSpeedY, _prevShipSpeedZ, _Options.CanUseBottomTrackVel, _Options.CanUseGpsVel, _Options.GpsHeadingOffset); ScreenData.RemoveShipSpeed.RemoveVelocityShip(ref ensemble, _prevShipSpeedTransverse, _prevShipSpeedLongitudinal, _prevShipSpeedNormal, _Options.CanUseBottomTrackVel, _Options.CanUseGpsVel, _Options.GpsHeadingOffset); // Create the new velocity vectors based off the new data DataSet.VelocityVectorHelper.CreateVelocityVector(ref ensemble); } // Record the previous ship speed values SetPreviousShipSpeed(ensemble); // Record the previous ranges SetPreviousRange(ensemble); }
/// <summary> /// Receive the ensemble from the codec. /// Then set the ensemble size in bytes /// so that the next ensemble can be found quicker. /// Set the flag that the ensemble was found. /// Then store the ensemble for playback. /// </summary> /// <param name="ensembleRaw">Ensemble binary data.</param> /// <param name="ensemble">Ensemble object.</param> /// <param name="origDataFormat">Original Data format.</param> private void _adcpCodec_ProcessDataEvent(byte[] ensembleRaw, DataSet.Ensemble ensemble, AdcpCodec.CodecEnum origDataFormat) { // Set the length of an ensemble to find the next ensemble // quicker BytesPerEnsemble = ensembleRaw.Length; // Copy the data var ens = ensemble.Clone(); byte[] raw = new byte[ensembleRaw.Length]; Buffer.BlockCopy(ensembleRaw, 0, raw, 0, ensembleRaw.Length); AddEnsemble(raw, ens, origDataFormat); }
/// <summary> /// Force a specific beam to be bad to do a 3 beam solution. This will take the beam /// from the options to choose the beam to mark bad. It will then mark the Bottom Track Beam Velocity value /// bad for all the bins in the Bottom Track Beam Velocity. It will then recalculate Bottom Track Earth Velocity data based /// off the new Bottom Track Beam Velocity. /// </summary> /// <param name="ensemble">Ensemble to set bad beam.</param> /// <param name="beam">Beam to mark bad.</param> /// <param name="origDataFormat">Original Data Format.</param> /// <returns>TRUE = Screening could be done.</returns> public static bool Force3BottomTrackBeamSolution(ref DataSet.Ensemble ensemble, int beam, AdcpCodec.CodecEnum origDataFormat) { // Verify the data exist if (!ensemble.IsEnsembleAvail || !ensemble.IsBottomTrackAvail) { return(false); } // Verify the given bad beam exist if (beam < 0 || beam > ensemble.BottomTrackData.NumBeams) { return(false); } // Set all the velocities to bad for the given bad beam ensemble.BottomTrackData.BeamVelocity[beam] = DataSet.Ensemble.BAD_VELOCITY; ensemble.BottomTrackData.BeamGood[beam] = 0; // Calculate the new Earth velocities Transform.BottomTrackTransform(ref ensemble, origDataFormat); return(true); }
/// <summary> /// Force a specific beam to be bad to do a 3 beam solution. This will take the beam /// from the options to choose the beam to mark bad. It will then mark the Beam Velocity value /// bad for all the bins in the Beam Velocity. It will then recalculate Earth Velocity data based /// off the new Beam Velocity. /// </summary> /// <param name="ensemble">Ensemble to set bad beam.</param> /// <param name="beam">Beam to mark bad.</param> /// <returns>TRUE = Screening could be done.</returns> /// <param name="origDataFormat">Original Data format.</param> public static bool Force3BeamSolution(ref DataSet.Ensemble ensemble, int beam, AdcpCodec.CodecEnum origDataFormat) { // Verify the data exist if (!ensemble.IsEnsembleAvail || !ensemble.IsBeamVelocityAvail || !ensemble.IsGoodBeamAvail) { return(false); } // Verify the given bad beam exist if (beam < 0 || beam > ensemble.EnsembleData.NumBeams) { return(false); } // Set all the velocities to bad for the given bad beam for (int bin = 0; bin < ensemble.BeamVelocityData.NumElements; bin++) { ensemble.BeamVelocityData.BeamVelocityData[bin, beam] = DataSet.Ensemble.BAD_VELOCITY; ensemble.GoodBeamData.GoodBeamData[bin, beam] = 0; } // Calculate the new Earth velocities Transform.ProfileTransform(ref ensemble, origDataFormat); return(true); }
/// <summary> /// Receive the ensemble and decode it to output the data. /// </summary> /// <param name="ens">Ensemble.</param> /// <param name="origDataFormat">Original Data Format.</param> public void ReceiveEnsemble(DataSet.Ensemble ens, AdcpCodec.CodecEnum origDataFormat) { // Set the buffer size to display data // To much data will make the system run slower int dataOutputMax = 5000; // Set the maximum bin for bin list if (ens.IsEnsembleAvail) { // If it different from what is now if (BinList.Count != ens.EnsembleData.NumBins) { // Subtract 1 because 0 based NumBins = ens.EnsembleData.NumBins - 1; // Clear and repopulate BinList.Clear(); for (int x = 0; x < ens.EnsembleData.NumBins; x++) { BinList.Add(x); } } } // If the HeadingOffset is set or // If they want to retransform the data or // They are replacing the heading with GPS heading, // The data needs to be retransformed to use the new heading. // Retransform the data with the new heading // Apply HDT heading if requried and available // This will also apply the heading offset if (_options.IsRetransformData || _options.IsUseGpsHeading || _options.HeadingOffset != 0) { // Retransform the Profile datas Transform.ProfileTransform(ref ens, origDataFormat, 0.25f, _options.SelectedHeadingSource, _options.HeadingOffset); // Retransform the Bottom Track data // This will also create the ship data Transform.BottomTrackTransform(ref ens, origDataFormat, 0.90f, 10.0f, _options.SelectedHeadingSource, _options.HeadingOffset); // WaterMass transform data // This will also create the ship data if (ens.IsInstrumentWaterMassAvail) { Transform.WaterMassTransform(ref ens, origDataFormat, 0.90f, 10.0f, _options.SelectedHeadingSource, _options.HeadingOffset, _options.ShipXdcrOffset); } } // Remove the Ship speed from the data RemoveShipSpeed(ref ens); // Water Track if (_options.IsCalculateWaterTrack) { _manualWT.Calculate(ref ens, _options.WtMinBin, _options.WtMaxBin); } if (_options.SelectedFormat == DataOutputViewOptions.ENCODING_VMDAS) { VmDasAsciiCodec.VmDasAsciiOutput output = _codecVmDas.Encode(ens, _options.VmDasMinBin, _options.VmDasMaxBin); // Display data DataOutput = output.Ascii; // Max size of data output buffer dataOutputMax = 5000; // Send data to serial port SendDataToSerial(output.Ascii); // Write data to file if turned on WriteData(output.Ascii); // Update the Min and Max Bin selection if (_options.VmDasMinBin != output.BinSelected.MinBin) { MinBin = output.BinSelected.MinBin; } if (_options.VmDasMaxBin != output.BinSelected.MaxBin) { MaxBin = output.BinSelected.MaxBin; } } else if (_options.SelectedFormat == DataOutputViewOptions.ENCODING_PD6_PD13) { // PD6 or PD13 EnsToPd6_13Codec.Pd6_13Data output = _codecPd6_13.Encode(ens); // Output all the strings foreach (var line in output.Data) { // Output to display DataOutput += line; // Output to the serial port // Trim it because the serial port adds a carrage return SendDataToSerial(line, false); // Write data to file if turned on WriteData(line.Trim()); } // Max size of data output buffer dataOutputMax = 1000; } else if (_options.SelectedFormat == DataOutputViewOptions.ENCODING_Binary_ENS) { // Convert to binary array byte[] rawEns = ens.Encode(); // Output to display DataOutput += ens.ToString(); // Output data to the serial port _serialPort.SendData(rawEns, 0, rawEns.Length); // Write data to file if turned on WriteData(rawEns); // Max size of data output buffer dataOutputMax = 10000; } else if (_options.SelectedFormat == DataOutputViewOptions.ENCODING_PD0) { byte[] pd0 = null; switch (_options.SelectedCoordTransform) { case PD0.CoordinateTransforms.Coord_Beam: pd0 = ens.EncodePd0Ensemble(PD0.CoordinateTransforms.Coord_Beam); break; case PD0.CoordinateTransforms.Coord_Instrument: pd0 = ens.EncodePd0Ensemble(PD0.CoordinateTransforms.Coord_Instrument); break; case PD0.CoordinateTransforms.Coord_Ship: pd0 = ens.EncodePd0Ensemble(PD0.CoordinateTransforms.Coord_Ship); break; case PD0.CoordinateTransforms.Coord_Earth: pd0 = ens.EncodePd0Ensemble(PD0.CoordinateTransforms.Coord_Earth); break; } // Output to display DataOutput += System.Text.ASCIIEncoding.ASCII.GetString(pd0); // Output data to serial port _serialPort.SendData(pd0, 0, pd0.Length); // Write data to file if turned on WriteData(pd0); // Max output buffer size dataOutputMax = 10000; } else if (_options.SelectedFormat == DataOutputViewOptions.ENCODING_RETRANSFORM_PD6) { } // Keep the Buffer to a set limit if (DataOutput.Length > dataOutputMax) { DataOutput = DataOutput.Substring(DataOutput.Length - dataOutputMax); } }
/// <summary> /// Initialize the value. /// </summary> /// <param name="rawData">Raw binary data.</param> /// <param name="ensemble">Ensemble data.</param> /// <param name="origDataFormat">Original Data format.</param> public EnsembleData(byte[] rawData, DataSet.Ensemble ensemble, AdcpCodec.CodecEnum origDataFormat) { RawData = rawData; Ensemble = ensemble; OrigDataFormat = origDataFormat; }
/// <summary> /// Process the ensemble data from the codec. /// </summary> /// <param name="binaryEnsemble">Binary ensemble data.</param> /// <param name="ensemble">Ensemble object.</param> /// <param name="dataFormat">Format the data was decoded.</param> private void _codec_ProcessDataEvent(byte[] binaryEnsemble, DataSet.Ensemble ensemble, AdcpCodec.CodecEnum dataFormat) { // Determine the data format switch (dataFormat) { case AdcpCodec.CodecEnum.Binary: // RTB _RtbDataBytes += binaryEnsemble.Length; _RtbDataCount++; log.Debug(string.Format("Binary Codec: Ensemble Size: {0}", binaryEnsemble.Length)); break; case AdcpCodec.CodecEnum.DVL: // RTD _RtdDataBytes += binaryEnsemble.Length; _RtdDataCount++; log.Debug(string.Format("DVL Codec: Ensemble Size: {0}", binaryEnsemble.Length)); break; case AdcpCodec.CodecEnum.PD0: // PD0 _Pd0DataBytes += binaryEnsemble.Length; _Pd0DataCount++; log.Debug(string.Format("PD0 Codec: Ensemble Size: {0}", binaryEnsemble.Length)); break; case AdcpCodec.CodecEnum.PD6_13: // PD6/13 _Pd6_13DataBytes += binaryEnsemble.Length; _Pd6_13DataCount++; log.Debug(string.Format("PD6_13 Codec: Ensemble Size: {0}", binaryEnsemble.Length)); break; case AdcpCodec.CodecEnum.PD4_5: // PD4/5 _Pd4_5DataBytes += binaryEnsemble.Length; _Pd4_5DataCount++; log.Debug(string.Format("PD4_5 Codec: Ensemble Size: {0}", binaryEnsemble.Length)); break; default: break; } // Pass the data to all Screen layers foreach (var vm in IoC.GetAllInstances(typeof(IProcessEnsLayer))) { ((IProcessEnsLayer)vm).ProcessEnsemble(ensemble, EnsembleSource.Serial, dataFormat); } // Pass the data to all Record layers foreach (var vm in IoC.GetAllInstances(typeof(IRecordEnsLayer))) { ((IRecordEnsLayer)vm).RecordEnsemble(binaryEnsemble, ensemble, EnsembleSource.Serial, dataFormat); } }