private static byte[] CalculateCrc(byte[] buffer) { var crc = ChecksumUtils.CalculateCrc(buffer, 1, 10); var crcBytes = BitConverter.GetBytes(crc); return(crcBytes); }
public void CrcUtilReturnProperValue() { var payload = new byte[] { 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; Assert.Equal(12, payload.Length); ushort crc = ChecksumUtils.CalculateCrc(payload); Assert.Equal(65120, crc); }
public void CrcUtilOverloadedMethodsReturnEqualValues() { var frame = new byte[] { 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x61, 0x3E }; Assert.Equal(16, frame.Length); var payload = new byte[12]; Buffer.BlockCopy(frame, 1, payload, 0, 12); var crc = ChecksumUtils.CalculateCrc(payload); Assert.Equal(65120, crc); var crc2 = ChecksumUtils.CalculateCrc(frame, 1, 12); Assert.Equal(crc, crc2); }
private static ushort CalculateFrameChecksum(byte[] data) => ChecksumUtils.CalculateCrc(data, 1, ReceiverFraming.NumOfBytesToCrcCalculation);