Beispiel #1
0
        public V45Packet(byte[] indata, int start = 0, bool ignoreLength = false)
        {
            try
            {
                this.m_status   = indata[start];
                this.m_command  = (V45Commands)indata[start + 1];
                this.m_sender   = indata[start + 2];
                this.m_receiver = indata[start + 3];
                this.m_length   = BitConverter.ToUInt16(indata, start + 4);

                if (m_length != indata.Length && !ignoreLength)
                {
                    throw new LengthException("Length error. Suggested: " + this.m_length.ToString() + " Received: " + indata.Length.ToString());
                }

                this.m_payLoad = new byte[m_length - 8];

                Array.Copy(indata, start + 6, m_payLoad, 0, m_length - 8);
                //.AddRange(indata.Skip(6).Take(this.Length - 8).ToArray());

                CRC16CITT tmpCRC = new CRC16CITT(CRC16CITT.InitialCrcValue.Zeros);
                this.m_CRC = BitConverter.ToUInt16(indata, start + 6 + this.Payload.Length);
                UInt16 tmprc = tmpCRC.ComputeChecksum(indata.Skip(start).Take(this.Length - 2).ToArray());

                if (this.m_CRC != tmprc)//steve--skip calibration commmand
                {
                    throw new CrcException("CRC error. Computed: " + tmprc.ToString() + " Received: " + this.m_CRC.ToString());
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Beispiel #2
0
        private ushort getCRC()
        {
            ushort rtn = 0;

            byte[] tmpdata = new byte[6 + m_payLoad.Length];

            tmpdata[0] = this.m_status;
            tmpdata[1] = (byte)this.m_command;
            tmpdata[2] = this.m_sender;
            tmpdata[3] = this.m_receiver;
            tmpdata[4] = (byte)this.m_length;
            tmpdata[5] = (byte)(this.m_length >> 8);
            Array.Copy(m_payLoad, 0, tmpdata, 6, m_payLoad.Length);

            CRC16CITT tmpCRC = new CRC16CITT(CRC16CITT.InitialCrcValue.Zeros);

            rtn = tmpCRC.ComputeChecksum(tmpdata);
            return(rtn);
        }