private BufferSpan _ToAdvancedProtocolFrame()
        {
            var frameLength = 7 + Data.Count;
            var frame       = new Byte[frameLength];

            frame[0] = 0x02;
            frame[1] = (Byte)(frameLength >> 8);
            frame[2] = (Byte)(frameLength & 0xff);
            frame[3] = Address;
            frame[4] = (Byte)Command;

            Buffer.BlockCopy(
                Data.Buffer,
                Data.Offset,
                frame,
                5,
                Data.Count
                );

            var crc = FeigChecksum.Calculate(BufferSpan.From(frame, 0, frameLength - 2));

            frame[frameLength - 2] = (Byte)(crc & 0xff);
            frame[frameLength - 1] = (Byte)(crc >> 8);

            return(BufferSpan.From(frame, frameLength));
        }
Example #2
0
        public void UseCase_123456789()
        {
            var buffer = Encoding.UTF8.GetBytes("123456789");

            var crc = FeigChecksum.Calculate(BufferSpan.From(buffer));

            Check.That(crc).IsEqualTo(0x6F91);
        }
Example #3
0
        public void UseCase()
        {
            var buffer = new Byte[] {
                0x0D,
                0x00,
                0x65,
                0x00,
                0x03,
                0x03,
                0x00,
                0x44,
                0x53,
                0x0D,
                0x30,
            };

            var crc = FeigChecksum.Calculate(BufferSpan.From(buffer));

            Check.That(crc).IsEqualTo(0x0933);
        }