using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AIK.Common.AIKProtocol { public static class ProtocolHelper { public static ushort CalculateCRC16(IEnumerable data) { if (data == null || !data.Any()) return 0; ushort crc = 0; foreach (byte b in data) { crc ^= (ushort)(b << 8); for (int i = 0; i < 8; i++) { if ((crc & 0x8000) != 0) { crc = (ushort)((crc << 1) ^ 0x1021); } else { crc = (ushort)(crc << 1); } } } return crc; } } }