コード例 #1
0
        // 添加一条USB消息
        private void AddFilterTrace(FKFilterTrace filterTrace)
        {
            // 检查是否符合筛选器的要求
            if (DoesTracePassFilters(filterTrace, FilterInclude.Include) &&
                DoesTracePassFilters(filterTrace, FilterInclude.Exclude))
            {
                if (m_nMaxTraces > 0)
                {
                    while (DataTrace_ListView.Items.Count >= m_nMaxTraces)
                    {
                        DataTrace_ListView.Items.RemoveAt(0);
                    }
                }
                // 创建一行
                ListViewItem item = new ListViewItem(filterTrace.DeviceId.ToString());
                for (int i = 1; i < DataTrace_ListView.Columns.Count; i++)
                {
                    switch (i)
                    {
                    case 1:
                        item.SubItems.Add(filterTrace.TypeToStr());
                        break;

                    case 2:
                        item.SubItems.Add(filterTrace.GetTimestampDelta(m_PrevTrace).ToString());
                        break;

                    case 3:
                        if (filterTrace.Buffer != null)
                        {
                            item.SubItems.Add(filterTrace.Buffer.Length.ToString());
                        }
                        else
                        {
                            item.SubItems.Add(Convert.ToString(0));
                        }
                        break;

                    case 4:
                        item.SubItems.Add(filterTrace.BufToHex());
                        break;

                    case 5:
                        item.SubItems.Add(filterTrace.BufToChars());
                        break;
                    }
                }
                DataTrace_ListView.TopItem = DataTrace_ListView.Items.Add(item);
                m_PrevTrace = filterTrace;
            }
        }
コード例 #2
0
        // 检查一条消息是否符合筛选器
        private bool DoesTracePassFilters(FKFilterTrace filterTrace, FilterInclude include)
        {
            List <FilterMatch> filters;

            if (include == FilterInclude.Include)
            {
                filters = fkFilterControl.IncludeFilters;
            }
            else
            {
                filters = fkFilterControl.ExcludeFilters;
            }

            if (filters.Count == 0)
            {
                return(true);
            }

            bool check = true;

            foreach (FilterMatch filter in filters)
            {
                switch (filter.FilterType)
                {
                case FilterType.Length:
                    switch (filter.LengthMatch)
                    {
                    case LengthMatch.GreaterThen:
                        check = filterTrace.Buffer.Length > filter.Length;
                        break;

                    case LengthMatch.LessThen:
                        check = filterTrace.Buffer.Length < filter.Length;
                        break;

                    case LengthMatch.EqualTo:
                        check = filterTrace.Buffer.Length == filter.Length;
                        break;
                    }
                    break;

                case FilterType.Hex:
                    check = filterTrace.BufToHex().Contains(filter.Filter);
                    break;

                case FilterType.Ascii:
                    check = filterTrace.BufToChars().Contains(filter.Filter);
                    break;
                }
                if (include == FilterInclude.Include)
                {
                    if (check)
                    {
                        return(true);
                    }
                    else
                    {
                        continue;
                    }
                }
                else
                {
                    if (check)
                    {
                        return(false);
                    }
                    else
                    {
                        continue;
                    }
                }
            }
            if (include == FilterInclude.Include)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }