Example #1
0
        public static KNXmessage CreateReadResponse(FAHFunctionPropertyCommand MessageToRespondTo, FaHDevice atHomeDevice)
        {
            try
            {
                if (MessageToRespondTo.PropertyControl != FAHFunctionPropertyCommand.PropertyControlTypes.ReadDesc)
                {
                    throw new InvalidCastException();
                }

                int ChannelIndex = MessageToRespondTo.ObjectID;
                int propIndex    = MessageToRespondTo.PropertyID;

                byte[] bData;
                bool   moreIndices;

                if (!atHomeDevice.ReadDescriptorValue(ChannelIndex, propIndex, out bData, out moreIndices))
                {
                    return(MessageToRespondTo.CreateCommandNotSupportedMessage());
                }

                KNXmessage kNXmessage = new KNXmessage(knxControlField.KnxPacketType.KNX_PacketShort)
                {
                    DestinationAddressType = KNXmessage.DestinationAddressFieldType.Individual
                };

                const int HEADERSIZE = 5;

                //Todo, check lenght?
                uint payloadSize = (uint)(HEADERSIZE + bData.Length);

                kNXmessage.Payload.NewPayload(KNXAdpu.ApduType.FunctionPropertyStateResponse, payloadSize);
                kNXmessage.Payload.ReadablePayloadPacket = new FPSR_DescriptorValueRead(kNXmessage.Payload);
                FPSR_DescriptorValueRead newPkg = (FPSR_DescriptorValueRead)kNXmessage.Payload.ReadablePayloadPacket;
                newPkg.UpdatePacketSettings();
                newPkg.FPSRpayload = bData;
                newPkg.PropertyID  = MessageToRespondTo.PropertyID;
                newPkg.ObjectID    = MessageToRespondTo.ObjectID;
                if (moreIndices)
                {
                    newPkg.resultCode = KNXHelpers.knxPropertyReturnValues.MoreIndices;
                }
                else
                {
                    newPkg.resultCode = KNXHelpers.knxPropertyReturnValues.Success;
                }
                return(kNXmessage);
            }
            catch
            {
                return(MessageToRespondTo.CreateCommandFailedMessage());
            }
        }