Пример #1
0
        /// <summary>
        /// 数据变化,搜索筛选
        /// dataList为搜索源
        /// searchDataList为搜索结果
        /// </summary>
        public void SearchData(string[] no_addr_data, ref DataSource.AddrDataListClass dataList, ref DataSource.AddrDataListClass searchDataList)
        {
            string no   = no_addr_data[0];
            string addr = no_addr_data[1];
            string data = no_addr_data[2];

            searchDataList.AddrDataCollection.Clear();

            for (int i = 0; i < dataList.AddrDataCollection.Count; i++)
            {
                bool checkResult1 = false, checkResult2 = false, checkResult3 = false;
                checkResult1 = string.IsNullOrEmpty(no) ||
                               (!string.IsNullOrEmpty(no) && dataList.AddrDataCollection[i].No.ToString("X6").Contains(no.ToUpper()));
                checkResult2 = string.IsNullOrEmpty(addr) ||
                               (!string.IsNullOrEmpty(addr) && dataList.AddrDataCollection[i].RealAddr.ToString("X6").Contains(addr.ToUpper()));
                checkResult3 = string.IsNullOrEmpty(data) ||
                               (!string.IsNullOrEmpty(data) && dataList.AddrDataCollection[i].Data.ToString("X6").Contains(data.ToUpper()));

                if (checkResult1 && checkResult2 && checkResult3)
                {
                    if (dataList.AddrDataCollection[i].WarnningColor == System.Windows.Media.Brushes.Yellow)
                    {
                        dataList.AddrDataCollection[i].WarnningColor = System.Windows.Media.Brushes.Transparent;
                    }
                    searchDataList.AddrDataCollection.Add(dataList.AddrDataCollection[i]);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// AddrDataListClass复制
        /// dataList为源
        /// copyDataList为目标,保存复制结果
        /// </summary>
        public void AddrDataListClassCopy(ref DataSource.AddrDataListClass dataList, ref DataSource.AddrDataListClass copyDataList)
        {
            if (dataList == null)
            {
                copyDataList = null;
            }

            if (copyDataList == null)
            {
                copyDataList = new DataSource.AddrDataListClass();
            }
            else
            {
                copyDataList.AddrDataCollection.Clear();
            }

            for (int i = 0; i < dataList.AddrDataCollection.Count; i++)
            {
                DataSource.AddrData oneData = new DataSource.AddrData();
                oneData.No   = dataList.AddrDataCollection[i].No;
                oneData.Addr = dataList.AddrDataCollection[i].Addr;
                oneData.BeforeIsLinearOffset  = dataList.AddrDataCollection[i].BeforeIsLinearOffset;
                oneData.BeforeIsSegmentOffset = dataList.AddrDataCollection[i].BeforeIsSegmentOffset;
                oneData.LinearOffset          = dataList.AddrDataCollection[i].LinearOffset;
                oneData.SegmentOffset         = dataList.AddrDataCollection[i].SegmentOffset;
                oneData.RealAddr      = dataList.AddrDataCollection[i].RealAddr;
                oneData.Data          = dataList.AddrDataCollection[i].Data;
                oneData.LineNum       = dataList.AddrDataCollection[i].LineNum;
                oneData.Remark        = dataList.AddrDataCollection[i].Remark;
                oneData.IsInsert      = dataList.AddrDataCollection[i].IsInsert;
                oneData.WarnningColor = dataList.AddrDataCollection[i].WarnningColor;
                copyDataList.AddrDataCollection.Add(oneData);
            }
        }
Пример #3
0
        /// <summary>
        /// 传入hex文件所有行数据
        /// dataList为解析后的数据的集合
        /// </summary>
        public DataSource.AddrDataListClass ConvertStringToDataList(string[] allLines)
        {
            DataSource.AddrDataListClass dataList = new DataSource.AddrDataListClass();
            dataList.AddrDataCollection = new System.Collections.ObjectModel.ObservableCollection <DataSource.AddrData>();

            NXPHexParse nxpHexParse = new NXPHexParse();

            List <NXPHexParse.HexParseDataOneAddrStruct> lsDataList = nxpHexParse.GetDataFromNxpINHX32(ref allLines);

            for (int i = 0; i < lsDataList.Count; i++)
            {
                string remark = string.Empty;
                System.Windows.Media.Brush warnningColor = System.Windows.Media.Brushes.Transparent;

                if (lsDataList[i].checkSumError)
                {
                    remark        = "CheckSum Error ";
                    warnningColor = System.Windows.Media.Brushes.LightCyan;
                }
                if (lsDataList[i].lengthError)
                {
                    remark       += "Length Error";
                    warnningColor = System.Windows.Media.Brushes.LightPink;
                }
                //lineNum默认不能为0,否则后面可能出错,-1表示没有这行,为插入值
                dataList.AddrDataCollection.Add(PacakOneAddrData(lsDataList[i]));
            }

            return(dataList);
        }
Пример #4
0
        /// <summary>
        /// 插入跳过的地址
        /// </summary>
        public DataSource.AddrDataListClass InsertSkipToDataList(ref DataSource.AddrDataListClass dataList)
        {
            DataSource.AddrDataListClass insertDataList = new DataSource.AddrDataListClass();
            insertDataList.AddrDataCollection = new System.Collections.ObjectModel.ObservableCollection <DataSource.AddrData>();

            int programFlashEndIndex = 0; //程序存储结束

            for (int i = 0; i < dataList.AddrDataCollection.Count; i++)
            {
                //大于最大地址
                if (dataList.AddrDataCollection[i].notProgramAddr)
                {
                    programFlashEndIndex = i - 1;
                    break;
                }
            }

            //查看程序存储最后一个是否有数据,没有则插入,方便下面判断,插入跳过的地址
            if (dataList.AddrDataCollection[programFlashEndIndex].RealAddr < NXPHexParse.HexParseDataOneAddrStruct.maxProgramAddr)
            {
                //第一个非程序地址,往前插入一个
                dataList.AddrDataCollection.Insert(programFlashEndIndex + 1, InsertOneAddrData(NXPHexParse.HexParseDataOneAddrStruct.maxProgramAddr));
                programFlashEndIndex++; //添加了一个,增加1
            }


            //逐步增加,填充省略的地址
            UInt32 fillAddr = 0;

            //循环查找是否有空缺的地址,然后增加地址进入,查找范围为程序存储
            for (int i = 0; i < programFlashEndIndex + 1; i++)
            {
                //其中有跳过的地址,补充进入
                if (fillAddr < dataList.AddrDataCollection[i].RealAddr)
                {
                    //补充跳过的地址为ffffff
                    //实际地址为i*2,从i*2开始,到包含的地址结束,填充地址
                    //地址仅为偶数,所以步长为2
                    for (uint t = fillAddr; t < dataList.AddrDataCollection[i].RealAddr; t += 2)
                    {
                        insertDataList.AddrDataCollection.Add(InsertOneAddrData(t));
                    }
                }
                insertDataList.AddrDataCollection.Add(dataList.AddrDataCollection[i]);
                fillAddr = dataList.AddrDataCollection[i].RealAddr + 2; //地址每次增长2个,2个16bits
            }

            //插入配置字
            for (int i = programFlashEndIndex + 1; i < dataList.AddrDataCollection.Count; i++)
            {
                insertDataList.AddrDataCollection.Add(dataList.AddrDataCollection[i]);
            }

            return(insertDataList);
        }
        public DataGridTest(Point location, Size size, ref DataSource.AddrDataListClass dataList)
        {
            InitializeComponent();


            this.Left = location.X + (size.Width - this.Width) / 2;
            this.Top  = location.Y + (size.Height - this.Height) / 2;

            m_DataList = dataList;

            dgMsg1.ItemsSource = dataList.AddrDataCollection;
        }
        /// <summary>
        /// 获取文件路径之后的操作
        /// </summary>
        /// <param name="filePath"></param>
        private void FileSelect(string filePath)
        {
            //读取数据
            string[] allLines = File.ReadAllLines(filePath);

            tbSelectedHexFilePath.Text    = filePath;
            tbSelectedHexFilePath.ToolTip = "总行数: " + allLines.Length.ToString();

            TextBlockAddMsg("Hex文件加载完毕," + tbSelectedHexFilePath.ToolTip, System.Windows.Media.Brushes.Green);

            m_AllAddrData = m_NxpCommonFunction.ConvertStringToDataList(allLines);
        }
Пример #7
0
        /// <summary>
        /// 删除插入的数据
        /// </summary>
        public DataSource.AddrDataListClass DeleteInsertToDataList(DataSource.AddrDataListClass dataList)
        {
            DataSource.AddrDataListClass dataList2 = new DataSource.AddrDataListClass();
            dataList2.AddrDataCollection = new System.Collections.ObjectModel.ObservableCollection <DataSource.AddrData>();

            for (int i = 0; i < dataList.AddrDataCollection.Count; i++)
            {
                if (!dataList.AddrDataCollection[i].IsInsert)
                {
                    dataList2.AddrDataCollection.Add(dataList.AddrDataCollection[i]);
                }
            }
            return(dataList2);
        }
Пример #8
0
        /// <summary>
        /// 将hex字符串解析显示
        /// </summary>
        private void RefreshShowHexFile(ref DataSource.HexStringListClass hexStringList)
        {
            lvHexString.SelectionChanged -= lvHexString_SelectionChanged;
            dgMsg1.SelectionChanged      -= dgMsg1_SelectionChanged;

            m_AddrDataList1.AddrDataCollection.Clear();
            m_SearchAddrDataList1.AddrDataCollection.Clear();

            m_AddrDataList1 = m_CommonFunc.HexStringToDataList(hexStringList); //转换为数据列表
            //m_AddrDataList1 = m_CommonFunc.InsertSkipToDataList(ref m_AddrDataList1); //插入跳过的地址
            //复制一份,用作筛选显示
            m_CommonFunc.AddrDataListClassCopy(ref m_AddrDataList1, ref m_SearchAddrDataList1);

            //指定显示的源
            lvHexString.ItemsSource = m_HexStringList.HexStringCollection;
            dgMsg1.ItemsSource      = m_SearchAddrDataList1.AddrDataCollection;
            lbFilter1.Content       = m_SearchAddrDataList1.AddrDataCollection.Count;

            dgMsg1.SelectionChanged      += dgMsg1_SelectionChanged;
            lvHexString.SelectionChanged += lvHexString_SelectionChanged;
        }
        public ChangeHexString(Point location, Size size, int changeRow, ref DataSource.AddrDataListClass dataList, ref DataSource.HexStringListClass hexList)
        {
            InitializeComponent();


            this.Left = location.X + (size.Width - this.Width) / 2;
            this.Top  = location.Y + (size.Height - this.Height) / 2;

            m_DataList = dataList;
            m_HexList  = hexList;

            cbDataLength.ItemsSource   = new string[] { "4", "8", "12", "16" };
            cbDataLength.SelectedIndex = 3;

            cbDataType.ItemsSource   = new string[] { "数据记录(0x00)", "文件记录结束(0x01)", "线性地址(0x04)" };
            cbDataType.SelectedIndex = 0;

            tbChangeRow.CurrentValue = changeRow;


            m_TmpDataList.AddrDataCollection = new System.Collections.ObjectModel.ObservableCollection <DataSource.AddrData>();
            dgMsg1.ItemsSource = m_TmpDataList.AddrDataCollection;
        }
        /// <summary>
        /// 选择Hex文件,并解析
        /// </summary>
        /// <param name="dataList"></param>
        /// <param name="searchDataList"></param>
        /// <returns>返回文件名</returns>
        private string ConvertHexString(ref DataSource.AddrDataListClass dataList, ref DataSource.AddrDataListClass searchDataList, string filenameStr = null)
        {
            string filename = string.Empty;

            if (string.IsNullOrEmpty(filenameStr))
            {
                OpenFileDialog opfDialog = new OpenFileDialog();
                opfDialog.InitialDirectory = Directory.GetCurrentDirectory().ToString();
                opfDialog.Filter           = "(*.hex)|*.hex|All files(*.*)|*.*";
                if (opfDialog.ShowDialog().Value)
                {
                    filename = opfDialog.FileName;
                }
            }
            else
            {
                filename = filenameStr;
            }

            if (string.IsNullOrEmpty(filename))
            {
                return(filename);
            }

            #region 根据文件处理hex
            //读取数据
            string[] allLines = File.ReadAllLines(filename);

            SpecialFunctions.HexParse.MicrochipHexParse microchipHexParse = new SpecialFunctions.HexParse.MicrochipHexParse();

            List <SpecialFunctions.HexParse.MicrochipHexParse.HexParseDataOneAddrStruct> lsDataList = microchipHexParse.GetDataFromMicrochipINHX32(ref allLines);

            dataList.AddrDataCollection.Clear(); //清除原来的数据
            searchDataList.AddrDataCollection.Clear();

            //逐步增加,填充省略的地址
            Int32 fillAddr = 0;

            for (int i = 0; i < lsDataList.Count; i++)
            {
                //其中有跳过的地址,补充进入
                if (fillAddr < lsDataList[i].addr)
                {
                    #region 补全缺失地址为0xffffff
                    //补充跳过的地址为ffffff
                    //实际地址为i*2,从i*2开始,到包含的地址结束,填充地址
                    //地址仅为偶数,所以步长为2
                    for (int t = fillAddr; t < lsDataList[i].addr; t += 2)
                    {
                        DataSource.AddrData addrData1 = new DataSource.AddrData();
                        addrData1.IsInsert      = true;
                        addrData1.No            = t / 2;
                        addrData1.RealAddr      = Convert.ToUInt32(t);
                        addrData1.Data          = 0x00ffffff;
                        addrData1.Remark        = "Hex无,插入FFFFFF";
                        addrData1.WarnningColor = System.Windows.Media.Brushes.LightGray;
                        dataList.AddrDataCollection.Add(addrData1);
                        searchDataList.AddrDataCollection.Add(addrData1);
                    }
                    #endregion
                    //自身
                    DataSource.AddrData addrData2 = new DataSource.AddrData();
                    addrData2.No       = Convert.ToInt32(lsDataList[i].addr / 2);
                    addrData2.RealAddr = Convert.ToUInt32(lsDataList[i].addr);
                    addrData2.Data     = lsDataList[i].data;
                    addrData2.LineNum  = lsDataList[i].lineNum;
                    //addrData2.WarnningColor = System.Windows.Media.Brushes.LightGreen;
                    dataList.AddrDataCollection.Add(addrData2);
                    searchDataList.AddrDataCollection.Add(addrData2);
                }
                else
                {
                    DataSource.AddrData addrData = new DataSource.AddrData();
                    addrData.No       = Convert.ToInt32(fillAddr / 2);
                    addrData.RealAddr = lsDataList[i].addr;
                    addrData.Data     = lsDataList[i].data;
                    addrData.LineNum  = lsDataList[i].lineNum;
                    //addrData.WarnningColor = System.Windows.Media.Brushes.LightGreen;
                    dataList.AddrDataCollection.Add(addrData);
                    searchDataList.AddrDataCollection.Add(addrData);
                }
                fillAddr = Convert.ToInt32(lsDataList[i].addr + 2);
            }

            #endregion


            return(filename);
        }