Ejemplo n.º 1
0
        public byte[] GetBytesCemi()
        {
            TunnelCemiRequest builder = new TunnelCemiRequest();

            builder.Build(UnicastAddress.FromString("0.0.0"), MulticastAddress.FromString("0/0/0"), ApciTypes.IndividualAddressRead);
            return(builder.GetBytes());
        }
        public byte[] GetBytesCemi()
        {
            TunnelCemiRequest builder = new TunnelCemiRequest();

            builder.Build(MulticastAddress.FromString("0/0/0"), MulticastAddress.FromString("0/0/0"), ApciTypes.IndividualAddressWrite, 255, _address.GetBytes());
            builder.SetPriority(Prios.System);
            return(builder.GetBytes());
        }
Ejemplo n.º 3
0
        public async Task <IMessageResponse> GroupValueRead(MulticastAddress ga)
        {
            MsgGroupReadReq message = new MsgGroupReadReq(ga);
            var             seq     = await _conn.Send(message);

            var x = await WaitForData(seq);

            return(x);
        }
Ejemplo n.º 4
0
        public byte[] GetBytesEmi1()
        {
            TunnelEmi1Request builder = new TunnelEmi1Request();

            builder.Build(UnicastAddress.FromString("0.0.0"), MulticastAddress.FromString("0/0/0"), ApciTypes.IndividualAddressRead);
            builder.SetChannelId(ChannelId);
            builder.SetSequence(SequenceCounter);
            return(builder.GetBytes());
        }
Ejemplo n.º 5
0
        public byte[] GetBytesEmi1()
        {
            List <byte> data = new List <byte>()
            {
                0x11, 0x00
            };
            TunnelRequest builder = new TunnelRequest();

            builder.Build(UnicastAddress.FromString("0.0.0"), MulticastAddress.FromString("0/0/0"), ApciTypes.IndividualAddressRead);
            data.AddRange(builder.GetBytes());
            return(data.ToArray());
        }
Ejemplo n.º 6
0
        public byte[] GetBytesCemi()
        {
            List <byte> data = new List <byte>()
            {
                0x11, 0x00
            };
            TunnelRequest builder = new TunnelRequest();

            builder.Build(MulticastAddress.FromString("0/0/0"), MulticastAddress.FromString("0/0/0"), ApciTypes.IndividualAddressWrite, 255, _address.GetBytes());
            builder.SetPriority(Prios.System);
            data.AddRange(builder.GetBytes());
            return(data.ToArray());
        }
        public byte[] GetBytesCemi()
        {
            TunnelCemiRequest builder = new TunnelCemiRequest();

            List <byte> data = new List <byte>();

            data.AddRange(Serial);

            data.AddRange(NewAddress.GetBytes());
            data.AddRange(new byte[] { 0, 0, 0, 0 });

            builder.Build(UnicastAddress.FromString("0.0.0"), MulticastAddress.FromString("0/0/0"), ApciTypes.IndividualAddressSerialNumberWrite, 255, data.ToArray());
            builder.SetPriority(Prios.System);
            return(builder.GetBytes());
        }
Ejemplo n.º 8
0
        public Builders.TunnelResponse Build(byte headerLength, byte protocolVersion, ushort totalLength, byte[] responseBytes)
        {
            var structureLength      = responseBytes[0];
            var communicationChannel = responseBytes[1];
            var sequenceCounter      = responseBytes[2];
            var messageCode          = responseBytes[4];
            var addInformationLength = responseBytes[5];
            var controlField         = responseBytes[6];
            var controlField2        = responseBytes[7];
            var npduLength           = responseBytes[12];

            byte[] npdu;

            if (npduLength != 0)
            {
                npdu = new byte[] { responseBytes[13], responseBytes[14] };
            }
            else
            {
                npdu = new byte[] { responseBytes[13] };
            }


            byte[]    data    = null;
            int       seqNumb = 0x0;
            ApciTypes type    = ApciTypes.Undefined;

            if (npduLength != 0)
            {
                BitArray bitsNpdu = new BitArray(npdu);
                if (bitsNpdu.Get(6))
                {
                    seqNumb = npdu[0] >> 2;
                    seqNumb = seqNumb & 0xF;
                }

                int apci1 = ((npdu[0] & 3) << 2) | (npdu[1] >> 6);

                switch (apci1)
                {
                case 0:
                    type = ApciTypes.GroupValueRead;
                    break;

                case 1:
                    type = ApciTypes.GroupValueResponse;
                    int datai2 = npdu[1] & 63;
                    data    = new byte[responseBytes.Length - 15 + 1];
                    data[0] = Convert.ToByte(datai2);
                    for (int i = 1; i < responseBytes.Length - 15 + 1; i++)
                    {
                        data[i] = responseBytes[i];
                    }
                    break;

                case 2:
                    type = ApciTypes.GroupValueWrite;
                    int datai = npdu[1] & 63;
                    data    = new byte[responseBytes.Length - 15 + 1];
                    data[0] = Convert.ToByte(datai);
                    for (int i = 1; i < responseBytes.Length - 15 + 1; i++)
                    {
                        data[i] = responseBytes[i];
                    }
                    break;

                case 3:
                    type = ApciTypes.IndividualAddressWrite;
                    break;

                case 4:
                    type = ApciTypes.IndividualAddressRead;
                    break;

                case 5:
                    type = ApciTypes.IndividualAddressResponse;
                    break;

                case 6:
                    type = ApciTypes.ADCRead;
                    break;

                case 7:
                    if (npdu[1] == 0)
                    {
                        type = ApciTypes.ADCResponse;
                    }
                    break;

                case 8:
                    type = ApciTypes.MemoryRead;
                    break;

                case 9:
                    type = ApciTypes.MemoryResponse;
                    break;

                case 10:
                    type = ApciTypes.MemoryWrite;
                    break;


                default:
                    apci1 = ((npdu[0] & 3) << 8) | npdu[1];
                    type  = (ApciTypes)apci1;
                    break;
                }

                if (data == null)
                {
                    data = new byte[responseBytes.Length - 15];

                    int c = 0;
                    for (int i = 15; i < responseBytes.Length; i++)
                    {
                        data[c] = responseBytes[i];
                        c++;
                    }
                }
            }
            else
            {
                data = new byte[0];
                int apci3 = npdu[0] & 3;

                BitArray bitsNpdu = new BitArray(npdu);
                if (bitsNpdu.Get(6))
                {
                    seqNumb = npdu[0] >> 2;
                    seqNumb = seqNumb & 0xF;
                }

                switch (apci3)
                {
                case 0:
                    type = ApciTypes.Connect;
                    break;

                case 1:
                    type = ApciTypes.Disconnect;
                    break;

                case 2:
                    type = ApciTypes.Ack;
                    break;

                case 3:
                    type = ApciTypes.NAK;
                    break;

                default:
                    Debug.WriteLine("Unbekantes NPDU: " + apci3);
                    break;
                }
            }

            BitArray bitsCtrl1 = new BitArray(new[] { responseBytes[6] });
            BitArray bitsCtrl2 = new BitArray(new[] { responseBytes[7] });

            IKnxAddress destAddr = null;

            if (bitsCtrl2.Get(7))
            {
                destAddr = MulticastAddress.FromByteArray(new[] { responseBytes[10], responseBytes[11] });
            }
            else
            {
                destAddr = UnicastAddress.FromByteArray(new[] { responseBytes[10], responseBytes[11] });
            }

            bool ackWanted = bitsCtrl1.Get(2);
            bool isRequest = ReqMC.Contains(responseBytes[4]);


            switch (type)
            {
            case ApciTypes.MemoryWrite:
            case ApciTypes.MemoryRead:
                byte[] data_temp = new byte[data.Length + 1];

                int restData = npdu[1] & 127;

                data_temp[0] = BitConverter.GetBytes(restData)[0];

                for (int i = 0; i < data.Length; i++)
                {
                    data_temp[i + 1] = data[i];
                }
                data = data_temp;
                break;
            }



            return(new Builders.TunnelResponse(headerLength, protocolVersion, totalLength, structureLength, communicationChannel,
                                               sequenceCounter, messageCode, addInformationLength, isRequest, ackWanted, controlField, controlField2,
                                               UnicastAddress.FromByteArray(new[] { responseBytes[8], responseBytes[9] }),
                                               destAddr, type, seqNumb,
                                               data));
        }
Ejemplo n.º 9
0
 public async void GroupValueWrite(MulticastAddress ga, byte[] data)
 {
     MsgGroupWriteReq message = new MsgGroupWriteReq(from, ga, data);
     await _conn.Send(message);
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Creates a telegram to write a group value
 /// </summary>
 /// <param name="from">Unicast Address from sender</param>
 /// <param name="to">Mulicast Address (GroupAddress)</param>
 /// <param name="data">Data to write</param>
 public MsgGroupWriteReq(UnicastAddress from, MulticastAddress to, byte[] data)
 {
     SourceAddress      = from;
     DestinationAddress = to;
     _data = data;
 }
Ejemplo n.º 11
0
 public async Task GroupValueWrite(MulticastAddress ga, byte data)
 {
     await GroupValueWrite(ga, new byte[] { data });
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Creates a telegram to read a group value
 /// </summary>
 /// <param name="address">Multicast Address (GroupAddress)</param>
 public MsgGroupReadReq(MulticastAddress address)
 {
     DestinationAddress = address;
 }