Example #1
0
        public ChannelExtensionBlock(Mdf mdf)
            : base(mdf)
        {
            byte[] data = new byte[Size - 4];
            int    read = Mdf.Data.Read(data, 0, data.Length);

            if (read != data.Length)
            {
                throw new FormatException();
            }

            Type = (ExtensionType)BitConverter.ToUInt16(data, 0);

            if (Type == ExtensionType.DIM)
            {
                DimBlockSupplement = new DimBlockSupplement(mdf);
            }
            else if (Type == ExtensionType.VectorCAN)
            {
                VectorCanBlockSupplement = new VectorCanBlockSupplement(mdf);
            }
        }
Example #2
0
        internal static ProgramBlock Read(Mdf mdf, Stream stream)
        {
            var block = new ProgramBlock(mdf);

            block.Read(stream);

            if (block.Identifier != "PR")
            {
                throw new FormatException();
            }

            var data = new byte[block.Size - 4];
            var read = stream.Read(data, 0, data.Length);

            if (read != data.Length)
            {
                throw new FormatException();
            }

            block.data = data;

            return(block);
        }
Example #3
0
 public TriggerBlock(Mdf mdf)
     : base(mdf)
 {
 }
Example #4
0
 private ChannelConversionBlock(Mdf mdf) : base(mdf)
 {
     AdditionalConversionData = new ConversionData(this);
 }
Example #5
0
 private DataGroupBlock(Mdf mdf) : base(mdf)
 {
     ChannelGroups = new ChannelGroupCollection(mdf, this);
 }
Example #6
0
 private ChannelBlock(Mdf mdf) : base(mdf)
 {
 }
Example #7
0
        public static ChannelBlock Read(Mdf mdf, Stream stream, uint position)
        {
            stream.Position = position;

            var block = new ChannelBlock(mdf);

            block.stream = stream;
            block.Read(stream);

            var data = new byte[block.Size - 4];
            var read = stream.Read(data, 0, data.Length);

            if (read != data.Length)
            {
                throw new FormatException();
            }

            block.next            = null;
            block.SourceDepending = null;
            block.Dependency      = null;
            block.Comment         = null;

            block.ptrNextChannelBlock       = BitConverter.ToUInt32(data, 0);
            block.ptrChannelConversionBlock = BitConverter.ToUInt32(data, 4);
            block.ptrChannelExtensionBlock  = BitConverter.ToUInt32(data, 8);
            block.ptrChannelDependencyBlock = BitConverter.ToUInt32(data, 12);
            block.ptrChannelComment         = BitConverter.ToUInt32(data, 16);
            block.Type              = (ChannelType)BitConverter.ToUInt16(data, 20);
            block.SignalName        = mdf.IDBlock.Encoding.GetString(data, 22, 32).Humanize();
            block.SignalDescription = mdf.IDBlock.Encoding.GetString(data, 54, 128).Humanize();
            block.BitOffset         = BitConverter.ToUInt16(data, 182);
            block.NumberOfBits      = BitConverter.ToUInt16(data, 184);
            block.SignalType        = (SignalType)BitConverter.ToUInt16(data, 186);
            block.ValueRange        = BitConverter.ToBoolean(data, 188);

            if (block.ValueRange)
            {
                block.MinValue = BitConverter.ToDouble(data, 190);
                block.MaxValue = BitConverter.ToDouble(data, 198);
            }

            block.SampleRate = BitConverter.ToDouble(data, 206);

            if (mdf.IDBlock.Version >= MIN_VERSION_LONG_SIGNAL_NAME)
            {
                block.ptrLongSignalName = BitConverter.ToUInt32(data, 214);
            }

            if (mdf.IDBlock.Version >= MIN_VERSION_DISPLAY_NAME)
            {
                block.ptrDisplayName = BitConverter.ToUInt32(data, 218);
            }

            if (mdf.IDBlock.Version >= MIN_VERSION_ADDITIONAL_BYTE_OFFSET)
            {
                block.AdditionalByteOffset = BitConverter.ToUInt16(data, 222);
            }

            if (block.ptrChannelExtensionBlock != 0)
            {
                stream.Position       = block.ptrChannelExtensionBlock;
                block.SourceDepending = new ChannelExtensionBlock(mdf);
            }

            return(block);
        }
Example #8
0
 private ProgramBlock(Mdf mdf) : base(mdf)
 {
 }
Example #9
0
 public static ProgramBlock Create(Mdf mdf)
 {
     return(Create(mdf, new byte[0]));
 }
Example #10
0
 public static TextBlock Create(Mdf mdf)
 {
     return(Create(mdf, ""));
 }
Example #11
0
 private TextBlock(Mdf mdf) : base(mdf)
 {
 }
Example #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HeaderBlock" /> class.
 /// </summary>
 /// <param name="mdf">The MDF.</param>
 /// <exception cref="System.FormatException"></exception>
 private HeaderBlock(Mdf mdf) : base(mdf)
 {
 }
Example #13
0
        internal static HeaderBlock Read(Mdf mdf, Stream stream)
        {
            var block = new HeaderBlock(mdf);

            block.Read(stream);

            var data = new byte[block.Size - 4];
            var read = stream.Read(data, 0, data.Length);

            if (read != data.Length)
            {
                throw new FormatException();
            }

            block.DataGroupsCount = BitConverter.ToUInt16(data, 12);
            block.Date            = mdf.IDBlock.Encoding.GetString(data, 14, 10).Humanize();
            block.Time            = mdf.IDBlock.Encoding.GetString(data, 24, 8).Humanize();
            block.Author          = mdf.IDBlock.Encoding.GetString(data, 32, 32).Humanize();
            block.Organization    = mdf.IDBlock.Encoding.GetString(data, 64, 32).Humanize();
            block.Project         = mdf.IDBlock.Encoding.GetString(data, 96, 32).Humanize();
            block.Subject         = mdf.IDBlock.Encoding.GetString(data, 128, 32).Humanize();

            if (mdf.IDBlock.Version >= 320)
            {
                block.TimeStamp           = BitConverter.ToUInt64(data, 160);
                block.UTCTimeOffset       = BitConverter.ToInt16(data, 168);
                block.TimeQuality         = (TimeQuality)BitConverter.ToUInt16(data, 170);
                block.TimerIdentification = mdf.IDBlock.Encoding.GetString(data, 172, 32).Humanize();
            }
            else
            {
                block.TimeStamp           = 0;
                block.UTCTimeOffset       = 0;
                block.TimeQuality         = 0;
                block.TimerIdentification = "";
            }

            var ptrFirstDataGroup = BitConverter.ToUInt32(data, 0);
            var ptrTextBlock      = BitConverter.ToUInt32(data, 4);
            var ptrProgramBlock   = BitConverter.ToUInt32(data, 8);

            // Check if ptrTextBlock is null
            if (ptrTextBlock != 0)
            {
                stream.Position   = ptrTextBlock;
                block.FileComment = TextBlock.Read(mdf, stream);
            }

            // Check if ptrProgramBlock is null
            if (ptrProgramBlock != 0)
            {
                stream.Position    = ptrProgramBlock;
                block.ProgramBlock = ProgramBlock.Read(mdf, stream);
            }

            // Check if ptrFirstDataGroup is null
            if (ptrFirstDataGroup != 0)
            {
                mdf.DataGroups.Read(DataGroupBlock.Read(mdf, stream, ptrFirstDataGroup));
            }

            return(block);
        }
Example #14
0
 private ChannelGroupBlock(Mdf mdf) : base(mdf)
 {
 }