Example #1
0
        /// <summary>
        /// 查询按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSearch_Click(object sender, EventArgs e)
        {
            bnyPath = txtBNYFilePath.Text.Trim();

            if (bnyPath == "")
            {
                MessageBox.Show("请先选择BNY文件", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            //bnyPath = @"H:\工作文件汇总\铁科院\程序\工具\BNY\data\20170409京广高速上行(广州南~武汉)_001.bny";

            //bnyPath = @"F:\个人文件\铁路\工程代码\文件工具\BNY工具\data\20170409京广高速上行(广州南~武汉)_001.bny";

            long bnyFileLength = common.GetBNYLastPosition(bnyPath);

            pageCount = 0;
            pageCount = Convert.ToInt32(bnyFileLength / (rowCount * BNYFile.GetChannelSize()));
            if (bnyFileLength % (rowCount * BNYFile.GetChannelSize()) > 0)
            {
                pageCount += 1;
            }

            var listAll = common.GetBNYData(bnyPath, rowCount, startPosition, ref endPosition);

            startPosition = endPosition;


            this.txtCurrentPage.Text = pageIndex.ToString();
            this.lblTotalPage.Text   = pageCount.ToString();

            float startmiled = common.GetBNYStartMile(bnyPath);
            float endmiled   = common.GetBNYEndMile(bnyPath);

            if (startmiled < endmiled)
            {
                isInc = true;
            }
            this.lbl_StartMile.Text = startmiled.ToString();
            this.lbl_EndMile.Text   = endmiled.ToString();

            DisplayData(listAll);
        }
Example #2
0
        /// <summary>
        /// 下一页按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnNext_Click(object sender, EventArgs e)
        {
            this.btnPrev.Enabled = true;
            if (pageIndex >= pageCount)
            {
                return;
            }
            else
            {
                startPosition = (pageIndex - 1) * rowCount * BNYFile.GetChannelSize();
                var listAll = common.GetBNYData(bnyPath, rowCount, startPosition, ref endPosition);

                pageIndex++;
                DisplayData(listAll);
                this.txtCurrentPage.Text = pageIndex.ToString();
                if (pageIndex == pageCount)
                {
                    this.btnNext.Enabled = false;
                }
            }
        }
Example #3
0
        /// <summary>
        /// 获取BNY数据并向cit文件中写入数据
        /// </summary>
        /// <param name="channelList"></param>
        private void GetBnyDataAndWriteCit(string citPath, string bnyPath, List <ChannelNew> channelList)
        {
            CitFileHelper citHelper = new CitFileHelper();

            int[] bnyChannelArr = channelList.Where(s => s.BNYChannelId >= 0).Select(s => s.BNYChannelId).ToArray();
            int   sampleNum     = 50000;
            long  startPosition = 0;
            long  endPosition   = 0;

            long bnyFileLength = common.GetBNYLastPosition(bnyPath);

            int    pageCount     = 0;
            double realPageCount = bnyFileLength * 1.0 / (sampleNum * BNYFile.GetChannelSize());

            if (realPageCount % ((int)realPageCount) > 0)
            {
                pageCount = ((int)realPageCount) + 1;
            }
            else
            {
                pageCount = (int)realPageCount;
            }

            List <float[]> bnyList    = new List <float[]>();
            List <float[]> resultList = new List <float[]>();

            float[] fvalue = new float[sampleNum];
            for (int i = 0; i < pageCount; i++)
            {
                bnyList       = common.GetBNYData(bnyPath, sampleNum, startPosition, ref endPosition);
                startPosition = endPosition;
                resultList.Clear();
                for (int j = 0; j < channelList.Count; j++)
                {
                    if (channelList[j].BNYChannelId >= 0)
                    {
                        if (bnyList[channelList[j].BNYChannelId].Length < sampleNum)
                        {
                            fvalue = new float[bnyList[channelList[j].BNYChannelId].Length];
                            if (channelList[j].BNYChannelId == 2)
                            {
                                if (channelList[j].dataChannelInfo.sNameEn == "KM")
                                {
                                    fvalue = bnyList[channelList[j].BNYChannelId].Select(p => ((float)(int)p)).ToArray();
                                }
                                else if (channelList[j].dataChannelInfo.sNameEn == "M")
                                {
                                    fvalue = bnyList[channelList[j].BNYChannelId].Select(p => (p - (int)p) * 1000).ToArray();
                                }
                                else
                                {
                                    fvalue = bnyList[channelList[j].BNYChannelId];
                                }
                            }
                            else
                            {
                                fvalue = bnyList[channelList[j].BNYChannelId];
                            }
                        }
                        else
                        {
                            if (channelList[j].BNYChannelId == 2)
                            {
                                if (channelList[j].dataChannelInfo.sNameEn == "KM")
                                {
                                    fvalue = bnyList[channelList[j].BNYChannelId].Select(p => ((float)(int)p)).ToArray();
                                }
                                else if (channelList[j].dataChannelInfo.sNameEn == "M")
                                {
                                    fvalue = bnyList[channelList[j].BNYChannelId].Select(p => (p - (int)p) * 1000).ToArray();
                                }
                                else
                                {
                                    fvalue = bnyList[channelList[j].BNYChannelId];
                                }
                            }
                            else
                            {
                                fvalue = bnyList[channelList[j].BNYChannelId];
                            }
                        }
                    }
                    else
                    {
                        fvalue = new float[bnyList[0].Length];
                    }
                    resultList.Add(fvalue);
                }
                citHelper.WriteChannelDataFloat(citPath, resultList);
                if (tokenSource.IsCancellationRequested)
                {
                    throw new OperationCanceledException();
                }
            }
        }
Example #4
0
        private void GetBnyData(string bnyPath, List <ChannelNew> channelList)
        {
            int  sampleNum     = 5000;
            long startPosition = 0;
            long endPosition   = 0;

            long bnyFileLength = common.GetBNYLastPosition(bnyPath);

            int    pageCount     = 0;
            double realPageCount = bnyFileLength * 1.0 / (sampleNum * BNYFile.GetChannelSize());

            if (realPageCount % ((int)realPageCount) > 0)
            {
                pageCount = ((int)realPageCount) + 1;
            }
            else
            {
                pageCount = (int)realPageCount;
            }

            List <float[]> bnyList    = new List <float[]>();
            List <float[]> resultList = new List <float[]>();

            float[] fvalue = new float[sampleNum];
            for (int i = 0; i < pageCount; i++)
            {
                bnyList       = common.GetBNYData(bnyPath, sampleNum, startPosition, ref endPosition);
                startPosition = endPosition;
                resultList.Clear();
                for (int j = 0; j < channelList.Count; j++)
                {
                    if (channelList[j].BNYChannelId >= 0)
                    {
                        if (bnyList[channelList[j].BNYChannelId].Length < sampleNum)
                        {
                            fvalue = new float[bnyList[channelList[j].BNYChannelId].Length];
                            if (channelList[j].BNYChannelId == 2)
                            {
                                if (channelList[j].dataChannelInfo.sNameEn == "KM")
                                {
                                    fvalue = bnyList[channelList[j].BNYChannelId].Select(p => ((float)(int)p)).ToArray();
                                }
                                else if (channelList[j].dataChannelInfo.sNameEn == "M")
                                {
                                    fvalue = bnyList[channelList[j].BNYChannelId].Select(p => (p - (int)p) * 1000).ToArray();
                                }
                                else
                                {
                                    fvalue = bnyList[channelList[j].BNYChannelId];
                                }
                            }
                            else
                            {
                                fvalue = bnyList[channelList[j].BNYChannelId];
                            }
                        }
                        else
                        {
                            if (channelList[j].BNYChannelId == 2)
                            {
                                if (channelList[j].dataChannelInfo.sNameEn == "KM")
                                {
                                    fvalue = bnyList[channelList[j].BNYChannelId].Select(p => ((float)(int)p)).ToArray();
                                }
                                else if (channelList[j].dataChannelInfo.sNameEn == "M")
                                {
                                    fvalue = bnyList[channelList[j].BNYChannelId].Select(p => (p - (int)p) * 1000).ToArray();
                                }
                                else
                                {
                                    fvalue = bnyList[channelList[j].BNYChannelId];
                                }
                            }
                            else
                            {
                                fvalue = bnyList[channelList[j].BNYChannelId];
                            }
                        }
                    }
                    else
                    {
                        fvalue = new float[bnyList[0].Length];
                    }
                    resultList.Add(fvalue);
                }
                if (channelDataList.ContainsKey(bnyPath))
                {
                    channelDataList[bnyPath].Enqueue(new List <float[]>(resultList));
                }
                if (tokenSource.IsCancellationRequested)
                {
                    token.ThrowIfCancellationRequested();
                    break;
                }
                int count = channelDataList[bnyPath].Count / 10;
                if (count > 1)
                {
                    Thread.Sleep(300 * count);
                }
            }
            channelDataList[bnyPath].Enqueue(null);
        }
Example #5
0
        /// <summary>
        /// 获取BNY数据并向cit文件中写入数据
        /// </summary>
        /// <param name="channelList"></param>
        private void GetBnyDataAndWriteCit(List <ChannelNew> channelList)
        {
            int[] bnyChannelArr = channelList.Where(s => s.BNYChannelId >= 0).Select(s => s.BNYChannelId).ToArray();

            int  sampleNum     = 1000;
            long startPosition = 0;
            long endPosition   = 0;

            long bnyFileLength = common.GetBNYLastPosition(bnyFilePath);

            int pageCount = Convert.ToInt32(bnyFileLength / (sampleNum * BNYFile.GetChannelSize()));

            List <float[]> bnyList = new List <float[]>();

            try
            {
                using (FileStream fs = new FileStream(createCitFilePath, FileMode.Append, FileAccess.Write, FileShare.ReadWrite))
                {
                    using (BinaryWriter bw = new BinaryWriter(fs, Encoding.Default))
                    {
                        DataHeadInfo           dhi             = citHelper.GetDataInfoHead(createCitFilePath);
                        List <DataChannelInfo> channelInfoList = citHelper.GetDataChannelInfoHead(createCitFilePath);
                        int    iChannelNumberSize = dhi.iChannelNumber * 2;
                        byte[] dataArray          = new byte[iChannelNumberSize];

                        List <Byte> dataList   = new List <Byte>();
                        short       tmpRmsData = 0;;
                        Byte[]      tmpBytes   = new Byte[2];
                        for (int i = 0; i < pageCount; i++)
                        {
                            bnyList       = common.GetBNYData(bnyFilePath, sampleNum, startPosition, ref endPosition);
                            startPosition = endPosition;

                            List <float[]> resultList = new List <float[]>();
                            //Action<float> action = new Action<float>({ });
                            for (int j = 0; j < channelList.Count; j++)
                            {
                                float[] fvalue = new float[sampleNum];

                                if (channelList[j].BNYChannelId >= 0)
                                {
                                    fvalue = bnyList[channelList[j].BNYChannelId];
                                }
                                resultList.Add(fvalue);
                            }

                            long iArrayLen = resultList[0].Length;
                            for (int k = 0; k < iArrayLen; k++)
                            {
                                if (citHelper.IsEncrypt(dhi))
                                {
                                    for (int iTmp = 0; iTmp < channelList.Count; iTmp++)
                                    {
                                        if (channelList[iTmp].BNYChannelId > 6)
                                        {
                                            tmpRmsData = (short)((resultList[iTmp][k] / 10 - channelInfoList[iTmp].fOffset) * channelInfoList[iTmp].fScale);
                                        }
                                        else
                                        {
                                            tmpRmsData = (short)((resultList[iTmp][k] - channelInfoList[iTmp].fOffset) * channelInfoList[iTmp].fScale);
                                        }
                                        tmpBytes = CitFileHelper.ByteXORByte(BitConverter.GetBytes(tmpRmsData));
                                        dataList.AddRange(tmpBytes);
                                    }
                                }
                                else
                                {
                                    for (int iTmp = 0; iTmp < channelList.Count; iTmp++)
                                    {
                                        try
                                        {
                                            if (channelList[iTmp].BNYChannelId > 6)
                                            {
                                                tmpRmsData = (short)((resultList[iTmp][k] / 10 - channelInfoList[iTmp].fOffset) * channelInfoList[iTmp].fScale);
                                            }
                                            else
                                            {
                                                tmpRmsData = (short)((resultList[iTmp][k] - channelInfoList[iTmp].fOffset) * channelInfoList[iTmp].fScale);
                                            }
                                            dataList.AddRange(BitConverter.GetBytes(tmpRmsData));
                                        }
                                        catch (Exception ex)
                                        {
                                            throw ex;
                                        }
                                    }
                                }
                                ///bw.BaseStream.Position = 100;
                                bw.Write(dataList.ToArray());
                                bw.Flush();

                                dataList.Clear();
                            }
                            if (token.IsCancellationRequested)
                            {
                                token.ThrowIfCancellationRequested();
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }