Exemplo n.º 1
0
        public override bool Equals(System.Object obj)
        {
            try
            {
                // If parameter is null return false.
                if (obj == null)
                {
                    return(false);
                }

                // If parameter cannot be cast to Point return false.
                cEMI p = obj as cEMI;
                if ((System.Object)p == null)
                {
                    return(false);
                }

                // Return true if the fields match:
                //Console.WriteLine("Vergleiche: \r\n{0} == \r\n{1}", this, p);
                if (!p.m_source.Equals(m_source))
                {
                    return(false);
                }
                if (!p.m_destination.Equals(m_destination))
                {
                    return(false);
                }
                if (p.DataLen != DataLen)
                {
                    return(false);
                }
                if (p.m_APCI != m_APCI)
                {
                    return(false);
                }

                for (int i = 0; i < m_value.Length; i++)
                {
                    //Console.WriteLine("Data[{0}]= {1} == {2}", i, m_value[i], p.m_value[i]);
                    if (p.m_value[i] != m_value[i])
                    {
                        return(false);
                    }
                }

                TimeSpan zeitDiff = p.m_ReceiveTime - receiveTime;
                if (Math.Abs(zeitDiff.TotalMilliseconds) > 500)
                {
                    return(false);
                }

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Exemplo n.º 2
0
 public HDKnx(cEMI emi)
 {
     this.emi = emi;
     //m_sourceAdr = emi.sourceAdr;
     m_destAdr = emi.destinationAdr;
     time      = emi.receiveTime;
     name      = "auto_" + time.ToShortTimeString();
     rawValue  = emi.GetRawData();
 }
Exemplo n.º 3
0
        internal void SetDataTelegramm(cEMI emi, byte SeqCounter)
        {
            List <byte> l = new List <byte>();

            KnxIpHeader header = new KnxIpHeader(knxnetip_services.TUNNELLING_REQUEST);

            header.Length = (short)(header.bytes.Length + emi.DataLen + 14);
            l.AddRange(header.bytes);
            l.Add(0x04);
            l.Add(con.channelId);
            l.Add(SeqCounter);
            l.Add(0x00);
            l.AddRange(emi.GetTelegramm());

            _bytes = l.ToArray();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Daten auf den Bus senden
        /// </summary>
        /// <param name="emi">Telegrammdaten die gesendet werden sollen</param>
        public void Send(cEMI emi)
        {
            try
            {
                KnxIpTelegrammGenerator Tele = new KnxIpTelegrammGenerator(this);
                Tele.SetDataTelegramm(emi, SeqCounter++);
                byte[] TeleBytes = Tele.bytes;

                // KnxNetForm
                Debug("D>:" + KnxTools.BytesToString(TeleBytes));

                udpClient.Send(TeleBytes, TeleBytes.Length);
            }
            catch (Exception e)
            {
                Err("Send: " + e.ToString());
            }
            return;
        }
Exemplo n.º 5
0
        public static HDKnx GetObject(cEMI emi)
        {
            // Suchen des passenden Objektes
            if (hdKnxObjList.ContainsKey(emi.destinationAdr))
            {
                return(hdKnxObjList[emi.destinationAdr]);
            }
            // Wenn keines gefunden, dann eines anlegen
            HDKnx hdKnx = null;

            switch (emi.DataLen)
            {
            case 1:
                hdKnx = new EIS1(emi);
                break;

            case 2:
                hdKnx = new EIS14(emi);
                break;

            case 3:
                hdKnx = new EIS5(emi);
                break;

            case 4:
                hdKnx = new EIS3(emi);
                break;

            case 5:
                hdKnx = new EIS11(emi);
                break;

            default:
                hdKnx = null;
                break;
            }
            hdKnxObjList.Add(emi.destinationAdr, hdKnx);
            return(hdKnx);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Diese Funktion wird vom UDP-Client aufgerufen wenn ein neues Telegramm eingetroffen ist
        /// </summary>
        /// <param name="ar"></param>
        public void ReceiveCallback(IAsyncResult ar)
        {
            int        Anz = (int)ar.AsyncState;
            IPEndPoint e   = new IPEndPoint(IPAddress.Any, 0);

            Byte[] receiveBytes = udpClient.EndReceive(ar, ref e);
            Anz++;
            Debug("Empf: Telegr[" + Anz + "]=" + KnxTools.BytesToString(receiveBytes));
            int AnzBytes = receiveBytes.Length;

            if (AnzBytes < 7)
            {
                Err("Err: Telegramm zu kurz, wird verworfen. " + KnxTools.BytesToString(receiveBytes));
                return;
            }
            try
            {
                // prüfen ob es ein ControlTelegramm ist
                if (receiveBytes[2] == 0x02)
                {   // es ist ein Controlltelegramm
                    switch (receiveBytes[3])
                    {
                    case 0x01:      // Search Request
                        Debug("Search Request from Gateway");
                        Debug("<S:" + KnxTools.BytesToString(receiveBytes));
                        break;

                    case 0x02:      // Search Response
                        _channelId = receiveBytes[6];
                        Debug("Search Response from Gateway");
                        Debug("<s:" + KnxTools.BytesToString(receiveBytes));
                        break;

                    case 0x03:      // Description Request
                        Debug("Description Request from Gateway");
                        Debug("<D:" + KnxTools.BytesToString(receiveBytes));
                        break;

                    case 0x04:      // Description Response
                        _channelId = receiveBytes[6];
                        Debug("Description Response from Gateway");
                        Debug("<d:" + KnxTools.BytesToString(receiveBytes));
                        break;

                    case 0x05:      // Connect Request
                        Info("Connection Request from Gateway");
                        Debug("<O:" + KnxTools.BytesToString(receiveBytes));
                        break;

                    case 0x06:      // Connect Response
                        _channelId = receiveBytes[6];
                        Info("ChannelId = " + _channelId);
                        Debug("<o:" + KnxTools.BytesToString(receiveBytes));
                        if (receiveBytes[7] == 0)
                        {
                            ConnectionState = KnxConnectionState.connected;
                        }
                        break;

                    case 0x07:      // Heartbeat Request
                        Debug("HeartbeatRequest for ChannelId = " + _channelId);
                        Debug("<H:" + KnxTools.BytesToString(receiveBytes));
                        break;

                    case 0x08:      // Heartbeat Response
                        Debug("HeartbeatResponse from ChannelId = " + _channelId);
                        Debug("<h:" + KnxTools.BytesToString(receiveBytes));
                        if (receiveBytes[7] == 0)
                        {
                            ConnectionState = KnxConnectionState.connected;
                        }
                        break;

                    case 0x09:      // Disconnect Request
                        Debug("DisconnectRequest for ChannelId = " + _channelId);
                        Debug("<C:" + KnxTools.BytesToString(receiveBytes));
                        break;

                    case 0x0A:      // Disconnect Response
                        Debug("Disconnected ChannelId = " + _channelId);
                        Debug("<c:" + KnxTools.BytesToString(receiveBytes));
                        if (receiveBytes[7] == 0)
                        {
                            ConnectionState = KnxConnectionState.disconnected;
                        }
                        break;

                    default:
                        Debug("<?:" + KnxTools.BytesToString(receiveBytes));
                        break;
                    }
                }
                else if (receiveBytes[2] == 0x04)
                {     // es ist kein Controlltelegramm
                    if (receiveBytes[3] == 0x20)
                    { // es ist ein Datentelegramm
                        // erst ein Ack senden
                        DataAck(receiveBytes[8]);
                        // Header entfernen
                        int idx = 0x0A;
                        int len = receiveBytes.Length - idx;

                        byte[] t = new byte[len];
                        Array.Copy(receiveBytes, idx, t, 0, len);
                        // und cemi Telegramm daraus erzeugen
                        cEMI emi = new cEMI(t);
                        Debug("ReceiveCallback: " + emi.ToString());
                        // Suchen des passenden HDKnx Objektes
                        HDKnx hdKnx = HDKnxHandler.GetObject(emi);
                        // und dort den Wert setzen, falls erforderlich
                        hdKnx.SetValue(emi);
                        // und auch das emi übergeben
                        hdKnx.emi = emi;

                        // Prüfen auf doppelte Telegramme
                        if (hdKnx.Equals(last_hdKnx))
                        {   // verwerfen
                            //Info("doppeltes Telegramm verworfen:");
                        }
                        else
                        {
                            //Console.WriteLine("Setze last Telegramm: \r\nvon {0} == \r\nzu  {1}",last_hdKnx, hdKnx);

                            last_hdKnx = new HDKnx(hdKnx.emi);
                            // Rohdaten melden falls gewünscht
                            if (rawTelegramReceived != null)
                            {
                                rawTelegramReceived(t);
                            }

                            // geänderte Daten melden falls gewünscht
                            if (dataChanged != null)
                            {
                                Debug("KnxNet.ReceiveCallback vor dataChanged" + t.ToString());
                                dataChanged(hdKnx);
                                Debug("KnxNet.ReceiveCallback nach dataChanged" + t.ToString());
                            }

                            if (telegramReceived != null)
                            {   // Ein Delegate ist eingerichtet, dann diesen aufrufen
                                telegramReceived(emi);
                            }
                            if (QueueEnable)
                            {   // in Queue speichern
                                lock (fromKnxQueue)
                                {
                                    fromKnxQueue.Enqueue(emi);
                                }
                                Debug("AddToQueue: " + emi.ToString());
                            }
                        }
                    }
                    else if (receiveBytes[3] == 0x21)
                    {   // Bestätigung eines Datentelegramm
                        Debug("Daten bestätigt  status = " + receiveBytes[9]);
                    }
                }
                ar = udpClient.BeginReceive(new AsyncCallback(ReceiveCallback), Anz);
            }
            catch (Exception ex)
            {
                Err("Err: Telegr[" + Anz + "]=" + KnxTools.BytesToString(receiveBytes));
                Err("Err: ReceiveCallback: " + ex.ToString());
                ar = udpClient.BeginReceive(new AsyncCallback(ReceiveCallback), Anz);
            }
        }
Exemplo n.º 7
0
 /// <summary>
 /// Setzt den RAW Wert aus einem Telegramm
 /// </summary>
 /// <param name="emi"></param>
 public virtual void SetValue(cEMI emi)
 {
     time     = emi.receiveTime;
     rawValue = emi.GetRawData();
 }