Example #1
0
 public KNXmessage(knxControlField.KnxPacketType PacketType)
 {
     ControlField = new knxControlField(PacketType, false, knxControlField.KnxPriority.KNX_PRIORITY_NORMAL);
     Payload      = new KNXPayload(this, 2);
     Timestamp    = DateTime.Now;
 }
Example #2
0
        public void ProcessKNXMessage(byte[] stagedPacket)
        {
            try
            {
                int dataIndex = 0;

                //Control Field
                ControlField = new knxControlField(stagedPacket[dataIndex++]);

                switch (ControlField.PacketType)
                {
                case knxControlField.KnxPacketType.KNX_PacketLong:
                    //Extended Control Field, only for long packet
                    ExtendedControlField = new KnxExtendedControlField(stagedPacket[dataIndex++]);
                    break;

                case knxControlField.KnxPacketType.KNX_PacketShort:
                    break;

                default:
                    throw new InvalidDataException();
                }

                //Source address field
                SourceAddress = KNXAddress.FromReversedBytes(stagedPacket[dataIndex++], stagedPacket[dataIndex++]);

                //Target address field
                TargetAddress = KNXAddress.FromReversedBytes(stagedPacket[dataIndex++], stagedPacket[dataIndex++]);

                switch (ControlField.PacketType)
                {
                case knxControlField.KnxPacketType.KNX_PacketLong:
                    //Payload Lenght, for long Packet
                    LongPacketDatalenght = (stagedPacket[dataIndex++]);
                    //Payload
                    Payload = new KNXPayload(stagedPacket, dataIndex++, this);
                    break;

                case knxControlField.KnxPacketType.KNX_PacketShort:
                    //DafSuLen for short Packet
                    dafLSDU = new KNXDafLSDU(stagedPacket[dataIndex++]);
                    //Payload
                    Payload = new KNXPayload(stagedPacket, dataIndex++, this);

                    //Page https://support.knx.org/hc/en-us/articles/115003188529-Payload not totally clear on how this is formatted
                    //This implementation seems to work for F@H

                    /*if (PayloadLenght == 0)
                     *  Console.WriteLine("No payload\\Apci");
                     * else if (PayloadLenght == 1)
                     * {
                     *  Console.WriteLine("Short payload with Apci");
                     *  Apci = new KNXApci(stagedPacket[dataIndex], stagedPacket[dataIndex++]);
                     * }
                     * else
                     * {
                     *  Console.WriteLine("Long payload with Apci");
                     *  Apci = new KNXApci(stagedPacket[dataIndex++], stagedPacket[dataIndex++]);
                     * }*/
                    break;

                default:
                    throw new InvalidDataException();
                }
            }
            catch (Exception e)
            {
                throw new Exception("Unable to process bytedata to KNXMessage", e);
            }
        }