private bool Check16citt(byte[] buffer, int offset, int length) { ICRC checker = getChecker(); if (checker == null) { throw new NotSupportedException(CRCType.ToString()); } var tmp = getPayloadFromMsg16bitcitt(buffer); var cs = checker.ComputeChecksumBytes(tmp); int datalen = buffer[CctalkMessage.PosDataLen]; byte LSB = buffer[CctalkMessage.PosSourceAddr]; byte MSB = buffer[datalen + 4]; if (cs[0] != MSB || cs[1] != LSB) { Debug.WriteLine(string.Format("Bad Cksum {0}{1} (calculated {2}{3})", String.Format("{0:x2}", MSB), String.Format("{0:x2}", LSB), String.Format("{0:x2}", cs[0]), String.Format("{0:x2}", cs[1]))); return(false); } return(true); }
ICRC getChecker() { if (CRCType == Helpers.CRCType.None) { return(null); } if (cr.ContainsKey(CRCType)) { return(cr[this.CRCType]); } ICRC toret = null; switch (CRCType) { case Helpers.CRCType.CRC8: toret = new CRC8(InitialCrcValue.Zeros); break; //case Helpers.CRCType.CRC16: // toret = new CRC16(InitialCrcValue.Zeros); // break; case Helpers.CRCType.CRC16CCITT: toret = new CRC16CCITT(InitialCrcValue.Zeros); break; //case Helpers.CRCType.CRC32: // toret = new CRC32(InitialCrcValue.Zeros); // break; } if (toret == null) { return(null); } cr.Add(CRCType, toret); return(toret); }
public virtual UInt32 GenerateModID() { ICRC algorithm = CRCFactory.Instance.Create(crcSetting); string crc_input = ModIdString; return(BitConverter.ToUInt32(algorithm.ComputeHash(Encoding.UTF8.GetBytes(crc_input).Select(dr => (byte)dr).ToArray()).Hash, 0) | 0x80000000); }
public Byte[] Execute(Byte[] source) { ICRC check = getChecker(); byte[] d = check.ComputeChecksumBytes(source); return(d); }
public Byte[] Execute(Byte[] source) { ICRC check = this.cr[CRCType.CRC16]; byte[] d = check.ComputeChecksumBytes(source); //this.arr[2] = d[1]; //this.arr[this.length - 1] = d[0]; return(d); }
private bool Check8(byte[] messageInBytes, int offset, int length) { ICRC checker = getChecker(); if (checker == null) { throw new NotSupportedException(CRCType.ToString()); } return(checker.ComputeChecksumBytes(messageInBytes)[0] == 0); }
public void PrepareBenchmark() { data = new byte[ArraySize]; Random rnd = new Random(Seed); rnd.NextBytes(data); crc8Provider = CRCFactory.Instance.Create(CRCConfig.CRC8); crc16Provider = CRCFactory.Instance.Create(CRCConfig.CRC16_USB); crc32Provider = CRCFactory.Instance.Create(CRCConfig.CRC32); }
public void execute() { byte[] tmp = new byte[this.length - 2]; tmp[0] = this.arr[0]; tmp[1] = this.arr[1]; tmp[2] = this.arr[3]; for (int i = 0; i < this.arr[1]; i++) { tmp[3 + i] = this.arr[4 + i]; } ICRC check = this.cr[CRCType.CRC16]; byte[] d = check.ComputeChecksumBytes(tmp); this.arr[2] = d[1]; this.arr[this.length - 1] = d[0]; }
public ModeResult Run(string[] args) { if (args.Length < 2) { Console.Out.WriteLine("Missing required arg: \"output\""); return(ModeResult.Fail); } string dataDirectory; if (args.Length >= 2) { dataDirectory = args[1]; } else { dataDirectory = StructuredDataInfo.GetDefaultDirectory(); } _info = new StructuredDataInfo(dataDirectory); ICRC crc32 = CRCFactory.Instance.Create(CRCConfig.CRC32); foreach (KeyValuePair <uint, string> instance in _info.KnownInstances) { //if (instance.Value.StartsWith("STUStatescript")) { if (instance.Value.StartsWith("M")) { continue; } string mirrorType = instance.Value.Replace("STU", "M"); if (!mirrorType.StartsWith("M")) { continue; } uint hash = BitConverter.ToUInt32(crc32.ComputeHash(Encoding.ASCII.GetBytes(mirrorType.ToLowerInvariant())).Hash, 0); if (_info.Instances.ContainsKey(hash)) { Console.Out.WriteLine($"{hash:X8}, {mirrorType}"); } //} } return(ModeResult.Success); }
private void CalcAndApply8(Byte[] messageInBytes) { if (messageInBytes == null) { throw new ArgumentNullException("messageInBytes"); } ICRC checker = getChecker(); if (checker == null) { throw new NotSupportedException(CRCType.ToString()); } var checksumPlace = messageInBytes.Length - 1; if (messageInBytes[checksumPlace] != 0) { throw new ArgumentException("Checksumm alredy set"); } byte retByte = checker.ComputeChecksumBytes(messageInBytes)[0]; messageInBytes[checksumPlace] = retByte; }
public RFC1662BinarySerialDevice(string portName, ICRC crc, int baudRate, Parity parity) : base(portName, baudRate, parity) { this.crc = crc; }
public RFC1662BinaryTCPDevice(BinaryTCPDevice device, ICRC crc) : base(device, crc) { }
public CRC32(UInt64 _poly, UInt64 _Init, bool _refIn, bool _refOut, UInt64 _XorOut, UInt64 _check, string[] _Names) : base(4, 1) { CRCAlgorithm = new CRC(32, _poly, _Init, _refIn, _refOut, _XorOut, _check, _Names); } // end constructor
public RFC1662BinarySerialDevice(SerialDevice device, ICRC crc) : base(device, crc) { }
public RFC1662BinaryDevice(T device, ICRC crc) { this.device = device; this.crc = crc; }
public RFC1662BinarySerialDevice(string portName, ICRC crc) : base(portName) { this.crc = crc; }
public BinaryDecoder(ICRC CrcController) { this.crcController = CrcController; }