public void DecodePd0Test() { PD0 pd0 = new PD0(); pd0.FixedLeader.SetCoordinateTransform(PD0.CoordinateTransforms.Coord_Earth); pd0.AddDataType(new Pd0Correlation(30)); pd0.AddDataType(new Pd0BottomTrack()); pd0.AddDataType(new Pd0EchoIntensity(30)); pd0.AddDataType(new Pd0PercentGood(30)); pd0.AddDataType(new Pd0Velocity(30)); DataSet.Ensemble ens = new DataSet.Ensemble(pd0); Assert.IsTrue(ens.IsCorrelationAvail, "IsCorrelationAvail is incorrect."); Assert.IsTrue(ens.IsBottomTrackAvail, "IsBottomTrackAvail is incorrect."); Assert.IsTrue(ens.IsAmplitudeAvail, "IsAmplitudeAvail is incorrect."); Assert.IsTrue(ens.IsGoodEarthAvail, "IsGoodEarthAvail is incorrect."); Assert.IsFalse(ens.IsGoodBeamAvail, "IsGoodBeamAvail is incorrect."); Assert.IsFalse(ens.IsBeamVelocityAvail, "IsBeamVelocityAvail is incorrect."); Assert.IsTrue(ens.IsEarthVelocityAvail, "IsEarthVelocityAvail is incorrect."); Assert.IsFalse(ens.IsInstrumentVelocityAvail, "IsInstrumentVelocityAvail is incorrect."); Assert.IsFalse(ens.IsInstrumentWaterMassAvail, "IsInstrumentWaterMassAvail is incorrect."); Assert.IsFalse(ens.IsNmeaAvail, "IsNmeaAvail is incorrect."); Assert.IsFalse(ens.IsProfileEngineeringAvail, "IsProfileEngineeringAvail is incorrect."); Assert.IsFalse(ens.IsBottomTrackEngineeringAvail, "IsBottomTrackEngineeringAvail is incorrect."); Assert.IsFalse(ens.IsSystemSetupAvail, "IsSystemSetupAvail is incorrect."); }
public void TestDecode() { PD0 pd0 = new PD0(); pd0.FixedLeader.NumberOfCells = 5; byte[] data = pd0.Encode(); // Size int size = Pd0VariableLeader.DATATYPE_SIZE; size += Pd0FixedLeader.DATATYPE_SIZE; size += 2; // Spare //size += 2; // Checksum size += pd0.Header.GetDataTypeSize(); Assert.AreEqual(2, pd0.Header.NumberOfDataTypes(), "Number of Data Types is incorrect."); Assert.AreEqual(5, pd0.Header.NumberOfDepthCells, "Number of depth cells is incorrect."); Assert.AreEqual(size, MathHelper.LsbMsbShort(data[2], data[3]), "Number of Bytes is incorrect."); Assert.AreEqual(2, data[5], "Number of Data Types is incorrect."); Assert.AreEqual(size + 2, data.Length, "Array Size is incorrect."); // Add 2 for the checksum int flOffset = pd0.Header.GetDataTypeSize(); Assert.AreEqual(flOffset, MathHelper.LsbMsbShort(data[6], data[7]), "Fixed Leader offset is incorrect."); int vlOffset = pd0.Header.GetDataTypeSize() + Pd0FixedLeader.DATATYPE_SIZE; Assert.AreEqual(vlOffset, MathHelper.LsbMsbShort(data[8], data[9]), "Variable Leader offset is incorrect."); }
public void TestEncodeVelCorrEchoPg() { PD0 pd0 = new PD0(); pd0.FixedLeader.NumberOfCells = 5; Pd0Velocity vel = new Pd0Velocity(5); vel.Velocities[0, 0] = 32; vel.Velocities[0, 1] = -32; pd0.AddDataType(vel); Pd0Correlation corr = new Pd0Correlation(5); corr.Correlation[0, 0] = 32; corr.Correlation[0, 1] = 255; pd0.AddDataType(corr); Pd0EchoIntensity ei = new Pd0EchoIntensity(5); ei.EchoIntensity[0, 0] = 32; ei.EchoIntensity[0, 1] = 255; pd0.AddDataType(ei); Pd0PercentGood pg = new Pd0PercentGood(5); pg.PercentGood[0, 0] = 32; pg.PercentGood[0, 1] = 255; pd0.AddDataType(pg); byte[] encode = pd0.Encode(); int flOffset = pd0.Header.GetFixedLeader().Offset; int velOffset = pd0.Header.GetVelocity().Offset; int corrOffset = pd0.Header.GetCorrelation().Offset; int eiOffset = pd0.Header.GetEchoIntensity().Offset; int pgOffset = pd0.Header.GetPercentGood().Offset; Assert.AreEqual(0, encode[flOffset], "Fixed Leader ID LSB is incorrect"); Assert.AreEqual(0, encode[flOffset + 1], "Fixed Leader ID MSB is incorrect"); Assert.AreEqual(5, encode[flOffset + 9], "Number of depth cells is incorrect"); Assert.AreEqual(32, MathHelper.LsbMsbShort(encode[velOffset + 2], encode[velOffset + 3]), "Velocity Bin 0, Beam 0 is incorrect."); Assert.AreEqual(-32, MathHelper.LsbMsbShort(encode[velOffset + 4], encode[velOffset + 5]), "Velocity Bin 0, Beam 1 is incorrect."); Assert.AreEqual(32, encode[corrOffset + 2], "Correlation Bin 0, Beam 0 is incorrect."); Assert.AreEqual(255, encode[corrOffset + 3], "Correlation Bin 0, Beam 1 is incorrect."); Assert.AreEqual(32, encode[eiOffset + 2], "Echo Intensity Bin 0, Beam 0 is incorrect."); Assert.AreEqual(255, encode[eiOffset + 3], "Echo Intensity Bin 0, Beam 1 is incorrect."); Assert.AreEqual(32, encode[pgOffset + 2], "Percent Good Bin 0, Beam 0 is incorrect."); Assert.AreEqual(255, encode[pgOffset + 3], "Percent Good Bin 0, Beam 1 is incorrect."); Assert.IsFalse(pd0.IsBottomTrackExist, "IsBottomTrackExist is incorrect."); Assert.IsTrue(pd0.IsCorrelationExist, "IsCorrelationExist is incorrect."); Assert.IsTrue(pd0.IsEchoIntensityExist, "IsEchoIntensityExist is incorrect."); Assert.IsTrue(pd0.IsPercentGoodExist, "IsPercentGoodExist is incorrect."); }
/// <summary> /// Convert the given binary data into an ensemble. /// Then publish the data to all subscribers. /// </summary> /// <param name="binaryEnsemble">Binary PD0 data.</param> public void DecodePd0Data(byte[] binaryEnsemble) { // Create the PD0 and RTI ensemble PD0 pd0Ensemble = new PD0(binaryEnsemble); // Send an event that data was processed // in this format if (ProcessDataEvent != null) { ProcessDataEvent(binaryEnsemble, pd0Ensemble); } // Reset the timeout _incomingDataTimeout = 0; }
public void DecodeRtiTest() { DataSet.Ensemble ens = EnsembleHelper.GenerateEnsemble(30); PD0 pd0 = new PD0(ens, PD0.CoordinateTransforms.Coord_Earth); Assert.IsTrue(pd0.IsVelocityExist, "IsVelocityExist is incorrect."); Assert.IsTrue(pd0.IsCorrelationExist, "IsCorrelationExist is incorrect."); Assert.IsTrue(pd0.IsEchoIntensityExist, "IsEchoIntensityExist is incorrect."); Assert.IsTrue(pd0.IsPercentGoodExist, "IsPercentGoodExist is incorrect."); Assert.IsTrue(pd0.IsBottomTrackExist, "IsBottomTrackExist is incorrect."); Assert.AreEqual(30, pd0.FixedLeader.NumberOfCells, "Number of cells is incorrect."); Assert.AreEqual(4, pd0.FixedLeader.NumberOfBeams, "Number of beams is incorrect."); Assert.AreEqual(PD0.CoordinateTransforms.Coord_Earth, pd0.FixedLeader.GetCoordinateTransform(), "Coordinate Transform is incorrect."); }
/// <summary> /// Decode the incoming data for ensemble data. /// First search for header. When a header is found, /// verify it is a good header. When the header is /// verified, get the payload size. Determine the /// buffer contains the entire ensemble. If the /// entire ensemble is present in the buffer, retreive /// the ensemble and place in a seperate byte array /// and remove it from the buffer. Then decode the /// ensemble for all the ranges present. /// </summary> private void DecodeIncomingData() { // Find the beginning of an ensemble // It will contain 0x7D and either 0x00 or 0x01 SearchForHeaderStart(); // Verify the incoming data can at least fit an ensemble // Subtract the header size because it is already removed if (_incomingDataBuffer.Count >= MIN_ENS_SIZE - HEADER_SIZE) { // Create an array to hold the ensemble byte[] ensemble = new byte[MIN_ENS_SIZE]; // Add the header back to the ensemble data ensemble[0] = ID; // Copy the remainder of the ensemble for (int x = HEADER_SIZE; x < MIN_ENS_SIZE; x++) { ensemble[x] = _incomingDataBuffer.Take(); } // Get the checksum values long calculatedChecksum = PD0.CalculateChecksum(ensemble, MIN_ENS_SIZE - 2); long ensembleChecksum = RetrieveEnsembleChecksum(ensemble); // Verify the checksum match if (calculatedChecksum == ensembleChecksum) { // Decode the binary data DecodeAdcpData(ensemble); } //else //{ // Debug.WriteLine(string.Format("Checksums do not match Cal: {0} Actual:{1}", calculatedChecksum, ensembleChecksum)); //} } }
public void TestEncodeVel() { PD0 pd0 = new PD0(); pd0.FixedLeader.NumberOfCells = 5; Pd0Velocity vel = new Pd0Velocity(5); vel.Velocities[0, 0] = 32; vel.Velocities[0, 1] = -32; pd0.AddDataType(vel); byte[] encode = pd0.Encode(); int flOffset = pd0.Header.GetFixedLeader().Offset; int velOffset = pd0.Header.GetVelocity().Offset; Assert.AreEqual(0, encode[flOffset], "Fixed Leader ID LSB is incorrect"); Assert.AreEqual(0, encode[flOffset + 1], "Fixed Leader ID MSB is incorrect"); Assert.AreEqual(5, encode[flOffset + 9], "Number of depth cells is incorrect"); Assert.AreEqual(32, MathHelper.LsbMsbShort(encode[velOffset + 2], encode[velOffset + 3]), "Velocity Bin 0, Beam 0 is incorrect."); Assert.AreEqual(-32, MathHelper.LsbMsbShort(encode[velOffset + 4], encode[velOffset + 5]), "Velocity Bin 0, Beam 1 is incorrect."); }
/// <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); }
public void TestDecodeVelocityPgCorrEiBt() { PD0 pd0 = new PD0(); pd0.FixedLeader.NumberOfCells = 5; #region Velocity Pd0Velocity vel = new Pd0Velocity(); // 2 Byte Header // 8 Bytes per depth cell // 4 Beams per depth cell // 2 Bytes per beam byte[] velData = new byte[42]; velData[0] = Pd0Velocity.ID_LSB; velData[1] = Pd0Velocity.ID_MSB; velData[2] = 0xE8; // DS0 Beam 0 LSB velData[3] = 0x00; // DS0 Beam 0 MSB velData[4] = 0xBD; // DS0 Beam 1 LSB velData[5] = 0xFE; // DS0 Beam 1 MSB velData[6] = 0xC8; // DS0 Beam 2 LSB velData[7] = 0x01; // DS0 Beam 2 MSB velData[8] = 0x72; // DS0 Beam 3 LSB velData[9] = 0xFD; // DS0 Beam 3 MSB velData[(4 * 8) + 2 + 0] = 0xD0; // DS4 Beam 0 LSB velData[(4 * 8) + 2 + 1] = 0x04; // DS4 Beam 0 MSB velData[(4 * 8) + 2 + 2] = 0xD5; // DS4 Beam 1 LSB velData[(4 * 8) + 2 + 3] = 0xFA; // DS4 Beam 1 MSB velData[(4 * 8) + 2 + 4] = 0xB0; // DS4 Beam 2 LSB velData[(4 * 8) + 2 + 5] = 0x05; // DS4 Beam 2 MSB velData[(4 * 8) + 2 + 6] = 0x8A; // DS4 Beam 3 LSB velData[(4 * 8) + 2 + 7] = 0xF9; // DS4 Beam 3 MSB vel.Decode(velData); #endregion pd0.AddDataType(vel); // Add Velocity #region Percent Good Pd0PercentGood pg = new Pd0PercentGood(); // 2 Byte Header // 4 Bytes per depth cell // 4 Beams per depth cell // 2 Bytes per beam byte[] pgData = new byte[22]; pgData[0] = Pd0PercentGood.ID_LSB; pgData[1] = Pd0PercentGood.ID_MSB; pgData[2] = 0xE8; // DS0 Beam 0 pgData[3] = 0x7B; // DS0 Beam 1 pgData[4] = 0x7A; // DS0 Beam 2 pgData[5] = 0xDF; // DS0 Beam 3 pgData[(4 * 4) + 2 + 0] = 0x6F; // DS4 Beam 0 pgData[(4 * 4) + 2 + 1] = 0xDE; // DS4 Beam 1 pgData[(4 * 4) + 2 + 2] = 0x15; // DS4 Beam 2 pgData[(4 * 4) + 2 + 3] = 0x22; // DS4 Beam 3 pg.Decode(pgData); #endregion pd0.AddDataType(pg); // Add Percent Good #region Correlation Pd0Correlation corr = new Pd0Correlation(); // 2 Byte Header // 4 Bytes per depth cell // 4 Beams per depth cell // 2 Bytes per beam byte[] corrData = new byte[22]; corrData[0] = Pd0Velocity.ID_LSB; corrData[1] = Pd0Velocity.ID_MSB; corrData[2] = 0xE8; // DS0 Beam 0 corrData[3] = 0x7B; // DS0 Beam 1 corrData[4] = 0x7A; // DS0 Beam 2 corrData[5] = 0xDF; // DS0 Beam 3 corrData[(4 * 4) + 2 + 0] = 0x6F; // DS4 Beam 0 corrData[(4 * 4) + 2 + 1] = 0xDE; // DS4 Beam 1 corrData[(4 * 4) + 2 + 2] = 0x15; // DS4 Beam 2 corrData[(4 * 4) + 2 + 3] = 0x22; // DS4 Beam 3 corr.Decode(corrData); #endregion pd0.AddDataType(corr); // Add Correlation #region Echo Intensity Pd0EchoIntensity ei = new Pd0EchoIntensity(); // 2 Byte Header // 4 Bytes per depth cell // 4 Beams per depth cell // 2 Bytes per beam byte[] eiData = new byte[22]; eiData[0] = Pd0Velocity.ID_LSB; eiData[1] = Pd0Velocity.ID_MSB; eiData[2] = 0xE8; // DS0 Beam 0 eiData[3] = 0x7B; // DS0 Beam 1 eiData[4] = 0x7A; // DS0 Beam 2 eiData[5] = 0xDF; // DS0 Beam 3 eiData[(4 * 4) + 2 + 0] = 0x6F; // DS4 Beam 0 eiData[(4 * 4) + 2 + 1] = 0xDE; // DS4 Beam 1 eiData[(4 * 4) + 2 + 2] = 0x15; // DS4 Beam 2 eiData[(4 * 4) + 2 + 3] = 0x22; // DS4 Beam 3 ei.Decode(eiData); #endregion pd0.AddDataType(ei); // Add Echo Intensity #region Bottom Track Pd0BottomTrack bt = new Pd0BottomTrack(); // 2 Byte Header // 4 Bytes per depth cell // 4 Beams per depth cell // 2 Bytes per beam byte[] btData = new byte[Pd0BottomTrack.DATATYPE_SIZE]; bt.Decode(btData); #endregion pd0.AddDataType(bt); // Add Bottom Track byte[] data = pd0.Encode(); // Size int size = pd0.FixedLeader.GetDataTypeSize(); size += pd0.VariableLeader.GetDataTypeSize(); size += 2; // Spare size += pd0.Header.GetDataTypeSize(); size += pd0.Velocity.GetDataTypeSize(); size += pd0.PercentGood.GetDataTypeSize(); size += pd0.Correlation.GetDataTypeSize(); size += pd0.EchoIntensity.GetDataTypeSize(); size += pd0.BottomTrack.GetDataTypeSize(); Assert.AreEqual(7, pd0.Header.NumberOfDataTypes(), "Number of Data Types is incorrect."); Assert.AreEqual(5, pd0.Header.NumberOfDepthCells, "Number of depth cells is incorrect."); Assert.AreEqual(size, MathHelper.LsbMsbShort(data[2], data[3]), "Number of Bytes is incorrect."); Assert.AreEqual(7, data[5], "Number of Data Types is incorrect."); Assert.AreEqual(size + 2, data.Length, "Array Size is incorrect."); // Add 2 for the checksum int flOffset = pd0.Header.GetDataTypeSize(); Assert.AreEqual(flOffset, MathHelper.LsbMsbShort(data[6], data[7]), "Fixed Leader offset is incorrect."); int vlOffset = pd0.Header.GetDataTypeSize() + Pd0FixedLeader.DATATYPE_SIZE; Assert.AreEqual(vlOffset, MathHelper.LsbMsbShort(data[8], data[9]), "Variable Leader offset is incorrect."); int velOffset = pd0.Header.GetDataTypeSize() + Pd0FixedLeader.DATATYPE_SIZE + Pd0VariableLeader.DATATYPE_SIZE; Assert.AreEqual(velOffset, MathHelper.LsbMsbShort(data[10], data[11]), "Velocity offset is incorrect."); int pgOffset = pd0.Header.GetDataTypeSize() + Pd0FixedLeader.DATATYPE_SIZE + Pd0VariableLeader.DATATYPE_SIZE + pd0.Velocity.GetDataTypeSize(); Assert.AreEqual(pgOffset, MathHelper.LsbMsbShort(data[12], data[13]), "Percent Good offset is incorrect."); int corrOffset = pd0.Header.GetDataTypeSize() + Pd0FixedLeader.DATATYPE_SIZE + Pd0VariableLeader.DATATYPE_SIZE + pd0.Velocity.GetDataTypeSize() + pd0.PercentGood.GetDataTypeSize(); Assert.AreEqual(corrOffset, MathHelper.LsbMsbShort(data[14], data[15]), "Correlation offset is incorrect."); int eiOffset = pd0.Header.GetDataTypeSize() + Pd0FixedLeader.DATATYPE_SIZE + Pd0VariableLeader.DATATYPE_SIZE + pd0.Velocity.GetDataTypeSize() + pd0.PercentGood.GetDataTypeSize() + pd0.Correlation.GetDataTypeSize(); Assert.AreEqual(eiOffset, MathHelper.LsbMsbShort(data[16], data[17]), "Echo Intensity offset is incorrect."); int btOffset = pd0.Header.GetDataTypeSize() + Pd0FixedLeader.DATATYPE_SIZE + Pd0VariableLeader.DATATYPE_SIZE + pd0.Velocity.GetDataTypeSize() + pd0.PercentGood.GetDataTypeSize() + pd0.Correlation.GetDataTypeSize() + pd0.EchoIntensity.GetDataTypeSize(); Assert.AreEqual(btOffset, MathHelper.LsbMsbShort(data[18], data[19]), "Bottom Track offset is incorrect."); }
/// <summary> /// Initialize and decode the given data. /// </summary> /// <param name="bt">RTI Bottom Track.</param> /// <param name="xform">PD0 Coordinate Transform.</param> public Pd0BottomTrack(DataSet.BottomTrackDataSet bt, PD0.CoordinateTransforms xform) : base(ID_LSB, ID_MSB, Pd0ID.Pd0Types.BottomTrack) { // Initialize and decode the data Initialize(); DecodeRtiEnsemble(bt, xform); }
public void TestEncodeVelCorrEchoPgBt() { PD0 pd0 = new PD0(); pd0.FixedLeader.NumberOfCells = 5; Pd0Velocity vel = new Pd0Velocity(5); vel.Velocities[0, 0] = 32; vel.Velocities[0, 1] = -32; pd0.AddDataType(vel); Pd0Correlation corr = new Pd0Correlation(5); corr.Correlation[0, 0] = 32; corr.Correlation[0, 1] = 255; pd0.AddDataType(corr); Pd0EchoIntensity ei = new Pd0EchoIntensity(5); ei.EchoIntensity[0, 0] = 32; ei.EchoIntensity[0, 1] = 255; pd0.AddDataType(ei); Pd0PercentGood pg = new Pd0PercentGood(5); pg.PercentGood[0, 0] = 32; pg.PercentGood[0, 1] = 255; pd0.AddDataType(pg); Pd0BottomTrack bt = new Pd0BottomTrack(); bt.BtPingsPerEnsemble = 20; bt.BtDelayBeforeReacquire = 20; bt.BtAmplitudeBeam0 = 255; pd0.AddDataType(bt); byte[] encode = pd0.Encode(); int flOffset = pd0.Header.GetFixedLeader().Offset; int velOffset = pd0.Header.GetVelocity().Offset; int corrOffset = pd0.Header.GetCorrelation().Offset; int eiOffset = pd0.Header.GetEchoIntensity().Offset; int pgOffset = pd0.Header.GetPercentGood().Offset; int btOffset = pd0.Header.GetBottomTrack().Offset; Assert.AreEqual(0, encode[flOffset], "Fixed Leader ID LSB is incorrect"); Assert.AreEqual(0, encode[flOffset + 1], "Fixed Leader ID MSB is incorrect"); Assert.AreEqual(5, encode[flOffset + 9], "Number of depth cells is incorrect"); Assert.AreEqual(32, MathHelper.LsbMsbShort(encode[velOffset + 2], encode[velOffset + 3]), "Velocity Bin 0, Beam 0 is incorrect."); Assert.AreEqual(-32, MathHelper.LsbMsbShort(encode[velOffset + 4], encode[velOffset + 5]), "Velocity Bin 0, Beam 1 is incorrect."); Assert.AreEqual(32, encode[corrOffset + 2], "Correlation Bin 0, Beam 0 is incorrect."); Assert.AreEqual(255, encode[corrOffset + 3], "Correlation Bin 0, Beam 1 is incorrect."); Assert.AreEqual(32, encode[eiOffset + 2], "Echo Intensity Bin 0, Beam 0 is incorrect."); Assert.AreEqual(255, encode[eiOffset + 3], "Echo Intensity Bin 0, Beam 1 is incorrect."); Assert.AreEqual(32, encode[pgOffset + 2], "Percent Good Bin 0, Beam 0 is incorrect."); Assert.AreEqual(255, encode[pgOffset + 3], "Percent Good Bin 0, Beam 1 is incorrect."); Assert.AreEqual(20, MathHelper.LsbMsbUShort(encode[btOffset + 2], encode[btOffset + 3]), "Bottom Track Pings per Ensemble is incorrect."); Assert.AreEqual(20, MathHelper.LsbMsbUShort(encode[btOffset + 4], encode[btOffset + 5]), "Bottom Track Delay Before Reacquire is incorrect."); Assert.AreEqual(255, encode[btOffset + 36], "Bottom Track Amplitude Beam 0 is incorrect."); Assert.IsTrue(pd0.IsBottomTrackExist, "IsBottomTrackExist is incorrect."); Assert.IsTrue(pd0.IsCorrelationExist, "IsCorrelationExist is incorrect."); Assert.IsTrue(pd0.IsEchoIntensityExist, "IsEchoIntensityExist is incorrect."); Assert.IsTrue(pd0.IsPercentGoodExist, "IsPercentGoodExist is incorrect."); }
/// <summary> /// Convert the RTI Bottom Track data set to the PD0 Bottom Tarack data type. /// </summary> /// <param name="bt">RTI Bottom Track data set.</param> /// <param name="xform">Coordinate Transform.</param> public void DecodeRtiEnsemble(DataSet.BottomTrackDataSet bt, PD0.CoordinateTransforms xform) { BtPingsPerEnsemble = (ushort)bt.ActualPingCount; // Pings per ensemble BtDelayBeforeReacquire = 0; // Delay Before Re-Acquire BtCorrMagMin = 0; // Low Correlation Threshold - CWPCT - Do not have enough info BtEvalAmpMin = 0; // Evaluation Amplitude Min - SNR - Do not have enough info BtPercentGoodMin = 0; // Percent Good Minimum - Do not have enough info BtMode = 0; // Bottom Track Mode - CBTBB - Do not have enough info BtErrVelMax = 0; // Error Velocity Maximum - CBTQT - Do not have enough info Reserved13_16 = 0; // Reserved #region Range // 4 Beam system if (bt.NumBeams >= PD0.NUM_BEAMS) { int beam = 0; for (beam = 0; beam < PD0.NUM_BEAMS; beam++) { ushort lsb = 0; byte msb = 0; switch (beam) { case 0: msb = (byte)Math.Floor((bt.Range[beam] * 100.0f) / ushort.MaxValue); lsb = (ushort)Math.Round((bt.Range[beam] * 100.0f) - (msb * ushort.MaxValue)); BtRangeLsbBeam3 = lsb; BtRangeMsbBeam3 = msb; break; case 1: msb = (byte)Math.Floor((bt.Range[beam] * 100.0f) / ushort.MaxValue); lsb = (ushort)Math.Round((bt.Range[beam] * 100.0f) - (msb * ushort.MaxValue)); BtRangeLsbBeam2 = lsb; BtRangeMsbBeam2 = msb; break; case 2: msb = (byte)Math.Floor((bt.Range[beam] * 100.0f) / ushort.MaxValue); lsb = (ushort)Math.Round((bt.Range[beam] * 100.0f) - (msb * ushort.MaxValue)); BtRangeLsbBeam0 = lsb; BtRangeMsbBeam0 = msb; break; case 3: msb = (byte)Math.Floor((bt.Range[beam] * 100.0f) / ushort.MaxValue); lsb = (ushort)Math.Round((bt.Range[beam] * 100.0f) - (msb * ushort.MaxValue)); BtRangeLsbBeam1 = lsb; BtRangeMsbBeam1 = msb; break; default: break; } } } // Vertical Beam else if (bt.NumBeams == 1) { ushort lsb = 0; byte msb = 0; msb = (byte)Math.Floor((bt.Range[0] * 100.0f) / ushort.MaxValue); lsb = (ushort)Math.Round((bt.Range[0] * 100.0f) - (msb * ushort.MaxValue)); BtRangeLsbBeam0 = lsb; BtRangeMsbBeam0 = msb; } #endregion #region Velocity switch(xform) { // Earth Coordinate Transform case PD0.CoordinateTransforms.Coord_Earth: // 4 Beam System if (bt.NumBeams >= PD0.NUM_BEAMS) { // Earth Beam 0 if (bt.EarthVelocity[0] != DataSet.Ensemble.BAD_VELOCITY) { BtVelocityBeam0 = (short)(Math.Round(bt.EarthVelocity[0] * 1000.0f)); // mm/s to m/s } else { // Bad velocity BtVelocityBeam0 = PD0.BAD_VELOCITY; } // Earth Beam 1 if (bt.EarthVelocity[1] != DataSet.Ensemble.BAD_VELOCITY) { BtVelocityBeam1 = (short)(Math.Round(bt.EarthVelocity[1] * 1000.0f)); // mm/s to m/s } else { // Bad velocity BtVelocityBeam1 = PD0.BAD_VELOCITY; } // Earth Beam 2 if (bt.EarthVelocity[2] != DataSet.Ensemble.BAD_VELOCITY) { BtVelocityBeam2 = (short)(Math.Round(bt.EarthVelocity[2] * 1000.0f)); // mm/s to m/s } else { // Bad velocity BtVelocityBeam2 = PD0.BAD_VELOCITY; } // Earth Beam 3 if (bt.EarthVelocity[3] != DataSet.Ensemble.BAD_VELOCITY) { BtVelocityBeam3 = (short)(Math.Round(bt.EarthVelocity[3] * 1000.0f)); // mm/s to m/s } else { // Bad velocity BtVelocityBeam3 = PD0.BAD_VELOCITY; } } // Vertical Beam else if (bt.NumBeams == 1) { // Earth Beam 0 if (bt.EarthVelocity[0] != DataSet.Ensemble.BAD_VELOCITY) { BtVelocityBeam0 = (short)(Math.Round(bt.EarthVelocity[0] * 1000.0f)); // mm/s to m/s } else { // Bad velocity BtVelocityBeam0 = PD0.BAD_VELOCITY; } } break; // Beam Coordinate Transform case PD0.CoordinateTransforms.Coord_Beam: // 4 Beam System if (bt.NumBeams >= PD0.NUM_BEAMS) { // Beam Beam 3 if (bt.BeamVelocity[0] != DataSet.Ensemble.BAD_VELOCITY) { BtVelocityBeam3 = (short)(Math.Round(bt.BeamVelocity[0] * 1000.0f)); // mm/s to m/s } else { // Bad velocity BtVelocityBeam3 = PD0.BAD_VELOCITY; } // Beam Beam 2 if (bt.BeamVelocity[1] != DataSet.Ensemble.BAD_VELOCITY) { BtVelocityBeam2 = (short)(Math.Round(bt.BeamVelocity[1] * 1000.0f)); // mm/s to m/s } else { // Bad velocity BtVelocityBeam2 = PD0.BAD_VELOCITY; } // Beam Beam 0 if (bt.BeamVelocity[2] != DataSet.Ensemble.BAD_VELOCITY) { BtVelocityBeam0 = (short)(Math.Round(bt.BeamVelocity[2] * 1000.0f)); // mm/s to m/s } else { // Bad velocity BtVelocityBeam0 = PD0.BAD_VELOCITY; } // Beam Beam 1 if (bt.BeamVelocity[3] != DataSet.Ensemble.BAD_VELOCITY) { BtVelocityBeam1 = (short)(Math.Round(bt.BeamVelocity[3] * 1000.0f)); // mm/s to m/s } else { // Bad velocity BtVelocityBeam1 = PD0.BAD_VELOCITY; } } // Vertical Beam else if (bt.NumBeams == 1) { // Beam Beam 3 if (bt.BeamVelocity[0] != DataSet.Ensemble.BAD_VELOCITY) { BtVelocityBeam0 = (short)(Math.Round(bt.BeamVelocity[0] * 1000.0f)); // mm/s to m/s } else { // Bad velocity BtVelocityBeam0 = PD0.BAD_VELOCITY; } } break; // Instrument Coordinate Transform case PD0.CoordinateTransforms.Coord_Instrument: // 4 Beam System if (bt.NumBeams >= PD0.NUM_BEAMS) { // Instrument Beam 1 if (bt.BeamVelocity[0] != DataSet.Ensemble.BAD_VELOCITY) { BtVelocityBeam1 = (short)(Math.Round(bt.BeamVelocity[0] * 1000.0f)); // mm/s to m/s } else { // Bad velocity BtVelocityBeam1 = PD0.BAD_VELOCITY; } // Instrument Beam 0 if (bt.BeamVelocity[1] != DataSet.Ensemble.BAD_VELOCITY) { BtVelocityBeam0 = (short)(Math.Round(bt.BeamVelocity[1] * 1000.0f)); // mm/s to m/s } else { // Bad velocity BtVelocityBeam0 = PD0.BAD_VELOCITY; } // Instrument Beam -2 if (bt.BeamVelocity[2] != DataSet.Ensemble.BAD_VELOCITY) { BtVelocityBeam2 = (short)(Math.Round(bt.BeamVelocity[2] * 1000.0f * -1.0f)); // mm/s to m/s } else { // Bad velocity BtVelocityBeam2 = PD0.BAD_VELOCITY; } // Instrument Beam 3 if (bt.BeamVelocity[3] != DataSet.Ensemble.BAD_VELOCITY) { BtVelocityBeam3 = (short)(Math.Round(bt.BeamVelocity[3] * 1000.0f)); // mm/s to m/s } else { // Bad velocity BtVelocityBeam3 = PD0.BAD_VELOCITY; } } // Vertical Beam else if (bt.NumBeams == 1) { // Instrument Beam 1 if (bt.BeamVelocity[0] != DataSet.Ensemble.BAD_VELOCITY) { BtVelocityBeam0 = (short)(Math.Round(bt.BeamVelocity[0] * 1000.0f)); // mm/s to m/s } else { // Bad velocity BtVelocityBeam0 = PD0.BAD_VELOCITY; } } break; default: break; } #endregion #region Correlation // 4 Beam System if (bt.NumBeams >= PD0.NUM_BEAMS) { // beam order 3,2,0,1 BtCorrelationMagnitudeBeam0 = (byte)(Math.Round(bt.Correlation[3] * 255.0f)); if (BtCorrelationMagnitudeBeam0 > PD0.BAD_CORRELATION) { BtCorrelationMagnitudeBeam0 = PD0.BAD_CORRELATION; } BtCorrelationMagnitudeBeam1 = (byte)(Math.Round(bt.Correlation[2] * 255.0f)); if (BtCorrelationMagnitudeBeam1 > PD0.BAD_CORRELATION) { BtCorrelationMagnitudeBeam1 = PD0.BAD_CORRELATION; } BtCorrelationMagnitudeBeam2 = (byte)(Math.Round(bt.Correlation[0] * 255.0f)); if (BtCorrelationMagnitudeBeam2 > PD0.BAD_CORRELATION) { BtCorrelationMagnitudeBeam2 = PD0.BAD_CORRELATION; } BtCorrelationMagnitudeBeam3 = (byte)(Math.Round(bt.Correlation[1] * 255.0f)); if (BtCorrelationMagnitudeBeam3 > PD0.BAD_CORRELATION) { BtCorrelationMagnitudeBeam3 = PD0.BAD_CORRELATION; } } // Vertical Beam else if (bt.NumBeams == 1) { BtCorrelationMagnitudeBeam0 = (byte)(Math.Round(bt.Correlation[0] * 255.0f)); if (BtCorrelationMagnitudeBeam0 > PD0.BAD_CORRELATION) { BtCorrelationMagnitudeBeam0 = PD0.BAD_CORRELATION; } } #endregion #region Evaluation Amplitude // 4 Beam System if (bt.NumBeams >= PD0.NUM_BEAMS) { // beam order 3,2,0,1 BtAmplitudeBeam0 = (byte)(Math.Round(bt.SNR[3] * 2.0f)); //0.5 counts per dB if (BtAmplitudeBeam0 > PD0.BAD_AMPLITUDE) { BtAmplitudeBeam0 = PD0.BAD_AMPLITUDE; } BtAmplitudeBeam1 = (byte)(Math.Round(bt.SNR[2] * 2.0f)); //0.5 counts per dB if (BtAmplitudeBeam1 > PD0.BAD_AMPLITUDE) { BtAmplitudeBeam1 = PD0.BAD_AMPLITUDE; } BtAmplitudeBeam2 = (byte)(Math.Round(bt.SNR[0] * 2.0f)); //0.5 counts per dB if (BtAmplitudeBeam2 > PD0.BAD_AMPLITUDE) { BtAmplitudeBeam2 = PD0.BAD_AMPLITUDE; } BtAmplitudeBeam3 = (byte)(Math.Round(bt.SNR[1] * 2.0f)); //0.5 counts per dB if (BtAmplitudeBeam3 > PD0.BAD_AMPLITUDE) { BtAmplitudeBeam3 = PD0.BAD_AMPLITUDE; } } // Vertical Beam else if (bt.NumBeams == 1) { BtAmplitudeBeam0 = (byte)(Math.Round(bt.SNR[0] * 2.0f)); //0.5 counts per dB if (BtAmplitudeBeam0 > PD0.BAD_AMPLITUDE) { BtAmplitudeBeam0 = PD0.BAD_AMPLITUDE; } } #endregion #region Percent Good // 4 Beam System if (bt.NumBeams >= PD0.NUM_BEAMS) { // beam order 3,2,0,1 BtPercentGoodBeam0 = (byte)(Math.Round((bt.EarthGood[3] * 100.0f) / BtPingsPerEnsemble)); if (BtPercentGoodBeam0 > PD0.BAD_PERCENT_GOOD) { BtPercentGoodBeam0 = PD0.BAD_PERCENT_GOOD; } BtPercentGoodBeam1 = (byte)(Math.Round((bt.EarthGood[2] * 100.0f) / BtPingsPerEnsemble)); if (BtPercentGoodBeam1 > PD0.BAD_PERCENT_GOOD) { BtPercentGoodBeam1 = PD0.BAD_PERCENT_GOOD; } BtPercentGoodBeam2 = (byte)(Math.Round((bt.EarthGood[0] * 100.0f) / BtPingsPerEnsemble)); if (BtPercentGoodBeam2 > PD0.BAD_PERCENT_GOOD) { BtPercentGoodBeam2 = PD0.BAD_PERCENT_GOOD; } BtPercentGoodBeam3 = (byte)(Math.Round((bt.EarthGood[1] * 100.0f) / BtPingsPerEnsemble)); if (BtPercentGoodBeam3 > PD0.BAD_PERCENT_GOOD) { BtPercentGoodBeam3 = PD0.BAD_PERCENT_GOOD; } } // Vertical Beam else if (bt.NumBeams == 1) { BtPercentGoodBeam0 = (byte)(Math.Round((bt.EarthGood[0] * 100.0f) / BtPingsPerEnsemble)); if (BtPercentGoodBeam0 > PD0.BAD_PERCENT_GOOD) { BtPercentGoodBeam0 = PD0.BAD_PERCENT_GOOD; } } #endregion #region Reference Layer BtRefLayerFar = 0; BtRefLayerMin = 0; BtRefLayerNear = 0; BtRefLayerVelocityBeam0 = 0; BtRefLayerVelocityBeam1 = 0; BtRefLayerVelocityBeam2 = 0; BtRefLayerVelocityBeam3 = 0; BtRefLayerCorrBeam0 = 0; BtRefLayerCorrBeam1 = 0; BtRefLayerCorrBeam2 = 0; BtRefLayerCorrBeam3 = 0; BtRefLayerEchoIntensityBeam0 = 0; BtRefLayerEchoIntensityBeam1 = 0; BtRefLayerEchoIntensityBeam2 = 0; BtRefLayerEchoIntensityBeam3 = 0; BtRefLayerEchoIntensityBeam0 = 0; BtRefLayerEchoIntensityBeam1 = 0; BtRefLayerEchoIntensityBeam2 = 0; BtRefLayerEchoIntensityBeam3 = 0; #endregion BtMaxDepth = 0; // Max Depth - CBTMX - Do not have enough info #region RSSI // 4 Beam System if (bt.NumBeams >= PD0.NUM_BEAMS) { // beam order 3,2,0,1 BtRssiBeam0 = bt.Amplitude[3] * 2.0f; //0.5 counts per dB if (BtRssiBeam0 > PD0.BAD_AMPLITUDE) { BtRssiBeam0 = PD0.BAD_AMPLITUDE; } BtRssiBeam1 = bt.Amplitude[2] * 2.0f; //0.5 counts per dB if (BtRssiBeam1 > PD0.BAD_AMPLITUDE) { BtRssiBeam1 = PD0.BAD_AMPLITUDE; } BtRssiBeam2 = bt.Amplitude[0] * 2.0f; //0.5 counts per dB if (BtRssiBeam2 > PD0.BAD_AMPLITUDE) { BtRssiBeam2 = PD0.BAD_AMPLITUDE; } BtRssiBeam3 = bt.Amplitude[1] * 2.0f; //0.5 counts per dB if (BtRssiBeam3 > PD0.BAD_AMPLITUDE) { BtRssiBeam3 = PD0.BAD_AMPLITUDE; } } // Vertical Beam else if (bt.NumBeams == 1) { BtRssiBeam0 = bt.Amplitude[0] * 2.0f; //0.5 counts per dB if (BtRssiBeam0 > PD0.BAD_AMPLITUDE) { BtRssiBeam0 = PD0.BAD_AMPLITUDE; } } #endregion BtGain = 0x01; // Gain Reserved82_85 = 0; // Reserved }
/// <summary> /// Initialize the data type. /// Take the RTI data sets to /// initialize the object. /// </summary> /// <param name="ens">RTI Ensemble aata set.</param> /// <param name="anc">RTI Ancillary data set.</param> /// <param name="sysSetup">SystemSetup data set.</param> /// <param name="xform">Coordinate transform used for this ensemble.</param> public Pd0FixedLeader(DataSet.EnsembleDataSet ens, DataSet.AncillaryDataSet anc, DataSet.SystemSetupDataSet sysSetup, PD0.CoordinateTransforms xform) : base(ID_LSB, ID_MSB, Pd0ID.Pd0Types.FixedLeader) { Initialize(); DecodeRtiEnsemble(ens, anc, sysSetup, xform); }
public void TestDecodeVelocityPg() { PD0 pd0 = new PD0(); pd0.FixedLeader.NumberOfCells = 5; #region Velocity Pd0Velocity vel = new Pd0Velocity(); // 2 Byte Header // 8 Bytes per depth cell // 4 Beams per depth cell // 2 Bytes per beam byte[] velData = new byte[42]; velData[0] = Pd0Velocity.ID_LSB; velData[1] = Pd0Velocity.ID_MSB; velData[2] = 0xE8; // DS0 Beam 0 LSB velData[3] = 0x00; // DS0 Beam 0 MSB velData[4] = 0xBD; // DS0 Beam 1 LSB velData[5] = 0xFE; // DS0 Beam 1 MSB velData[6] = 0xC8; // DS0 Beam 2 LSB velData[7] = 0x01; // DS0 Beam 2 MSB velData[8] = 0x72; // DS0 Beam 3 LSB velData[9] = 0xFD; // DS0 Beam 3 MSB velData[(4 * 8) + 2 + 0] = 0xD0; // DS4 Beam 0 LSB velData[(4 * 8) + 2 + 1] = 0x04; // DS4 Beam 0 MSB velData[(4 * 8) + 2 + 2] = 0xD5; // DS4 Beam 1 LSB velData[(4 * 8) + 2 + 3] = 0xFA; // DS4 Beam 1 MSB velData[(4 * 8) + 2 + 4] = 0xB0; // DS4 Beam 2 LSB velData[(4 * 8) + 2 + 5] = 0x05; // DS4 Beam 2 MSB velData[(4 * 8) + 2 + 6] = 0x8A; // DS4 Beam 3 LSB velData[(4 * 8) + 2 + 7] = 0xF9; // DS4 Beam 3 MSB vel.Decode(velData); #endregion pd0.AddDataType(vel); // Add Velocity #region Percent Good Pd0PercentGood pg = new Pd0PercentGood(); // 2 Byte Header // 4 Bytes per depth cell // 4 Beams per depth cell // 2 Bytes per beam byte[] pgData = new byte[22]; pgData[0] = Pd0PercentGood.ID_LSB; pgData[1] = Pd0PercentGood.ID_MSB; pgData[2] = 0xE8; // DS0 Beam 0 pgData[3] = 0x7B; // DS0 Beam 1 pgData[4] = 0x7A; // DS0 Beam 2 pgData[5] = 0xDF; // DS0 Beam 3 pgData[(4 * 4) + 2 + 0] = 0x6F; // DS4 Beam 0 pgData[(4 * 4) + 2 + 1] = 0xDE; // DS4 Beam 1 pgData[(4 * 4) + 2 + 2] = 0x15; // DS4 Beam 2 pgData[(4 * 4) + 2 + 3] = 0x22; // DS4 Beam 3 pg.Decode(pgData); #endregion pd0.AddDataType(pg); // Add Percent Good byte[] data = pd0.Encode(); // Size int size = Pd0VariableLeader.DATATYPE_SIZE; size += Pd0FixedLeader.DATATYPE_SIZE; size += 2; // Spare //size += 2; // Checksum size += pd0.Header.GetDataTypeSize(); size += pd0.Velocity.GetDataTypeSize(); size += pd0.PercentGood.GetDataTypeSize(); Assert.AreEqual(4, pd0.Header.NumberOfDataTypes(), "Number of Data Types is incorrect."); Assert.AreEqual(5, pd0.Header.NumberOfDepthCells, "Number of depth cells is incorrect."); Assert.AreEqual(size, MathHelper.LsbMsbShort(data[2], data[3]), "Number of Bytes is incorrect."); Assert.AreEqual(4, data[5], "Number of Data Types is incorrect."); Assert.AreEqual(size + 2, data.Length, "Array Size is incorrect."); // Add 2 for the checksum int flOffset = pd0.Header.GetDataTypeSize(); Assert.AreEqual(flOffset, MathHelper.LsbMsbShort(data[6], data[7]), "Fixed Leader offset is incorrect."); int vlOffset = pd0.Header.GetDataTypeSize() + Pd0FixedLeader.DATATYPE_SIZE; Assert.AreEqual(vlOffset, MathHelper.LsbMsbShort(data[8], data[9]), "Variable Leader offset is incorrect."); int velOffset = pd0.Header.GetDataTypeSize() + Pd0FixedLeader.DATATYPE_SIZE + Pd0VariableLeader.DATATYPE_SIZE; Assert.AreEqual(velOffset, MathHelper.LsbMsbShort(data[10], data[11]), "Velocity offset is incorrect."); int pgOffset = pd0.Header.GetDataTypeSize() + Pd0FixedLeader.DATATYPE_SIZE + Pd0VariableLeader.DATATYPE_SIZE + pd0.Velocity.GetDataTypeSize(); Assert.AreEqual(pgOffset, MathHelper.LsbMsbShort(data[12], data[13]), "Percent Good offset is incorrect."); }
/// <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); if (ProcessDataEvent != null) { // Pass the data to the subscribers ProcessDataEvent(binaryEnsemble, rtiEns); } _pd0Counter++; // Check which buffers to clear CheckCodecBuffers(CodecEnum.PD0); }
/// <summary> /// Convert the given binary data into an ensemble. /// Then publish the data to all subscribers. /// </summary> /// <param name="binaryEnsemble">Binary PD0 data.</param> private void DecodePd0Data(byte[] binaryEnsemble) { // Create the PD0 and RTI ensemble PD0 pd0Ensemble = new PD0(binaryEnsemble); // Send an event that data was processed // in this format if (ProcessDataEvent != null) { ProcessDataEvent(binaryEnsemble, pd0Ensemble); } }
public void TestDecodeVelocity() { PD0 pd0 = new PD0(); pd0.FixedLeader.NumberOfCells = 5; #region Velocity Pd0Velocity vel = new Pd0Velocity(); // 2 Byte Header // 8 Bytes per depth cell // 4 Beams per depth cell // 2 Bytes per beam byte[] velData = new byte[42]; velData[0] = Pd0Velocity.ID_LSB; velData[1] = Pd0Velocity.ID_MSB; velData[2] = 0xE8; // DS0 Beam 0 LSB velData[3] = 0x00; // DS0 Beam 0 MSB velData[4] = 0xBD; // DS0 Beam 1 LSB velData[5] = 0xFE; // DS0 Beam 1 MSB velData[6] = 0xC8; // DS0 Beam 2 LSB velData[7] = 0x01; // DS0 Beam 2 MSB velData[8] = 0x72; // DS0 Beam 3 LSB velData[9] = 0xFD; // DS0 Beam 3 MSB velData[(4 * 8) + 2 + 0] = 0xD0; // DS4 Beam 0 LSB velData[(4 * 8) + 2 + 1] = 0x04; // DS4 Beam 0 MSB velData[(4 * 8) + 2 + 2] = 0xD5; // DS4 Beam 1 LSB velData[(4 * 8) + 2 + 3] = 0xFA; // DS4 Beam 1 MSB velData[(4 * 8) + 2 + 4] = 0xB0; // DS4 Beam 2 LSB velData[(4 * 8) + 2 + 5] = 0x05; // DS4 Beam 2 MSB velData[(4 * 8) + 2 + 6] = 0x8A; // DS4 Beam 3 LSB velData[(4 * 8) + 2 + 7] = 0xF9; // DS4 Beam 3 MSB vel.Decode(velData); #endregion pd0.AddDataType(vel); // Add Velocity byte[] data = pd0.Encode(); // Size int size = Pd0VariableLeader.DATATYPE_SIZE; size += Pd0FixedLeader.DATATYPE_SIZE; size += 2; // Spare //size += 2; // Checksum size += pd0.Header.GetDataTypeSize(); size += pd0.Velocity.GetDataTypeSize(); Assert.AreEqual(3, pd0.Header.NumberOfDataTypes(), "Number of Data Types is incorrect."); Assert.AreEqual(5, pd0.Header.NumberOfDepthCells, "Number of depth cells is incorrect."); Assert.AreEqual(size, MathHelper.LsbMsbShort(data[2], data[3]), "Number of Bytes is incorrect."); Assert.AreEqual(3, data[5], "Number of Data Types is incorrect."); Assert.AreEqual(size + 2, data.Length, "Array Size is incorrect."); // Add 2 for the checksum int flOffset = pd0.Header.GetDataTypeSize(); Assert.AreEqual(flOffset, MathHelper.LsbMsbShort(data[6], data[7]), "Fixed Leader offset is incorrect."); int vlOffset = pd0.Header.GetDataTypeSize() + Pd0FixedLeader.DATATYPE_SIZE; Assert.AreEqual(vlOffset, MathHelper.LsbMsbShort(data[8], data[9]), "Variable Leader offset is incorrect."); int velOffset = pd0.Header.GetDataTypeSize() + Pd0FixedLeader.DATATYPE_SIZE + Pd0VariableLeader.DATATYPE_SIZE; Assert.AreEqual(velOffset, MathHelper.LsbMsbShort(data[10], data[11]), "Velocity offset is incorrect."); }
public void TestEncodeVelCorrEcho() { PD0 pd0 = new PD0(); pd0.FixedLeader.NumberOfCells = 5; Pd0Velocity vel = new Pd0Velocity(5); vel.Velocities[0, 0] = 32; vel.Velocities[0, 1] = -32; pd0.AddDataType(vel); Pd0Correlation corr = new Pd0Correlation(5); corr.Correlation[0, 0] = 32; corr.Correlation[0, 1] = 255; pd0.AddDataType(corr); Pd0EchoIntensity ei = new Pd0EchoIntensity(5); ei.EchoIntensity[0, 0] = 32; ei.EchoIntensity[0, 1] = 255; pd0.AddDataType(ei); byte[] encode = pd0.Encode(); int flOffset = pd0.Header.GetFixedLeader().Offset; int velOffset = pd0.Header.GetVelocity().Offset; int corrOffset = pd0.Header.GetCorrelation().Offset; int eiOffset = pd0.Header.GetEchoIntensity().Offset; Assert.AreEqual(0, encode[flOffset], "Fixed Leader ID LSB is incorrect"); Assert.AreEqual(0, encode[flOffset + 1], "Fixed Leader ID MSB is incorrect"); Assert.AreEqual(5, encode[flOffset + 9], "Number of depth cells is incorrect"); Assert.AreEqual(32, MathHelper.LsbMsbShort(encode[velOffset + 2], encode[velOffset + 3]), "Velocity Bin 0, Beam 0 is incorrect."); Assert.AreEqual(-32, MathHelper.LsbMsbShort(encode[velOffset + 4], encode[velOffset + 5]), "Velocity Bin 0, Beam 1 is incorrect."); Assert.AreEqual(32, encode[corrOffset + 2], "Correlation Bin 0, Beam 0 is incorrect."); Assert.AreEqual(255, encode[corrOffset + 3], "Correlation Bin 0, Beam 1 is incorrect."); Assert.AreEqual(32, encode[eiOffset + 2], "Echo Intensity Bin 0, Beam 0 is incorrect."); Assert.AreEqual(255, encode[eiOffset + 3], "Echo Intensity Bin 0, Beam 1 is incorrect."); Assert.IsFalse(pd0.IsBottomTrackExist, "IsBottomTrackExist is incorrect."); Assert.IsTrue(pd0.IsCorrelationExist, "IsCorrelationExist is incorrect."); Assert.IsTrue(pd0.IsEchoIntensityExist, "IsEchoIntensityExist is incorrect."); Assert.IsFalse(pd0.IsPercentGoodExist, "IsPercentGoodExist is incorrect."); }
/// <summary> /// Decode the incoming data for ensemble data. /// First search for header. When a header is found, /// verify it is a good header. When the header is /// verified, get the payload size. Determine the /// buffer contains the entire ensemble. If the /// entire ensemble is present in the buffer, retreive /// the ensemble and place in a seperate byte array /// and remove it from the buffer. Then decode the /// ensemble for all the ranges present. /// </summary> private void DecodeIncomingData() { // Find the beginning of an ensemble // It will contain 2 0x7F at the start SearchForHeaderStart(); // Verify the incoming data can at least fit the header if (_incomingDataBuffer.Count > Pd0Header.HEADER_MIN_BYTE) { // If found 2 bytes of 0x7F // Continue forward // Find ensemble number and ensemble size if (VerifyHeaderStart()) { // Get Ensemble size int currentEnsembleSize = GetEnsembleSize(); // Ensure the entire ensemble is present // before proceeding if (_incomingDataBuffer.Count >= currentEnsembleSize && currentEnsembleSize > 0) { // Create an array to hold the ensemble byte[] ensemble = new byte[currentEnsembleSize]; // Lock the buffer, to ensure the same data is copied lock (_bufferLock) { // Check one more time just in case the buffer was modified if (_incomingDataBuffer.Count >= currentEnsembleSize) { // Copy the ensemble to a byte array _incomingDataBuffer.CopyTo(0, ensemble, 0, currentEnsembleSize); // Remove ensemble from buffer _incomingDataBuffer.RemoveRange(0, currentEnsembleSize); } } // Get the checksum values ushort calculatedChecksum = PD0.CalculateChecksum(ensemble, currentEnsembleSize - PD0.CHECKSUM_NUM_BYTE); ushort ensembleChecksum = RetrieveEnsembleChecksum(ensemble); // Verify the checksum match if (calculatedChecksum == ensembleChecksum) { // Decode the binary data DecodePd0Data(ensemble); } } } else { // Lock the buffer while removing lock (_bufferLock) { if (_incomingDataBuffer.Count > 0) { // Remove the first element to continue searching _incomingDataBuffer.RemoveAt(0); } } } } }
/// <summary> /// Set the Coordinate Transform based off the value given. /// </summary> /// <param name="xform">Coordinate Transform to set.</param> public void SetCoordinateTransform(PD0.CoordinateTransforms xform) { switch (xform) { case PD0.CoordinateTransforms.Coord_Beam: // 00 CoordinateTransform = MathHelper.ZeroBitByte(CoordinateTransform, 3); CoordinateTransform = MathHelper.ZeroBitByte(CoordinateTransform, 4); break; case PD0.CoordinateTransforms.Coord_Instrument: // 01 CoordinateTransform = MathHelper.SetBitByte(CoordinateTransform, 3); CoordinateTransform = MathHelper.ZeroBitByte(CoordinateTransform, 4); break; case PD0.CoordinateTransforms.Coord_Ship: // 10 CoordinateTransform = MathHelper.ZeroBitByte(CoordinateTransform, 3); CoordinateTransform = MathHelper.SetBitByte(CoordinateTransform, 4); break; case PD0.CoordinateTransforms.Coord_Earth: // 11 CoordinateTransform = MathHelper.SetBitByte(CoordinateTransform, 3); CoordinateTransform = MathHelper.SetBitByte(CoordinateTransform, 4); break; } }
/// <summary> /// Convert the RTI Ancillary and Ensemble data set to the PD0 Fixed Leader data type. /// </summary> /// <param name="ens">RTI Ensemble data set.</param> /// <param name="anc">RTI Ancillary data set.</param> /// <param name="sysSetup">SystemSetup data set.</param> /// <param name="xform">Coordinate Transform.</param> public void DecodeRtiEnsemble(DataSet.EnsembleDataSet ens, DataSet.AncillaryDataSet anc, DataSet.SystemSetupDataSet sysSetup, PD0.CoordinateTransforms xform) { // Ensure the values were given, or create default values if (ens == null) { ens = new DataSet.EnsembleDataSet(); } if (anc == null) { anc = new DataSet.AncillaryDataSet(); } if (sysSetup == null) { sysSetup = new DataSet.SystemSetupDataSet(); } CpuFirmwareVersion = (byte)ens.SysFirmware.FirmwareMinor; // Firmware Major CpuFirmwareRevision = (byte)ens.SysFirmware.FirmwareRevision; // Firmware Minor switch(ens.SubsystemConfig.SubSystem.GetSystemFrequency()) { case Subsystem.SystemFrequency.Freq_75kHz: SetSystemFrequency(SystemFrequency.Freq_75kHz); // 75 kHz Set30DegreeBeamAngle(); // 30 Degree Beam Angle SetBeamConfiguration(BeamConfigs.BeamConfig_4_Beam_Janus); // 4 Beam Janus SetConvex(); // Set Convex SetSensorConfig1(); // Set Sensor Config 1 SetHeadAttached(); // Set Head Attached break; case Subsystem.SystemFrequency.Freq_150kHz: SetSystemFrequency(SystemFrequency.Freq_150kHz); // 150 kHz Set30DegreeBeamAngle(); // 20 Degree Beam Angle SetBeamConfiguration(BeamConfigs.BeamConfig_4_Beam_Janus); // 4 Beam Janus SetConvex(); // Set Convex SetSensorConfig1(); // Set Sensor Config 1 SetHeadAttached(); // Set Head Attached break; case Subsystem.SystemFrequency.Freq_300kHz: SetSystemFrequency(SystemFrequency.Freq_300kHz); // 300 kHz Set20DegreeBeamAngle(); // 20 Degree Beam Angle SetBeamConfiguration(BeamConfigs.BeamConfig_4_Beam_Janus); // 4 Beam Janus SetConvex(); // Set Convex SetSensorConfig1(); // Set Sensor Config 1 SetHeadAttached(); // Set Head Attached break; case Subsystem.SystemFrequency.Freq_600kHz: SetSystemFrequency(SystemFrequency.Freq_600kHz); // 600 kHz Set20DegreeBeamAngle(); // 20 Degree Beam Angle SetBeamConfiguration(BeamConfigs.BeamConfig_4_Beam_Janus); // 4 Beam Janus SetConvex(); // Set Convex SetSensorConfig1(); // Set Sensor Config 1 SetHeadAttached(); // Set Head Attached break; case Subsystem.SystemFrequency.Freq_1200kHz: SetSystemFrequency(SystemFrequency.Freq_1200kHz); // 1200 kHz Set20DegreeBeamAngle(); // 20 Degree Beam Angle SetBeamConfiguration(BeamConfigs.BeamConfig_4_Beam_Janus); // 4 Beam Janus SetConvex(); // Set Convex SetSensorConfig1(); // Set Sensor Config 1 SetHeadAttached(); // Set Head Attached break; case Subsystem.SystemFrequency.Freq_2000kHz: SetSystemFrequency(SystemFrequency.Freq_2400kHz); // 2400 kHz Set20DegreeBeamAngle(); // 20 Degree Beam Angle SetBeamConfiguration(BeamConfigs.BeamConfig_4_Beam_Janus); // 4 Beam Janus SetConvex(); // Set Convex SetSensorConfig1(); // Set Sensor Config 1 SetHeadAttached(); // Set Head Attached break; case Subsystem.SystemFrequency.Freq_38kHz: default: break; } if (anc.Roll < 90 && anc.Roll > -90) { SetBeamsUpward(); // Set Beams Upward } else { SetBeamsDownward(); // Set Beams Downward } RealSimFlag = false; LagLength = 0; // Lag Length NumberOfBeams = (byte)ens.NumBeams; // Number of Beams NumberOfCells = (byte)ens.NumBins; // Number of bins PingsPerEnsemble = (ushort)ens.ActualPingCount; // Pings per ensemble DepthCellLength = (ushort)Math.Round(anc.BinSize * 100); // Depth Cell length BlankAfterTransmit = 0; // Blank - CWPBL - Do not have enough info ProfilingMode = 0; // Signal Processing Mode - CWPBB - Do not have enough info LowCorrThresh = 0; // Low Correlation Threshold - CWPCT - Do not have enough info NumCodeRepeats = (byte)sysSetup.WpRepeatN; // Number of Code Repeats PercentGoodMinimum = 0; // Percent Good Minimum - Do not have enough info ErrorVelMaximum = 0; // Error Velocity Maximum - Do not have enough info TimeBetweenPingMinutes = 0; // Time Between Pings Minutes - CWPTBP - Do not have enough info TimeBetweenPingSeconds = 0; // Time Between Pings Seconds - CWPTBP - Do not have enough info TimeBetweenPingHundredths = 0; // Time Between Pings Hundredths -CWPTBP - Do not have enough info SetCoordinateTransform(xform); // Set Coordinate Transform HeadingAlignment = 0; // Heading alignment HeadingBias = 0; // Heading Bias SensorSource = 0x5d; // Sensor Source SensorsAvailable = 0x5d; // Sensors Available Bin1Distance = (ushort)Math.Round(anc.FirstBinRange * 100); // Bin 1 distance XmitPulseLength = 0; // Transmit Pulse Length - Do not have enough info ReferenceLayerAverageStartCell = 0; // Reference Layer Average Start Cell - Do not have enough info ReferenceLayerAverageEndCell = 0; // Reference Layer Average End Cell - Do not have enough info FalseTargetThresh = 0; // False Target Threshold Spare_40 = 0xFE; // Spare TransmitLagDistance = 0; // Lag Distance - CWPLL - Do not have enough info CpuBoardSerialNumber = ens.SysSerialNumber.ToString(); // CPU Board Serial Number SystemBandwidth = 12; // System Bandwidth SystemPower = 0; // System Power BaseFrequencyIndex = 0; // Base Frequency Index BeamAngle = 0; // Beam Angle }
/// <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); }