Beispiel #1
0
        /// <summary>
        /// Восстанавливает CAN-сообщение из буфера АППИ
        /// </summary>
        /// <param name="Buff">10 байт буфера</param>
        public static CanFrame FromBufferBytes(Byte[] Buff)
        {
            int id  = (int)BitConverter.ToUInt16(Buff.Take(2).Reverse().ToArray(), 0) >> 4;
            int len = Buff[1] & 0x0f;

            if (len > 8)
            {
                throw new AppiBufferDecodeException("Расшифрована неправильная длина CAN-сообщения ({0} байт)", len);
            }
            return(CanFrame.NewWithId(id, Buff, 2, len));
        }
Beispiel #2
0
        public static IEnumerable <CanFrame> GetRandomFrames()
        {
            var r = new Random();

            while (true)
            {
                var data = new byte[r.Next(0, 8)];
                r.NextBytes(data);
                yield return(CanFrame.NewWithId((UInt16)r.Next(0, 0x7ff), data));
            }
            // ReSharper disable once FunctionNeverReturns
        }