internal static FlightDataHeader Parse(byte[] bytes,
            FlightBinaryDataHeaderDefinition definition)
        {
            FlightDataHeader header = new FlightDataHeader();
            string testVal = new string(System.Text.Encoding.GetEncoding("ASCII").GetChars(bytes));
            System.Diagnostics.Debug.WriteLine(testVal);
            List<FlightDataContentSegment> segments = new List<FlightDataContentSegment>();

            int current = 0;

            foreach (var seg in definition.Segments)
            {
                if (seg.SegmentName == "(NULL)")
                {
                    current = seg.BytesCount;
                    continue;
                }

                int step = seg.BytesCount;
                StringBuilder builder = new StringBuilder();
                List<byte> bts = new List<byte>();
                for (int i = current; i < current + step; i++)
                {
                    if (i >= bytes.Length)
                        break;
                    bts.Add(bytes[i]);
                    //builder.Append(bytes[i]);
                }

                if (bts.Count > 0)
                //builder.Length > 0)
                {
                    FlightDataContentSegment ds = new FlightDataContentSegment();
                    if (seg.DataTypeStr == DataTypeConverter.LONG)
                    {
                    }
                    else if (seg.DataTypeStr == DataTypeConverter.FLOAT)
                    {
                    }
                    else if (seg.DataTypeStr == DataTypeConverter.INT32)
                    {

                        string v = new string(System.Text.Encoding.GetEncoding("ASCII").GetChars(bts.ToArray()));
                        builder.Append(v);
                        // FlightDataContentSegment ds = new FlightDataContentSegment();
                        ds.DataTypeStr = seg.DataTypeStr;
                        ds.SegmentName = seg.SegmentName;
                        ds.Value = 0;//debug //builder.ToString().Trim('\0');
                    }
                    else
                    {
                        string v = new string(System.Text.Encoding.GetEncoding("ASCII").GetChars(bts.ToArray()));
                        builder.Append(v);
                        ds.DataTypeStr = seg.DataTypeStr;
                        ds.SegmentName = seg.SegmentName;
                        ds.Value = 0;//debug builder.ToString().Trim('\0');
                    }
                    segments.Add(ds);
                }

                current += step;
            }

            return header;
        }
        private void DoCore()
        {
            DateTime start = DateTime.Now;

            m_Reader.BaseStream.Position = this.Definition.HeaderDefinition.BytesCount;

            List<FlightDataContentFrame> frames = new List<FlightDataContentFrame>();

            while (m_Reader.BaseStream.Length > m_Reader.BaseStream.Position + 1)
            {
                FlightDataReading.AircraftModel1.FlightDataContentFrame frame = new FlightDataContentFrame();
                long current = m_Reader.BaseStream.Position;

                List<FlightDataContentSegment> segments = new List<FlightDataContentSegment>();
                foreach (var seg in this.Definition.FrameDefinition.Segments)
                {
                    FlightDataContentSegment content = new FlightDataContentSegment()
                    {
                        DataTypeStr = seg.DataTypeStr,
                        SegmentName = seg.SegmentName
                    };

                    if (seg.DataTypeStr == DataTypeConverter.FLOAT)
                    {
                        float floatVal = m_Reader.ReadSingle();
                        content.Value = floatVal;// floatVal.ToString();
                    }
                    else if (seg.DataTypeStr == DataTypeConverter.INT32)
                    {
                        int intVal = m_Reader.ReadInt32();
                        content.Value = intVal;// intVal.ToString();
                    }
                    else if (seg.DataTypeStr == DataTypeConverter.LONG)
                    {
                        long longVal = m_Reader.ReadInt64();
                        content.Value = longVal;// longVal.ToString();
                    }
                    else if (seg.DataTypeStr == DataTypeConverter.DATETIME)
                    {
                        content.Value = 0;// string.Empty;
                    }
                    else
                    {
                        byte[] strs = m_Reader.ReadBytes(seg.BytesCount);
                        content.Value = 0;// new string(System.Text.Encoding.GetEncoding("ASCII").GetChars(strs));
                    }
                    segments.Add(content);
                }

                var filtered = segments.Where(
                     new Func<FlightDataContentSegment, bool>(
                         delegate(FlightDataContentSegment seg1)
                         {
                             if (seg1 == null || string.IsNullOrEmpty(seg1.SegmentName) || seg1.SegmentName == "ID")
                                 return false;
                             return true;
                         }));

                frame.Segments = filtered.ToArray();//segments.ToArray();
                frames.Add(frame);

                if (this.m_Reader.BaseStream.Position != current + this.Definition.FrameDefinition.BytesCount)
                {
                    if (this.m_Reader.BaseStream.Position + 1 >= this.m_Reader.BaseStream.Length)
                        break;
                    this.m_Reader.BaseStream.Position = current + this.Definition.FrameDefinition.BytesCount;
                }
            }

            this.Frames = frames;

            return;

            //PHYHeader header = PHYHelper.ReadPHYHeader(m_Reader);
            //int secondCount = PHYHelper.GetFlyParamSeconds(header);

            //Task task1 = this.DoAddFlightRecordAsync(header);

            //string aircraftModel = header.AircrfName;

            ////获取需要读取的飞参列表
            //List<FlyParameter> needReadParams = FlyParameter.Parameters.Values.ToList();

            //Dictionary<string, FlyParameter> paramMap = new Dictionary<string, FlyParameter>();
            //foreach (FlyParameter fp in needReadParams)
            //    paramMap.Add(fp.ID, fp);

            //this.InitLevel2Entities(paramMap, secondCount);

            //for (int i = 1; i <= secondCount; i++)
            //{
            //    //读取当前秒的飞参值
            //    foreach (FlyParameter fp in needReadParams)
            //    {
            //        float[] values = PHYHelper.ReadFlyParameter(m_Reader, i, header, fp);
            //        FlightDataEntities.FlightRawData dt
            //            = new FlightDataEntities.FlightRawData() { ParameterID = fp.ID, Second = i, Values = values };
            //        this.PutRawDataToMongoDB(dt);

            //        FlightRecordEntity entity = new FlightRecordEntity() { FlightSecond = i, ParameterID = fp.ID, Values = values };
            //        this.PutEntityToLevel2Mentities(entity, secondCount);
            //    }
            //}

            //Task task2 =
            //    Task.Run(new Action(delegate()
            //{
            //    this.FlushDataToMongoDB(secondCount);
            //}));
            ////一边入库一边处理Fault判定

            //if (task1 != null)
            //    task1.Wait();
            //if (task2 != null)
            //    task2.Wait();
        }
        private void ReadSimpleSegment(List<FlightDataContentSegment> segments,
            FlightBinaryDataContentSegmentDefinition seg, BitArray bitArray)
        {
            var s3 = DateTime.Now;

            FlightDataContentSegment content = new FlightDataContentSegment()
            {
                DataTypeStr = seg.DataTypeStr,
                SegmentName = seg.SegmentName
            };

            //每个Index长度是4(byteCount)
            long currentPos = m_Reader.BaseStream.Position;
            if (seg.DataTypeStr == DataTypeConverter.FLOAT)
            {
                var s1 = DateTime.Now;
                float floatVal = m_Reader.ReadSingle();
                var s2 = DateTime.Now;
                TestSpan1 += s2.Subtract(s1);
                if (currentPos + seg.BytesCount != m_Reader.BaseStream.Position)
                    m_Reader.BaseStream.Position = currentPos + seg.BytesCount;
                content.Value = floatVal;// floatVal.ToString();
                TestSpan2 += DateTime.Now.Subtract(s2);

            }
            else if (seg.DataTypeStr == DataTypeConverter.INT32)
            {
                int intVal = m_Reader.ReadInt32();
                content.Value = intVal;// intVal.ToString();
                if (currentPos + seg.BytesCount != m_Reader.BaseStream.Position)
                    m_Reader.BaseStream.Position = currentPos + seg.BytesCount;
            }
            else if (seg.DataTypeStr == DataTypeConverter.LONG)
            {
                long longVal = m_Reader.ReadInt64();
                content.Value = longVal;// longVal.ToString();
                if (currentPos + seg.BytesCount != m_Reader.BaseStream.Position)
                    m_Reader.BaseStream.Position = currentPos + seg.BytesCount;
            }
            else if (seg.DataTypeStr == DataTypeConverter.DATETIME)
            {
                content.Value = 0;// string.Empty;
                if (currentPos + seg.BytesCount != m_Reader.BaseStream.Position)
                    m_Reader.BaseStream.Position = currentPos + seg.BytesCount;
            }
            else
            {
                byte[] strs = m_Reader.ReadBytes(seg.BytesCount);
                content.Value = 0;// new string(System.Text.Encoding.GetEncoding("ASCII").GetChars(strs));
                if (currentPos + seg.BytesCount != m_Reader.BaseStream.Position)
                    m_Reader.BaseStream.Position = currentPos + seg.BytesCount;
            }
            TestSpan3 += DateTime.Now.Subtract(s3);

            segments.Add(content);
        }
        private FlightDataReadingHeader DoReadHeaderCore()
        {
            FlightDataReadingHeader header = new FlightDataReadingHeader();

            List<FlightDataContentSegment> segments = new List<FlightDataContentSegment>();

            m_Reader.BaseStream.Position = 0;
            foreach (var seg in this.Definition.HeaderDefinition.Segments)
            {
                FlightDataContentSegment content = new FlightDataContentSegment()
                {
                    DataTypeStr = seg.DataTypeStr,
                    SegmentName = seg.SegmentName
                };

                if (seg.DataTypeStr == DataTypeConverter.FLOAT)
                {
                    float floatVal = m_Reader.ReadSingle();
                    content.Value = floatVal;// floatVal.ToString();
                }
                else if (seg.DataTypeStr == DataTypeConverter.INT32)
                {
                    int intVal = m_Reader.ReadInt32();
                    content.Value = intVal;// intVal.ToString();
                }
                else if (seg.DataTypeStr == DataTypeConverter.LONG)
                {
                    long longVal = m_Reader.ReadInt64();
                    content.Value = longVal;// longVal.ToString();
                }
                else if (seg.DataTypeStr == DataTypeConverter.DATETIME)
                {
                    content.Value = 0;// string.Empty;
                }
                else
                {
                    byte[] strs = m_Reader.ReadBytes(seg.BytesCount);
                    content.Value = 0;// new string(System.Text.Encoding.GetEncoding("ASCII").GetChars(strs));
                }
                segments.Add(content);
            }

            m_Reader.BaseStream.Position = this.Definition.HeaderDefinition.BytesCount;

            header.Segments = segments.ToArray();
            return header;
        }
        private void ReadComplexSegment(List<FlightDataContentSegment> segments,
            FlightBinaryDataContentSegmentDefinition seg, BitArray bitArray)
        {
            var single = m_Reader.ReadSingle();
            var toInt = (int)single;
            List<int> bitValues = new List<int>();

            for (int i = 0; i < 16; i++)
            {
                int bitValue = BaseFunction.GetBit(toInt, i);
                bitValues.Add(bitValue);
            }

            for (int j = 0; j < Math.Min(seg.BitsDefinition.Length, bitValues.Count); j++)
            {
                var seg2 = seg.BitsDefinition[j];
                FlightDataContentSegment resultSeg = new FlightDataContentSegment()
                {
                    DataTypeStr = seg2.DataTypeStr,
                    SegmentName = seg2.SegmentName,
                };

                if (seg2.BitsCount == 1)
                {
                    resultSeg.Value = bitValues[j];
                }
                segments.Add(resultSeg);
            }
        }