Ejemplo n.º 1
0
        private void ProcessDatagramHeaders(byte[] datagram)
        {
            // HEADER
            // TODO: Might be interesting to take out these magic numbers for the datagram indices
            var knxDatagram = new KnxDatagram
            {
                HeaderLength    = datagram[0],
                ProtocolVersion = datagram[1],
                ServiceType     = new[] { datagram[2], datagram[3] },
                TotalLength     = datagram[4] + datagram[5]
            };

            var channelId = datagram[7];

            if (channelId != this.ChannelId)
            {
                return;
            }

            var sequenceNumber = datagram[8];
            var process        = true;

            lock (this.SequenceNumberLock)
            {
                if (sequenceNumber <= this.m_rxSequenceNumber)
                {
                    process = false;
                }

                this.m_rxSequenceNumber = sequenceNumber;
            }

            if (process)
            {
                // TODO: Magic number 10, what is it?
                var cemi = new byte[datagram.Length - 10];
                Array.Copy(datagram, 10, cemi, 0, datagram.Length - 10);

                switch (DatagramProcessing.ProcessCEMI(ref knxDatagram, cemi, this.ThreeLevelGroupAddressing, this.IsDebug))
                {
                case ResponseType.Event:
                    base.EventReceived(knxDatagram.DestinationAddress, knxDatagram.Data);
                    break;

                case ResponseType.Status:
                    base.StatusReceived(knxDatagram.DestinationAddress, knxDatagram.Data);
                    break;
                }
            }

            this.SendTunnelingAck(sequenceNumber);
        }