/// <summary> /// Initialize the PD0 Data Type. /// </summary> /// <param name="lsb">LSB ID.</param> /// <param name="msb">MSB ID.</param> /// <param name="type">PD0 Data Type.</param> public Pd0DataType(byte lsb, byte msb, Pd0ID.Pd0Types type) { // Set the ID ID = new Pd0ID(lsb, msb, type); Offset = 0; }
/// <summary> /// Decode the given data into an object. /// </summary> /// <param name="data">Data to decode.</param> /// <param name="numDepthCells">NOT USED.</param> /// <param name="numBeams">NOT USED</param> public void Decode(byte[] data, int numDepthCells = 0, int numBeams = 4) { try { if (data.Length > HEADER_MIN_BYTE) { // Ensure the correct data type is given if (data[0] == ID_LSB && data[1] == ID_MSB) { // Number of bytes NumberOfBytes = MathHelper.LsbMsbInt(data[2], data[3]); //DataTypes.Clear(); // Clear anything currently stored int numDT = data[5]; // Number of Data types int dtOffset = HEADER_MIN_BYTE; // Start of the offsets RTI.PD0.CoordinateTransforms xform = RTI.PD0.CoordinateTransforms.Coord_Earth; // Determine the size of each data type. // This will start at the end of the header //int prevOffset = dtOffset + (numDT * SHORT_NUM_BYTE); // Collect each offset for (int x = 0; x < numDT; x++) { // Get the offset and add it to the list byte lsb = data[dtOffset]; byte msb = data[dtOffset + 1]; ushort offset = MathHelper.LsbMsbUShort(lsb, msb); if (data.Length > offset) { // Determine the data type byte lsbID = data[offset]; byte msbID = data[offset + 1]; Pd0ID id = Pd0ID.GetType(lsbID, msbID); // Set the XFORM // Create and add the data type to the ensemble switch (id.Type) { case Pd0ID.Pd0Types.FixedLeader: // Copy the buffer byte[] flBuffer = new byte[Pd0FixedLeader.DATATYPE_SIZE]; Buffer.BlockCopy(data, offset, flBuffer, 0, flBuffer.Length); if (DataTypes.ContainsKey(Pd0ID.Pd0Types.FixedLeader)) { GetFixedLeader().Decode(flBuffer); xform = GetFixedLeader().GetCoordinateTransform(); } else { AddDataType(new Pd0FixedLeader(flBuffer, offset)); } break; case Pd0ID.Pd0Types.VariableLeader: // Copy the buffer byte[] vlBuffer = new byte[Pd0VariableLeader.DATATYPE_SIZE]; Buffer.BlockCopy(data, offset, vlBuffer, 0, vlBuffer.Length); if (DataTypes.ContainsKey(Pd0ID.Pd0Types.VariableLeader)) { GetVariableLeader().Decode(vlBuffer); } else { AddDataType(new Pd0VariableLeader(vlBuffer, offset)); } break; case Pd0ID.Pd0Types.BottomTrack: // Copy the buffer byte[] btBuffer = new byte[Pd0BottomTrack.DATATYPE_SIZE]; Buffer.BlockCopy(data, offset, btBuffer, 0, btBuffer.Length); // Decode the data if (DataTypes.ContainsKey(Pd0ID.Pd0Types.BottomTrack)) { GetBottomTrack().Decode(btBuffer, GetFixedLeader().NumberOfBeams); } else { AddDataType(new Pd0BottomTrack(btBuffer, offset, GetFixedLeader().NumberOfBeams)); } break; case Pd0ID.Pd0Types.Velocity: // Copy the buffer byte[] velBuffer = new byte[Pd0Velocity.GetVelocitySize(GetFixedLeader().NumberOfCells, GetFixedLeader().NumberOfBeams)]; Buffer.BlockCopy(data, offset, velBuffer, 0, velBuffer.Length); // Decode the data if (DataTypes.ContainsKey(Pd0ID.Pd0Types.Velocity)) { GetVelocity().Decode(velBuffer, GetFixedLeader().NumberOfCells, GetFixedLeader().NumberOfBeams); } else { AddDataType(new Pd0Velocity(velBuffer, offset, GetFixedLeader().NumberOfCells, GetFixedLeader().NumberOfBeams)); } break; case Pd0ID.Pd0Types.Correlation: // Copy the buffer byte[] corrBuffer = new byte[Pd0Correlation.GetCorrelationSize(GetFixedLeader().NumberOfCells, GetFixedLeader().NumberOfBeams)]; Buffer.BlockCopy(data, offset, corrBuffer, 0, corrBuffer.Length); // Decode the data if (DataTypes.ContainsKey(Pd0ID.Pd0Types.Correlation)) { GetCorrelation().Decode(corrBuffer, GetFixedLeader().NumberOfCells, GetFixedLeader().NumberOfBeams); } else { AddDataType(new Pd0Correlation(corrBuffer, offset, GetFixedLeader().NumberOfCells, GetFixedLeader().NumberOfBeams)); } break; case Pd0ID.Pd0Types.EchoIntensity: // Copy the buffer byte[] eiBuffer = new byte[Pd0EchoIntensity.GetEchoIntensitySize(GetFixedLeader().NumberOfCells, GetFixedLeader().NumberOfBeams)]; Buffer.BlockCopy(data, offset, eiBuffer, 0, eiBuffer.Length); // Decode the data if (DataTypes.ContainsKey(Pd0ID.Pd0Types.EchoIntensity)) { GetEchoIntensity().Decode(eiBuffer, GetFixedLeader().NumberOfCells, GetFixedLeader().NumberOfBeams); } else { AddDataType(new Pd0EchoIntensity(eiBuffer, offset, GetFixedLeader().NumberOfCells, GetFixedLeader().NumberOfBeams)); } break; case Pd0ID.Pd0Types.PercentGood: // Copy the buffer byte[] pgBuffer = new byte[Pd0PercentGood.GetPercentGoodSize(GetFixedLeader().NumberOfCells, GetFixedLeader().NumberOfBeams)]; Buffer.BlockCopy(data, offset, pgBuffer, 0, pgBuffer.Length); // Decode the data if (DataTypes.ContainsKey(Pd0ID.Pd0Types.PercentGood)) { GetPercentGood().Decode(pgBuffer, GetFixedLeader().NumberOfCells, GetFixedLeader().NumberOfBeams); } else { AddDataType(new Pd0PercentGood(pgBuffer, offset, GetFixedLeader().NumberOfCells, GetFixedLeader().NumberOfBeams)); } break; case Pd0ID.Pd0Types.NmeaData: // Get the Dataset Size // Get the first 6 bytes to determine the size // Number of bytes to read for NMEA size byte[] nmeaSize = new byte[6]; Buffer.BlockCopy(data, offset, nmeaSize, 0, 6); int nmeaDsSize = Pd0NmeaData.GetNmeaDataSize(nmeaSize); // Copy the buffer byte[] nmeaBuffer = new byte[nmeaDsSize]; Buffer.BlockCopy(data, offset, nmeaBuffer, 0, nmeaBuffer.Length); // Decode the data if (DataTypes.ContainsKey(Pd0ID.Pd0Types.NmeaData)) { GetNmeaData().Decode(nmeaBuffer); } else { AddDataType(new Pd0NmeaData(nmeaBuffer, offset)); } break; default: Debug.WriteLine(string.Format("Unknown PD0 ID {0}", id.Type)); break; } } // Move the offset to the next value dtOffset += 2; } } } } catch (Exception ex) { log.Error("Error Decoding PD0 Data. ", ex); } }