Ejemplo n.º 1
0
        public Byte[] Execute(Byte[] source)
        {
            ICRC check = getChecker();

            byte[] d = check.ComputeChecksumBytes(source);
            return(d);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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];
        }
Ejemplo n.º 6
0
        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;
        }