Ejemplo n.º 1
0
        /*
         * FunctionPropertyStateResponse     KNX_PRIORITY_NORMAL     H:6, Single, FF:0x00    [0x6F-0x01]     [0x00-0x01]      Ch007:1->Success
         * 0      1       2       3       4       5       6        7       8       9       10      11      12      13      14      15      16      17      18      19      20      21
         * 0x02   0xC9    0x07    0x01    0x00    0x01    0x00     0x12    0x00    0xEC    0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x01    0x00    0x00    0x00    0x01
         *      *       *       *       *       FlID
         */

        public static KNXmessage CreateResponse(FAHFunctionPropertyCommand MessageToRespondTo, FaHDevice atHomeDevice)
        {
            if (MessageToRespondTo.PropertyControl != FAHFunctionPropertyCommand.PropertyControlTypes.ReadFuncList)
            {
                throw new InvalidCastException();
            }

            //TODO, add as actual param to device!
            //FahDeviceParametersNew p = new FahDeviceParametersNew();
            //p.dataType = FahDeviceParametersNew.ParameterType.deviceInfo;
            //p.Response = KNXHelpers.knxPropertyReturnValues.Success;

            /*
             * if (atHomeDevice.FunctionList == null)
             * {
             *  atHomeDevice.FunctionList = new byte[] { 0x01, 0x00, 0x12, 0x00, 0xEC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01 };
             *  atHomeDevice.Serialize("input.
             * ");
             * }*/

            KNXmessage kNXmessage = new KNXmessage(knxControlField.KnxPacketType.KNX_PacketLong);

            kNXmessage.DestinationAddressType = KNXmessage.DestinationAddressFieldType.Individual;

            const int HEADERSIZE = 5;
            bool      moreIndices;

            byte[] bData; // atHomeDevice.Channels[MessageToRespondTo.ObjectID].Properties[MessageToRespondTo.PropertyID].FunctionList[(byte)MessageToRespondTo.FieldID].data;
            if (!atHomeDevice.ReadFunctionList(MessageToRespondTo.ObjectID, MessageToRespondTo.PropertyID, (int)MessageToRespondTo.FieldID, out bData, out moreIndices))
            {
                return(MessageToRespondTo.CreateCommandNotSupportedMessage());
            }

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

            kNXmessage.Payload.NewPayload(KNXAdpu.ApduType.FunctionPropertyStateResponse, payloadSize);
            kNXmessage.Payload.ReadablePayloadPacket = new FPSR_FunctionList(kNXmessage.Payload);
            FPSR_FunctionList newPkg = (FPSR_FunctionList)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);
        }