예제 #1
0
        private double?GetValue(ISOChannelType type)
        {
            if (_point.ContainsKey(type))
            {
                return(_point[type]);
            }

            return(null);
        }
예제 #2
0
        public ISOChannelInfo(byte[] signatureBinary, int index, ISOChannelType type)
        {
            ChannelType = type;
            FromIndex   = index;
            info        = new BitArray(new byte[1] {
                signatureBinary[index]
            });
            ToIndex = FromIndex + 1 + 2 * Convert.ToInt32(HasScale) + 2 * Convert.ToInt32(HasMinValue) + 2 * Convert.ToInt32(HasMaxValue) + 2 * Convert.ToInt32(HasAvgValue) + 2 * Convert.ToInt32(HasStd);

            int descBytes = index + 1;

            if (HasScale)
            {
                byte[] raw = new byte[2] {
                    signatureBinary[descBytes], signatureBinary[descBytes + 1]
                };
                BitArray mantissMask = new BitArray(new byte[2] {
                    0b00000111, 0b11111111
                });
예제 #3
0
        private List <ISOSignaturePoint> ParsePoints(byte[] samples, int sampleCount)
        {
            List <ISOSignaturePoint> result = new List <ISOSignaturePoint>();
            int sampleSize = samples.Length / sampleCount;

            for (int i = 0; i < samples.Length; i = i + sampleSize)
            {
                Dictionary <ISOChannelType, double> point = new Dictionary <ISOChannelType, double>();
                int idx = i;
                foreach (ISOChannelInfo ci in channelsDescription.ChannelInfo)
                {
                    ISOChannelType    channelType = ci.ChannelType;
                    ByteSizeAttribute bsAttr      = (ByteSizeAttribute)channelType.GetType().GetField(channelType.ToString())
                                                    .GetCustomAttributes(typeof(ByteSizeAttribute), false)[0];

                    int byteSize = bsAttr.ByteSize;

                    byte[] valueRaw = new byte[byteSize];
                    Array.Copy(samples, idx, valueRaw, 0, byteSize);
                    valueRaw = valueRaw.Reverse().ToArray();

                    double value;

                    switch (channelType)
                    {
                    case ISOChannelType.X:
                    case ISOChannelType.Y:
                    case ISOChannelType.VX:
                    case ISOChannelType.VY:
                    case ISOChannelType.AX:
                    case ISOChannelType.AY:
                    case ISOChannelType.TX:
                    case ISOChannelType.TY:
                    {
                        value = (int)BitConverter.ToUInt16(valueRaw, 0) - 32768;
                        break;
                    }

                    case ISOChannelType.Z:
                    case ISOChannelType.T:
                    case ISOChannelType.DT:
                    case ISOChannelType.F:
                    case ISOChannelType.Az:
                    case ISOChannelType.E:
                    case ISOChannelType.R:
                    {
                        value = (int)BitConverter.ToUInt16(valueRaw, 0);
                        break;
                    }

                    case ISOChannelType.S:
                    {
                        value = valueRaw[0] > 0 ? 1.0 : 0;
                        break;
                    }

                    default:
                    {
                        throw new Exception("Cannot parse ISO signature sample");
                    }
                    }

                    point[channelType] = value;

                    idx += byteSize;
                }

                result.Add(new ISOSignaturePoint(point));
            }

            return(result);
        }