Example #1
0
        internal virtual void HandleFrame(KnxFrame frame)
        {
            _heartbeatMonitor.Reset();

            switch (frame.ServiceType)
            {
            case KnxHelper.ServiceType.SearchRequest:
                break;

            case KnxHelper.ServiceType.SearchResponse:
                break;

            case KnxHelper.ServiceType.DescriptionRequest:
                break;

            case KnxHelper.ServiceType.DescriptionResponse:
                break;

            case KnxHelper.ServiceType.ConnectRequest:
                break;

            case KnxHelper.ServiceType.ConnectResponse:
                var connectResponse = (ConnectResponseFrame)frame;
                if (connectResponse.IsValid)
                {
                    IndividualAddress = connectResponse.IndividualAddress;
                    Connected         = true;
                    SetSequenceNumber(0);
                    ChannelId = connectResponse.ChannelId;

                    OnConnected?.Invoke(this, EventArgs.Empty);
                }
                else
                {
                    OnDisconnected?.Invoke(this, EventArgs.Empty);
                    Connected = false;
                }
                break;

            case KnxHelper.ServiceType.ConnectionstateRequest:
                break;

            case KnxHelper.ServiceType.ConnectionstateResponse:
                break;

            case KnxHelper.ServiceType.DisconnectRequest:
                SendFrame(new DisconnectResponseFrame(this));
                Connected = false;
                OnDisconnected?.Invoke(this, EventArgs.Empty);
                break;

            case KnxHelper.ServiceType.DisconnectResponse:
                break;

            case KnxHelper.ServiceType.DeviceConfigurationRequest:
                break;

            case KnxHelper.ServiceType.DeviceConfigurationAck:
                break;

            case KnxHelper.ServiceType.TunnellingRequest:
                var p   = (TunnelingRequestFrame)frame;
                var ack = new TunnelingAckFrame(this, p.FrameSequenceNumber);
                SendFrame(ack);

                if (KnxHelper.ProcessCemi(p.Datagram, p.CemiPacket))
                {
                    OnDatagramReceived?.Invoke(this, new KnxDatgramEventArgs(p.Datagram));
                }

                break;

            case KnxHelper.ServiceType.TunnellingAck:
                break;

            case KnxHelper.ServiceType.RoutingIndication:
                break;

            case KnxHelper.ServiceType.RoutingLostMessage:
                break;

            case KnxHelper.ServiceType.SecureWrapper:
                break;

            case KnxHelper.ServiceType.SessionRequest:
                break;

            case KnxHelper.ServiceType.SessionResponse:
                break;

            case KnxHelper.ServiceType.SessionAuthenticate:
                break;

            case KnxHelper.ServiceType.SessionStatus:
                break;

            case KnxHelper.ServiceType.TimerNotify:
                break;

            case KnxHelper.ServiceType.Unknown:
                break;
            }
        }
Example #2
0
        internal virtual KnxFrame ParseFrame(byte[] data)
        {
            var type = KnxHelper.GetServiceType(data);

            switch (type)
            {
            case KnxHelper.ServiceType.SearchRequest:
                break;

            case KnxHelper.ServiceType.SearchResponse:
                break;

            case KnxHelper.ServiceType.DescriptionRequest:
                break;

            case KnxHelper.ServiceType.DescriptionResponse:
                break;

            case KnxHelper.ServiceType.ConnectRequest:
                break;

            case KnxHelper.ServiceType.ConnectResponse:
                return(ConnectResponseFrame.CreateFrame(data, Connection));

            case KnxHelper.ServiceType.ConnectionstateRequest:
                break;

            case KnxHelper.ServiceType.ConnectionstateResponse:
                return(ConnectionStateResponseFrame.CreateFrame(data, Connection));

            case KnxHelper.ServiceType.DisconnectRequest:
                return(DisconnectRequestFrame.Parse(Connection, data));

            case KnxHelper.ServiceType.DisconnectResponse:
                return(new DisconnectResponseFrame(Connection));

            case KnxHelper.ServiceType.DeviceConfigurationRequest:
                break;

            case KnxHelper.ServiceType.DeviceConfigurationAck:
                break;

            case KnxHelper.ServiceType.TunnellingRequest:
                return(TunnelingRequestFrame.CreateFrame(data, Connection, 0, false));

            case KnxHelper.ServiceType.TunnellingAck:
                return(TunnelingAckFrame.Parse(Connection, data));

            case KnxHelper.ServiceType.RoutingIndication:
                break;

            case KnxHelper.ServiceType.RoutingLostMessage:
                break;

            case KnxHelper.ServiceType.SecureWrapper:
                break;

            case KnxHelper.ServiceType.SessionRequest:
                break;

            case KnxHelper.ServiceType.SessionResponse:
                break;

            case KnxHelper.ServiceType.SessionAuthenticate:
                break;

            case KnxHelper.ServiceType.SessionStatus:
                break;

            case KnxHelper.ServiceType.TimerNotify:
                break;

            case KnxHelper.ServiceType.Unknown:
                break;
            }

            return(null);
        }
        public static TunnelingAckFrame Parse(KnxConnection knx, byte[] data)
        {
            TunnelingAckFrame frame = new TunnelingAckFrame(knx, data[8]);

            return(frame);
        }