예제 #1
0
        public DescriptionResponse(bool status,
                                   EIBAddress addr,
                                   string serial,
                                   IPAddress mcast,
                                   PhysicalAddress mac,
                                   string name)
            : base(EIBMessages.EIB_MC_DESCRIPTION_RESPONSE)
        {
            Debug.Assert(addr != null, "Address cannot be null");
            Debug.Assert(serial != null, "SerialNumber cannot be null");
            Debug.Assert(mcast != null, "Multicast Address cannot be null");
            Debug.Assert(mac != null, "MAC Address cannot be null");
            Debug.Assert(name != null, "Name cannot be null");

            descriptiontypecode = EIBMessages.DEVICE_INFO;
            knxmedium           = 0x02; //TP1
            devicestatus        = status ? (byte)0x1 : (byte)0x0;
            eibaddress          = addr;
            //projectinstallationidentifier = 0x0;
            serialnumber     = serial;
            multicastaddress = mcast;
            macaddress       = mac;
            this.name        = name;

            this.supp_dib_structlength        = 10;
            this.supp_dib_descriptiontypecode = EIBMessages.SUPP_SVC_FAMILIES;
            this.supp_dib_data = new byte[8] {
                EIBMessages.EIBNETIP_CORE, 0x1,
                EIBMessages.EIBNETIP_DEVMGMT, 0x1,
                EIBMessages.EIBNETIP_TUNNELING, 0x1,
                EIBMessages.EIBNETIP_ROUTING, 0x1
            };
        }
예제 #2
0
        public CemiFrame(EIBAddress src, EIBAddress dest, byte[] value, bool need_ack)
        {
            if (value == null)
            {
                throw new Exception("Value byte Array is null");
            }

            _mc     = 0x29;
            _addil  = 0;
            _ctrl1  = need_ack ? (byte)0x02 : (byte)0;
            _ctrl1 |= 0x80; //standard frame
            _ctrl2  = 0x60; // default: routing counter = 6
            if (dest._is_logical)
            {
                _ctrl2 |= 0x80;
            }
            _src         = src;
            _dst         = dest;
            _apci_length = (byte)value.Length;
            _tpci        = 0;
            _apci        = value[0];

            if (_apci_length > 1)
            {
                _addil_data = new byte[_apci_length - 1];
                for (int i = 1; i < _apci_length; ++i)
                {
                    _addil_data[i - 1] = value[i];
                }
            }
        }
예제 #3
0
        public CemiFrame(EIBAddress src, EIBAddress dest, byte[] value, bool need_ack)
        {
            if (value == null)
            {
                throw new Exception("Value byte Array is null");
            }

            _mc = 0x29;
            _addil = 0;
            _ctrl1 = need_ack ? (byte)0x02 : (byte)0;
            _ctrl1 |= 0x80; //standard frame
            _ctrl2 = 0x60; // default: routing counter = 6
            if (dest._is_logical)
            {
                _ctrl2 |= 0x80;
            }
            _src = src;
            _dst = dest;
            _apci_length = (byte)value.Length;
            _tpci = 0;
            _apci = value[0];

            if (_apci_length > 1)
            {
                _addil_data = new byte[_apci_length - 1];
                for (int i = 1; i < _apci_length; ++i)
                {
                    _addil_data[i - 1] = value[i];
                }
            }
        }
예제 #4
0
        public static EIBAddress GetRandomAddress()
        {
            Random r = new Random();

            byte[] arr = new byte[2];
            r.NextBytes(arr);
            EIBAddress addr = new EIBAddress(arr, true);

            return(addr);
        }
예제 #5
0
        private void btnSendPkt_Click(object sender, EventArgs e)
        {
            if (_remote_data_endpoint == null)
            {
                MessageBox.Show("No EIB Client is connected. cannot sent packets.", "Error", MessageBoxButtons.OK);
                return;
            }

            if (this.tbValue.Text == null || this.tbValue.Text.Length == 0)
            {
                MessageBox.Show("No value was provided. you must enter the cEMI frame value to send", "Error", MessageBoxButtons.OK);
                return;
            }
            if (!hex_regex.IsMatch(this.tbValue.Text))
            {
                MessageBox.Show("The cEMI frame value is not valid HEX format.", "Error", MessageBoxButtons.OK);
                return;
            }

            for (int i = 0; i < this.nudNumPkts.Value; ++i)
            {
                EIBAddress dst_addr;
                EIBAddress src_addr = new EIBAddress(this.tbSrcAddress.Text);
                if (this.checkBox1.Checked)
                {
                    dst_addr = EIBAddress.GetRandomAddress();
                }
                else
                {
                    dst_addr = new EIBAddress(this.tbDestAddress.Text);
                }
                CemiFrame frame = new CemiFrame(src_addr,
                                                dst_addr,
                                                StringToByteArray(this.tbValue.Text),
                                                cbNeedAck.Checked);
                byte[] data = null;
                switch (_mode)
                {
                case DEVICE_MODE.MODE_TUNNELING:
                    TunnelRequest req = new TunnelRequest(frame, _send_sequence);
                    data = req.ToByteArray();
                    break;

                case DEVICE_MODE.MODE_ROUTING:
                    RoutingIndication roi = new RoutingIndication(frame);
                    data = roi.ToByteArray();
                    break;
                }

                _sock.SendTo(data, _remote_data_endpoint);
                LogSend(String.Format("Data packet. Dest addr: {0} Value 0x{1}", dst_addr.ToString(), this.tbValue.Text));
                System.Threading.Thread.Sleep(10);
            }
        }
예제 #6
0
        public CemiFrame(Stream s)
        {
            _mc    = (byte)s.ReadByte();
            _addil = (byte)s.ReadByte();
            _ctrl1 = (byte)s.ReadByte();
            _ctrl2 = (byte)s.ReadByte();

            byte[] addr = new byte[2];
            s.Read(addr, 0, 2);
            _src = new EIBAddress(addr, false);
            s.Read(addr, 0, 2);
            _dst = new EIBAddress(addr, (_ctrl2 & 0x80) != 0);

            _apci_length = (byte)s.ReadByte();
            _tpci        = (byte)s.ReadByte();
            _apci        = (byte)s.ReadByte();

            if (_apci_length > 1)
            {
                _addil_data = new byte[_apci_length - 1];
                s.Read(_addil_data, 0, _apci_length - 1);
            }
        }
예제 #7
0
        private void btnSendPkt_Click(object sender, EventArgs e)
        {
            if (_remote_data_endpoint == null)
            {
                MessageBox.Show("No EIB Client is connected. cannot sent packets.", "Error", MessageBoxButtons.OK);
                return;
            }

            if (this.tbValue.Text == null || this.tbValue.Text.Length == 0)
            {
                MessageBox.Show("No value was provided. you must enter the cEMI frame value to send", "Error", MessageBoxButtons.OK);
                return;
            }
            if (!hex_regex.IsMatch(this.tbValue.Text))
            {
                MessageBox.Show("The cEMI frame value is not valid HEX format.", "Error", MessageBoxButtons.OK);
                return;
            }

            for (int i = 0; i < this.nudNumPkts.Value; ++i)
            {
                EIBAddress dst_addr;
                EIBAddress src_addr = new EIBAddress(this.tbSrcAddress.Text);
                if (this.checkBox1.Checked)
                    dst_addr = EIBAddress.GetRandomAddress();
                else
                    dst_addr = new EIBAddress(this.tbDestAddress.Text);
                CemiFrame frame = new CemiFrame(src_addr,
                                                dst_addr,
                                                StringToByteArray(this.tbValue.Text),
                                                cbNeedAck.Checked);
                byte[] data = null;
                switch (_mode)
                {
                    case DEVICE_MODE.MODE_TUNNELING:
                        TunnelRequest req = new TunnelRequest(frame, _send_sequence);
                        data = req.ToByteArray();
                        break;
                    case DEVICE_MODE.MODE_ROUTING:
                        RoutingIndication roi = new RoutingIndication(frame);
                        data = roi.ToByteArray();
                        break;
                }

                _sock.SendTo(data, _remote_data_endpoint);
                LogSend(String.Format("Data packet. Dest addr: {0} Value 0x{1}", dst_addr.ToString(), this.tbValue.Text));
                System.Threading.Thread.Sleep(10);
            }
        }
예제 #8
0
        public CemiFrame(Stream s)
        {
            _mc = (byte)s.ReadByte();
            _addil = (byte)s.ReadByte();
            _ctrl1 = (byte)s.ReadByte();
            _ctrl2 = (byte)s.ReadByte();

            byte[] addr = new byte[2];
            s.Read(addr, 0, 2);
            _src = new EIBAddress(addr, false);
            s.Read(addr, 0, 2);
            _dst = new EIBAddress(addr, (_ctrl2 & 0x80) != 0);

            _apci_length = (byte)s.ReadByte();
            _tpci = (byte)s.ReadByte();
            _apci = (byte)s.ReadByte();

            if (_apci_length > 1)
            {
                _addil_data = new byte[_apci_length - 1];
                s.Read(_addil_data, 0, _apci_length - 1);
            }
        }
예제 #9
0
 public static EIBAddress GetRandomAddress()
 {
     Random r = new Random();
     byte[] arr = new byte[2];
     r.NextBytes(arr);
     EIBAddress addr = new EIBAddress(arr,true);
     return addr;
 }
예제 #10
0
        public DescriptionResponse(bool status,
            EIBAddress addr,
            string serial,
            IPAddress mcast,
            PhysicalAddress mac,
            string name)
            : base(EIBMessages.EIB_MC_DESCRIPTION_RESPONSE)
        {
            Debug.Assert(addr != null, "Address cannot be null");
            Debug.Assert(serial != null, "SerialNumber cannot be null");
            Debug.Assert(mcast != null, "Multicast Address cannot be null");
            Debug.Assert(mac != null, "MAC Address cannot be null");
            Debug.Assert(name != null, "Name cannot be null");

            descriptiontypecode = EIBMessages.DEVICE_INFO;
            knxmedium = 0x02; //TP1
            devicestatus = status ? (byte)0x1 : (byte)0x0;
            eibaddress = addr;
            //projectinstallationidentifier = 0x0;
            serialnumber = serial;
            multicastaddress = mcast;
            macaddress = mac;
            this.name = name;

            this.supp_dib_structlength = 10;
            this.supp_dib_descriptiontypecode = EIBMessages.SUPP_SVC_FAMILIES;
            this.supp_dib_data = new byte[8] {
                EIBMessages.EIBNETIP_CORE , 0x1,
                EIBMessages.EIBNETIP_DEVMGMT , 0x1,
                EIBMessages.EIBNETIP_TUNNELING , 0x1,
                EIBMessages.EIBNETIP_ROUTING , 0x1
            };
        }