Esempio n. 1
0
 public netForm_Universal(netdata netdata, string mac, netForm parent)
 {
     tForm = parent;
     InitializeComponent();
     button3.Text = translate.getInfo("form2", "button3");
     button4.Text = translate.getInfo("form2", "button4");
     for (int i = 0; i < label.Length; i++)
     {
         label[i] = (Label)Controls.Find("RF_label" + i.ToString(), true)[0];
     }
     for (int i = 1; i < comboBox.Length; i++)
     {
         comboBox[i] = (ComboBox)Controls.Find("RF_C" + (i - 1).ToString(), true)[0];
     }
     for (int i = 0; i < textBox.Length; i++)
     {
         textBox[i] = (TextBox)Controls.Find("RF_T" + i.ToString(), true)[0];
     }
     Rf.ControlEnable(label, textBox, comboBox, false);
     xServer        = new submenuTUdpServer1(1901);
     _syncContext   = SynchronizationContext.Current;
     xServer.UIForm = this;
     _Netdata       = netdata;
     _Mac           = mac;
     Rf.GetConfigFile(netdata.Version - 1);
 }
Esempio n. 2
0
        public void SetInfo(netdata data)
        {
            _Netdata = data;
            if (data.Version < 4)
            {
                panel_baudRate.Enabled = true;
                tabPage2.Parent        = null;
            }
            else
            {
                panel_baudRate.Enabled = false;
            }

            if (data.Version == 8)
            {
                tabPage2.Parent        = null;
                panel_baudRate.Enabled = false;
            }
            this.cmIPmode.SelectedIndex = data.DHCP;
            this.edIP.Text           = funs.ByteArrayToIPAddress(data.IP);
            this.edMask.Text         = funs.ByteArrayToIPAddress(data.mask);
            this.edGaway.Text        = funs.ByteArrayToIPAddress(data.gateway);
            this.eddns.Text          = funs.ByteArrayToIPAddress(data.dnsServer);
            this.eddnsBack.Text      = funs.ByteArrayToIPAddress(data.dnsServerBack);
            this.edlocalport.Text    = ntohs((short)data.localport).ToString();
            this.edPort.Text         = ntohs((short)data.objport).ToString();
            this.cmObj.SelectedIndex = data.domain_type;
            this.edDomain.Text       = System.Text.Encoding.Default.GetString(data.desc);
            if (data.domain_type == 0)
            {
                byte[] x = new byte[4];
                x[0] = data.desc[0];
                x[1] = data.desc[1];
                x[2] = data.desc[2];
                x[3] = data.desc[3];
                this.edDomain.Text = funs.ByteArrayToIPAddress(x);
            }
            else
            {
                this.edDomain.Text = System.Text.Encoding.Default.GetString(data.desc);
            }
            this.cmProtocol.SelectedIndex = data.protocol;
            this.edBord.Text             = funs.byte3_str(data.boad);// ntohs((short)data.boad).ToString();
            this.comboBox1.SelectedIndex = data.com;
            this.edLink.Text             = data.link.ToString();
            this.edTimeout.Text          = ntohs((short)data.time_root).ToString();
            this.cmRegMode.SelectedIndex = data.reg_send_mode;

            this.edregdata.Text         = funs.byteToHexStr(funs.SubByte(data.reg_data, 0, data.regLen));
            this.edheatdata.Text        = funs.byteToHexStr(funs.SubByte(data.Heartbeat, 0, data.hbLen));
            this.edheattime.Text        = ntohs((short)data.HeartTime).ToString();
            this.cmhbType.SelectedIndex = data.hbType;
            comboBox2.SelectedIndex     = data.clear;
        }
Esempio n. 3
0
        public static void send(string mac, netdata xdata)
        {
            TCmdHead xCmd = new TCmdHead()
            {
                cmd = 0x01FE,
                mac = funs.Mac2Byte(mac)
            };
            int CmdSize  = Marshal.SizeOf(xCmd);
            int dataSize = Marshal.SizeOf(xdata);

            byte[] xBuf = funs.copybyte(funs.StructToBytes(xCmd, CmdSize), funs.StructToBytes(xdata, dataSize));
            send(xBuf, LocalIPEndPiont, RemoteIPEndPoint);
        }
Esempio n. 4
0
        private void toolStripButton2_Click(object sender, EventArgs e)
        {//配置
            ListView listView = listView1;

            if (this.listView1.SelectedItems.Count == 0)
            {
                MessageBox.Show(translate.getInfo("form1", "btn2_show"));
                return;
            }
            ListView.SelectedIndexCollection c = this.listView1.SelectedIndices;
            netdata_new netData_new;
            string      netMac = listView.Items[c[0]].SubItems[1].Text;

            if (listView.Items[c[0]].SubItems[7].Text == "unknown")
            {
                MessageBox.Show(translate.getInfo("form1", "cmd_error"));
                return;
            }
            netData_new = (netdata_new)(listView.Items[c[0]].Tag);

            netForm_Eth dataForm = new netForm_Eth();//this

            xServer.Stop();
            // dataForm.Language = Language;
            dataForm._Mac       = netMac;
            dataForm.IPEndPoint = netData_new.ipEndPoint;
            dataForm.SetInfo(netData_new.xdata);
            dataForm.E830_BaudVsibleSet(netcfg.E830_ETH2A.E830ETH_Flag);               //E830
            dataForm.ShowDialog();

            //funs.Delay1ms(200);
            xServer.Start();
            //funs.Delay1ms(200);
            netdata xdata = netData_new.xdata;

            if (dataForm.DialogResult == DialogResult.OK)
            {
                xdata = dataForm.GetInfo();
                flag  = 1;
            }
            else
            {
                xdata = dataForm._Netdata;
                flag  = 0;
            }

            udpclient.send(netMac, xdata);
        }
Esempio n. 5
0
        private void UniversalFormShow()
        {
            Form = new netForm_Universal(_Netdata, _Mac, tForm);
            var form = (netForm_Universal)Form;

            Rf.GetConfigFile(_Netdata.Version - 1);
            int     i       = Rf.GetClass();
            int     x       = Rf.GetConfigBaudRate();
            netdata netdata = _Netdata;

            netdata.boad = funs.int2byte3(Rf.GetConfigBaudRate());
            netdata.com  = 0x00;
            udpclient.send(_Mac, netdata);
            timer1.Enabled       = true;
            form.FormBorderStyle = FormBorderStyle.None; //隐藏子窗体边框(去除最小花,最大化,关闭等按钮)
            form.TopLevel        = false;                //指示子窗体非顶级窗体
            panel1.Controls.Add(form);                   //将子窗体载入panel
            form.UDPserverStart();
            form.Show();
        }
Esempio n. 6
0
        public void ChangePort(int Port, bool mtu)//
        {
            netdata _netdata = netdata;

            _netdata.protocol  = 2;//UDP client
            _netdata.localport = (UInt16)ntohs(Port);
            _netdata.objport   = (UInt16)ntohs(Port);
            byte [] bytes = funs.IpToByte(udpclient.LocalIPEndPiont.Address.ToString());
            for (int i = 0; i < bytes.Length; i++)
            {
                _netdata.desc[i] = bytes[i];
            }
            if (mtu)
            {
                _netdata.MTU = (UInt16)(ntohs(0x7000) | _netdata.MTU);
            }
            else
            {
                _netdata.MTU = (UInt16)(ntohs(0x8fff) & _netdata.MTU);
            }
            udpclient.send(Mac, _netdata);
            funs.Delay1ms(50);
            udpclient.send(Mac, 0x03fe);//重启生效
        }
Esempio n. 7
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (_Netdata.Version > 3)
            {
                if (submenuFlag == false)
                {
                    if (_Netdata.Version != 7)
                    {
                        ((netForm_Universal)Form).Exit();
                        _Netdata = ((netForm_Universal)Form)._Netdata;
                    }
                    else
                    {
                        ((E70)Form).Exit();
                    }
                }
            }
            netdata xxdata = GetInfo();

            if (xxdata.hbLen != 255)
            {
                this.DialogResult = DialogResult.OK;
            }
        }
Esempio n. 8
0
        public netdata GetInfo()
        {
            netdata xdata = _Netdata;

            xdata.hbLen = 255;
            xdata.DHCP  = (byte)cmIPmode.SelectedIndex;
            if (!funs.IsIP(this.edIP.Text))
            {
                this.edIP.Focus();
                MessageBox.Show(translate.getInfo("form2", "msg0"));
                return(xdata);
            }
            xdata.IP = funs.IpToByte(this.edIP.Text);
            if (!funs.IsIP(this.edMask.Text))
            {
                this.edMask.Focus();
                MessageBox.Show(translate.getInfo("form2", "msg1"));
                return(xdata);
            }
            xdata.mask = funs.IpToByte(this.edMask.Text);
            if (!funs.IsIP(this.edGaway.Text))
            {
                this.edGaway.Focus();
                MessageBox.Show(translate.getInfo("form2", "msg2"));
                return(xdata);
            }
            xdata.gateway = funs.IpToByte(this.edGaway.Text);
            if (!funs.IsIP(this.eddns.Text))
            {
                this.eddns.Focus();
                MessageBox.Show(translate.getInfo("form2", "msg3"));
                return(xdata);
            }
            xdata.dnsServer = funs.IpToByte(this.eddns.Text);
            if (!funs.IsIP(this.eddnsBack.Text))
            {
                this.eddnsBack.Focus();
                MessageBox.Show(translate.getInfo("form2", "msg4"));
                return(xdata);
            }
            xdata.dnsServerBack = funs.IpToByte(this.eddnsBack.Text);
            if (!funs.IsPort(this.edPort.Text))
            {
                this.edPort.Focus();
                MessageBox.Show(translate.getInfo("form2", "msg5"));
                return(xdata);
            }
            xdata.objport = (UInt16)ntohs(int.Parse(this.edPort.Text));
            if (!funs.IsPort(this.edlocalport.Text))
            {
                this.edlocalport.Focus();
                MessageBox.Show(translate.getInfo("form2", "msg6"));
                return(xdata);
            }
            xdata.localport   = (UInt16)ntohs(int.Parse(edlocalport.Text));
            xdata.domain_type = (byte)cmObj.SelectedIndex;

            //*
            if (cmObj.SelectedIndex == 0)
            {
                if (!funs.IsIP(this.edDomain.Text))
                {
                    this.edDomain.Focus();
                    MessageBox.Show(translate.getInfo("form2", "msg0"));
                    return(xdata);
                }
                byte[] x = funs.IpToByte(this.edDomain.Text);
                xdata.desc    = new byte[64];
                xdata.desc[0] = x[0];
                xdata.desc[1] = x[1];
                xdata.desc[2] = x[2];
                xdata.desc[3] = x[3];
            }
            else
            {
                xdata.desc = System.Text.Encoding.Default.GetBytes(edDomain.Text.PadRight(64, '\0'));
            }//*/
            xdata.protocol = (byte)this.cmProtocol.SelectedIndex;
            if (xdata.Version < 4)
            {
                xdata.boad = funs.int2byte3(int.Parse(this.edBord.Text));// (UInt16)ntohs(short.Parse(this.edBord.Text));
                xdata.com  = (byte)(this.comboBox1.SelectedIndex);
            }
            else if (xdata.Version == 8)      //E830
            {
                xdata.boad = funs.int2byte3(9600);
            }
            xdata.link = (Byte)int.Parse(this.edLink.Text);
            if (!funs.IsEdTimeout(this.edTimeout.Text))
            {
                this.edTimeout.Focus();
                MessageBox.Show(translate.getInfo("form2", "msg9"));
                return(xdata);
            }

            if (!funs.IsEdheattime(this.edheattime.Text))
            {
                this.edheattime.Focus();
                MessageBox.Show(translate.getInfo("form2", "msg9"));
                return(xdata);
            }
            if (!funs.IsBaudrate(this.edBord.Text))
            {
                this.edBord.Focus();
                MessageBox.Show(translate.getInfo("form2", "msg9"));
                return(xdata);
            }
            if (!funs.IsEdLink(this.edLink.Text))
            {
                this.edLink.Focus();
                MessageBox.Show(translate.getInfo("form2", "msg9"));
                return(xdata);
            }
            xdata.time_root     = (UInt16)ntohs(short.Parse(this.edTimeout.Text));
            xdata.reg_send_mode = (byte)this.cmRegMode.SelectedIndex;
            xdata.clear         = (byte)comboBox2.SelectedIndex;
            byte[] xarr;
            if (ck_reg.Checked)
            {
                xarr = funs.HexString2Bytes(edregdata.Text);
            }
            else
            {
                xarr = ASCIIEncoding.Default.GetBytes(edregdata.Text);
            }
            xdata.regLen = (byte)xarr.Length;
            if (xarr.Length > 40)
            {
                xdata.regLen = 40;
            }
            xdata.reg_data = new byte[40];
            Array.Copy(xarr, xdata.reg_data, xdata.regLen);

            if (ck_heath.Checked)
            {
                xarr = funs.HexString2Bytes(edheatdata.Text);
            }
            else
            {
                xarr = ASCIIEncoding.Default.GetBytes(edheatdata.Text);
            }
            xdata.hbLen = (byte)xarr.Length;
            if (xarr.Length > 40)
            {
                xdata.hbLen = 40;
            }
            xdata.Heartbeat = new byte[40];
            Array.Copy(xarr, xdata.Heartbeat, xdata.hbLen);

            xdata.HeartTime = (UInt16)ntohs(int.Parse(this.edheattime.Text));
            xdata.hbType    = (byte)cmhbType.SelectedIndex;
            byte[] vBytes = new byte[2];
            for (int i = 0; i < 4; i += 2)
            {
                vBytes[i / 2] = 0;
            }
            try
            {
            }
            catch (Exception)
            {
            }
            return(xdata);
        }