Beispiel #1
0
        private void ProcessNewDataPck(DecodedDataPck dataPck)
        {
            if (dataPck.DataPck != null && dataPck.Status == DecodeStatus.Complete)
            {
                switch (dataPck.DataPck.Type)
                {
                case DataPckTypes.DataPcks.SendConf:
                {
                    if (this.transAction == TransmissionAction.WaitingAck)
                    {
                        this.transAction = TransmissionAction.WaitingDataPckSend;
                    }
                    break;
                }

                default:
                {
                    if (dataPck.DataPck.AckRequired == DataPckTypes.True)
                    {
                        //Send Ack
                        this.SendDataPck(new ReSendDataPckController(DataPckTypes.False)
                            {
                                CrcController = new CRC32()
                            }.GetByteArray());
                    }

                    //Push the new message onto the recv queue for the message processing obj
                    this.recvQueue.Add(new QuadRecvPck(dataPck.DataPck, dataPck.DataPckCrc));

                    break;
                }
                }
            }
        }
        public void Decode(byte[] dataPck, out DecodedDataPck decodedDataPck)
        {
            var    status  = DecodeStatus.FailedCrcCheck;
            UInt32 readCrc = 0;

            DataPck pck = null;

            if (this.crcController != null)
            {
                //Extract CRC
                readCrc = BitConverter.ToUInt32(dataPck, 2);
                var computedCrc = this.crcController.CalculateCrc(
                    new ArraySegment <byte>(dataPck, 6, DataPckTypes.DataPckDataSize));


                var arraySeg    = new ArraySegment <byte>(dataPck, 6, DataPckTypes.DataPckDataSize);
                var dataPckType = DataPckDecoderHelper.DataPacketType(arraySeg);
                status = readCrc == computedCrc ? DecodeStatus.Complete : DecodeStatus.FailedCrcCheck;
                DataPckDecoderHelper.ByteArrayToDataPckClass(arraySeg, dataPckType, out pck);
            }
            else
            {
                throw new ArgumentNullException();
            }

            decodedDataPck = new DecodedDataPck(readCrc, status, pck);
        }