Beispiel #1
0
        private static void ProcessLeaves(IEnumerator <Validation> valsNew, Header header, ValidationLeaf rootLeaf)
        {
            byte           parentKey = Tools.GetByte(valsNew.Current.ParamHexValue);
            ValidationLeaf parentVl  = rootLeaf;

            while (valsNew.MoveNext())
            {
                ValidationLeaf vl = new ValidationLeaf
                {
                    Rule    = valsNew.Current,
                    Results = new Dictionary <byte, IList <ValidationLeaf> >()
                };
                IList <ValidationLeaf> vlList = new List <ValidationLeaf>();
                vlList.Add(vl);
                parentVl.Results.Add(parentKey, vlList);
                parentVl  = vl;
                parentKey = Tools.GetByte(valsNew.Current.ParamHexValue);
            }
            ValidationLeaf headerLeaf = new ValidationLeaf
            {
                Header  = header,
                Rule    = null,
                Results = new Dictionary <byte, IList <ValidationLeaf> >()
            };
            IList <ValidationLeaf> lvl = new List <ValidationLeaf>();

            lvl.Add(headerLeaf);
            parentVl.Results.Add(parentKey, lvl);
        }
Beispiel #2
0
        public bool ParseHeaderWithCrc(byte[] data, byte crcBytes, byte frequency, out Header header)
        {
            header = null;
            bool ret = false;

            if (data.Length > 7 + crcBytes && CrcOk(data, data[7], crcBytes) && FrequencyHeaders.ContainsKey(frequency))
            {
                ret = true;
                ValidationLeaf vl = GetHeader(data, _frameHeaderRules[FrequencyHeaders[frequency]]);
                if (vl != null)
                {
                    if (vl.Header != null)
                    {
                        header = vl.Header;
                    }
                }
            }
            return(ret);
        }
Beispiel #3
0
        private static void InsertRules(IEnumerator <Validation> valsNew, Header header, ValidationLeaf existingVl)
        {
            byte key = Tools.GetByte(valsNew.Current.ParamHexValue);

            if (existingVl.Results.ContainsKey(key))
            {
                if (valsNew.MoveNext())
                {
                    IList <ValidationLeaf> children = existingVl.Results[key];
                    ValidationLeaf         child    = children.FirstOrDefault(x => AreEqualRules(x.Rule, valsNew.Current));
                    if (child != null)
                    {
                        InsertRules(valsNew, header, child);
                    }
                    else
                    {
                        //parent has another child with same key
                        ValidationLeaf newLeaf = new ValidationLeaf
                        {
                            Rule    = valsNew.Current,
                            Results = new Dictionary <byte, IList <ValidationLeaf> >()
                        };
                        ProcessLeaves(valsNew, header, newLeaf);
                        children.Add(newLeaf);
                    }
                }
                else
                {
                    foreach (var item in existingVl.Results[key])
                    {
                        item.Header = header;
                    }
                }
            }
            else
            {
                // same rule with new key
                ProcessLeaves(valsNew, header, existingVl);
            }
        }
Beispiel #4
0
        private void InsertRules(IEnumerable <Validation> validations, Header header)
        {
            IEnumerator <Validation> valsNew = validations.GetEnumerator();

            if (valsNew.MoveNext())
            {
                ValidationLeaf existingVl = _frameHeaderRules[header.BaseHeaderDefinition.Key].FirstOrDefault(x => AreEqualRules(x.Rule, valsNew.Current));
                if (existingVl != null)
                {
                    InsertRules(valsNew, header, existingVl);
                }
                else
                {
                    ValidationLeaf newLeaf = new ValidationLeaf
                    {
                        Rule    = valsNew.Current,
                        Results = new Dictionary <byte, IList <ValidationLeaf> >()
                    };
                    ProcessLeaves(valsNew, header, newLeaf);
                    _frameHeaderRules[header.BaseHeaderDefinition.Key].Add(newLeaf);
                }
            }
        }
Beispiel #5
0
        private static ValidationLeaf GetHeader(byte[] data, IList <ValidationLeaf> vLeaves)
        {
            ValidationLeaf ret = null;

            foreach (var item in vLeaves)
            {
                if (item.Header != null)
                {
                    //System.Diagnostics.Debug.Write("{" + item.Header.Name + "}");
                    ret = item;
                }
            }

            if (ret == null)
            {
                foreach (var item in vLeaves)
                {
                    if (data.Length > item.Rule.DataIndex.IndexInData)
                    {
                        byte val = (byte)((data[item.Rule.DataIndex.IndexInData] & item.Rule.DataIndex.MaskInData) >> item.Rule.DataIndex.OffsetInData);
                        if (item.Results.ContainsKey(val))
                        {
                            //System.Diagnostics.Debug.Write(item.Rule.ParamName + ":TRUE->");
                            ret = GetHeader(data, item.Results[val]);
                            if (ret != null)
                            {
                                break;
                            }
                        }
                    }
                }
            }
            else
            {
                while (ret.Rule != null)
                {
                    if (data.Length > ret.Rule.DataIndex.IndexInData)
                    {
                        byte val = (byte)((data[ret.Rule.DataIndex.IndexInData] & ret.Rule.DataIndex.MaskInData) >> ret.Rule.DataIndex.OffsetInData);
                        if (ret.Results.ContainsKey(val))
                        {
                            //System.Diagnostics.Debug.Write(ret.Rule.ParamName + ":TRUE->");
                            ValidationLeaf deep = GetHeader(data, ret.Results[val]);
                            if (deep != null)
                            {
                                ret = deep;
                            }
                        }
                        else
                        {
                            //System.Diagnostics.Debug.Write(ret.Rule.ParamName + ":FALSE->");
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }
            return(ret);
        }