public static string ComputeHash(byte[] bytes, CrcAlgorithm crcAlgorithm) { Parameters parameters = CrcStdParams.Get(crcAlgorithm); Crc crc = new Crc(parameters); IEnumerable <byte> result = crc.ComputeHash(bytes).Take(parameters.HashSize / 8).Reverse(); return(HexUtil.ConvertHexStringArrayToHexString(HexUtil.ConvertByteArrayToHexStringArray(result))); }
public override Location Parse(MessageInput input) { PackageIdentifier packageIdentifier = (PackageIdentifier)input.DataMessage.Bytes[2]; Dictionary <PackageIdentifier, Func <Location> > dictionary = new Dictionary <PackageIdentifier, Func <Location> > { { PackageIdentifier.Login, () => { HandleLoginPackage(input); return(null); } }, { PackageIdentifier.Heartbeat, () => { SendAcknowledge(input); return(null); } }, { PackageIdentifier.Location, () => HandleLocationForV20(input) }, { PackageIdentifier.Warning, () => HandleLocationForV20(input) }, { PackageIdentifier.Report, () => HandleLocationForV20(input) }, { PackageIdentifier.Message, () => { Location location = GetLocationV20(input); string number = HexUtil.ConvertHexStringArrayToHexString( HexUtil.ConvertByteArrayToHexStringArray(input.DataMessage.ByteReader.Get(21))); SendAcknowledge(input, number); return(location); } }, { PackageIdentifier.ParamSet, () => { SendAcknowledge(input, "00"); return(null); } }, { PackageIdentifier.GPSOld, () => HandleMessageForV18(input, false) }, { PackageIdentifier.AlarmOld, () => HandleMessageForV18(input) }, { PackageIdentifier.TerminalStateOld, () => HandleMessageForV18(input) } }; return(dictionary.ContainsKey(packageIdentifier) ? dictionary[packageIdentifier].Invoke() : null); }
public DataMessage(byte[] bytes, string splitMessageBy) { Bytes = bytes; Hex = HexUtil.ConvertByteArrayToHexStringArray(Bytes); HexString = string.Join("", Hex); String = Encoding.ASCII.GetString(Bytes); CommaSplit = String.Split(","); BarSplit = String.Split("|"); Reader = new MessageReader(String); ByteReader = new ByteReader(bytes); Split = string.IsNullOrEmpty(splitMessageBy) ? CommaSplit : String.Split(splitMessageBy); }