예제 #1
0
        private static bool ProcessResponse(out bool moreIndices, bool keepKNxPacketResult = false, bool WriteToDevice = true)
        {
            while (knxMsgtoProcess == null)
            {
                //Todo add exit counter
                Thread.Sleep(5);
            }

            moreIndices = false;

            FahPayloadInterpeter.TryToInterpret(ref knxMsgtoProcess);

            if (knxMsgtoProcess.Payload.Apdu.apduType == KNXAdpu.ApduType.FunctionPropertyStateResponse)
            {
                knxMsgtoProcess.Payload.ReadablePayloadPacket = ((FAHFunctionPropertyStateResponse)knxMsgtoProcess.Payload.ReadablePayloadPacket).ProcessPayload(lastRequestedPropertyControl, ByteDataParm);
                FAHFunctionPropertyStateResponse fAHFunction = knxMsgtoProcess.Payload.ReadablePayloadPacket as FAHFunctionPropertyStateResponse;

                ConsoleWriteOnEmptyLine(string.Format("Processing {0} ", knxMsgtoProcess.HeaderAsString));
                knxMsgtoProcess.Payload.ReadablePayloadPacket.PrintUnaccountedBytes();

                if (keepKNxPacketResult)
                {
                    knxLastMsgProcessed = knxMsgtoProcess;
                }

                if (fAHFunction.resultCode == KNXHelpers.knxPropertyReturnValues.MoreIndices || fAHFunction.resultCode == KNXHelpers.knxPropertyReturnValues.Success)
                {
                    if (!WriteToDevice)
                    {
                        if (fAHFunction.resultCode == KNXHelpers.knxPropertyReturnValues.MoreIndices)
                        {
                            moreIndices = true;
                        }
                        else
                        {
                            moreIndices = false;
                        }
                        Thread.Sleep(100);
                        knxMsgtoProcess = null;
                        return(true);
                    }
                    if (fAHFunction.SaveToDevice(ref deviceToLearn, out moreIndices))
                    {
                        if (fAHFunction.resultCode == KNXHelpers.knxPropertyReturnValues.MoreIndices)
                        {
                            moreIndices = true;
                        }
                        else
                        {
                            moreIndices = false;
                        }
                        Thread.Sleep(100);
                        knxMsgtoProcess = null;
                        return(true);
                    }
                }
                knxMsgtoProcess = null;
            }
            return(false);
        }
예제 #2
0
        public static KNXmessage CreateFAHFunctionPropertyCommand(FaHDevice faHDevice, PropertyControlTypes propertyControlType, byte ObjectID, byte PropertyID, byte[] payload = null)
        {
            if (payload == null)
            {
                payload = new byte[0];
            }
            KNXmessage kNXmessage = new KNXmessage(knxControlField.KnxPacketType.KNX_PacketShort);

            kNXmessage.DestinationAddressType = KNXmessage.DestinationAddressFieldType.Group;
            kNXmessage.SourceAddress          = new KNXAddress(1);
            kNXmessage.TargetAddress          = faHDevice.KnxAddress;
            kNXmessage.HopCount = 6;
            kNXmessage.DestinationAddressType = KNXmessage.DestinationAddressFieldType.Individual;
            kNXmessage.Payload.NewPayload(KNXAdpu.ApduType.FunctionPropertyCommand, (uint)(5 + payload.Length));
            kNXmessage.Payload.ReadablePayloadPacket = new FAHFunctionPropertyCommand(kNXmessage.Payload);
            FAHFunctionPropertyCommand newPkg = (FAHFunctionPropertyCommand)kNXmessage.Payload.ReadablePayloadPacket;

            newPkg.PropertyControl = propertyControlType;
            if (payload.Length != 0)
            {
                kNXmessage.Payload.UpdateBytes(payload, 5, payload.Length);
            }
            newPkg.ObjectID   = ObjectID;
            newPkg.PropertyID = PropertyID;
            return(kNXmessage);
        }
예제 #3
0
        public static KNXmessage CreateResponse(FAHFunctionPropertyCommand MessageToRespondTo, FaHDevice atHomeDevice)
        {
            if (MessageToRespondTo.PropertyControl != FAHFunctionPropertyCommand.PropertyControlTypes.ReadDesc)
            {
                throw new InvalidCastException();
            }

            bool moreIndices = false;
            int  OIDindex    = MessageToRespondTo.PropertyID;

            byte[] bData;
            byte   indice = 0;

            if (MessageToRespondTo.FieldID != null)
            {
                indice = (byte)(MessageToRespondTo.FieldID);
            }

            if (!atHomeDevice.ReadOIDData(MessageToRespondTo.ObjectID, MessageToRespondTo.PropertyID, indice, out bData, out moreIndices))
            {
                return(MessageToRespondTo.CreateInvalidIndexMessage());
            }

            //OidChannel 5 needs ShortPkg! (currently based on packet payload lenght)
            KNXmessage kNXmessage;

            if (bData.Length < 5)
            {
                kNXmessage = new KNXmessage(knxControlField.KnxPacketType.KNX_PacketShort);
            }
            else
            {
                kNXmessage = new KNXmessage(knxControlField.KnxPacketType.KNX_PacketLong);
            }

            kNXmessage.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_DeviceOIDData(kNXmessage.Payload);
            FPSR_DeviceOIDData newPkg = (FPSR_DeviceOIDData)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);
        }
예제 #4
0
        public static KNXmessage CreateResponse(FaHDevice atHomeDevice, KNXAddress AddressToSendTo)
        {
            KNXmessage kNXmessage = new KNXmessage(knxControlField.KnxPacketType.KNX_PacketLong);

            //kNXmessage.HopCount = 6;
            kNXmessage.SourceAddress = atHomeDevice.KnxAddress;

            uint payloadSize = __FAHChannelStart + (atHomeDevice.ChannelCount * 2);

            kNXmessage.TargetAddress = AddressToSendTo;
            kNXmessage.Payload.NewPayload(KNXAdpu.ApduType.DeviceDescriptorResponse, payloadSize);
            kNXmessage.Payload.ReadablePayloadPacket = new FAHDeviceDescriptorResponse(kNXmessage.Payload);
            FAHDeviceDescriptorResponse newPkg = (FAHDeviceDescriptorResponse)kNXmessage.Payload.ReadablePayloadPacket;

            newPkg.UpdatePacketSettings();
            newPkg.DescriptorType   = 3;
            newPkg.__UnknownValue0  = new KNXu16SimpleStruct(0x0E, 0x00); //14 00
            newPkg.FahDeviceAddress = atHomeDevice.FaHAddress;
            newPkg.fahSystemID      = atHomeDevice.SystemID;
            newPkg.faHDeviceType    = atHomeDevice.DeviceType;
            newPkg.ConsistencyValue = atHomeDevice.ConsistancyValue;
            //kNXmessage.DestinationAddressType = KNXmessage.DestinationAddressFieldType.Group;

            for (int i = 1; i <= atHomeDevice.ChannelCount; i++)
            {
                KNXu16SimpleStruct addr;
                if (atHomeDevice.ReadChannelIndentifier(i, out addr))
                {
                    newPkg.SetDeviceChannel((uint)i, addr);
                }
                //else NULL
            }
            return(kNXmessage);
        }
예제 #5
0
        public static KNXmessage CreateResponse(FAHFunctionPropertyCommand MessageToRespondTo, FaHDevice atHomeDevice)
        {
            if (MessageToRespondTo.PropertyControl != FAHFunctionPropertyCommand.PropertyControlTypes.ReadDesc)
            {
                throw new InvalidCastException();
            }

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

            const int HEADERSIZE = 5;

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

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

            newPkg.UpdatePacketSettings();
            newPkg.FPSRpayload = atHomeDevice.DeviceParameterInfo;
            newPkg.PropertyID  = MessageToRespondTo.PropertyID;
            newPkg.ObjectID    = MessageToRespondTo.ObjectID;
            newPkg.resultCode  = KNXHelpers.knxPropertyReturnValues.Success;

            //Part of the FPSRpayload at this moment!
            newPkg.FieldID = (byte)MessageToRespondTo.FieldID;

            return(kNXmessage);
        }
예제 #6
0
        public static KNXmessage CreateResponse(FAHFunctionPropertyCommand MessageToRespondTo, FaHDevice atHomeDevice)
        {
            if (MessageToRespondTo.PropertyControl != FAHFunctionPropertyCommand.PropertyControlTypes.ReadDesc)
            {
                throw new InvalidCastException();
            }

            KNXmessage kNXmessage;

            string Description;

            atHomeDevice.ReadChannelDescription(MessageToRespondTo.ObjectID, MessageToRespondTo.PropertyID, out Description);

            if (Description.Length > 10)
            {
                kNXmessage = new KNXmessage(knxControlField.KnxPacketType.KNX_PacketLong);
            }
            else
            {
                kNXmessage = new KNXmessage(knxControlField.KnxPacketType.KNX_PacketShort);
            }
            kNXmessage.DestinationAddressType = KNXmessage.DestinationAddressFieldType.Individual;
            uint payloadSize = (uint)(FPSRHEADERSIZE + DescriptionByteLenght(Description));

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

            newPkg.UpdatePacketSettings();
            newPkg.PropertyID  = MessageToRespondTo.PropertyID;
            newPkg.ObjectID    = MessageToRespondTo.ObjectID;
            newPkg.resultCode  = KNXHelpers.knxPropertyReturnValues.Success;
            newPkg.Description = Description;
            return(kNXmessage);
        }
예제 #7
0
        public static KNXmessage CreateFAHGroupValueResponse(FaHDevice faHDevice, KNXAddress GroupValueAddress, byte[] Payload)
        {
            if (Payload == null)
            {
                throw new InvalidDataException();
            }

            uint plLen;

            if (Payload.Length == 1) //Encoded in second byte
            {
                plLen = 0;
            }
            else
            {   //Not encoded
                plLen = (uint)Payload.Length;
            }

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

            kNXmessage.DestinationAddressType = KNXmessage.DestinationAddressFieldType.Group;
            kNXmessage.SourceAddress          = faHDevice.KnxAddress;
            kNXmessage.TargetAddress          = GroupValueAddress;
            kNXmessage.HopCount = 6;
            kNXmessage.Payload.NewPayload(KNXAdpu.ApduType.GroupValueResponse, 2 + plLen);
            kNXmessage.Payload.ReadablePayloadPacket = new FAHGroupValueResponse(kNXmessage.Payload);
            FAHGroupValueResponse newPkg = (FAHGroupValueResponse)kNXmessage.Payload.ReadablePayloadPacket;

            newPkg.MessageData = Payload;
            return(kNXmessage);
        }
예제 #8
0
        public static KNXmessage CreateReadResponse(FAHFunctionPropertyCommand MessageToRespondTo, FaHDevice atHomeDevice)
        {
            try
            {
                if (MessageToRespondTo.PropertyControl != FAHFunctionPropertyCommand.PropertyControlTypes.ReadDevHealth)
                {
                    throw new InvalidCastException();
                }

                byte[] bData = atHomeDevice.DeviceHealthStatus.ByteData;

                KNXmessage kNXmessage = new KNXmessage(knxControlField.KnxPacketType.KNX_PacketLong)
                {
                    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_ReadDeviceHealth(kNXmessage.Payload);
                FPSR_ReadDeviceHealth newPkg = (FPSR_ReadDeviceHealth)kNXmessage.Payload.ReadablePayloadPacket;
                newPkg.UpdatePacketSettings();
                newPkg.FPSRpayload = bData;
                newPkg.PropertyID  = MessageToRespondTo.PropertyID;
                newPkg.ObjectID    = MessageToRespondTo.ObjectID;
                return(kNXmessage);
            }
            catch
            {
                return(MessageToRespondTo.CreateCommandNotSupportedMessage());
            }
        }
예제 #9
0
 public override bool SendKNXMessage(KNXmessage knxMsg)
 {
     if (tcpClient.Connected)
     {
         return(PrepareAndSendDataToServerIfConnected(knxMsg.toByteArray()));
     }
     return(false);
 }
예제 #10
0
        private void GetCurrentGroupValueStatus()
        {
            //Request current status
            FreeAtHomeDevices.FaHDevice d = new FreeAtHomeDevices.FaHDevice();
            d.KnxAddress.knxAddress = 0;
            KNXmessage a = FAHGroupValueRead.CreateFAHGroupValueRead(d, knxGroupToMonitor, new byte[] { });

            kNXUart.SendKNXMessage(a);
        }
예제 #11
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);
        }
예제 #12
0
        public static KNXmessage CreateReadResponse(FAHFunctionPropertyCommand MessageToRespondTo, FaHDevice atHomeDevice)
        {
            try
            {
                if (MessageToRespondTo.PropertyControl != FAHFunctionPropertyCommand.PropertyControlTypes.ReadBasicInfo)
                {
                    throw new InvalidCastException();
                }

                int ChannelIndex = MessageToRespondTo.ObjectID;
                int propIndex    = MessageToRespondTo.PropertyID;
                int fieldID      = (int)MessageToRespondTo.FieldID;

                byte[] bData;//= atHomeDevice.Channels[ChannelIndex].Properties[propIndex].FieldData[fieldID].data;
                bool   moreIndices;

                if (!atHomeDevice.ReadPropertyValue(ChannelIndex, propIndex, fieldID, 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_PropertyValueRead(kNXmessage.Payload);
                FPSR_PropertyValueRead newPkg = (FPSR_PropertyValueRead)kNXmessage.Payload.ReadablePayloadPacket;
                newPkg.UpdatePacketSettings();
                newPkg.FPSRpayload = bData;
                newPkg.PropertyID  = MessageToRespondTo.PropertyID;
                newPkg.ObjectID    = MessageToRespondTo.ObjectID;
                newPkg.FieldID     = (byte)MessageToRespondTo.FieldID;
                if (moreIndices)
                {
                    newPkg.resultCode = KNXHelpers.knxPropertyReturnValues.MoreIndices;
                }
                else
                {
                    newPkg.resultCode = KNXHelpers.knxPropertyReturnValues.Success;
                }
                return(kNXmessage);
            }
            catch
            {
                return(MessageToRespondTo.CreateCommandNotSupportedMessage());
            }
        }
예제 #13
0
        static bool DiscoverDevice(ref KNXUartConnection kNXUart)
        {
            if (deviceToLearn.KnxAddress.knxAddress == 0 || deviceToLearn.ChannelCount == 0)
            {
                ConsoleWriteHeader("Waiting for Device Discovery Response ");
                //*----------------------------------------------------------------------------
                devLearnState = DeviceLearningState.deviceDiscovery;
                KNXmessage knxDeviceDescriptorRead = FAHDeviceDescriptorRead.CreateFAHDeviceDescriptorRead();
                Console.Write(string.Format("{0}; {1} ", knxDeviceDescriptorRead.Timestamp.ToString(KNXHelpers.DateTimeFormat), knxDeviceDescriptorRead.HeaderAsString));
                knxDeviceDescriptorRead.Payload.ReadablePayloadPacket.PrintUnaccountedBytes();
                kNXUart.WriteDirect(knxDeviceDescriptorRead, false);

                while (devLearnState != DeviceLearningState.deviceDiscoveryResponse)
                {
                    Console.Write('.');
                    Thread.Sleep(1000);
                }
                Console.WriteLine("OK: " + deviceToLearn.FaHAddress);

                /*
                 * if (deviceToLearn.SystemID == new FahSystemID(0xFF, 0xFF) || deviceToLearn.KnxAddress == new KNXAddress(0xFF, 0xFF))
                 * {
                 *  deviceToLearn.SystemID = SystemID;
                 *  deviceToLearn.KnxAddress = new KNXAddress(0x6F, 0x01);
                 * }*/
                //deviceToLearn.SetAddressInformation(new KNXAddress(0xFF, 0xFF), SystemID);
            }
            else
            {
                Console.WriteLine("Device ID known: {0}-->{1}", deviceToLearn.FaHAddress, deviceToLearn.KnxAddress);
            }

            //*----------------------------------------------------------------------------

            //if (deviceToLearn.SystemID == new FahSystemID(0xFF, 0xFF) || deviceToLearn.KnxAddress == new KNXAddress(0xFF, 0xFF))
            {
                ConsoleWriteHeader("IndividualAddressSerialNumberWrite");
                KNXmessage knxSetSerialNumber = FAHIndividualAddressSerialNumberWrite.CreateFAHIndividualAddressSerialNumberWrite(deviceToLearn);
                if (!kNXUart.WriteDirect(knxSetSerialNumber, true))
                {
                    return(false);
                }

                Console.WriteLine("OK: " + deviceToLearn.KnxAddress);
            }

            /*else
             * {
             *  writehead("Keeping Address: " + deviceToLearn.KnxAddress);
             * }*/
            devLearnState = DeviceLearningState.deviceReadSettings;
            return(true);
        }
예제 #14
0
        public static KNXmessage CreateResponse(FAHFunctionPropertyCommand MessageToRespondTo, FaHDevice atHomeDevice)
        {
            if (MessageToRespondTo.PropertyControl != FAHFunctionPropertyCommand.PropertyControlTypes.ReadIconId)
            {
                throw new InvalidCastException();
            }

            //int objId = MessageToRespondTo.ObjectID;
            UInt16 Icon = atHomeDevice.ReadIconInfo(MessageToRespondTo.ObjectID, MessageToRespondTo.PropertyID);//   KNXHelpers.GetCheckNullUint16Value(atHomeDevice.Channels[objId].Properties[MessageToRespondTo.PropertyID].IconId, 0xFFFF);

            /*
             * if (Room == 0 && X== 0 && Y == 0)
             * {
             *  atHomeDevice.ChannelProperties[MessageToRespondTo.ObjectID].Properties[MessageToRespondTo.PropertyID].RoomID = 0xFFFF;
             *  Room = 0xFFFF;
             *  atHomeDevice.ChannelProperties[MessageToRespondTo.ObjectID].Properties[MessageToRespondTo.PropertyID].X = 0xFFFF;
             *  X = 0xFFFF;
             *  atHomeDevice.ChannelProperties[MessageToRespondTo.ObjectID].Properties[MessageToRespondTo.PropertyID].X = 0xFFFF;
             *  Y = 0xFFFF;
             *  atHomeDevice.Serialize("input.json");
             * }*/

            //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.json");
             * }*/

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

            kNXmessage.DestinationAddressType = KNXmessage.DestinationAddressFieldType.Individual;

            uint payloadSize = (uint)(FPSRHEADERSIZE + VALUESIZE);

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

            newPkg.UpdatePacketSettings();
            newPkg.PropertyID = MessageToRespondTo.PropertyID;
            newPkg.ObjectID   = MessageToRespondTo.ObjectID;
            newPkg.resultCode = KNXHelpers.knxPropertyReturnValues.Success;
            newPkg.Icon       = Icon;
            return(kNXmessage);
        }
예제 #15
0
        public static KNXmessage CreateFAHDeviceDescriptorRead()
        {
            KNXmessage kNXmessage = new KNXmessage(knxControlField.KnxPacketType.KNX_PacketShort)
            {
                DestinationAddressType = KNXmessage.DestinationAddressFieldType.Group,
                SourceAddress          = new KNXAddress(1),
                HopCount = 6
            };

            kNXmessage.Payload.NewPayload(KNXAdpu.ApduType.DeviceDescriptorRead, 2);
            kNXmessage.Payload.ReadablePayloadPacket = new FAHDeviceDescriptorRead(kNXmessage.Payload);
            FAHDeviceDescriptorRead newPkg = (FAHDeviceDescriptorRead)kNXmessage.Payload.ReadablePayloadPacket;

            newPkg.DescriptorType = 3;
            return(kNXmessage);
        }
        public static KNXmessage CreateFAHIndividualAddressSerialNumberWrite(FaHDevice faHDevice)
        {
            KNXmessage kNXmessage = new KNXmessage(knxControlField.KnxPacketType.KNX_PacketShort);

            kNXmessage.DestinationAddressType = KNXmessage.DestinationAddressFieldType.Group;
            kNXmessage.SourceAddress          = new KNXAddress(1);
            kNXmessage.HopCount = 6;
            kNXmessage.Payload.NewPayload(KNXAdpu.ApduType.IndividualAddressSerialNumberWrite, 12);
            kNXmessage.Payload.ReadablePayloadPacket = new FAHIndividualAddressSerialNumberWrite(kNXmessage.Payload);
            FAHIndividualAddressSerialNumberWrite newPkg = (FAHIndividualAddressSerialNumberWrite)kNXmessage.Payload.ReadablePayloadPacket;

            newPkg.FaHDeviceAddress = faHDevice.FaHAddress;
            newPkg.FahSystemID      = faHDevice.SystemID;
            newPkg.kNXAddress       = faHDevice.KnxAddress;
            return(kNXmessage);
        }
예제 #17
0
        public KNXmessage Process(FaHDevice atHomeDevice)
        {
            if (PropertyControl != FAHFunctionPropertyCommand.PropertyControlTypes.WriteValue)
            {
                throw new InvalidCastException();
            }

            int ChannelIndex = ObjectID;
            int propIndex    = PropertyID;
            int lFieldID     = (int)FieldID;
            //TODO check to keep fieldID in value to store??/
            bool       hasMoreIndices = atHomeDevice.WritePropertyValue(ChannelIndex, propIndex, lFieldID, RemainderBytesAsPayload(5));
            KNXmessage k = CreateEmptySuccessMessage(hasMoreIndices);

            k.Payload.AppendPayload(new byte[] { (byte)FieldID });
            return(k);
        }
예제 #18
0
        private static void KNXUart_OnKNXMessage(KNXNetworkLayerTemplate caller, KNXBaseTypes.KNXmessage Message, KNXNetworkLayerTemplate.KnxPacketEvents uartEvent)
        {
            if (Message.ControlField.RepeatFrame)
            {
                //Repeatframe
                return;
            }
            if (Message.SourceAddress == SysApEmulator.KnxAddress)
            {
                //Self
                return;
            }

            switch (devLearnState)
            {
            case DeviceLearningState.deviceDiscovery:
                if (Message.Payload.Apdu.apduType == KNXAdpu.ApduType.DeviceDescriptorResponse)
                {
                    Message.Payload.ReadablePayloadPacket = new FAHDeviceDescriptorResponse(Message.Payload);
                    bool more;
                    ((FAHDeviceDescriptorResponse)Message.Payload.ReadablePayloadPacket).SaveToDevice(ref deviceToLearn, out more);
                    devLearnState = DeviceLearningState.deviceDiscoveryResponse;
                    return;
                }
                break;

            case DeviceLearningState.deviceReadSettings:
                if (Message.SourceAddress == deviceToLearn.KnxAddress)
                {
                    if (Message.ControlField.RepeatFrame)
                    {
                        //For now ignore
                        return;
                    }
                    knxMsgtoProcess = Message;
                }
                break;

            default:
                Console.Write(string.Format("{0} ", Message.HeaderAsString));
                Message.Payload.ReadablePayloadPacket.PrintUnaccountedBytes();
                break;
            }
        }
예제 #19
0
        public static KNXmessage CreateResponse(FAHFunctionPropertyCommand MessageToRespondTo, FaHDevice atHomeDevice)
        {
            try
            {
                if (MessageToRespondTo.PropertyControl != FAHFunctionPropertyCommand.PropertyControlTypes.ReadBasicInfo)
                {
                    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.BasicDeviceInformation == null)
                 * {
                 *  atHomeDevice.BasicDeviceInformation = new byte[] { 0xFF, 0xEB, 0xFE, 0xFF, 0x08, 0x00, 0x37, 0x00, 0x6A, 0xF6, 0xD1, 0x00, 0x00, 0x02, 0x7E };
                 * }*/

                KNXmessage kNXmessage = new KNXmessage(knxControlField.KnxPacketType.KNX_PacketLong);
                kNXmessage.DestinationAddressType = KNXmessage.DestinationAddressFieldType.Individual;

                const int HEADERSIZE = 5;

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

                kNXmessage.Payload.NewPayload(KNXAdpu.ApduType.FunctionPropertyStateResponse, payloadSize);
                kNXmessage.Payload.ReadablePayloadPacket = new FPSR_BasicDeviceInfo(kNXmessage.Payload);
                FPSR_BasicDeviceInfo newPkg = (FPSR_BasicDeviceInfo)kNXmessage.Payload.ReadablePayloadPacket;
                newPkg.UpdatePacketSettings();
                newPkg.FPSRpayload = atHomeDevice.BasicDeviceInformation;
                newPkg.PropertyID  = MessageToRespondTo.PropertyID;
                newPkg.ObjectID    = MessageToRespondTo.ObjectID;
                newPkg.resultCode  = KNXHelpers.knxPropertyReturnValues.Success;
                return(kNXmessage);
            }
            catch
            {
                return(null);
            }
        }
예제 #20
0
        public void WriteOut(KNXmessage Message)
        {
            if (!write)
            {
                throw new InvalidOperationException();
            }
            try
            {
                string dtFormat = Message.Timestamp.ToString("yyyy-MM-dd HH:mm:ss.fff");

                string str = string.Format("{0}; {1}", dtFormat, KNXHelpers.GetStringHex(Message.toByteArray()));
                if (!string.IsNullOrEmpty(str))
                {
                    fReg.WriteLine(str);
                    fReg.Flush();
                }
            }
            catch { }
        }
예제 #21
0
        private KNXmessage CreateEmptyMessage(KNXHelpers.knxPropertyReturnValues returnCode)
        {
            KNXmessage kNXmessage = new KNXmessage(knxControlField.KnxPacketType.KNX_PacketShort)
            {
                DestinationAddressType = KNXmessage.DestinationAddressFieldType.Individual
            };

            uint payloadSize = FPCHEADERSIZE;

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

            newPkg.UpdatePacketSettings();
            newPkg.PropertyID = PropertyID;
            newPkg.ObjectID   = ObjectID;
            newPkg.resultCode = returnCode;
            return(kNXmessage);
        }
예제 #22
0
 public static void TryToInterpret(ref KNXmessage Message)
 {
     if (Message.Payload.Apdu.apduType == KNXAdpu.ApduType.DeviceDescriptorResponse)
     {
         Message.Payload.ReadablePayloadPacket = new FAHDeviceDescriptorResponse(Message.Payload);
     }
     else if (Message.Payload.Apdu.apduType == KNXAdpu.ApduType.DeviceDescriptorRead)
     {
         Message.Payload.ReadablePayloadPacket = new FAHDeviceDescriptorRead(Message.Payload);
     }
     else if (Message.Payload.Apdu.apduType == KNXAdpu.ApduType.FunctionPropertyStateResponse)
     {
         Message.Payload.ReadablePayloadPacket = new FAHFunctionPropertyStateResponse(Message.Payload);
     }
     else if (Message.Payload.Apdu.apduType == KNXAdpu.ApduType.FunctionPropertyCommand)
     {
         Message.Payload.ReadablePayloadPacket = new FAHFunctionPropertyCommand(Message.Payload);
     }
     else if (Message.Payload.Apdu.apduType == KNXAdpu.ApduType.ABBSetBinaryInputType)
     {
         Message.Payload.ReadablePayloadPacket = new ABBSetBinaryInputType(Message.Payload);
     }
     else if (Message.Payload.Apdu.apduType == KNXAdpu.ApduType.GroupValueWrite)
     {
         Message.Payload.ReadablePayloadPacket = new FAHGroupValueWrite(Message.Payload);
     }
     else if (Message.Payload.Apdu.apduType == KNXAdpu.ApduType.Restart)
     {
         Message.Payload.ReadablePayloadPacket = new FAHRestart(Message.Payload);
     }
     else if (Message.Payload.Apdu.apduType == KNXAdpu.ApduType.IndividualAddressSerialNumberWrite)
     {
         Message.Payload.ReadablePayloadPacket = new FAHIndividualAddressSerialNumberWrite(Message.Payload);
     }
     else if (Message.Payload.Apdu.apduType == KNXAdpu.ApduType.ABBResponseBinaryInputType)
     {
         Message.Payload.ReadablePayloadPacket = new ABBResponseBinaryInputType(Message.Payload);
     }
 }
예제 #23
0
        public KNXmessage ReadNextMessage()
        {
            try
            {
                if (write)
                {
                    throw new InvalidOperationException();
                }
                string line = fRead.ReadLine();

                if (line == null)
                {
                    return(null);
                }

                if (line.StartsWith("#"))
                {
                    return(ReadNextMessage());
                }

                string[] data = line.Split(';');

                //Data
                string[] payload = data[1].Trim().Split(',');
                byte[]   btdata  = new byte[payload.Length];
                int      i       = 0;
                foreach (string s in payload)
                {
                    btdata[i] = Convert.ToByte(s.Trim().Substring(2), 16);
                    i++;
                }
                return(KNXmessage.fromByteArray(btdata, DateTime.Parse(data[0])));
            }
            catch
            {
                return(null);
            }
        }
예제 #24
0
        public static KNXmessage UpdateConsistancyTag(FAHFunctionPropertyCommand MessageToRespondTo, FaHDevice atHomeDevice)
        {
            if (MessageToRespondTo.PropertyControl != FAHFunctionPropertyCommand.PropertyControlTypes.UpdConsistencyTag)
            {
                throw new InvalidCastException();
            }

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

            kNXmessage.DestinationAddressType = KNXmessage.DestinationAddressFieldType.Individual;

            uint payloadSize = (uint)(FPSRHEADERSIZE + 2);

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

            newPkg.UpdatePacketSettings();
            newPkg.PropertyID       = MessageToRespondTo.PropertyID;
            newPkg.ObjectID         = MessageToRespondTo.ObjectID;
            newPkg.resultCode       = KNXHelpers.knxPropertyReturnValues.Success;
            newPkg.ConsistancyValue = atHomeDevice.GenerateNewConsistancyTag();
            return(kNXmessage);
        }
예제 #25
0
        private static void KNXUart_OnKNXMessage(KNXNetworkLayerTemplate caller, KNXBaseTypes.KNXmessage Message, KNXNetworkLayerTemplate.KnxPacketEvents uartEvent)
        {
            stdOut.WriteOut(Message);
            try
            {
                FahPayloadInterpeter.TryToInterpret(ref Message);

                if (Message.Payload.Apdu.apduType == KNXAdpu.ApduType.FunctionPropertyStateResponse)
                {
                    Message.Payload.ReadablePayloadPacket = ((FAHFunctionPropertyStateResponse)Message.Payload.ReadablePayloadPacket).ProcessPayload(lastRequestedPropertyControl, ByteDataParm);

                    if (((FAHFunctionPropertyStateResponse)Message.Payload.ReadablePayloadPacket).resultCode != KNXHelpers.knxPropertyReturnValues.CommandNotSupported)
                    {
                        /*
                         * bool more;
                         * if (!((FAHFunctionPropertyStateResponse)Message.Payload.ReadablePayloadPacket).SaveToDevice(ref fahDevToLearn, out more))
                         * {
                         *  Console.BackgroundColor = ConsoleColor.Red;
                         *  Console.Write("Not saved: ");
                         *  Console.BackgroundColor = ConsoleColor.Black;
                         * }*/
                    }
                }
                else if (Message.Payload.Apdu.apduType == KNXAdpu.ApduType.FunctionPropertyCommand)
                {
                    ((FAHFunctionPropertyCommand)Message.Payload.ReadablePayloadPacket).GetPropertyControlForReply(ref ByteDataParm, ref lastRequestedPropertyControl);
                }

                string ret = string.Format("{0}; {1} ", Message.Timestamp.ToString(KNXHelpers.DateTimeFormat), Message.HeaderAsString);
                Console.Write(ret);
                Message.Payload.ReadablePayloadPacket.PrintUnaccountedBytes(false);

                switch (Message.Payload.Apdu.apduType)
                {
                case KNXAdpu.ApduType.IndividualAddressSerialNumberWrite:
                    var fasnw = Message.Payload.ReadablePayloadPacket as FAHIndividualAddressSerialNumberWrite;

                    /*
                     * bool more;
                     * fasnw.SaveToDevice(ref fahDevToReturn, out more);
                     */
                    //Succes
                    return;

                case KNXAdpu.ApduType.DeviceDescriptorRead:
                    //LastCreatedMsg = FAHDeviceDescriptorResponse.CreateResponse(fahDevToReturn, Message.SourceAddress);
                    return;

                case KNXAdpu.ApduType.GroupValueWrite:
                    return;

                case KNXAdpu.ApduType.FunctionPropertyCommand:
                    var fpc = Message.Payload.ReadablePayloadPacket as FAHFunctionPropertyCommand;

                    /*KNXmessage k = fpc.ProcessAndCreateResponse(fahDevToReturn);
                     * if (k != null)
                     * {
                     *  LastCreatedMsg = k;
                     * }*/
                    break;

                case KNXAdpu.ApduType.DeviceDescriptorResponse:
                    FAHDeviceDescriptorResponse fAHDeviceDescriptorResponse = Message.Payload.ReadablePayloadPacket as FAHDeviceDescriptorResponse;

                    /*bool mi;
                     * fAHDeviceDescriptorResponse.SaveToDevice(ref fahDevToLearn, out mi);
                     *
                     * var z = fAHDeviceDescriptorResponse.FahDeviceAddress;
                     * if (fAHDeviceDescriptorResponse.FahDeviceAddress == fahDevToReturn.FaHAddress)
                     * {
                     *  if (LastCreatedMsg.ToHexString() != Message.ToHexString())
                     *  {
                     *      Console.BackgroundColor = ConsoleColor.Blue;
                     *      Console.WriteLine("Gen: {0}", LastCreatedMsg.ToHexString());
                     *      Console.BackgroundColor = ConsoleColor.Red;
                     *      Console.WriteLine("Err: {0}", Message.ToHexString());
                     *  }
                     *  Console.BackgroundColor = ConsoleColor.Black;
                     *  Console.WriteLine("------------------------------------------------------------------------------------------------------------------------------------");
                     *  LastCreatedMsg = new KNXmessage(knxControlField.KnxPacketType.KNX_PacketShort);
                     *
                     * }
                     */
                    break;

                default:
                    /*if (LastCreatedMsg.ToHexString() != Message.ToHexString())
                     * {
                     *  Console.BackgroundColor = ConsoleColor.Blue;
                     *  Console.WriteLine("Gen: {0}", LastCreatedMsg.ToHexString());
                     *  Console.BackgroundColor = ConsoleColor.Red;
                     *  Console.WriteLine("Err: {0}", Message.ToHexString());
                     * }*/
                    Console.BackgroundColor = ConsoleColor.Black;
                    Console.WriteLine("------------------------------------------------------------------------------------------------------------------------------------");
                    LastCreatedMsg = new KNXmessage(knxControlField.KnxPacketType.KNX_PacketShort);
                    break;
                }
            }
            catch (Exception e)
            {
                Console.Write("Error parsing: " + e);
            }
        }
예제 #26
0
        static void Main(string[] args)
        {
            //Can be used to replay log messages to an existing device
            //fahDevToReturn = FaHDevice.DeserializeFromFile(@"ABB700C730A9-learn-metvloeren.json", true);
            //fahDevToLearn = FaHDevice.DeserializeFromFile(@"ABB700C730A9-learn-metvloeren.json", true);

            Console.SetWindowSize(Console.WindowWidth * 2, Console.WindowHeight);
            stdOut = new ReadWriteKNXDataLog("Output_" + DateTime.Now.Ticks + ".txt", true);
            //stdIn = new ReadWriteKNXDataLog(@"replay_log.txt", false);

            FaHTCPClient.TCPknxClient kNXUart = new FaHTCPClient.TCPknxClient("172.16.16.20", 9998);

            /*KNXUartModule.KNXUartConnection kNXUart = new KNXUartConnection(AppSettings.Default.ComPort)
             * {
             *  AllowWrite = AppSettings.Default.KNXWriteEnabled
             * };*/

            kNXUart.OnKNXMessage += KNXUart_OnKNXMessage;
            kNXUart.OnKNXEvent   += KNXUart_OnKNXEvent;
            //kNXUart.ResetAndInit();

            /*
             * int i = 0;
             * while (true)
             * {
             *  KNXmessage k = stdIn.ReadNextMessage();
             *  if (k == null) break;
             *  if (i > 0)
             *      KNXUart_OnKNXMessage(null, k, KNXUartConnection.UartEvents.GotKNXPacket);
             *
             *  i++;
             * }*/

            while (true)
            {
                string ret = Console.ReadLine();
                if (ret.ToLower() == "exit")
                {
                    Console.WriteLine("Exit Accepted");
                    return;
                }

                if (ret.ToLower() == "x")
                {
                    //[0x00 - 0x01]     [0x14 - 0xC8]      0x00 0x80 0x66
                    //[0xEB - 0x01]     [0xB5 - 0x50]      0x00[0x80 | 0x09]

                    //[0x00 - 0x01]     [0x14 - 0xC8]      0x00 0x80 0x59
                    //[0x00 - 0x01]     [0x3D - 0x26]      0x00 0x80 0x45 0x1E 0xD1 0x58

                    FaHDevice nulldev = new FaHDevice();
                    nulldev.KnxAddress.u16valueHigh = 1;
                    KNXAddress TargetGroupValue = new KNXAddress(0x14, 0xC8);
                    byte[]     data             = new byte[] { 0x66 };

                    KNXmessage GroupWriteMessage = FAHGroupValueWrite.CreateFAHGroupValueWrite(nulldev, TargetGroupValue, data, false);
                    KNXUart_OnKNXMessage(null, GroupWriteMessage, KNXNetworkLayerTemplate.KnxPacketEvents.GotKNXPacket);

                    kNXUart.SendKNXMessage(GroupWriteMessage);

                    //*************************************************************
                    KNXAddress TargetGroupValue1 = new KNXAddress(0x3D, 0x26);
                    byte[]     data1             = new byte[] { 0x45, 0x1E, 0xD1, 0x66 };

                    KNXmessage GroupWriteMessage1 = FAHGroupValueWrite.CreateFAHGroupValueWrite(nulldev, TargetGroupValue1, data1, true);
                    KNXUart_OnKNXMessage(null, GroupWriteMessage1, KNXNetworkLayerTemplate.KnxPacketEvents.GotKNXPacket);

                    kNXUart.SendKNXMessage(GroupWriteMessage1);

                    //**********************************************************************//
                }


                if (ret.ToLower() == "+")
                {
                    FaHDevice  nulldev          = new FaHDevice();
                    KNXAddress TargetGroupValue = new KNXAddress(0xC6, 0x4D);
                    byte[]     data             = new byte[] { 0x01 };

                    KNXmessage GroupWriteMessage = FAHGroupValueWrite.CreateFAHGroupValueWrite(nulldev, TargetGroupValue, data, true);
                    KNXUart_OnKNXMessage(null, GroupWriteMessage, KNXNetworkLayerTemplate.KnxPacketEvents.GotKNXPacket);

                    kNXUart.SendKNXMessage(GroupWriteMessage);


                    //2021 - 10 - 03 11:08:33.826; GroupValueWrite KNX_PRIORITY_HIGH[NoExtdFrame]   [0x00 - 0x01]     [0x3D - 0x26]      0x00 0x80 0x06 0xB0 0xFF 0x57
                }
                if (ret.ToLower() == "-")
                {
                    FaHDevice  nulldev          = new FaHDevice();
                    KNXAddress TargetGroupValue = new KNXAddress(0xC6, 0x4D);
                    byte[]     data             = new byte[] { 0x00 };

                    KNXmessage GroupWriteMessage = FAHGroupValueWrite.CreateFAHGroupValueWrite(nulldev, TargetGroupValue, data, true);
                    KNXUart_OnKNXMessage(null, GroupWriteMessage, KNXNetworkLayerTemplate.KnxPacketEvents.GotKNXPacket);


                    //[0xC6 - 0x4D]      0x00[0x80 | 0x01]

                    kNXUart.SendKNXMessage(GroupWriteMessage);


                    //2021 - 10 - 03 11:08:33.826; GroupValueWrite KNX_PRIORITY_HIGH[NoExtdFrame]   [0x00 - 0x01]     [0x3D - 0x26]      0x00 0x80 0x06 0xB0 0xFF 0x57
                }


                Console.WriteLine("# " + ret);
                stdOut.WriteComment(ret);
            }
        }
예제 #27
0
        public static KNXmessage CreateResponse(FAHFunctionPropertyCommand MessageToRespondTo, FaHDevice atHomeDevice)
        {
            if (MessageToRespondTo.PropertyControl != FAHFunctionPropertyCommand.PropertyControlTypes.ReadBasicInfo && MessageToRespondTo.PropertyControl != FAHFunctionPropertyCommand.PropertyControlTypes.ReadDesc)
            {
                throw new InvalidCastException();
            }

            int ChannelIndex = MessageToRespondTo.ObjectID;

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

            /*
             * if (atHomeDevice.Channels[ChannelIndex].DeviceChannelInfo == null)
             * {
             *  if(ChannelIndex==0)
             *      atHomeDevice.Channels[ChannelIndex].DeviceChannelInfo = new byte[] { 0x00, 0x80, 0x00, 0x43, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x55 };
             *  else if (ChannelIndex == 1)
             *      atHomeDevice.Channels[ChannelIndex].DeviceChannelInfo = new byte[] { 0x00, 0x40, 0x00, 0x45, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x2A };
             *  else if (ChannelIndex == 2)
             *      atHomeDevice.Channels[ChannelIndex].DeviceChannelInfo = new byte[] { 0x00, 0x60, 0x00, 0x46, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x2A };
             *  else if (ChannelIndex == 3)
             *      atHomeDevice.Channels[ChannelIndex].DeviceChannelInfo = new byte[] { 0x00, 0x80, 0x00, 0x44, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x55 };
             *  else if (ChannelIndex == 4)
             *      atHomeDevice.Channels[ChannelIndex].DeviceChannelInfo = new byte[] { 0x00, 0x40, 0x00, 0x47, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x2A };
             *  else if (ChannelIndex == 5)
             *      atHomeDevice.Channels[ChannelIndex].DeviceChannelInfo = new byte[] { 0x00, 0x60, 0x00, 0x48, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x2A };
             *  else if (ChannelIndex == 6)
             *      atHomeDevice.Channels[ChannelIndex].DeviceChannelInfo = new byte[] { 0x02, 0x60, 0x00, 0x4F, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xAA };
             *  else
             *      atHomeDevice.Channels[ChannelIndex].DeviceChannelInfo = new byte[] { 0x00};
             *  atHomeDevice.Serialize("input.json");
             * }*/

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

            const int HEADERSIZE = 5;

            byte[] bData;

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

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

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

            newPkg.UpdatePacketSettings();
            newPkg.FPSRpayload = bData;
            newPkg.PropertyID  = MessageToRespondTo.PropertyID;
            newPkg.ObjectID    = MessageToRespondTo.ObjectID;
            newPkg.resultCode  = KNXHelpers.knxPropertyReturnValues.Success;
            return(kNXmessage);
        }
예제 #28
0
        static void LearnDevice(ref KNXUartConnection kNXUart)
        {
            byte counter = 0;
            bool moreIndices;

            for (byte i = 1; i <= 10; i++)
            {
                //*----------------------------------------------------------------------------
                ConsoleWriteHeader("ReadCons");
                KNXmessage ReadCons = FAHFunctionPropertyCommand.CreateFAHFunctionPropertyCommand(deviceToLearn, FAHFunctionPropertyCommand.PropertyControlTypes.ReadConns, 7, 2, new byte[] { i, 1 });
                ConsoleWriteOnEmptyLine(string.Format("Sending {0} ", ReadCons.HeaderAsString));
                ReadCons.Payload.ReadablePayloadPacket.PrintUnaccountedBytes();

                ((FAHFunctionPropertyCommand)ReadCons.Payload.ReadablePayloadPacket).GetPropertyControlForReply(ref ByteDataParm, ref lastRequestedPropertyControl);
                if (!kNXUart.WriteDirect(ReadCons, true))
                {
                    return;
                }
                else
                if (!ProcessResponse(out moreIndices))
                {
                    ConsoleWriteLine("Invalid data");
                }
            }

            for (byte i = 1; i <= 10; i++)
            {
                //*----------------------------------------------------------------------------
                ConsoleWriteHeader("ReadCons");
                KNXmessage ReadCons = FAHFunctionPropertyCommand.CreateFAHFunctionPropertyCommand(deviceToLearn, FAHFunctionPropertyCommand.PropertyControlTypes.ReadConns, 8, 3, new byte[] { i, 1 });
                ConsoleWriteOnEmptyLine(string.Format("Sending {0} ", ReadCons.HeaderAsString));
                ReadCons.Payload.ReadablePayloadPacket.PrintUnaccountedBytes();

                ((FAHFunctionPropertyCommand)ReadCons.Payload.ReadablePayloadPacket).GetPropertyControlForReply(ref ByteDataParm, ref lastRequestedPropertyControl);
                if (!kNXUart.WriteDirect(ReadCons, true))
                {
                    return;
                }
                else
                if (!ProcessResponse(out moreIndices))
                {
                    ConsoleWriteLine("Invalid data");
                }
            }

            for (byte i = 1; i <= 10; i++)
            {
                //*----------------------------------------------------------------------------
                ConsoleWriteHeader("ReadCons");
                KNXmessage ReadCons = FAHFunctionPropertyCommand.CreateFAHFunctionPropertyCommand(deviceToLearn, FAHFunctionPropertyCommand.PropertyControlTypes.ReadConns, 8, 2, new byte[] { i, 1 });
                ConsoleWriteOnEmptyLine(string.Format("Sending {0} ", ReadCons.HeaderAsString));
                ReadCons.Payload.ReadablePayloadPacket.PrintUnaccountedBytes();

                ((FAHFunctionPropertyCommand)ReadCons.Payload.ReadablePayloadPacket).GetPropertyControlForReply(ref ByteDataParm, ref lastRequestedPropertyControl);
                if (!kNXUart.WriteDirect(ReadCons, true))
                {
                    return;
                }
                else
                if (!ProcessResponse(out moreIndices))
                {
                    ConsoleWriteLine("Invalid data");
                }
            }

            for (byte i = 1; i <= deviceToLearn.ChannelCount; i++)
            {
                for (byte propID = 2; propID <= 3; propID++)
                {
                    moreIndices = true;
                    counter     = 1;
                    while (moreIndices)
                    {
                        //*----------------------------------------------------------------------------
                        ConsoleWriteHeader("ReadCons ch:" + i + ":" + propID + " id:" + counter);
                        KNXmessage ReadCons = FAHFunctionPropertyCommand.CreateFAHFunctionPropertyCommand(deviceToLearn, FAHFunctionPropertyCommand.PropertyControlTypes.ReadConns, i, propID, new byte[] { counter++, 0x01 });
                        ((FAHFunctionPropertyCommand)ReadCons.Payload.ReadablePayloadPacket).GetPropertyControlForReply(ref ByteDataParm, ref lastRequestedPropertyControl);
                        if (!kNXUart.WriteDirect(ReadCons, true))
                        {
                            return;
                        }
                        else
                        if (!ProcessResponse(out moreIndices))
                        {
                            ConsoleWriteLine("Invalid data");
                        }
                    }
                }
            }

            for (byte i = 1; i <= 10; i++)
            {
                moreIndices = true;
                byte ix = 1;
                while (moreIndices)
                {
                    //*----------------------------------------------------------------------------
                    ConsoleWriteHeader("ReadBasicInfo");
                    KNXmessage ReadBasicInfo = FAHFunctionPropertyCommand.CreateFAHFunctionPropertyCommand(deviceToLearn, FAHFunctionPropertyCommand.PropertyControlTypes.ReadBasicInfo, i, 5, new byte[] { ix++ });
                    ((FAHFunctionPropertyCommand)ReadBasicInfo.Payload.ReadablePayloadPacket).GetPropertyControlForReply(ref ByteDataParm, ref lastRequestedPropertyControl);
                    if (!kNXUart.WriteDirect(ReadBasicInfo, true))
                    {
                        return;
                    }
                    else
                    if (!ProcessResponse(out moreIndices))
                    {
                        ConsoleWriteLine("Invalid data");
                    }
                }
            }

            for (byte i = 1; i <= deviceToLearn.ChannelCount; i++)
            {
                //*----------------------------------------------------------------------------
                ConsoleWriteHeader("ReadCons");
                KNXmessage ReadCons = FAHFunctionPropertyCommand.CreateFAHFunctionPropertyCommand(deviceToLearn, FAHFunctionPropertyCommand.PropertyControlTypes.ReadConns, i, 1, null);
                ((FAHFunctionPropertyCommand)ReadCons.Payload.ReadablePayloadPacket).GetPropertyControlForReply(ref ByteDataParm, ref lastRequestedPropertyControl);
                if (!kNXUart.WriteDirect(ReadCons, true))
                {
                    return;
                }
                else
                if (!ProcessResponse(out moreIndices))
                {
                    ConsoleWriteLine("Invalid data");
                }
            }

            for (byte i = 1; i <= 10; i++)
            {
                //*----------------------------------------------------------------------------
                ConsoleWriteHeader("ReadCons");
                KNXmessage ReadCons = FAHFunctionPropertyCommand.CreateFAHFunctionPropertyCommand(deviceToLearn, FAHFunctionPropertyCommand.PropertyControlTypes.ReadConns, 7, i, null);
                ((FAHFunctionPropertyCommand)ReadCons.Payload.ReadablePayloadPacket).GetPropertyControlForReply(ref ByteDataParm, ref lastRequestedPropertyControl);
                if (!kNXUart.WriteDirect(ReadCons, true))
                {
                    return;
                }
                else
                if (!ProcessResponse(out moreIndices))
                {
                    ConsoleWriteLine("Invalid data");
                }
            }

            for (byte i = 0; i <= 10; i++)
            {
                //*----------------------------------------------------------------------------
                ConsoleWriteHeader("ReadCons");
                KNXmessage ReadCons = FAHFunctionPropertyCommand.CreateFAHFunctionPropertyCommand(deviceToLearn, FAHFunctionPropertyCommand.PropertyControlTypes.ReadConns, 8, i, null);
                ((FAHFunctionPropertyCommand)ReadCons.Payload.ReadablePayloadPacket).GetPropertyControlForReply(ref ByteDataParm, ref lastRequestedPropertyControl);
                if (!kNXUart.WriteDirect(ReadCons, true))
                {
                    return;
                }
                else
                if (!ProcessResponse(out moreIndices))
                {
                    ConsoleWriteLine("Invalid data");
                }
            }

            if (true)
            {
                //*----------------------------------------------------------------------------
                ConsoleWriteHeader("ReadDevHealth");
                KNXmessage ReadDevHealth = FAHFunctionPropertyCommand.CreateFAHFunctionPropertyCommand(deviceToLearn, FAHFunctionPropertyCommand.PropertyControlTypes.ReadDevHealth, 0, 1, null);
                ((FAHFunctionPropertyCommand)ReadDevHealth.Payload.ReadablePayloadPacket).GetPropertyControlForReply(ref ByteDataParm, ref lastRequestedPropertyControl);
                if (!kNXUart.WriteDirect(ReadDevHealth, true))
                {
                    return;
                }
                else
                if (!ProcessResponse(out moreIndices))
                {
                    return;
                }
            }

            if (true)
            {
                //*----------------------------------------------------------------------------
                ConsoleWriteHeader("ReadDesc");
                KNXmessage ReadDesc = FAHFunctionPropertyCommand.CreateFAHFunctionPropertyCommand(deviceToLearn, FAHFunctionPropertyCommand.PropertyControlTypes.ReadDesc, 1, 5, null);
                ((FAHFunctionPropertyCommand)ReadDesc.Payload.ReadablePayloadPacket).GetPropertyControlForReply(ref ByteDataParm, ref lastRequestedPropertyControl);
                if (!kNXUart.WriteDirect(ReadDesc, true))
                {
                    return;
                }
                else
                if (!ProcessResponse(out moreIndices))
                {
                    ConsoleWriteLine("Invalid data");
                }
            }

            for (byte i = 0; i <= deviceToLearn.ChannelCount + 5; i++)
            {
                //*----------------------------------------------------------------------------
                ConsoleWriteHeader("ReadBasicInfo Chn: " + i);
                KNXmessage ReadBasicInfo = FAHFunctionPropertyCommand.CreateFAHFunctionPropertyCommand(deviceToLearn, FAHFunctionPropertyCommand.PropertyControlTypes.ReadBasicInfo, i, 1, null);
                ((FAHFunctionPropertyCommand)ReadBasicInfo.Payload.ReadablePayloadPacket).GetPropertyControlForReply(ref ByteDataParm, ref lastRequestedPropertyControl);
                if (!kNXUart.WriteDirect(ReadBasicInfo, true))
                {
                    return;
                }
                else
                if (!ProcessResponse(out moreIndices))
                {
                    Console.WriteLine("Failed");
                }
            }

            if (true)
            {
                //*----------------------------------------------------------------------------
                ConsoleWriteHeader("ReadDesc");
                KNXmessage ReadDesc = FAHFunctionPropertyCommand.CreateFAHFunctionPropertyCommand(deviceToLearn, FAHFunctionPropertyCommand.PropertyControlTypes.ReadDesc, 0, 4, new byte[] { 0x01 });
                ((FAHFunctionPropertyCommand)ReadDesc.Payload.ReadablePayloadPacket).GetPropertyControlForReply(ref ByteDataParm, ref lastRequestedPropertyControl);
                if (!kNXUart.WriteDirect(ReadDesc, true))
                {
                    return;
                }
                else
                if (!ProcessResponse(out moreIndices))
                {
                    return;
                }
            }

            if (true)
            {
                //*----------------------------------------------------------------------------
                ConsoleWriteHeader("ReadCons-ShouldFail");
                KNXmessage ReadCons = FAHFunctionPropertyCommand.CreateFAHFunctionPropertyCommand(deviceToLearn, FAHFunctionPropertyCommand.PropertyControlTypes.ReadConns, 0, 4, new byte[] { 0x01 });
                ((FAHFunctionPropertyCommand)ReadCons.Payload.ReadablePayloadPacket).GetPropertyControlForReply(ref ByteDataParm, ref lastRequestedPropertyControl);
                if (!kNXUart.WriteDirect(ReadCons, true))
                {
                    return;
                }
                else
                if (ProcessResponse(out moreIndices))
                {
                    return;
                }
            }

            if (true)
            {
                //*----------------------------------------------------------------------------
                ConsoleWriteHeader("ReadBasicInfo-ShouldFail");
                KNXmessage ReadBasicInfo = FAHFunctionPropertyCommand.CreateFAHFunctionPropertyCommand(deviceToLearn, FAHFunctionPropertyCommand.PropertyControlTypes.ReadBasicInfo, 0, 7, new byte[] { 0x01 });
                ((FAHFunctionPropertyCommand)ReadBasicInfo.Payload.ReadablePayloadPacket).GetPropertyControlForReply(ref ByteDataParm, ref lastRequestedPropertyControl);
                if (!kNXUart.WriteDirect(ReadBasicInfo, true))
                {
                    return;
                }
                else
                if (ProcessResponse(out moreIndices))
                {
                    return;
                }
            }

            for (byte i = 1; i <= deviceToLearn.ChannelCount; i++)
            {
                //*----------------------------------------------------------------------------
                ConsoleWriteHeader("ReadBasicInfo " + i);
                KNXmessage ReadBasicInfo = FAHFunctionPropertyCommand.CreateFAHFunctionPropertyCommand(deviceToLearn, FAHFunctionPropertyCommand.PropertyControlTypes.ReadBasicInfo, i, 1, null);
                ((FAHFunctionPropertyCommand)ReadBasicInfo.Payload.ReadablePayloadPacket).GetPropertyControlForReply(ref ByteDataParm, ref lastRequestedPropertyControl);
                if (!kNXUart.WriteDirect(ReadBasicInfo, true))
                {
                    return;
                }
                else
                if (!ProcessResponse(out moreIndices))
                {
                    ConsoleWriteLine("Invalid data");
                }
            }

            if (true)
            {
                //*----------------------------------------------------------------------------
                ConsoleWriteHeader("ReadDesc");
                KNXmessage ReadDesc = FAHFunctionPropertyCommand.CreateFAHFunctionPropertyCommand(deviceToLearn, FAHFunctionPropertyCommand.PropertyControlTypes.ReadDesc, 7, 5, null);
                ((FAHFunctionPropertyCommand)ReadDesc.Payload.ReadablePayloadPacket).GetPropertyControlForReply(ref ByteDataParm, ref lastRequestedPropertyControl);
                if (!kNXUart.WriteDirect(ReadDesc, true))
                {
                    return;
                }
                else
                if (!ProcessResponse(out moreIndices))
                {
                    ConsoleWriteLine("Invalid data");
                }
                //return;
            }

            for (byte i = 0; i < 10; i++)
            {
                moreIndices = true;
                counter     = 1;
                while (moreIndices)
                {
                    //*----------------------------------------------------------------------------
                    ConsoleWriteHeader("ReadFunctList");
                    KNXmessage ReadFunctList = FAHFunctionPropertyCommand.CreateFAHFunctionPropertyCommand(deviceToLearn, FAHFunctionPropertyCommand.PropertyControlTypes.ReadFuncList, i, 1, new byte[] { counter++ });
                    ((FAHFunctionPropertyCommand)ReadFunctList.Payload.ReadablePayloadPacket).GetPropertyControlForReply(ref ByteDataParm, ref lastRequestedPropertyControl);
                    if (!kNXUart.WriteDirect(ReadFunctList, true))
                    {
                        return;
                    }
                    else
                    if (!ProcessResponse(out moreIndices))
                    {
                        ConsoleWriteLine("Invalid data");
                    }
                }
            }

            moreIndices = true;
            counter     = 1;
            while (moreIndices)
            {
                //*----------------------------------------------------------------------------
                ConsoleWriteHeader("ReadDesc Ndice:" + counter);
                KNXmessage ReadDesc = FAHFunctionPropertyCommand.CreateFAHFunctionPropertyCommand(deviceToLearn, FAHFunctionPropertyCommand.PropertyControlTypes.ReadDesc, 7, 4, new byte[] { (byte)counter++ });
                ((FAHFunctionPropertyCommand)ReadDesc.Payload.ReadablePayloadPacket).GetPropertyControlForReply(ref ByteDataParm, ref lastRequestedPropertyControl);
                if (!kNXUart.WriteDirect(ReadDesc, true))
                {
                    return;
                }
                else
                if (!ProcessResponse(out moreIndices))
                {
                    ConsoleWriteLine("Invalid data");
                }
            }

            if (true)
            {
                //*----------------------------------------------------------------------------
                ConsoleWriteHeader("ReadCons-ShouldFail");
                KNXmessage ReadCons = FAHFunctionPropertyCommand.CreateFAHFunctionPropertyCommand(deviceToLearn, FAHFunctionPropertyCommand.PropertyControlTypes.ReadConns, 7, 4, new byte[] { 0x01 });
                ((FAHFunctionPropertyCommand)ReadCons.Payload.ReadablePayloadPacket).GetPropertyControlForReply(ref ByteDataParm, ref lastRequestedPropertyControl);
                if (!kNXUart.WriteDirect(ReadCons, true))
                {
                    return;
                }
                else
                if (ProcessResponse(out moreIndices))
                {
                    return;
                }
            }

            if (true)
            {
                //*----------------------------------------------------------------------------
                ConsoleWriteHeader("ReadBasicInfo-ShouldFail");
                KNXmessage ReadBasicInfo = FAHFunctionPropertyCommand.CreateFAHFunctionPropertyCommand(deviceToLearn, FAHFunctionPropertyCommand.PropertyControlTypes.ReadBasicInfo, 7, 7, new byte[] { 0x01 });
                ((FAHFunctionPropertyCommand)ReadBasicInfo.Payload.ReadablePayloadPacket).GetPropertyControlForReply(ref ByteDataParm, ref lastRequestedPropertyControl);
                if (!kNXUart.WriteDirect(ReadBasicInfo, true))
                {
                    return;
                }
                else
                if (ProcessResponse(out moreIndices))
                {
                    return;
                }
            }

            moreIndices = true;
            counter     = 1;
            while (moreIndices)
            {
                //*----------------------------------------------------------------------------
                ConsoleWriteHeader("ReadDesc OID:" + counter);
                KNXmessage ReadDesc = FAHFunctionPropertyCommand.CreateFAHFunctionPropertyCommand(deviceToLearn, FAHFunctionPropertyCommand.PropertyControlTypes.ReadDesc, 7, 3, new byte[] { (byte)counter++ });
                ((FAHFunctionPropertyCommand)ReadDesc.Payload.ReadablePayloadPacket).GetPropertyControlForReply(ref ByteDataParm, ref lastRequestedPropertyControl);
                if (!kNXUart.WriteDirect(ReadDesc, true))
                {
                    return;
                }
                else
                if (!ProcessResponse(out moreIndices))
                {
                    ConsoleWriteLine("Invalid data");
                }
            }

            moreIndices = true;
            counter     = 1;
            while (moreIndices)
            {
                //*----------------------------------------------------------------------------
                ConsoleWriteHeader("ReadDesc OID:" + counter);
                KNXmessage ReadDesc = FAHFunctionPropertyCommand.CreateFAHFunctionPropertyCommand(deviceToLearn, FAHFunctionPropertyCommand.PropertyControlTypes.ReadDesc, 7, 2, new byte[] { (byte)counter++ });
                ((FAHFunctionPropertyCommand)ReadDesc.Payload.ReadablePayloadPacket).GetPropertyControlForReply(ref ByteDataParm, ref lastRequestedPropertyControl);
                if (!kNXUart.WriteDirect(ReadDesc, true))
                {
                    return;
                }
                else
                if (!ProcessResponse(out moreIndices))
                {
                    ConsoleWriteLine("Invalid data");
                }
            }

            if (true)
            {
                //*----------------------------------------------------------------------------
                ConsoleWriteHeader("ReadBasicInfo");
                KNXmessage ReadBasicInfo = FAHFunctionPropertyCommand.CreateFAHFunctionPropertyCommand(deviceToLearn, FAHFunctionPropertyCommand.PropertyControlTypes.ReadBasicInfo, 0, 4, new byte[] { 0x01 });
                ((FAHFunctionPropertyCommand)ReadBasicInfo.Payload.ReadablePayloadPacket).GetPropertyControlForReply(ref ByteDataParm, ref lastRequestedPropertyControl);
                if (!kNXUart.WriteDirect(ReadBasicInfo, true))
                {
                    return;
                }
                else
                if (!ProcessResponse(out moreIndices))
                {
                    return;
                }
            }

            if (true)
            {
                //*----------------------------------------------------------------------------
                ConsoleWriteHeader("ReadDesc");
                KNXmessage ReadDesc = FAHFunctionPropertyCommand.CreateFAHFunctionPropertyCommand(deviceToLearn, FAHFunctionPropertyCommand.PropertyControlTypes.ReadDesc, 0, 1, null);
                ((FAHFunctionPropertyCommand)ReadDesc.Payload.ReadablePayloadPacket).GetPropertyControlForReply(ref ByteDataParm, ref lastRequestedPropertyControl);
                if (!kNXUart.WriteDirect(ReadDesc, true))
                {
                    return;
                }
                else
                if (!ProcessResponse(out moreIndices))
                {
                    ConsoleWriteLine("Invalid data");
                }
            }

            for (byte i = 0; i <= deviceToLearn.ChannelCount + 2; i++)
            {
                //*----------------------------------------------------------------------------
                ConsoleWriteHeader("ReadFlr_RmNr");
                KNXmessage ReadCons = FAHFunctionPropertyCommand.CreateFAHFunctionPropertyCommand(deviceToLearn, FAHFunctionPropertyCommand.PropertyControlTypes.ReadFlr_RmNr, i, 1, null);
                ((FAHFunctionPropertyCommand)ReadCons.Payload.ReadablePayloadPacket).GetPropertyControlForReply(ref ByteDataParm, ref lastRequestedPropertyControl);
                if (!kNXUart.WriteDirect(ReadCons, true))
                {
                    return;
                }
                else
                if (!ProcessResponse(out moreIndices))
                {
                    ConsoleWriteLine("Invalid data");
                }
            }

            for (byte i = 1; i <= deviceToLearn.ChannelCount + 2; i++)
            {
                //*----------------------------------------------------------------------------
                ConsoleWriteHeader("ReadIconId");
                KNXmessage ReadCons = FAHFunctionPropertyCommand.CreateFAHFunctionPropertyCommand(deviceToLearn, FAHFunctionPropertyCommand.PropertyControlTypes.ReadIconId, i, 1, null);
                ((FAHFunctionPropertyCommand)ReadCons.Payload.ReadablePayloadPacket).GetPropertyControlForReply(ref ByteDataParm, ref lastRequestedPropertyControl);
                if (!kNXUart.WriteDirect(ReadCons, true))
                {
                    return;
                }
                else
                if (!ProcessResponse(out moreIndices))
                {
                    ConsoleWriteLine("Invalid data");
                }
            }

            if (true)
            {
                //*----------------------------------------------------------------------------
                ConsoleWriteHeader("ReadBasicInfo");
                KNXmessage ReadBasicInfo = FAHFunctionPropertyCommand.CreateFAHFunctionPropertyCommand(deviceToLearn, FAHFunctionPropertyCommand.PropertyControlTypes.ReadBasicInfo, 0, 16, new byte[] { 0x00, 0x00 });
                ((FAHFunctionPropertyCommand)ReadBasicInfo.Payload.ReadablePayloadPacket).GetPropertyControlForReply(ref ByteDataParm, ref lastRequestedPropertyControl);
                if (!kNXUart.WriteDirect(ReadBasicInfo, true))
                {
                    return;
                }
                else
                if (!ProcessResponse(out moreIndices))
                {
                    ConsoleWriteLine("Invalid data");
                }
            }

            if (true)
            {
                //*----------------------------------------------------------------------------
                ConsoleWriteHeader("ReadDesc");
                KNXmessage ReadDesc = FAHFunctionPropertyCommand.CreateFAHFunctionPropertyCommand(deviceToLearn, FAHFunctionPropertyCommand.PropertyControlTypes.ReadDesc, 1, 1, null);
                ((FAHFunctionPropertyCommand)ReadDesc.Payload.ReadablePayloadPacket).GetPropertyControlForReply(ref ByteDataParm, ref lastRequestedPropertyControl);
                if (!kNXUart.WriteDirect(ReadDesc, true))
                {
                    return;
                }
                else
                if (!ProcessResponse(out moreIndices))
                {
                    ConsoleWriteLine("Invalid data");
                }
            }

            if (true)
            {
                //*----------------------------------------------------------------------------
                ConsoleWriteHeader("__UnsupportedCommand__0x07");
                KNXmessage ReadDesc = FAHFunctionPropertyCommand.CreateFAHFunctionPropertyCommand(deviceToLearn, FAHFunctionPropertyCommand.PropertyControlTypes.__UnsupportedCommand__0x07, 1, 1, new byte[] { 0x07 });
                ((FAHFunctionPropertyCommand)ReadDesc.Payload.ReadablePayloadPacket).GetPropertyControlForReply(ref ByteDataParm, ref lastRequestedPropertyControl);
                if (!kNXUart.WriteDirect(ReadDesc, true))
                {
                    return;
                }
                else
                if (ProcessResponse(out moreIndices))
                {
                    return;
                }
            }

            for (byte i = 1; i <= deviceToLearn.ChannelCount; i++)
            {
                for (byte propID = 2; propID <= 3; propID++)
                {
                    moreIndices = true;
                    counter     = 1;
                    while (moreIndices)
                    {
                        //*----------------------------------------------------------------------------
                        ConsoleWriteHeader("ReadCons ch:" + i + ":" + propID + " id:" + counter);
                        KNXmessage ReadCons = FAHFunctionPropertyCommand.CreateFAHFunctionPropertyCommand(deviceToLearn, FAHFunctionPropertyCommand.PropertyControlTypes.ReadConns, i, propID, new byte[] { counter++, 0x01 });
                        ((FAHFunctionPropertyCommand)ReadCons.Payload.ReadablePayloadPacket).GetPropertyControlForReply(ref ByteDataParm, ref lastRequestedPropertyControl);
                        if (!kNXUart.WriteDirect(ReadCons, true))
                        {
                            return;
                        }
                        else
                        if (!ProcessResponse(out moreIndices))
                        {
                            ConsoleWriteLine("Invalid data");
                        }
                    }
                }
            }

            if (true)
            {
                byte i = 7;
                for (byte propID = 2; propID <= 3; propID++)
                {
                    moreIndices = true;
                    counter     = 1;
                    while (moreIndices)
                    {
                        //*----------------------------------------------------------------------------
                        ConsoleWriteHeader("ReadCons ch:" + i + ":" + propID + " id:" + counter);
                        KNXmessage ReadCons = FAHFunctionPropertyCommand.CreateFAHFunctionPropertyCommand(deviceToLearn, FAHFunctionPropertyCommand.PropertyControlTypes.ReadConns, i, propID, new byte[] { counter++, 0x01 });
                        ((FAHFunctionPropertyCommand)ReadCons.Payload.ReadablePayloadPacket).GetPropertyControlForReply(ref ByteDataParm, ref lastRequestedPropertyControl);
                        if (!kNXUart.WriteDirect(ReadCons, true))
                        {
                            return;
                        }
                        else
                        if (!ProcessResponse(out moreIndices))
                        {
                            ConsoleWriteLine("Invalid data");
                        }
                    }
                }
            }

            for (byte channelID = 1; channelID <= deviceToLearn.ChannelCount; channelID++)
            {
                ConsoleWriteHeader("ReadBasicInfo channel:" + channelID);
                for (byte propID = 3; propID <= 5; propID++)
                {
                    moreIndices = true;
                    counter     = 1;
                    while (moreIndices)
                    {
                        //*----------------------------------------------------------------------------
                        ConsoleWriteHeader("ReadBasicInfo ch:" + channelID + ":" + propID + " id:" + counter);
                        KNXmessage ReadBasicInfo = FAHFunctionPropertyCommand.CreateFAHFunctionPropertyCommand(deviceToLearn, FAHFunctionPropertyCommand.PropertyControlTypes.ReadBasicInfo, channelID, propID, new byte[] { counter++ });
                        ((FAHFunctionPropertyCommand)ReadBasicInfo.Payload.ReadablePayloadPacket).GetPropertyControlForReply(ref ByteDataParm, ref lastRequestedPropertyControl);
                        if (!kNXUart.WriteDirect(ReadBasicInfo, true))
                        {
                            return;
                        }
                        else
                        if (!ProcessResponse(out moreIndices))
                        {
                            ConsoleWriteLine("Invalid data");
                        }
                    }
                }
            }

            if (true)
            {
                byte channelID = 7;
                ConsoleWriteHeader("ReadBasicInfo channel:" + channelID);
                for (byte propID = 3; propID <= 5; propID++)
                {
                    moreIndices = true;
                    counter     = 1;
                    while (moreIndices)
                    {
                        //*----------------------------------------------------------------------------
                        ConsoleWriteHeader("ReadBasicInfo ch:" + channelID + ":" + propID + " id:" + counter);
                        KNXmessage ReadBasicInfo = FAHFunctionPropertyCommand.CreateFAHFunctionPropertyCommand(deviceToLearn, FAHFunctionPropertyCommand.PropertyControlTypes.ReadBasicInfo, channelID, propID, new byte[] { counter++ });
                        ((FAHFunctionPropertyCommand)ReadBasicInfo.Payload.ReadablePayloadPacket).GetPropertyControlForReply(ref ByteDataParm, ref lastRequestedPropertyControl);
                        if (!kNXUart.WriteDirect(ReadBasicInfo, true))
                        {
                            return;
                        }
                        else
                        if (!ProcessResponse(out moreIndices))
                        {
                            ConsoleWriteLine("Invalid data");
                        }
                    }
                }
            }

            if (true)
            {
                byte channelID = 8;
                ConsoleWriteHeader("ReadBasicInfo channel:" + channelID);
                for (byte propID = 3; propID <= 5; propID++)
                {
                    moreIndices = true;
                    counter     = 1;
                    while (moreIndices)
                    {
                        //*----------------------------------------------------------------------------
                        ConsoleWriteHeader("ReadBasicInfo ch:" + channelID + ":" + propID + " id:" + counter);
                        KNXmessage ReadBasicInfo = FAHFunctionPropertyCommand.CreateFAHFunctionPropertyCommand(deviceToLearn, FAHFunctionPropertyCommand.PropertyControlTypes.ReadBasicInfo, channelID, propID, new byte[] { counter++ });
                        ((FAHFunctionPropertyCommand)ReadBasicInfo.Payload.ReadablePayloadPacket).GetPropertyControlForReply(ref ByteDataParm, ref lastRequestedPropertyControl);
                        if (!kNXUart.WriteDirect(ReadBasicInfo, true))
                        {
                            return;
                        }
                        else
                        if (!ProcessResponse(out moreIndices))
                        {
                            ConsoleWriteLine("Invalid data");
                        }
                    }
                }
            }

            for (byte channelID = 1; channelID <= deviceToLearn.ChannelCount + 2; channelID++)
            {
                //*----------------------------------------------------------------------------
                ConsoleWriteHeader("ReadDesc:" + channelID);
                KNXmessage ReadDesc = FAHFunctionPropertyCommand.CreateFAHFunctionPropertyCommand(deviceToLearn, FAHFunctionPropertyCommand.PropertyControlTypes.ReadDesc, channelID, 1, null);
                ((FAHFunctionPropertyCommand)ReadDesc.Payload.ReadablePayloadPacket).GetPropertyControlForReply(ref ByteDataParm, ref lastRequestedPropertyControl);
                Console.WriteLine(ReadDesc.ToHexString());

                if (!kNXUart.WriteDirect(ReadDesc, true))
                {
                    return;
                }
                else
                if (!ProcessResponse(out moreIndices))
                {
                    ConsoleWriteLine("Invalid data");
                }
            }

            Console.WriteLine("Setting Interface types we know");

            if (deviceToLearn.DeviceType == FaHDeviceType.SensorSwitchactuator22gang)
            {
                Console.WriteLine("Switch 2\\2");
                //Dit kunnen we sturen
                //deviceToLearn.WriteChannelPropertyType(1, 2, FaHDeviceProperties.ChannelType.NotDefined, FaHDeviceProperties.SensorActorInterfaceType.NotDefined);
                //deviceToLearn.WriteChannelPropertyType(4, 2, FaHDeviceProperties.ChannelType.NotDefined, FaHDeviceProperties.SensorActorInterfaceType.NotDefined);
                deviceToLearn.WriteChannelPropertyType(1, 3, FaHDeviceProperties.ChannelType.chanOutputOnClickChannelType, FaHDeviceProperties.SensorActorInterfaceType.ButtonLeft);
                deviceToLearn.WriteChannelPropertyType(4, 3, FaHDeviceProperties.ChannelType.chanOutputOnClickChannelType, FaHDeviceProperties.SensorActorInterfaceType.ButtonRight);

                //Deze moeten we monitoren
                deviceToLearn.WriteChannelPropertyType(7, 2, FaHDeviceProperties.ChannelType.chanInputActorGroupMessage, FaHDeviceProperties.SensorActorInterfaceType.Actor1);
                deviceToLearn.WriteChannelPropertyType(8, 2, FaHDeviceProperties.ChannelType.chanInputActorGroupMessage, FaHDeviceProperties.SensorActorInterfaceType.Actor2);

                //Dit moeten we sturen als waarde veranderd
                deviceToLearn.WriteChannelPropertyType(7, 3, FaHDeviceProperties.ChannelType.chanOutputActorChangedValue, FaHDeviceProperties.SensorActorInterfaceType.Actor1);
                deviceToLearn.WriteChannelPropertyType(8, 3, FaHDeviceProperties.ChannelType.chanOutputActorChangedValue, FaHDeviceProperties.SensorActorInterfaceType.Actor2);

                deviceToLearn.DeviceHealthStatus.DeviceReboots = 0;
                deviceToLearn.DeviceHealthStatus.Uptime        = 0;
            }
            else
            {
                Console.WriteLine("Unkown");
            }

            ConsoleWriteHeader("Read Completed:" + deviceToLearn.FaHAddress);
            deviceToLearn.Serialize(deviceToLearn.FaHAddress + "-learn.json");
        }
예제 #29
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);
        }
예제 #30
0
        public KNXmessage ProcessAndCreateResponse(FaHDevice device)
        {
            KNXmessage k = null;

            switch (PropertyControl)
            {
            case PropertyControlTypes.__UnsupportedCommand__0x07:
                k = CreateCommandNotSupportedMessage();
                break;

            case PropertyControlTypes.ReadConns:
                //ConctionID
                if (payloadReference.PayloadByteData.Length == 7)
                {
                    k = FPSR_ConnectionInfo.CreateResponse(this, device);
                    //Should not exist?
                }
                else if (payloadReference.PayloadByteData.Length == 5)
                {
                    k = FPSR_ConnectionInfo.CreateResponse(this, device);
                }
                else
                {
                    k = CreateCommandNotSupportedMessage();
                }
                break;

            case PropertyControlTypes.ReadBasicInfo:
                if (this.ObjectID == 0 && PropertyID == 1)
                {
                    k = FPSR_BasicDeviceInfo.CreateResponse(this, device);
                    break;
                }
                else if (ObjectID > 0 && PropertyID == 1)
                {
                    k = FPSR_DeviceChannelInfo.CreateResponse(this, device);
                    break;
                }
                else
                {
                    k = FPSR_PropertyValueRead.CreateReadResponse(this, device);
                    break;
                }

            case PropertyControlTypes.ReadDevHealth:
                k = FPSR_ReadDeviceHealth.CreateReadResponse(this, device);
                break;

            case PropertyControlTypes.ReadDesc:
                if (this.ObjectID == 0 && PropertyID == 4)
                {
                    k = FPSR_DeviceParameterInfo.CreateResponse(this, device);
                }
                else if (PropertyID == 1)
                {
                    k = FPSR_ChannelDescription.CreateResponse(this, device);
                }
                else if (PropertyID >= 2 && ObjectID == 7)
                {
                    k = FPSR_DeviceOIDData.CreateResponse(this, device);
                }
                else if (PropertyID >= 2)
                {
                    k = FPSR_DescriptorValueRead.CreateReadResponse(this, device);
                }
                break;

            case PropertyControlTypes.WriteValue:
                payloadReference.ReadablePayloadPacket = new FPC_PropertyValueWrite(payloadReference);
                FPC_PropertyValueWrite fPSR_PropertyValue = this.payloadReference.ReadablePayloadPacket as FPC_PropertyValueWrite;
                k = fPSR_PropertyValue.Process(device);
                break;

            case PropertyControlTypes.ReadFlr_RmNr:
                k = FPSR_RoomInfo.CreateResponse(this, device);
                break;

            case PropertyControlTypes.ReadIconId:
                k = FPSR_IconInfo.CreateResponse(this, device);
                break;

            case PropertyControlTypes.DeleteConn:
                payloadReference.ReadablePayloadPacket = new FPC_DeleteConnection(payloadReference);
                FPC_DeleteConnection fPC_Delete = this.payloadReference.ReadablePayloadPacket as FPC_DeleteConnection;
                k = fPC_Delete.Process(device);
                break;

            case PropertyControlTypes.AssignConn:
                if (PropertyID == 1)     //Property ID 1 == name of channel
                {
                    payloadReference.ReadablePayloadPacket = new FPC_WriteDescription(payloadReference);
                    FPC_WriteDescription fPC_WriteDescription = this.payloadReference.ReadablePayloadPacket as FPC_WriteDescription;
                    k = fPC_WriteDescription.Process(device);
                }
                else
                {
                    payloadReference.ReadablePayloadPacket = new FPC_AssignConnection(payloadReference);
                    FPC_AssignConnection fPC_Assign = this.payloadReference.ReadablePayloadPacket as FPC_AssignConnection;
                    k = fPC_Assign.Process(device);
                }
                break;

            case PropertyControlTypes.WriteIconId:
                payloadReference.ReadablePayloadPacket = new FPC_WriteIcon(payloadReference);
                FPC_WriteIcon fPC_WriteIcon = this.payloadReference.ReadablePayloadPacket as FPC_WriteIcon;
                k = fPC_WriteIcon.Process(device);
                break;

            case PropertyControlTypes.WriteFlr_RmNr:
                payloadReference.ReadablePayloadPacket = new FPC_WriteRoomInfo(payloadReference);
                FPC_WriteRoomInfo fPC_WriteRoomInfo = this.payloadReference.ReadablePayloadPacket as FPC_WriteRoomInfo;
                k = fPC_WriteRoomInfo.Process(device);
                break;

            case PropertyControlTypes.UpdConsistencyTag:
                k = FPSR_ConsistancyTag.UpdateConsistancyTag(this, device);
                break;


            case FAHFunctionPropertyCommand.PropertyControlTypes.ReadFuncList:
                k = FPSR_FunctionList.CreateResponse(this, device);
                break;
            }
            if (k != null)
            {
                k.SourceAddress = device.KnxAddress;
                k.TargetAddress = this.payloadReference.OwnerOfPayload.SourceAddress;
            }
            return(k);
        }