Esempio n. 1
0
        public byte[] GetBytesCemi()
        {
            TunnelCemiRequest builder = new TunnelCemiRequest();

            builder.Build(UnicastAddress.FromString("0.0.0"), DestinationAddress, ApciTypes.Connect, 255);
            return(builder.GetBytes());
        }
Esempio n. 2
0
        public byte[] GetBytesCemi()
        {
            TunnelCemiRequest builder = new TunnelCemiRequest();

            builder.Build(SourceAddress, DestinationAddress, ApciTypes.GroupValueWrite, 255, _data);
            return(builder.GetBytes());
        }
Esempio n. 3
0
        public byte[] GetBytesCemi()
        {
            TunnelCemiRequest builder = new TunnelCemiRequest();

            builder.Build(UnicastAddress.FromString("0.0.0"), MulticastAddress.FromString("0/0/0"), ApciTypes.IndividualAddressRead);
            return(builder.GetBytes());
        }
Esempio n. 4
0
        public byte[] GetBytesCemi()
        {
            TunnelCemiRequest builder = new TunnelCemiRequest();

            builder.Build(UnicastAddress.FromString("0.0.0"), DestinationAddress, ApciTypes.DeviceDescriptorRead, SequenceNumber);
            return(builder.GetBytes());
        }
        public byte[] GetBytesCemi()
        {
            TunnelCemiRequest builder = new TunnelCemiRequest();

            builder.Build(MulticastAddress.FromString("0/0/0"), MulticastAddress.FromString("0/0/0"), ApciTypes.IndividualAddressWrite, 255, _address.GetBytes());
            builder.SetPriority(Prios.System);
            return(builder.GetBytes());
        }
        public byte[] GetBytesCemi()
        {
            TunnelCemiRequest builder = new TunnelCemiRequest();

            byte[] data = { ObjectIndex, PropertyId, 0x10, 0x01 };

            builder.Build(UnicastAddress.FromString("0.0.0"), DestinationAddress, ApciTypes.PropertyValueRead, SequenceNumber, data);
            return(builder.GetBytes());
        }
        public byte[] GetBytesCemi()
        {
            TunnelCemiRequest builder = new TunnelCemiRequest();

            List <byte> data = new List <byte>();

            data.AddRange(Serial);

            data.AddRange(NewAddress.GetBytes());
            data.AddRange(new byte[] { 0, 0, 0, 0 });

            builder.Build(UnicastAddress.FromString("0.0.0"), MulticastAddress.FromString("0/0/0"), ApciTypes.IndividualAddressSerialNumberWrite, 255, data.ToArray());
            builder.SetPriority(Prios.System);
            return(builder.GetBytes());
        }
Esempio n. 8
0
        public byte[] GetBytesCemi()
        {
            TunnelCemiRequest builder = new TunnelCemiRequest();
            List <byte>       data    = new List <byte> {
                Convert.ToByte(Data.Length)
            };

            byte[] addr = BitConverter.GetBytes(Convert.ToInt16(Address));
            Array.Reverse(addr);
            data.AddRange(addr);
            data.AddRange(Data);

            builder.Build(UnicastAddress.FromString("0.0.0"), DestinationAddress, ApciTypes.MemoryWrite, SequenceNumber, data.ToArray());
            return(builder.GetBytes());
        }
Esempio n. 9
0
        public byte[] GetBytesCemi()
        {
            TunnelCemiRequest builder = new TunnelCemiRequest();
            List <byte>       data    = new List <byte>()
            {
                ObjectIndex, PropertyId, PropertyIndex
            };

            builder.Build(UnicastAddress.FromString("0.0.0"), DestinationAddress, ApciTypes.PropertyValueRead, SequenceNumber, data.ToArray());

            data = new List <byte>()
            {
                0x11, 0x00
            };
            data.AddRange(builder.GetBytes());
            return(data.ToArray());
        }
Esempio n. 10
0
        public byte[] GetBytesCemi()
        {
            byte[] send_data = new byte[Data.Length + 4];

            send_data[0] = ObjectIndex;
            send_data[1] = PropertyId;
            send_data[2] = 0x10;
            send_data[3] = 0x01;

            for (int i = 0; i < Data.Length; i++)
            {
                send_data[i + 4] = Data[i];
            }

            TunnelCemiRequest builder = new TunnelCemiRequest();

            builder.Build(UnicastAddress.FromString("0.0.0"), DestinationAddress, ApciTypes.PropertyValueWrite, SequenceNumber, send_data);
            return(builder.GetBytes());
        }
Esempio n. 11
0
        public byte[] GetBytesCemi()
        {
            if (Length > 256)
            {
                throw new Exception("Bei cEmi kann maximal 256 Bytes ausgelesen werden. (Angefordert waren " + Length + " bytes)");
            }


            List <byte> data = new List <byte> {
                BitConverter.GetBytes(Length)[0]
            };

            byte[] addr = BitConverter.GetBytes(Address);
            data.Add(addr[1]);
            data.Add(addr[0]);

            Builders.TunnelCemiRequest builder = new TunnelCemiRequest();
            builder.Build(UnicastAddress.FromString("0.0.0"), DestinationAddress, ApciTypes.MemoryRead, SequenceNumber, data.ToArray());

            return(builder.GetBytes());
        }
Esempio n. 12
0
        private void ProcessReceivingMessages(UdpClient _udpClient)
        {
            Debug.WriteLine("Höre jetzt auf: " + (_udpClient.Client.LocalEndPoint as IPEndPoint).Port);
            Task.Run(async() =>
            {
                int rofl = 0;
                try
                {
                    while (!StopProcessing)
                    {
                        rofl++;
                        var result      = await _udpClient.ReceiveAsync();
                        var knxResponse = _receiveParserDispatcher.Build(result.Buffer);

                        //if(!(knxResponse is SearchResponse))
                        //    Debug.WriteLine("Telegram angekommen: " + knxResponse?.ToString());


                        switch (knxResponse)
                        {
                        case ConnectStateResponse connectStateResponse:
                            Debug.WriteLine("Connection State Response: " + connectStateResponse.Status.ToString());
                            switch (connectStateResponse.Status)
                            {
                            case 0x00:
                                IsConnected = true;
                                ConnectionChanged?.Invoke(IsConnected);
                                break;

                            default:
                                Debug.WriteLine("Connection State: Fehler: " + connectStateResponse.Status.ToString());
                                LastError   = ConnectionErrors.NotConnectedToBus;
                                IsConnected = false;
                                ConnectionChanged?.Invoke(IsConnected);
                                break;
                            }
                            break;

                        case ConnectResponse connectResponse:
                            _flagCRRecieved = true;
                            switch (connectResponse.Status)
                            {
                            case 0x00:
                                _sequenceCounter      = 0;
                                _communicationChannel = connectResponse.CommunicationChannel;
                                IsConnected           = true;
                                ConnectionChanged?.Invoke(IsConnected);
                                PhysicalAddress = connectResponse.ConnectionResponseDataBlock.KnxAddress;
                                Debug.WriteLine("Connected: Eigene Adresse: " + PhysicalAddress.ToString());
                                break;

                            default:
                                Debug.WriteLine("Connected: Fehler: " + connectResponse.Status.ToString());
                                LastError   = ConnectionErrors.Undefined;
                                IsConnected = false;
                                ConnectionChanged?.Invoke(IsConnected);
                                break;
                            }
                            break;

                        case Builders.TunnelResponse tunnelResponse:
                            if (tunnelResponse.IsRequest && tunnelResponse.DestinationAddress != PhysicalAddress)
                            {
                                Debug.WriteLine("Telegram erhalten das nicht mit der Adresse selbst zu tun hat!");
                                Debug.WriteLine("Typ: " + tunnelResponse.APCI);
                                Debug.WriteLine("Eigene Adresse: " + PhysicalAddress.ToString());
                                break;
                            }

                            _sendMessages.Add(new Responses.TunnelResponse(0x06, 0x10, 0x0A, 0x04, _communicationChannel, tunnelResponse.SequenceCounter, 0x00).GetBytes());

                            //Debug.WriteLine("Telegram APCI: " + tunnelResponse.APCI.ToString());

                            if (tunnelResponse.APCI.ToString().EndsWith("Response"))
                            {
                                TunnelCemiRequest builder = new TunnelCemiRequest();
                                builder.Build(UnicastAddress.FromString("0.0.0"), tunnelResponse.SourceAddress, ApciTypes.Ack, tunnelResponse.SequenceNumber);
                                _ = Send(builder.GetBytes(), _sequenceCounter);
                                _sequenceCounter++;
                                //Debug.WriteLine("Got Response " + tunnelResponse.SequenceCounter + " . " + tunnelResponse.SequenceNumber);
                            }
                            else if (tunnelResponse.APCI == ApciTypes.Ack)
                            {
                                OnTunnelAck?.Invoke(new MsgAckRes()
                                {
                                    ChannelId          = tunnelResponse.CommunicationChannel,
                                    SequenceCounter    = tunnelResponse.SequenceCounter,
                                    SequenceNumber     = tunnelResponse.SequenceNumber,
                                    SourceAddress      = tunnelResponse.SourceAddress,
                                    DestinationAddress = tunnelResponse.DestinationAddress
                                });
                                break;
                            }


                            List <string> temp = new List <string>();
                            var q = from t in Assembly.GetExecutingAssembly().GetTypes()
                                    where t.IsClass && t.IsNested == false && (t.Namespace == "Kaenx.Konnect.Messages.Response" || t.Namespace == "Kaenx.Konnect.Messages.Request")
                                    select t;

                            IMessage message = null;

                            foreach (Type t in q.ToList())
                            {
                                IMessage resp = (IMessage)Activator.CreateInstance(t);

                                if (resp.ApciType == tunnelResponse.APCI)
                                {
                                    message = resp;
                                    break;
                                }
                            }


                            if (message == null)
                            {
                                //throw new Exception("Kein MessageParser für den APCI " + tunnelResponse.APCI);
                                message = new MsgDefaultRes()
                                {
                                    ApciType = tunnelResponse.APCI
                                };
                                Debug.WriteLine("Kein MessageParser für den APCI " + tunnelResponse.APCI);
                            }

                            message.Raw                = tunnelResponse.Data;
                            message.ChannelId          = tunnelResponse.CommunicationChannel;
                            message.SequenceCounter    = tunnelResponse.SequenceCounter;
                            message.SequenceNumber     = tunnelResponse.SequenceNumber;
                            message.SourceAddress      = tunnelResponse.SourceAddress;
                            message.DestinationAddress = tunnelResponse.DestinationAddress;

                            switch (CurrentType)
                            {
                            case ProtocolTypes.cEmi:
                                message.ParseDataCemi();
                                break;

                            case ProtocolTypes.Emi1:
                                message.ParseDataEmi1();
                                break;

                            case ProtocolTypes.Emi2:
                                message.ParseDataEmi2();
                                break;

                            default:
                                throw new NotImplementedException("Unbekanntes Protokoll - TunnelResponse KnxIpTunneling");
                            }


                            if (tunnelResponse.APCI.ToString().EndsWith("Response"))
                            {
                                OnTunnelResponse?.Invoke(message as IMessageResponse);
                            }
                            else
                            {
                                OnTunnelRequest?.Invoke(message as IMessageRequest);
                            }

                            break;

                        case SearchResponse searchResponse:
                            MsgSearchRes msg = new MsgSearchRes(searchResponse.responseBytes);
                            switch (CurrentType)
                            {
                            case ProtocolTypes.cEmi:
                                msg.ParseDataCemi();
                                break;

                            case ProtocolTypes.Emi1:
                                msg.ParseDataEmi1();
                                break;

                            case ProtocolTypes.Emi2:
                                msg.ParseDataEmi2();
                                break;

                            default:
                                throw new NotImplementedException("Unbekanntes Protokoll - SearchResponse KnxIpTunneling");
                            }
                            OnSearchResponse?.Invoke(msg);
                            break;

                        case TunnelAckResponse tunnelAck:
                            //Do nothing
                            break;

                        case DisconnectResponse disconnectResponse:
                            IsConnected           = false;
                            _communicationChannel = 0;
                            ConnectionChanged?.Invoke(IsConnected);
                            break;
                        }
                    }

                    Debug.WriteLine("Stopped Processing Messages " + _udpClient.Client.LocalEndPoint.ToString());
                    _udpClient.Close();
                    _udpClient.Dispose();
                }
                catch
                {
                }
            });
        }