/// <summary> /// Computes a CRC 16 checksum of the specified bytes using the given algorithm /// </summary> /// <param name="algorithm">The CRC 16 Algorithm to use</param> /// <param name="bytes">The buffer to compute the CRC upon</param> /// <param name="start">The start index upon which to compute the CRC</param> /// <param name="length">The length of the buffer upon which to compute the CRC</param> /// <returns>The specified CRC</returns> public static ushort ComputeChecksum(Crc16Algorithm algorithm, byte[] bytes, int start, int length) { switch (algorithm) { case Crc16Algorithm.Standard: return(Standard.ComputeChecksum(bytes, start, length)); case Crc16Algorithm.Ccitt: return(CcittInitialZero.ComputeChecksum(bytes, start, length)); case Crc16Algorithm.CcittKermit: return(CcittKermit.ComputeChecksum(bytes, start, length)); case Crc16Algorithm.CcittInitialValue0xFFFF: return(CcittInitial0xFFFF.ComputeChecksum(bytes, start, length)); case Crc16Algorithm.CcittInitialValue0x1D0F: return(CcittInitial0x1D0F.ComputeChecksum(bytes, start, length)); case Crc16Algorithm.Dnp: return(Dnp.ComputeChecksum(bytes, start, length)); case Crc16Algorithm.Modbus: return(Standard.ComputeChecksum(bytes, start, length, ushort.MaxValue)); } throw new UnknownAlgorithmException("Unknown Algorithm"); }
/// <summary> /// Computes a CRC 16 checksum of the specified bytes using the given algorithm /// </summary> /// <param name="algorithm">The CRC 16 Algorithm to use</param> /// <param name="bytes">The buffer to compute the CRC upon</param> /// <returns>The specified CRC</returns> public static ushort ComputeChecksum(Crc16Algorithm algorithm, params byte[] bytes) { return(ComputeChecksum(algorithm, bytes, 0, bytes?.Length ?? 0)); }
public UnknownAlgorithmException(Crc16Algorithm algorithm) { this.Algorithm = algorithm; }