예제 #1
0
        public void SetValue_InputValue_ExpectedSubGroupSet(byte[] input, int expected)
        {
            KnxGroupAddress addr = new KnxGroupAddress()
            {
                Value = input
            };

            Assert.Equal(expected, addr.SubGroup);
        }
예제 #2
0
        public static KnxAddress Parse(string address)
        {
            if (address.Contains("."))
            {
                return(KnxIndividualAddress.Parse(address));
            }

            return(KnxGroupAddress.Parse(address));
        }
예제 #3
0
        public void SendMessage(KnxGroupAddress destinationAddress, byte[] data, int lengthInBits)
        {
            byte len;

            if (lengthInBits <= 4)
            {
                len = 1;
            }
            else if (lengthInBits <= 8)
            {
                len = 2;
            }
            else if (lengthInBits <= 16)
            {
                len = 3;
            }
            else
            {
                len = 4;
            }

            IList <byte> buffer = new List <byte> {
                0xBC,
                0xE0,
                _connection.SourceAddress.Value[0],
                _connection.SourceAddress.Value[1],
                destinationAddress.Value[0],
                destinationAddress.Value[1],
                (byte)(len & 0x0F), 0x00
            };

            switch (len)
            {
            case 1:
                buffer.Add((byte)(0x80 | (data[0] & 0x0F)));
                break;

            case 2:
                buffer.Add(0x80);
                buffer.Add(data[0]);
                break;

            case 3:
                buffer.Add(0x80);
                buffer.Add(data[1]);
                buffer.Add(data[2]);
                break;
            }


            SendCEMI(new CommonExternalMessageInterface()
            {
                MessageCode        = CommonExternalMessageInterface.CmeiMessageCode.LDataReq,
                ServiceInformation = buffer.ToArray()
            });
        }
예제 #4
0
        public void StringParserTestFreeStyle()
        {
            var ga = KnxGroupAddress.Parse("230");

            Assert.IsInstanceOf <KnxFreeStyleGroupAddress>(ga);

            KnxFreeStyleGroupAddress threeLevelGa = (KnxFreeStyleGroupAddress)ga;

            Assert.AreEqual(230, threeLevelGa.SubGroup);
            Assert.AreEqual(true, threeLevelGa.Equals(230));
            Assert.AreEqual(true, threeLevelGa.Equals("230"));
        }
예제 #5
0
        private static void LightOnOff(KnxConnection connection)
        {
            Console.WriteLine("Press [ENTER] to send command ({0}) - false", LightOnOffAddress);
            Console.ReadLine();
            connection.Action(KnxGroupAddress.Parse(LightOnOffAddress), false);
            Thread.Sleep(200);

            Console.WriteLine("Press [ENTER] to send command ({0}) - true", LightOnOffAddress);
            Console.ReadLine();
            connection.Action(KnxGroupAddress.Parse(LightOnOffAddress), true);
            Thread.Sleep(200);
        }
예제 #6
0
        public void StringParserTestTwoLevel()
        {
            var ga = KnxGroupAddress.Parse("18/230");

            Assert.IsInstanceOf <KnxTwoLevelGroupAddress>(ga);

            KnxTwoLevelGroupAddress threeLevelGa = (KnxTwoLevelGroupAddress)ga;

            Assert.AreEqual(18, threeLevelGa.MainGroup);
            Assert.AreEqual(230, threeLevelGa.SubGroup);
            Assert.AreEqual(true, threeLevelGa.Equals(18, 230));
            Assert.AreEqual(true, threeLevelGa.Equals("18/230"));
        }
예제 #7
0
        public void ByteParserTest()
        {
            var gaThreeLevel = KnxGroupAddress.Parse(new byte[] { 0xa0, 0xb4 }, KnxGroupAddressStyle.ThreeLevel);
            var gaTwoLevel   = KnxGroupAddress.Parse(new byte[] { 0xa0, 0xb4 }, KnxGroupAddressStyle.TwoLevel);
            var gaFreeStyle  = KnxGroupAddress.Parse(new byte[] { 0xa0, 0xb4 }, KnxGroupAddressStyle.Free);

            Assert.IsInstanceOf <KnxThreeLevelGroupAddress>(gaThreeLevel);
            Assert.IsInstanceOf <KnxTwoLevelGroupAddress>(gaTwoLevel);
            Assert.IsInstanceOf <KnxFreeStyleGroupAddress>(gaFreeStyle);

            Assert.AreEqual("20/0/180", gaThreeLevel.ToString());
            Assert.AreEqual("20/180", gaTwoLevel.ToString());
            Assert.AreEqual("41140", gaFreeStyle.ToString());
        }
예제 #8
0
        public static void Main(string[] args)
        {
            KnxTunnelingConnection connection         = new KnxTunnelingConnection("172.16.1.122", 3671);
            KnxGroupAddress        temperatureAddress = KnxGroupAddress.Parse("15/1/0");
            KnxGroupAddress        relayAddress       = KnxGroupAddress.Parse("15/3/0");
            DataTypeParser         parser             = new DataTypeParser();

            connection.Logger = new ConsoleLogger();

            connection.OnConnect    += (sender, eventArgs) => Console.WriteLine("Connected");
            connection.OnDisconnect += (sender, eventArgs) => Console.WriteLine("Disconnected");
            connection.OnData       += (sender, eventArgs) =>
            {
                Console.WriteLine(eventArgs.SourceAddress + " -> " + eventArgs.DestinationAddress + " : " + ByteArrayToString(eventArgs.Data));

                if (eventArgs.DestinationAddress == temperatureAddress && (eventArgs.RequestType == APCIType.AGroupValueWrite || eventArgs.RequestType == APCIType.AGroupValueResponse))
                {
                    Console.WriteLine("Temp: " + parser.DTP9(eventArgs.Data).FloatValue);
                }
            };

            connection.Connect();

            while (true)
            {
                ConsoleKey key = Console.ReadKey().Key;

                if (key == ConsoleKey.Q)
                {
                    break;
                }
                else if (key == ConsoleKey.A)
                {
                    connection.RequestValue(temperatureAddress);
                }
                else if (key == ConsoleKey.Z)
                {
                    connection.SendValue(relayAddress, new byte[] { 0 }, 1);
                }
                else if (key == ConsoleKey.X)
                {
                    connection.SendValue(relayAddress, new byte[] { 1 }, 1);
                }
            }

            connection.Disconnect();

            Task.Delay(1000).Wait();
        }
예제 #9
0
        public void RequestValue(KnxGroupAddress address)
        {
            IList <byte> buffer = new List <byte> {
                0xBC,
                0xE0,
                _connection.SourceAddress.Value[0],
                _connection.SourceAddress.Value[1],
                address.Value[0],
                address.Value[1],
                0x01, 0x00, 0x00
            };

            SendCEMI(new CommonExternalMessageInterface()
            {
                MessageCode        = CommonExternalMessageInterface.CmeiMessageCode.LDataReq,
                ServiceInformation = buffer.ToArray()
            });
        }
예제 #10
0
        public void TunnelingActionFeedbackTest()
        {
            ResetEvent = new ManualResetEventSlim();

            KnxConnection connection = new KnxConnectionTunneling("127.0.0.1", 3671, "127.0.0.1", 3672)
            {
                Debug = false
            };

            connection.KnxEventDelegate += Event;

            connection.Connect();

            Thread.Sleep(50);

            connection.Action(KnxGroupAddress.Parse(LightOnOffAddress), true);

            if (!ResetEvent.Wait(Timeout))
            {
                Assert.Fail("Didn't receive feedback from the action");
            }
        }
예제 #11
0
 /// <summary>
 /// Request a value to be read from the bus. If there's a response it will be readable in the OnData event.
 /// </summary>
 /// <param name="address">The knx group address to read from</param>
 public void RequestValue(KnxGroupAddress address)
 {
     _sender.RequestValue(address);
 }
예제 #12
0
 /// <summary>
 /// Send a value to a given address
 /// </summary>
 /// <param name="address">The knx group address to send data to</param>
 /// <param name="data">The data</param>
 /// <param name="dataLength">The data-length in bits</param>
 public void SendValue(KnxGroupAddress address, byte[] data, int dataLength)
 {
     _sender.SendMessage(address, data, dataLength);
 }
예제 #13
0
        public void Parse_InputValue_CorrectSubGroup(string input, int expected)
        {
            KnxGroupAddress addr = KnxGroupAddress.Parse(input);

            Assert.Equal(expected, addr.SubGroup);
        }