/// <summary> /// Each ensemble will have its own file. So the filename will contain the subsystem and /// ensemble number. /// </summary> /// <param name="ensemble">Ensemble to encode to PD0.</param> /// <param name="isMultipleFile">Set flag if you want individual files per ensemble or combine it all into one file.</param> public void Write(DataSet.Ensemble ensemble, bool isMultipleFile = false) { if (ensemble == null) { return; } //// Check Amplitude //if (!_options.IsAmplitudeDataSetOn) { ensemble.IsAmplitudeAvail = false; } //else //{ // // Verify the dataset exist // if (!ensemble.IsAmplitudeAvail) // { // // Set that data set was not used // _options.IsAmplitudeDataSetOn = false; // } //} //// Check Beam Velocity //if (!_options.IsBeamVelocityDataSetOn) { ensemble.IsBeamVelocityAvail = false; } //else //{ // // Verify the dataset exist // if (!ensemble.IsBeamVelocityAvail) // { // // Set that data set was not used // _options.IsBeamVelocityDataSetOn = false; // } //} //// Check Earth Velocity //if (!_options.IsEarthVelocityDataSetOn) { ensemble.IsEarthVelocityAvail = false; } //else //{ // // Verify the dataset exist // if (!ensemble.IsEarthVelocityAvail) // { // // Set that data set was not used // _options.IsEarthVelocityDataSetOn = false; // } //} //// Check Instrument Velocity //if (!_options.IsInstrumentVelocityDataSetOn) { ensemble.IsInstrumentVelocityAvail = false; } //else //{ // // Verify the dataset exist // if (!ensemble.IsInstrumentVelocityAvail) // { // // Set that data set was not used // _options.IsInstrumentVelocityDataSetOn = false; // } //} //// Check Correlation //if (!_options.IsCorrelationDataSetOn) { ensemble.IsCorrelationAvail = false; } //else //{ // // Verify the dataset exist // if (!ensemble.IsCorrelationAvail) // { // // Set that data set was not used // _options.IsCorrelationDataSetOn = false; // } //} //// Check Good Beam //if (!_options.IsGoodBeamDataSetOn) { ensemble.IsGoodBeamAvail = false; } //else //{ // // Verify the dataset exist // if (!ensemble.IsGoodBeamAvail) // { // // Set that data set was not used // _options.IsGoodBeamDataSetOn = false; // } //} //// Check Good Earth //if (!_options.IsGoodEarthDataSetOn) { ensemble.IsGoodEarthAvail = false; } //else //{ // // Verify the dataset exist // if (!ensemble.IsGoodEarthAvail) // { // // Set that data set was not used // _options.IsGoodEarthDataSetOn = false; // } //} //// Check Bottom Track //if (!_options.IsBottomTrackDataSetOn) { ensemble.IsBottomTrackAvail = false; } //else //{ // if (!ensemble.IsBottomTrackAvail) // { // // Set that data set was not used // _options.IsBottomTrackDataSetOn = false; // } //} //// Check Earth Water Mass //if (!_options.IsEarthWaterMassDataSetOn) { ensemble.IsEarthWaterMassAvail = false; } //else //{ // if (!ensemble.IsEarthWaterMassAvail) // { // // Set that data set was not used // _options.IsEarthWaterMassDataSetOn = false; // } //} //// Check Instrument Water Mass //if (!_options.IsInstrumentWaterMassDataSetOn) { ensemble.IsInstrumentWaterMassAvail = false; } //else //{ // if (!ensemble.IsInstrumentWaterMassAvail) // { // // Set that data set was not used // _options.IsInstrumentWaterMassDataSetOn = false; // } //} //// Check Nmea Data //if (!_options.IsNmeaDataSetOn) { ensemble.IsNmeaAvail = false; } //else //{ // if (!ensemble.IsNmeaAvail) // { // // Set that data set was not used // _options.IsNmeaDataSetOn = false; // } //} //// Check Profile Engineering //if (!_options.IsProfileEngineeringDataSetOn) { ensemble.IsProfileEngineeringAvail = false; } //else //{ // if (!ensemble.IsProfileEngineeringAvail) // { // // Set that data set was not used // _options.IsProfileEngineeringDataSetOn = false; // } //} //// Check System Setup //if (!_options.IsSystemSetupDataSetOn) { ensemble.IsSystemSetupAvail = false; } //else //{ // if (!ensemble.IsSystemSetupAvail) // { // // Set that data set was not used // _options.IsSystemSetupDataSetOn = false; // } //} //// Check ADCP GPS //if (!_options.IsAdcpGpsDataSetOn) { ensemble.IsAdcpGpsDataAvail = false; } //else //{ // if (!ensemble.IsAdcpGpsDataAvail) // { // // Set that data set was not used // _options.IsAdcpGpsDataSetOn = false; // } //} //// Check GPS 1 //if (!_options.IsGps1DataSetOn) { ensemble.IsGps1DataAvail = false; } //else //{ // if (!ensemble.IsGps1DataAvail) // { // // Set that data set was not used // _options.IsGps1DataSetOn = false; // } //} //// Check GPS 2 //if (!_options.IsGps2DataSetOn) { ensemble.IsGps2DataAvail = false; } //else //{ // if (!ensemble.IsGps2DataAvail) // { // // Set that data set was not used // _options.IsGps2DataSetOn = false; // } //} //// Check NMEA 1 //if (!_options.IsNmea1DataSetOn) { ensemble.IsNmea1DataAvail = false; } //else //{ // if (!ensemble.IsNmea1DataAvail) // { // // Set that data set was not used // _options.IsNmea1DataSetOn = false; // } //} //// Check NMEA 2 //if (!_options.IsNmea2DataSetOn) { ensemble.IsNmea2DataAvail = false; } //else //{ // if (!ensemble.IsNmea2DataAvail) // { // // Set that data set was not used // _options.IsNmea2DataSetOn = false; // } //} // Write the data to the file _writer.Write(ensemble.EncodePd0Ensemble(_options.CoordinateTransform)); }
/// <summary> /// Receive the ensemble and decode it to output the data. /// </summary> /// <param name="ens">Ensemble.</param> public void ReceiveEnsemble(DataSet.Ensemble ens) { int dataOutputMax = 5000; // If the HeadingOffset is set or // If the the want to retransform the data or // The 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 (_IsRetransformData || _IsUseGpsHeading || _HeadingOffset != 0) { // Retransform the Profile datas Transform.ProfileTransform(ref ens, 0.25f, _IsUseGpsHeading, _HeadingOffset); // Retransform the Bottom Track data // This will also create the ship data Transform.BottomTrackTransform(ref ens, 0.90f, 10.0f, _IsUseGpsHeading, _HeadingOffset); // WaterMass transform data // This will also create the ship data if (ens.IsInstrumentWaterMassAvail) { Transform.WaterMassTransform(ref ens, 0.90f, 10.0f, _IsUseGpsHeading, _HeadingOffset, _ShipXdcrOffset); } } if (_SelectedFormat == ENCODING_VMDAS) { VmDasAsciiCodec.VmDasAsciiOutput output = _codecVmDas.Encode(ens, _MinBin, _MaxBin); // 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 (_MinBin != output.BinSelected.MinBin) { MinBin = output.BinSelected.MinBin; } if (_MaxBin != output.BinSelected.MaxBin) { MaxBin = output.BinSelected.MaxBin; } } else if (_SelectedFormat == 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.Trim()); // Write data to file if turned on WriteData(line.Trim()); } // Max size of data output buffer dataOutputMax = 1000; } else if (_SelectedFormat == 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 (_SelectedFormat == ENCODING_PD0) { byte[] pd0 = null; switch (_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 (_SelectedFormat == ENCODING_RETRANSFORM_PD6) { } if (DataOutput.Length > dataOutputMax) { DataOutput = DataOutput.Substring(DataOutput.Length - dataOutputMax); } }
/// <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); } }