Beispiel #1
0
            public static Frame Parse(byte[] message)
            {
                Frame ret = null;

                switch (DetermineFrameType(message[0]))
                {
                case FrameType.Single:
                    ret = new SingleFrame(message);
                    break;

                case FrameType.First:
                    ret = new FirstFrame(message);
                    break;

                case FrameType.Consecutive:
                    ret = new ConsecutiveFrame(message);
                    break;

                case FrameType.Flow:
                    ret = new FlowControlFrame(message);
                    break;

                default:
                    break;
                }
                return(ret);
            }
Beispiel #2
0
            public static Frame Parse(byte[] message, bool awaitingConsecutive)
            {
                Frame ret = null;

                if (awaitingConsecutive)
                {
                    ret         = new Frame(message);
                    ret.RawData = message.Skip(1).ToArray();
                    return(ret);
                }

                switch (DetermineFrameType(message[0]))
                {
                case FrameType.Single:
                    ret = new SingleFrame(message);
                    break;

                case FrameType.First:
                    ret = new FirstFrame(message);
                    break;

                case FrameType.Consecutive:
                    ret = new ConsecutiveFrame(message);
                    break;

                case FrameType.Flow:
                    ret = new FlowControlFrame(message);
                    break;

                default:
                    break;
                }
                return(ret);
            }
        public void Consecutive_CreateFrame_OutOfRangeException()
        {
            _rnd = new Random();
            var data = new byte[_rnd.Next(8, 100)];

            _rnd.NextBytes(data);

            var consecutiveFrame = new ConsecutiveFrame(data, 1);
        }
        public void Consecutive_CreateFrame()
        {
            _rnd = new Random();
            var index = _rnd.Next(9);
            var data  = new byte[7];

            _rnd.NextBytes(data);
            var consecutiveFrame = new ConsecutiveFrame(data, index);

            Assert.AreEqual(consecutiveFrame.Index, index, "Значение свойства Index не соответствует переданному значению.");
            Assert.AreEqual(BitConverter.ToString(consecutiveFrame.Data), BitConverter.ToString(data), "Значение свойства Data не соответствует переданному значению.");
        }
        public void Consecutive_GetCanFrame()
        {
            _rnd = new Random();
            const int descriptor = 0xfc08;
            var       index      = _rnd.Next(9);
            var       data       = new byte[7];

            _rnd.NextBytes(data);

            var consecutiveFrame = new ConsecutiveFrame(data, index);

            var consCanFrame = consecutiveFrame.GetCanFrame(descriptor);

            var result = string.Format("{0:X2}-{1}", (byte)((0x2 & 0x0f) << 4 | index & 0x0f), BitConverter.ToString(consecutiveFrame.Data));

            Assert.AreEqual(consCanFrame.Descriptor, descriptor, "Ошибка при вычислении дескриптора");
            Assert.AreEqual(BitConverter.ToString(consCanFrame.Data), result, "Ошибка при записи данных");
        }