Esempio n. 1
0
        public virtual string GetReport(params byte[] bytes)
        {
            //Get only the bytes that belong to the field
            bytes = bytes.Where((byte i, int j) => { return(Bytes.Contains(j + 2)); }).ToArray();
            if (LittleEndian)
            {
                bytes = bytes.Reverse().ToArray();
            }
            StringBuilder res = new StringBuilder(string.Format(@"----------------- Field: {0} ----------------
", Name));

            res.Append(string.Join(" ", bytes.Select(x => x.ToString("X2"))));
            res.Append(" = "); //Add binary representation
            res.AppendLine(string.Join(" ", bytes.Select(x => Convert.ToString(x, 2).PadLeft(8, '0'))));
            if (CustomParser != null)
            {
                try
                {
                    res.AppendLine(CustomParser(bytes));
                }
                catch (Exception e)
                {
                    ErrorListener.Add(new Exception(
                                          string.Format("Error in a custom parser for field {0}", Name), e));
                }
            }
            //res.AppendLine("------------------");
            return(res.ToString());
        }
Esempio n. 2
0
        public override string GetReport(params byte[] bytes)
        {
            StringBuilder res = new StringBuilder(base.GetReport(bytes));  //This sets up "Field" headline and binary representation

            //Now parse bits
            bytes = bytes.Where((byte b, int i) => { return(Bytes.Contains(i + 2)); }).ToArray();
            if (!LittleEndian)
            {
                bytes = bytes.Reverse().ToArray();                 //The following cycle reverses the order one again!
            }
            for (int i = 0; i < bytes.Length; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    bool val = (bytes[i] & (1u << j)) != 0;
                    Dictionary <int, string> dic = val ? BitsSetDesc : BitsUnsetDesc;
                    if (dic != null)
                    {
                        int num = i * 8 + j;
                        if (dic.ContainsKey(num))
                        {
                            res.AppendLine(string.Format("#{0}={1} - {2}", num, val ? '1' : '0', dic[num]));
                        }
                    }
                }
            }
            return(res.ToString());
        }
Esempio n. 3
0
 public void WithValidBytes_ReturnsContainsValue(bool expected, byte input)
 {
     Assert.AreEqual(expected, Bytes.Contains(input), "Get Contains value");
 }