Exemplo n.º 1
0
 /// <summary>
 /// Closes the current block file stream.
 /// </summary>
 /// <remarks>
 /// The reciever can still be used.
 /// Any new chuncks will start building a new file.
 /// </remarks>
 public void Close()
 {
     mClient.RaiseFrameReceivedEvent -= FrameReceivedEventHandler;
     mMemStream.Close();
     mMemStream        = null;
     mCRC              = 0;
     mCRCOk            = false;
     mFlags            = 0;
     mLastIndexWritten = 0;
 }
Exemplo n.º 2
0
        protected virtual void ProcessChunk1(byte[] data)
        {
            // collect the CRC
            if (data.Length > 1)
            {
                ushort crc = 0;

                // MSB CRC
                crc   = data[1];
                crc <<= 8;
                // LSB CRC
                crc |= data[0];

                if (crc != mCRC)
                {
                    mCRC = crc;

                    // may need a new block file
                    if (mCRCOk)
                    {
                        CreateMemoryStream();
                    }

                    mCRCOk = false;
                }
            }

            // try the flags field
            if (data.Length > 2)
            {
                mFlags = (CANLib.BlockFlags)data[2];
            }

            // have we got the version
            if (data.Length > 7 && (mFlags & CANLib.BlockFlags.VersionPresent) != 0)
            {
                mBlockVersion = data[7];
            }

            // have we got the size yet
            if (data.Length > 6)
            {
                if (!BitConverter.IsLittleEndian)
                {
                    Array.Reverse(data, 3, 4);
                }
                uint size = BitConverter.ToUInt32(data, 3);
                if (size != mSize)
                {
                    mSize = size;

                    // deal with null blocks
                    if (size == 0)
                    {
                        mLastIndexWritten = 0;
                        mCRCOk            = true;
                        BlockCompleted();
                    }
                    else
                    {
                        // may need a new block file
                        if (mCRCOk)
                        {
                            CreateMemoryStream(size);
                        }

                        mCRCOk = false;
                    }
                }
            }
        }