Esempio n. 1
0
        public static KNXmessage CreateResponse(FAHFunctionPropertyCommand MessageToRespondTo, FaHDevice atHomeDevice)
        {
            if (MessageToRespondTo.PropertyControl != FAHFunctionPropertyCommand.PropertyControlTypes.ReadConns)
            {
                throw new InvalidCastException();
            }


            int  ChannelIndex = MessageToRespondTo.ObjectID;
            int  propIndex    = MessageToRespondTo.PropertyID;
            byte requestedIndice;
            byte propertyInfo;
            bool moreIndices;

            KNXAddress[] GroupValueAddress;
            //byte[] additionalData = null;
            uint payloadSize = (uint)(FPSRHEADERSIZE + 2);

            if (MessageToRespondTo.FPCpayload == null)
            {
                requestedIndice = 0;
                //There is no field requested; default to 0
            }
            else
            {
                requestedIndice = MessageToRespondTo.FPCpayload[0];
            }

            if (!atHomeDevice.ReadConnectionValue(ChannelIndex, propIndex, requestedIndice, out propertyInfo, out GroupValueAddress, out moreIndices))
            {
                return(MessageToRespondTo.CreateCommandNotSupportedMessage());
            }

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

            if (GroupValueAddress != null)
            {
                payloadSize += (uint)GroupValueAddress.Length * 2; //Address is not empty, add space to store it.

                /*if (additionalData != null)
                 * {
                 *  payloadSize += (uint)additionalData.Length;
                 * }*/
            }

            kNXmessage.Payload.NewPayload(KNXAdpu.ApduType.FunctionPropertyStateResponse, payloadSize);
            kNXmessage.Payload.ReadablePayloadPacket = new FPSR_ConnectionInfo(kNXmessage.Payload);
            FPSR_ConnectionInfo newPkg = (FPSR_ConnectionInfo)kNXmessage.Payload.ReadablePayloadPacket;

            newPkg.UpdatePacketSettings();
            newPkg.ConnectionID         = requestedIndice;
            newPkg.ConnectionSubIndexID = propertyInfo;
            if (GroupValueAddress != null)
            {
                newPkg.GroupValueAddress = GroupValueAddress;

                /*if(additionalData!=null)
                 * {
                 *
                 * }*/
            }
            newPkg.PropertyID = MessageToRespondTo.PropertyID;
            newPkg.ObjectID   = MessageToRespondTo.ObjectID;
            if (moreIndices && requestedIndice != 0)  //for 0 (no params) there are no more indices to report
            {
                newPkg.resultCode = KNXHelpers.knxPropertyReturnValues.MoreIndices;
            }
            else
            {
                newPkg.resultCode = KNXHelpers.knxPropertyReturnValues.Success;
            }

            return(kNXmessage);
        }