Esempio n. 1
0
        /// <summary>
        /// This get method return a new frame object for a given bytestream and frame object's version attribute number
        /// </summary>
        /// <param name="size"> Parse Frame according to size </param>
        /// <param name="bytestream"> Input Byte Stream for parsing </param>
        /// <param name="newFrame"> Output a new FrameObject </param>
        public static void SvaFrameParser(uint size, byte[] bytestream, out FrameObject newFrame)
        {
            FrameObject currentframe = new FrameObject();

            // Default Version is 1.0 = 10;
            currentframe.FieldOne = uint.MaxValue;
            currentframe.FieldTwo = uint.MinValue;


            ushort[] testbytes = { 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00 };
            currentframe.FieldThree = testbytes;

            //append addition fields using a special switch case
            while ((uint)size != 256U)
            {
                currentframe.FieldFour = uint.MaxValue;
                if ((uint)size == 512U)
                {
                    break;
                }
                currentframe.FieldFive = uint.MaxValue;
                if ((uint)size == 1024U)
                {
                    break;
                }
                currentframe.FieldSix = uint.MaxValue;
                if ((uint)size == 2048U)
                {
                    break;
                }
                currentframe.FieldSeven = uint.MaxValue;
                if ((uint)size == 4096U)
                {
                    break;
                }
            }

            newFrame = currentframe.ShallowCopy();
        }
Esempio n. 2
0
        public TctFileReader(string filepath)
        {
            #region BackgroundWorker
            byte[] versionInBytes = new byte[20];
            try
            {
                if (File.Exists(filepath))
                {
                    throw new FileNotFoundException();
                }

                SourceStream = File.Open(filepath, FileMode.Open, FileAccess.Read);

                if (!SourceStream.CanRead || !SourceStream.CanSeek)
                {
                    throw new IOException();
                }

                string versionTag        = ReadVersion(versionInBytes);
                uint   expectedframesize = GetFrameSize(versionTag);

                if (expectedframesize != uint.MinValue)
                {
                    SourceStream.Seek(0, SeekOrigin.Begin);
                }
                else
                {
                    throw new Exception("No Version Number Found in File");
                }



                uint         syncpattern = 0x5A5A5A; // Constant
                uint         fieldone;
                uint         fieldtwo;
                uint         frameCount     = 0;
                uint         frameByteCount = 0;
                BinaryReader skreader       = new BinaryReader(SourceStream);

                while (frameCount >= 0)
                {
                    fieldone = skreader.ReadUInt32();
                    fieldtwo = skreader.ReadUInt32();

                    if (fieldtwo == syncpattern)
                    {
                        //Further Process
                        FrameObject newFrame = new FrameObject();
                        FrameParser.SvaFrameParser(expectedframesize, skreader.ReadBytes((int)(expectedframesize - (sizeof(uint) * 2))), out newFrame);
                        //skreader.Seek(-sizeof(uint), SeekOrigin.Current);
                        //fill fieldone and fieldtwo value;
                        newFrame.FieldOne = fieldone;
                        newFrame.FieldTwo = fieldtwo;
                    }

                    //expectedFramevalue.Item1 is expectedFramesize
                    if (((skreader.BaseStream.Length - skreader.BaseStream.Position) < expectedframesize) && (frameCount == uint.MinValue))
                    {
                        //End of Stream
                        break;
                    }
                }
            }
            catch (IOException)
            {
                ;
            }
            #endregion
        }