示例#1
0
        /// <summary>
        /// Initializes a new instance of the PingRecord class that contain the values extracted from the given byte array.
        /// </summary>
        /// <param name="byteArray">The size of array need to be at least of 256 bytes.</param>
        /// <param name="startByte">The first byte of this ping.</param>
        /// <param name="NumberOfSamples">The number of samples that are stored.</param>
        /// <param name="BytesPerSample">The quantity of bytes for each sample stored.</param>
        /// <param name="IsDataUnipolar">The polarity of the data.</param>
        public PingRecord(byte[] byteArray, UInt32 startByte, UInt32 NumberOfSamples, UInt16 BytesPerSample, bool IsDataUnipolar)
        {
            _channelHeaders = new List <PingChannelHeader>();
            _channelData    = new List <PingChannelData>();

            var bytesToEnd = byteArray.Length - startByte;

            if (bytesToEnd >= 320)
            {
                // Convert the array in a stream
                using (BinaryReader dp = new BinaryReader(ArrayToStream.BytesToMemory(byteArray)))
                {
                    // Read the PingHeader
                    dp.BaseStream.Seek(startByte, SeekOrigin.Begin);
                    _header = new PingHeader(dp.ReadBytes(256));

                    if (bytesToEnd >= _header.NumberBytesThisRecord)
                    {
                        for (int c = 0; c < _header.NumberChannelsToFollow; c++)
                        {
                            // Read the PingChannelHeader
                            _channelHeaders.Add(new PingChannelHeader(dp.ReadBytes(64)));

                            // Extract the bytes that contain the data
                            long   oft     = startByte + ((NumberOfSamples * BytesPerSample) * c) + ((c + 1) * 64);
                            byte[] chnData = byteArray.SubArray(oft, NumberOfSamples * BytesPerSample);

                            for (int d = 0; d < NumberOfSamples; d++)
                            {
                                chnData[d] = byteArray[d + oft];
                            }
                            // Read the PingChannelData
                            _channelData.Add(new PingChannelData(chnData, NumberOfSamples, BytesPerSample, IsDataUnipolar));
                            // Update the position in the stream
                            dp.ReadBytes((int)NumberOfSamples * BytesPerSample);
                        }
                    }
                }
            }
        }
示例#2
0
        /// <summary>
        /// Initializes a new instance of the XtfDocument class that contain the values extracted from the given byte array.
        /// </summary>
        /// <param name="byteArray"></param>
        public XtfDocument(Byte[] byteArray)
        {
            _MainHeader    = new XtfMainHeader();
            _Channels      = new List <ChannelInfo> {
            };
            _PacketIndexes = new List <IndexEntry> {
            };
            _Stats         = new StatCollection();

            if (byteArray.Length >= 1024)
            {
                using (BinaryReader dp = new BinaryReader(ArrayToStream.BytesToMemory(byteArray)))
                {
                    // Make sure to start from the first byte
                    dp.BaseStream.Seek(0, SeekOrigin.Begin);

                    // Read the header of the file.
                    _MainHeader = new XtfMainHeader(dp.ReadBytes(256));

                    // Read the channel data attacched to the header of the file.
                    _Channels.Clear();
                    int chnum = _MainHeader.NumberOfSonarChannels + _MainHeader.NumberOfBathymetryChannels - 1;
                    if (chnum >= 0)
                    {
                        if (chnum <= 6)
                        {
                            for (int i = 0; i <= chnum; i++)
                            {
                                _Channels.Add(new ChannelInfo(dp.ReadBytes(128)));
                            }
                        }
                        else
                        {
                            if (byteArray.Length >= 2048)
                            {
                                for (int i = 0; i <= chnum; i++)
                                {
                                    _Channels.Add(new ChannelInfo(dp.ReadBytes(128)));
                                }
                            }
                            else
                            {
                                for (int i = 0; i <= 6; i++)
                                {
                                    _Channels.Add(new ChannelInfo(dp.ReadBytes(128)));
                                }
                            }
                        }
                    }

                    UInt32 actualByte;
                    UInt32 totalBytes = (UInt32)byteArray.Length;

                    // Compute the dimension of the header.
                    if (_Channels.Count <= 6)
                    {
                        actualByte = 1024;
                    }
                    else
                    {
                        if (_Channels.Count <= 14)
                        {
                            actualByte = 2048;
                        }
                        else
                        {
                            actualByte = 3072;
                        }                           // Up to 22 channels seem to be more than enough.
                    }
                    // Make sure to start from the first packet after the header.
                    dp.BaseStream.Seek(actualByte - 1, SeekOrigin.Begin);

                    // read all the data packets
                    bool IsEndOfStream = false;
                    long bytesToEnd;

                    while (!IsEndOfStream)
                    {
                        try
                        {
                            // Explicit cast to fix the difference operator with uint values
                            bytesToEnd = (long)totalBytes - (long)actualByte;

                            if (bytesToEnd > 256)
                            {
                                PacketSniffer snif = new PacketSniffer(dp.ReadBytes(256));
                                if (snif.MagicNumber == MagicNumber)
                                {
                                    _PacketIndexes.Add(new IndexEntry(snif.HeaderType, actualByte));
                                    _Stats.AddPacket(snif);
                                    // Update the reading position
                                    actualByte = actualByte + snif.NumberBytesThisRecord;
                                    dp.BaseStream.Seek(actualByte - 1, SeekOrigin.Begin);
                                }
                                else
                                {
                                    // Update the reading position
                                    actualByte = actualByte + 1;
                                    dp.BaseStream.Seek(actualByte - 1, SeekOrigin.Begin);
                                }

                                IsEndOfStream = false;
                            }
                            else
                            {
                                if (bytesToEnd >= 64)
                                {
                                    PacketSniffer snif = new PacketSniffer(dp.ReadBytes(14));
                                    if (snif.MagicNumber == MagicNumber)
                                    {
                                        _PacketIndexes.Add(new IndexEntry(snif.HeaderType, actualByte));
                                        _Stats.AddPacket(snif);
                                        // Update the reading position
                                        actualByte = actualByte + snif.NumberBytesThisRecord;
                                        dp.BaseStream.Seek(actualByte - 1, SeekOrigin.Begin);
                                    }
                                    else
                                    {
                                        // Update the reading position
                                        actualByte = actualByte + 1;
                                        dp.BaseStream.Seek(actualByte - 1, SeekOrigin.Begin);
                                    }
                                    IsEndOfStream = true;
                                }
                                else
                                {
                                    IsEndOfStream = true;
                                }
                            }
                        }
                        catch
                        {
                            // Error
                        }
                    }
                }
            }
        }
示例#3
0
        /// <summary>
        /// Initializes a new instance of the XtfMainHeader class that contain the values extracted from the given byte array.
        /// </summary>
        /// <param name="byteArray">The size of array need to be at least of 256 bytes.</param>
        public XtfMainHeader(Byte[] byteArray)
        {
            _FileFormat              = 123;
            _SystemType              = 1;
            _RecordingProgramName    = "nd";
            _RecordingProgramVersion = "223";
            _SonarName    = "nd";
            _SonarType    = 0;
            _NoteString   = "nd";
            _ThisFileName = "nd";
            _NavigationCoordinateUnits      = 0;
            _NumberOfSonarChannels          = 0;
            _NumberOfBathymetryChannels     = 0;
            _NumberOfSnippetChannels        = 0;
            _NumberOfForwardLookArrays      = 0;
            _NumberOfEchoStrengthChannels   = 0;
            _NumberOfInterferometryChannels = 0;
            _ReferencePointHeight           = 0;
            _NavigationLatency   = 0;
            _NavigationOffsetY   = 0;
            _NavigationOffsetX   = 0;
            _NavigationOffsetZ   = 0;
            _NavigationOffsetYaw = 0;
            _MRUOffsetY          = 0;
            _MRUOffsetX          = 0;
            _MRUOffsetZ          = 0;
            _MRUOffsetYaw        = 0;
            _MRUOffsetPitch      = 0;
            _MRUOffsetRoll       = 0;

            if (byteArray.Length >= 256)
            {
                using (BinaryReader dp = new BinaryReader(ArrayToStream.BytesToMemory(byteArray)))
                {
                    _FileFormat              = dp.ReadByte();                           // 0
                    _SystemType              = dp.ReadByte();                           // 1
                    _RecordingProgramName    = new String(dp.ReadChars(8));             // 2-3-4-5-6-7-8-9
                    _RecordingProgramVersion = new String(dp.ReadChars(8));             // 10-11-12-13-14-15-16-17
                    _SonarName    = new String(dp.ReadChars(16));                       // 18-19-20-21-22-23-24-25-26-27-28-29-30-31-32-33
                    _SonarType    = dp.ReadUInt16();                                    // 34-35
                    _NoteString   = new String(dp.ReadChars(64));                       // 36 -> 99
                    _ThisFileName = new String(dp.ReadChars(64));                       // 100 -> 163
                    _NavigationCoordinateUnits      = (CoordinateUnits)dp.ReadUInt16(); // 164-165
                    _NumberOfSonarChannels          = dp.ReadUInt16();                  // 166-167
                    _NumberOfBathymetryChannels     = dp.ReadUInt16();                  // 168-169
                    _NumberOfSnippetChannels        = dp.ReadByte();                    // 170
                    _NumberOfForwardLookArrays      = dp.ReadByte();                    // 171
                    _NumberOfEchoStrengthChannels   = dp.ReadUInt16();                  // 172-173
                    _NumberOfInterferometryChannels = dp.ReadByte();                    // 174
                    dp.ReadByte();                                                      // 175 Reserved
                    dp.ReadUInt16();                                                    // 176-177 Reserved
                    _ReferencePointHeight = dp.ReadSingle();                            // 178-179-180-181
                    dp.ReadBytes(12);                                                   // 182 -> 193 ProjectionType Not currently used
                    dp.ReadBytes(10);                                                   // 194 -> 203 SpheroidType Not currently used
                    _NavigationLatency = dp.ReadInt32();                                // 204-205-206-207
                    dp.ReadSingle();                                                    // 208-209-210-211 OriginY Not currently used
                    dp.ReadSingle();                                                    // 212-213-214-215 OriginX Not currently used
                    _NavigationOffsetY   = dp.ReadSingle();                             // 216-217-218-219
                    _NavigationOffsetX   = dp.ReadSingle();                             // 220-221-222-223
                    _NavigationOffsetZ   = dp.ReadSingle();                             // 224-225-226-227
                    _NavigationOffsetYaw = dp.ReadSingle();                             // 228-229-230-231
                    _MRUOffsetY          = dp.ReadSingle();                             // 232-233-234-235
                    _MRUOffsetX          = dp.ReadSingle();                             // 236-237-238-239
                    _MRUOffsetZ          = dp.ReadSingle();                             // 240-241-242-243
                    _MRUOffsetYaw        = dp.ReadSingle();                             // 244-245-246-247
                    _MRUOffsetPitch      = dp.ReadSingle();                             // 248-249-250-251
                    _MRUOffsetRoll       = dp.ReadSingle();                             // 252-253-254-255
                }
            }

            #endregion contructors
        }
示例#4
0
        /// <summary>
        /// Initializes a new instance of the PacketSniffer class that contain the values extracted from the given byte array.
        /// </summary>
        /// <param name="byteArray">14 bytes array for basic information OR 256 byte for packet time.</param>
        public PacketSniffer(Byte[] byteArray)
        {
            _MagicNumber            = 0;
            _HeaderType             = 0;
            _SubChannelNumber       = 0;
            _NumberChannelsToFollow = 0;
            _NumberBytesThisRecord  = 0;
            _PacketTime             = DateTime.MinValue;
            _TimeTag = 0;

            using (BinaryReader pd = new BinaryReader(ArrayToStream.BytesToMemory(byteArray)))
            {
                if (byteArray.Length >= 14)
                {
                    // Read the basic information of the packet
                    XtfBasePacket basePkt = new XtfBasePacket(byteArray);

                    _MagicNumber            = basePkt.MagicNumber;
                    _HeaderType             = basePkt.HeaderType;
                    _SubChannelNumber       = basePkt.SubChannelNumber;
                    _NumberChannelsToFollow = basePkt.NumberChannelsToFollow;
                    _NumberBytesThisRecord  = basePkt.NumberBytesThisRecord;

                    if (byteArray.Length >= 256)
                    {
                        // Extract packet time from each packet type known
                        switch (HeaderType)
                        {
                        // Ping header packet types
                        case 0:
                        case 2:
                        case 4:
                        case 5:
                        case 8:
                        case 9:
                        case 10:
                        case 14:
                        case 16:
                        case 17:
                        case 18:
                        case 19:
                        case 22:
                        case 25:
                        case 27:
                        case 28:
                        case 60:
                        case 61:
                        case 62:
                        case 65:
                        case 66:
                        case 68:
                        case 69:
                        case 73:
                            PingHeader tmpHdr0 = new PingHeader(byteArray);
                            _PacketTime = tmpHdr0.PacketTime;
                            break;

                        // Notes - text annotation packet types
                        case 1:
                            Notes tmpHdr1 = new Notes(byteArray);
                            _PacketTime = tmpHdr1.PacketTime;
                            break;

                        // Attitude Data packet types
                        case 3:
                        case 103:
                            AttitudeData tmpHdr2 = new AttitudeData(byteArray);
                            _PacketTime = tmpHdr2.PacketTime;
                            _TimeTag    = tmpHdr2.TimeTag;
                            break;

                        // Raw Serial packet types
                        case 6:
                            RawSerialHeader tmpHdr3 = new RawSerialHeader(byteArray);
                            _PacketTime = tmpHdr3.PacketTime;
                            break;

                        // High speed sensor packet types
                        case 11:
                        case 15:
                            HighSpeedSensor tmpHdr4 = new HighSpeedSensor(byteArray);
                            _PacketTime = tmpHdr4.PacketTime;
                            break;

                        // Gyro packet types
                        case 23:
                        case 84:
                            Gyro tmpHdr5 = new Gyro(byteArray);
                            _PacketTime = tmpHdr5.PacketTime;
                            _TimeTag    = tmpHdr5.TimeTag;
                            break;

                        // QPS Singlebeam packet types
                        case 26:
                            QpsSingleBeam tmpHdr6 = new QpsSingleBeam(byteArray);
                            _PacketTime = tmpHdr6.PacketTime;
                            break;

                        // Navigation packet types
                        case 42:
                        case 100:
                            Navigation tmpHdr7 = new Navigation(byteArray);
                            _PacketTime = tmpHdr7.PacketTime;
                            _TimeTag    = tmpHdr7.TimeTag;
                            break;

                        // Pos Raw Navigation packet types
                        case 107:
                            PosRawNavigation tmpHdr8 = new PosRawNavigation(byteArray);
                            _PacketTime = tmpHdr8.PacketTime;
                            break;

                        // Navigation packet types
                        case 199:
                            RawCustomHeader tmpHdr9 = new RawCustomHeader(byteArray);
                            _PacketTime = tmpHdr9.PacketTime;
                            _TimeTag    = tmpHdr9.TimeTag;
                            break;

                        default:
                            break;
                        }
                    }
                }
            }
        }