Example #1
0
        private void AddNeiborToList_Click(object sender, EventArgs e)
        {
            int nodenum = NeiborNodeLst.RowCount;

            int[] dat = new int[1];
            if (nodenum > 0)
            {
                SourceDataClass.InitForPack(nodenum * 24 + 4 + 20);
                dat[0] = 3;
                SourceDataClass.OutPutIntBit(dat, 8);
                dat[0] = nodenum * 24 + 4 + 20;
                SourceDataClass.OutPutIntBit(dat, 12);
                dat[0] = nodenum;
                SourceDataClass.OutPutIntBit(dat, 4);    //邻节点数
                for (int i = 0; i < nodenum; i++)
                {
                    dat[0] = int.Parse(NeiborNodeLst.Rows[i].Cells[1].Value.ToString());
                    SourceDataClass.OutPutIntBit(dat, 6);    //邻节点
                    dat[0] = (int)(double.Parse(NeiborNodeLst.Rows[i].Cells[2].Value.ToString()) * 10);
                    SourceDataClass.OutPutIntBit(dat, 16);   //距离
                    int value = Convert.ToInt32(Enum.Parse(typeof(SourceDataClass.ChannlValue), NeiborNodeLst.Rows[i].Cells[3].Value.ToString()));
                    dat[0] = value;
                    SourceDataClass.OutPutIntBit(dat, 2);    //评价
                }

                //加入列表
                MainForm.pMainForm.comlistwin.AddCmd(NodeBox.Text, "邻节点表", SourceDataClass.packdata);
                StatusLabel.Text = "邻节点表已加入命令列表";
                MainForm.pMainForm.RefreshListStat();
                MessageBox.Show("邻节点表已加入命令列表!");
            }
        }
Example #2
0
        private void ConfBtn_Click(object sender, EventArgs e)
        {
            if (nodeinfolist.Items.Count > 0)
            {
                if (DestNodeBox.Text == "")
                {
                    return;
                }
                int   nodenum = nodeinfolist.Items.Count;
                int[] dat     = new int[1];
                SourceDataClass.InitForPack(nodenum * 115 + 6 + 20);
                dat[0] = 2;
                SourceDataClass.OutPutIntBit(dat, 8);
                dat[0] = nodenum * 115 + 6 + 20;
                SourceDataClass.OutPutIntBit(dat, 12);
                dat[0] = nodenum;
                SourceDataClass.OutPutIntBit(dat, 6);//节点数
                foreach (string nodename in NodeInfo.Keys)
                {
                    SourceDataClass.OutPutArrayBit((BitArray)NodeInfo[nodename]);
                }

                //加入列表
                MainForm.pMainForm.comlistwin.AddCmd("节点" + DestNodeBox.Text.TrimStart('节', '点'), "节点信息表", SourceDataClass.packdata);
                MainForm.pMainForm.RefreshListStat();
                MessageBox.Show("节点信息表已加入命令列表!");

                DialogResult = DialogResult.OK;
            }
            else
            {
                MessageBox.Show("尚未添加任何节点信息!");
                DialogResult = DialogResult.Ignore;
            }
        }
Example #3
0
        private void AddRoute_Click(object sender, EventArgs e)
        {
            foreach (string startnode in NewRouteMap.Keys)
            {
                NodeGrid = (List <string[]>)NewRouteMap[startnode];

                int   nodenum = NodeGrid.Count;
                int[] dat     = new int[1];
                SourceDataClass.InitForPack(nodenum * 33 + 6 + 20);
                dat[0] = 6;
                SourceDataClass.OutPutIntBit(dat, 8);
                dat[0] = nodenum * 33 + 6 + 20;
                SourceDataClass.OutPutIntBit(dat, 12);
                dat[0] = nodenum;
                SourceDataClass.OutPutIntBit(dat, 6);//路由条数
                foreach (string[] log in NodeGrid)
                {
                    dat[0] = int.Parse(log[log.Length - 1].TrimStart('节', '点'));
                    SourceDataClass.OutPutIntBit(dat, 6);
                    dat[0] = int.Parse(log[1].TrimStart('节', '点'));
                    SourceDataClass.OutPutIntBit(dat, 6);
                    dat[0] = log.Length - 1;
                    SourceDataClass.OutPutIntBit(dat, 4);
                    dat[0] = 0; //节点序列号
                    SourceDataClass.OutPutIntBit(dat, 15);
                    dat[0] = 0; //路由状态
                    SourceDataClass.OutPutIntBit(dat, 2);
                }
                MainForm.pMainForm.comlistwin.AddCmd(startnode, "路由表", SourceDataClass.packdata);
            }
            StatusLabel.Text = "全路由表已加入命令列表";

            MainForm.pMainForm.RefreshListStat();
            MessageBox.Show("全路由表已加入命令列表!");
        }
Example #4
0
        private void AddToList_Click(object sender, EventArgs e)
        {
            int[] dat = new int[1];
            if (DestNodeName.Text != "")
            {
                SourceDataClass.InitForPack(20 + 32);
                dat[0] = 140;
                SourceDataClass.OutPutIntBit(dat, 8);

                dat[0] = 52;
                SourceDataClass.OutPutIntBit(dat, 12);
                if (radioButton2.Checked)
                {
                    dat[0] = SetTime.Value;
                    SourceDataClass.OutPutIntBit(dat, 32);
                }
                else
                {
                    dat[0] = 0;
                    SourceDataClass.OutPutIntBit(dat, 32);
                }
                //加入列表
                MainForm.pMainForm.comlistwin.AddCmd(DestNodeName.Text, "设备数据定时回传开关", SourceDataClass.packdata);

                MainForm.pMainForm.RefreshListStat();
                MessageBox.Show("设备数据定时回传开关命令已加入命令列表!");
            }
        }
Example #5
0
        private void AddToList_Click(object sender, EventArgs e)
        {
            if (DestNodeName.Text == "")
            {
                return;
            }
            int[] dat = new int[1];
            SourceDataClass.clear();
            SourceDataClass.InitForPack(20 + 16);
            dat[0] = 142;
            SourceDataClass.OutPutIntBit(dat, 8);
            dat[0] = 36;
            SourceDataClass.OutPutIntBit(dat, 12);
            BitArray a = new BitArray(16);

            for (int i = 0; i < 16; i++)
            {
                a[i] = CommType.GetItemChecked(i);
            }
            SourceDataClass.OutPutArrayBit(a);
            //加入列表
            MainForm.pMainForm.comlistwin.AddCmd(DestNodeName.Text, "通信制式开关", SourceDataClass.packdata);

            MainForm.pMainForm.RefreshListStat();
            MessageBox.Show("通信制式开关命令已加入命令列表!");
        }
Example #6
0
        //打包所有数据区到未加0xAA为止,将有相同目的地址的数据打包在一个块中
        private byte[] pack()
        {
            NodeFindOut.Clear();
            CmdTable.Clear(); //每次打包前清空。
            int total = 0;    //数据总长度,不包括包头

            for (int i = 0; i < CmdNode.Count; i++)
            {
                if (CmdTable.ContainsKey(CmdNode[i]))
                {
                    BitArray ba    = (BitArray)CmdTable[CmdNode[i]];//取出已有的数据
                    BitArray newba = new BitArray(ba.Length + CmdForSend[i].Length);
                    for (int a = 0; a < ba.Length; a++)
                    {
                        newba[a] = ba[a];
                    }
                    for (int j = 0; j < CmdForSend[i].Length; j++)
                    {
                        newba[ba.Length + j] = CmdForSend[i][j];
                    }
                    CmdTable[CmdNode[i]] = newba;//将新的数据放进哈希表
                }
                else
                {
                    CmdTable.Add(CmdNode[i], CmdForSend[i]);
                    NodeFindOut.Add(CmdNode[i]);
                }
                total += CmdForSend[i].Length;
            }
            //打包协议
            int blocknum = CmdTable.Keys.Count;//块数

            total += blocknum * 34 + 6;

            SourceDataClass.InitForPack(total);
            int[] b = new int[1];
            b[0] = blocknum;
            SourceDataClass.OutPutIntBit(b, 6);
            for (int i = 0; i < blocknum; i++)
            {
                BitArray ba       = (BitArray)CmdTable[NodeFindOut[i]];//数据区集合
                int      blocklen = ba.Length + 34;
                BitArray blockba  = new BitArray(blocklen);
                b[0] = PackageIndex;
                PackageIndex++;
                SourceDataClass.OutPutIntBit(b, 10);
                b[0] = blocklen;
                SourceDataClass.OutPutIntBit(b, 12);
                b[0] = int.Parse(SourceNodeBox.Text.TrimStart('节', '点'));
                SourceDataClass.OutPutIntBit(b, 6);
                b[0] = int.Parse(NodeFindOut[i].TrimStart('节', '点'));
                SourceDataClass.OutPutIntBit(b, 6);
                SourceDataClass.OutPutArrayBit(ba);
            }
            byte[] cmd = new byte[(int)Math.Ceiling(((double)total) / 8)];
            SourceDataClass.packdata.CopyTo(cmd, 0);
            return(cmd);
        }
Example #7
0
        private void AddTrace_Click(object sender, EventArgs e)
        {
            if (CmdList.Items.Count > 0)
            {
                if (SourceNodeBox.Text != "")
                {
                    this.Hide();
                    pack();
                    TrackForm Tf = new TrackForm();
                    for (int i = 0; i < NodeFindOut.Count; i++)
                    {
                        string[] str = new string[] { NodeFindOut[i] };
                        Tf.Trace.Rows.Add(str);
                    }
                    //try
                    {
                        if (Tf.ShowDialog() == DialogResult.OK)
                        {
                            for (int j = 0; j < Tf.Trace.Rows.Count; j++)
                            {
                                string str = (string)Tf.Trace.Rows[j].Cells[1].Value;
                                if (str == null)
                                {
                                    continue;
                                }
                                string[] nodename = str.Split(' ', ',');
                                int[]    dat      = new int[1];
                                int      nodenum  = nodename.Length;
                                SourceDataClass.InitForPack(nodenum * 6 + 20);
                                dat[0] = 8;
                                SourceDataClass.OutPutIntBit(dat, 8);
                                dat[0] = nodenum * 6 + 20;
                                SourceDataClass.OutPutIntBit(dat, 12);
                                for (int i = 0; i < nodenum; i++)
                                {
                                    dat[0] = int.Parse(nodename[i]);
                                    SourceDataClass.OutPutIntBit(dat, 6);//节点
                                }

                                //加入列表
                                MainForm.pMainForm.comlistwin.AddCmd((string)Tf.Trace.Rows[j].Cells[0].Value, "路径安排", SourceDataClass.packdata);
                            }
                        }
                    }
                    //catch (Exception MyEx)
                    {
                        //MessageBox.Show(MyEx.Message);
                    }
                    Tf.Dispose();
                    this.Show();
                }
            }
        }
Example #8
0
        private void AddToList_Click(object sender, EventArgs e)
        {
            int[] dat = new int[1];
            if (DestNodeName.Text != "")
            {
                SourceDataClass.InitForPack(20 + 16);

                dat[0] = 141;
                SourceDataClass.OutPutIntBit(dat, 8);
                dat[0] = 36;
                SourceDataClass.OutPutIntBit(dat, 12);
                if (radioButton1.Checked)
                {
                    dat[0] = 0;
                    SourceDataClass.OutPutIntBit(dat, 1);
                    dat[0] = EmitAmp.Value;
                    SourceDataClass.OutPutIntBit(dat, 7);
                }
                else
                {
                    dat[0] = 1;
                    SourceDataClass.OutPutIntBit(dat, 1);
                    dat[0] = 0;
                    SourceDataClass.OutPutIntBit(dat, 7);
                }
                if (radioButton4.Checked)
                {
                    dat[0] = 0;
                    SourceDataClass.OutPutIntBit(dat, 1);
                    dat[0] = ReceGain.Value;
                    SourceDataClass.OutPutIntBit(dat, 7);
                }
                else
                {
                    dat[0] = 1;
                    SourceDataClass.OutPutIntBit(dat, 1);
                    dat[0] = 0;
                    SourceDataClass.OutPutIntBit(dat, 7);
                }
                //加入列表
                MainForm.pMainForm.comlistwin.AddCmd(DestNodeName.Text, "收发自动调节", SourceDataClass.packdata);

                MainForm.pMainForm.RefreshListStat();
                MessageBox.Show("收发自动调节命令已加入命令列表!");
            }
        }
Example #9
0
        private void AddRouteToList_Click(object sender, EventArgs e)
        {
            int nodenum = RouteGrid.RowCount;

            int[] dat = new int[1];
            if (RouteGrid.RowCount > 0)
            {
                SourceDataClass.InitForPack(nodenum * 33 + 6 + 20);
                dat[0] = 6;
                SourceDataClass.OutPutIntBit(dat, 8);
                dat[0] = nodenum * 33 + 6 + 20;
                SourceDataClass.OutPutIntBit(dat, 12);
                dat[0] = nodenum;
                SourceDataClass.OutPutIntBit(dat, 6);//路由条数
                for (int i = 0; i < nodenum; i++)
                {
                    dat[0] = int.Parse(RouteGrid.Rows[i].Cells[0].Value.ToString());
                    SourceDataClass.OutPutIntBit(dat, 6);                            //目标节点
                    dat[0] = int.Parse(RouteGrid.Rows[i].Cells[1].Value.ToString());
                    SourceDataClass.OutPutIntBit(dat, 6);                            //下一跳地址
                    dat[0] = int.Parse(RouteGrid.Rows[i].Cells[2].Value.ToString()); //跳数
                    SourceDataClass.OutPutIntBit(dat, 4);                            //跳数
                    dat[0] = int.Parse(RouteGrid.Rows[i].Cells[3].Value.ToString());
                    SourceDataClass.OutPutIntBit(dat, 15);
                    int value = Convert.ToInt32(Enum.Parse(typeof(SourceDataClass.RouteStatus), RouteGrid.Rows[i].Cells[4].Value.ToString()));
                    dat[0] = value;
                    SourceDataClass.OutPutIntBit(dat, 2);
                }

                //加入列表
                MainForm.pMainForm.comlistwin.AddCmd(NodeBox.Text, "路由表", SourceDataClass.packdata);
                StatusLabel.Text = "路由表已加入命令列表";

                MainForm.pMainForm.RefreshListStat();
                MessageBox.Show("路由表已加入命令列表!");
            }
        }
Example #10
0
        private byte[] Pack()
        {
            //打包协议
            try
            {
                //路径安排
                if (PathAsignCheck.Checked)
                {
                    if (Path.Text == "")
                    {
                        PathAsignCheck.Checked = false;
                        throw new Exception("路径安排不能为空");
                    }
                    string[] nodename = Path.Text.Split(' ', ',');
                    int[]    dat      = new int[1];

                    int nodenum = nodename.Length;
                    SourceDataClass.InitForPack(nodenum * 6 + 20);
                    dat[0] = 8;
                    SourceDataClass.OutPutIntBit(dat, 8);
                    dat[0] = nodenum * 6 + 20;
                    SourceDataClass.OutPutIntBit(dat, 12);
                    for (int i = 0; i < nodenum; i++)
                    {
                        dat[0] = int.Parse(nodename[i]);
                        SourceDataClass.OutPutIntBit(dat, 6);//节点
                    }
                    BitArray ba = SourceDataClass.packdata;
                    balst.Add(ba);
                }
                //
                byte[]   bstr = System.Text.Encoding.Default.GetBytes(SourceText.Text);
                BitArray bta  = new BitArray(bstr);
                SourceDataClass.InitForPack(bta.Length + 20);
                int[] b = new int[1];
                b[0] = 101;
                SourceDataClass.OutPutIntBit(b, 8);
                b[0] = bta.Length + 20;
                SourceDataClass.OutPutIntBit(b, 12);
                SourceDataClass.OutPutArrayBit(bta);
                balst.Add(SourceDataClass.packdata);

                int blocklen = 34 + 6;//
                if (balst.Count > 0)
                {
                    for (int i = 0; i < balst.Count; i++)
                    {
                        blocklen += balst[i].Length;
                    }
                }
                SourceDataClass.InitForPack(blocklen);

                b[0] = 1;
                SourceDataClass.OutPutIntBit(b, 6);
                BitArray blockba = new BitArray(blocklen);
                b[0] = ComListForm.PackageIndex;
                ComListForm.PackageIndex++;
                SourceDataClass.OutPutIntBit(b, 10);
                b[0] = blocklen - 6;//仅包括块头定义,块长度不包括块数长度
                SourceDataClass.OutPutIntBit(b, 12);
                b[0] = int.Parse(SourceNodeBox.Text.TrimStart('节', '点'));
                SourceDataClass.OutPutIntBit(b, 6);
                b[0] = int.Parse(DestNodeName.Text.TrimStart('节', '点'));
                SourceDataClass.OutPutIntBit(b, 6);
                for (int i = 0; i < balst.Count; i++)
                {
                    SourceDataClass.OutPutArrayBit(balst[i]);
                }
                balst.Clear();
                byte[] cmd = new byte[(int)Math.Ceiling(((double)blocklen) / 8)];
                SourceDataClass.packdata.CopyTo(cmd, 0);
                //BinaryWriter bw = new BinaryWriter(new FileStream("ping.dat", FileMode.Create));
                //bw.Write(cmd);
                //bw.Close();
                return(cmd);
            }
            catch (Exception MyEx)
            {
                balst.Clear();
                MessageBox.Show(MyEx.Message);
                return(new byte[0]);
            }
        }
Example #11
0
        private void AddToList_Click(object sender, EventArgs e)
        {
            int[] dat = new int[1];
            if (DestNodeName.Text != "")
            {
                if (this.Text == "获取节点信息")
                {
                    SourceDataClass.InitForPack(20);
                    dat[0] = 103;
                    SourceDataClass.OutPutIntBit(dat, 8);
                    dat[0] = 20;
                    SourceDataClass.OutPutIntBit(dat, 12);

                    //加入列表
                    MainForm.pMainForm.comlistwin.AddCmd(DestNodeName.Text, "获取节点信息", SourceDataClass.packdata);

                    MainForm.pMainForm.RefreshListStat();
                    MessageBox.Show("获取节点信息命令已加入命令列表!");
                }
                else if (this.Text == "获取路由信息")
                {
                    SourceDataClass.InitForPack(20);
                    dat[0] = 113;
                    SourceDataClass.OutPutIntBit(dat, 8);
                    dat[0] = 20;
                    SourceDataClass.OutPutIntBit(dat, 12);

                    //加入列表
                    MainForm.pMainForm.comlistwin.AddCmd(DestNodeName.Text, "获取路由信息", SourceDataClass.packdata);

                    MainForm.pMainForm.RefreshListStat();
                    MessageBox.Show("获取路由信息命令已加入命令列表!");
                }
                else if (this.Text == "获取设备数据")
                {
                    SourceDataClass.InitForPack(28);
                    dat[0] = 115;
                    SourceDataClass.OutPutIntBit(dat, 8);
                    dat[0] = 28;
                    SourceDataClass.OutPutIntBit(dat, 12);
                    dat[0] = 2;//默认值
                    if (CommBox.SelectedIndex != -1)
                    {
                        dat[0] = CommBox.SelectedIndex;
                    }

                    SourceDataClass.OutPutIntBit(dat, 8);
                    //加入列表
                    MainForm.pMainForm.comlistwin.AddCmd(DestNodeName.Text, "获取设备数据", SourceDataClass.packdata);

                    MainForm.pMainForm.RefreshListStat();
                    MessageBox.Show("获取设备数据命令已加入命令列表!");
                }
                else if (this.Text == "获取邻节点信息")
                {
                    SourceDataClass.InitForPack(21);
                    dat[0] = 111;
                    SourceDataClass.OutPutIntBit(dat, 8);
                    dat[0] = 21;
                    SourceDataClass.OutPutIntBit(dat, 12);
                    dat[0] = 0;//默认值
                    if (RebuildBox.SelectedIndex == 0)
                    {
                        dat[0] = 0;
                    }
                    if (RebuildBox.SelectedIndex == 1)
                    {
                        dat[0] = 1;
                    }
                    SourceDataClass.OutPutIntBit(dat, 1);
                    //加入列表
                    MainForm.pMainForm.comlistwin.AddCmd(DestNodeName.Text, "获取邻节点信息", SourceDataClass.packdata);

                    MainForm.pMainForm.RefreshListStat();
                    MessageBox.Show("获取邻节点信息命令已加入命令列表!");
                }
                else if (this.Text == "获取网络简表")
                {
                    SourceDataClass.InitForPack(20);
                    dat[0] = 109;
                    SourceDataClass.OutPutIntBit(dat, 8);
                    dat[0] = 20;
                    SourceDataClass.OutPutIntBit(dat, 12);

                    //加入列表
                    MainForm.pMainForm.comlistwin.AddCmd(DestNodeName.Text, "获取网络简表", SourceDataClass.packdata);

                    MainForm.pMainForm.RefreshListStat();
                    MessageBox.Show("获取网络简表命令已加入命令列表!");
                }
                else if (this.Text == "获取节点信息表")
                {
                    SourceDataClass.InitForPack(20);
                    dat[0] = 105;
                    SourceDataClass.OutPutIntBit(dat, 8);
                    dat[0] = 20;
                    SourceDataClass.OutPutIntBit(dat, 12);

                    //加入列表
                    MainForm.pMainForm.comlistwin.AddCmd(DestNodeName.Text, "获取节点信息表", SourceDataClass.packdata);

                    MainForm.pMainForm.RefreshListStat();
                    MessageBox.Show("获取节点信息表命令已加入命令列表!");
                }
                else if (this.Text == "获取网络表")
                {
                    SourceDataClass.InitForPack(21);
                    dat[0] = 107;
                    SourceDataClass.OutPutIntBit(dat, 8);
                    dat[0] = 21;
                    SourceDataClass.OutPutIntBit(dat, 12);
                    dat[0] = 0;//默认值
                    if (RebuildBox.SelectedIndex == 0)
                    {
                        dat[0] = 0;
                    }
                    if (RebuildBox.SelectedIndex == 1)
                    {
                        dat[0] = 1;
                    }
                    SourceDataClass.OutPutIntBit(dat, 1);
                    //加入列表
                    MainForm.pMainForm.comlistwin.AddCmd(DestNodeName.Text, "获取网络表", SourceDataClass.packdata);

                    MainForm.pMainForm.RefreshListStat();
                    MessageBox.Show("获取网络表命令已加入命令列表!");
                }
                else if (this.Text == "获取节点状态")
                {
                    SourceDataClass.InitForPack(20);
                    dat[0] = 121;
                    SourceDataClass.OutPutIntBit(dat, 8);
                    dat[0] = 20;
                    SourceDataClass.OutPutIntBit(dat, 12);

                    //加入列表

                    MainForm.pMainForm.comlistwin.AddCmd(DestNodeName.Text, "获取节点状态", SourceDataClass.packdata);

                    MainForm.pMainForm.RefreshListStat();
                    MessageBox.Show("获取节点状态命令已加入命令列表!");
                }
                else if (this.Text == "获取设备状态")
                {
                    SourceDataClass.InitForPack(28);
                    dat[0] = 117;
                    SourceDataClass.OutPutIntBit(dat, 8);
                    dat[0] = 28;
                    SourceDataClass.OutPutIntBit(dat, 12);
                    dat[0] = 2;//默认值
                    if (CommBox.SelectedIndex != -1)
                    {
                        dat[0] = CommBox.SelectedIndex;
                    }
                    SourceDataClass.OutPutIntBit(dat, 8);
                    //加入列表
                    MainForm.pMainForm.comlistwin.AddCmd(DestNodeName.Text, "获取设备状态", SourceDataClass.packdata);

                    MainForm.pMainForm.RefreshListStat();
                    MessageBox.Show("获取设备状态命令已加入命令列表!");
                }
            }
        }
Example #12
0
        //将信息加入下面的列表
        private void AddBtn_Click(object sender, EventArgs e)
        {
            if (NodeNameBox.Text == "")
            {
                return;
            }
            try
            {
                int[] dat = new int[1];
                SourceDataClass.clear();
                SourceDataClass.InitForPack(115);
                dat[0] = int.Parse(NodeNameBox.Text.TrimStart('节', '点'));
                SourceDataClass.OutPutIntBit(dat, 6);
                dat[0] = Nodetypebox.Text == "静态节点" ? 0 : 1;
                SourceDataClass.OutPutIntBit(dat, 1);
                dat[0] = int.Parse(EmitSet.Text);
                SourceDataClass.OutPutIntBit(dat, 3);
                dat[0] = Convert.ToInt32(Enum.Parse(typeof(SourceDataClass.DeviceAddr), Set1Box.Text));
                SourceDataClass.OutPutIntBit(dat, 8);
                dat[0] = Convert.ToInt32(Enum.Parse(typeof(SourceDataClass.DeviceAddr), Set2Box.Text));
                SourceDataClass.OutPutIntBit(dat, 8);
                int energy = int.Parse(leftenergy.Text);
                if (energy < 5)
                {
                    dat[0] = 0;
                }
                else if ((energy >= 5) && (energy < 20))
                {
                    dat[0] = 1;
                }
                else if ((energy >= 20) && (energy < 35))
                {
                    dat[0] = 2;
                }
                else if ((energy >= 35) && (energy < 50))
                {
                    dat[0] = 3;
                }
                else if ((energy >= 50) && (energy < 65))
                {
                    dat[0] = 4;
                }
                else if ((energy >= 65) && (energy < 80))
                {
                    dat[0] = 5;
                }
                else if ((energy >= 80) && (energy < 95))
                {
                    dat[0] = 6;
                }
                else if ((energy >= 95))
                {
                    dat[0] = 7;
                }
                SourceDataClass.OutPutIntBit(dat, 3);
                BitArray a = new BitArray(16);
                for (int i = 0; i < 16; i++)
                {
                    a[i] = CommType.GetItemChecked(i);
                }
                SourceDataClass.OutPutArrayBit(a);


                if (Lang.Value < 0)
                {
                    dat[0] = 0x8ffffff + (int)((double)Math.Abs(Lang.Value) * 60 * 10000);
                }
                else
                {
                    dat[0] = (int)((double)Math.Abs(Lang.Value) * 60 * 10000);
                }
                SourceDataClass.OutPutIntBit(dat, 28);
                if (Lat.Value < 0)
                {
                    dat[0] = 0x8ffffff + (int)((double)Math.Abs(Lat.Value) * 60 * 10000);
                }
                else
                {
                    dat[0] = (int)((double)Math.Abs(Lat.Value) * 60 * 10000);
                }
                SourceDataClass.OutPutIntBit(dat, 28);
                dat[0] = (int)(DepthInput.Value / 0.5);
                SourceDataClass.OutPutIntBit(dat, 14);
                if (NodeInfo.ContainsKey(NodeNameBox.Text))
                {
                    NodeInfo.Remove(NodeNameBox.Text);
                }
                //加入hash表
                NodeInfo.Add(NodeNameBox.Text, SourceDataClass.packdata);
                //替换之前的记录
                string log = ParseDataAndDisplay((BitArray)NodeInfo[NodeNameBox.Text], false);
                if (nodeinfolist.Items.Count == 0)//第一条记录
                {
                    nodeinfolist.Items.Add(log);
                }
                for (int i = 0; i < nodeinfolist.Items.Count; i++)
                {
                    if (CheckListNodeName(i, NodeNameBox.Text))
                    {
                        nodeinfolist.Items[i] = log;
                        break;
                    }
                    if (i == nodeinfolist.Items.Count - 1)//最后一项也比过了,说明当前列表中没有
                    {
                        nodeinfolist.Items.Add(log);
                    }
                }
                SourceDataClass.clear();
            }
            catch (Exception ex)
            {
                SourceDataClass.clear();
                MessageBox.Show(ex.Message);
            }
        }
Example #13
0
        private void AddAllToCmd_Click(object sender, EventArgs e)
        {
            string                  message       = "要广播网络表吗?";
            string                  caption       = "网络表命令";
            MessageBoxButtons       buttons       = MessageBoxButtons.YesNoCancel;
            MessageBoxIcon          icon          = MessageBoxIcon.Question;
            MessageBoxDefaultButton defaultResult = MessageBoxDefaultButton.Button1;
            // Show message box
            DialogResult result = MessageBox.Show(message, caption, buttons, icon, defaultResult);

            if (result == DialogResult.Yes)
            {
                int   nodenum = NetGrid.RowCount;
                int[] dat     = new int[1];
                if (nodenum > 0)
                {
                    SourceDataClass.InitForPack(nodenum * 30 + 4 + 20);
                    dat[0] = 4;
                    SourceDataClass.OutPutIntBit(dat, 8);
                    dat[0] = nodenum * 30 + 4 + 20;
                    SourceDataClass.OutPutIntBit(dat, 12);
                    dat[0] = nodenum;
                    SourceDataClass.OutPutIntBit(dat, 4);//邻节点数
                    for (int i = 0; i < nodenum; i++)
                    {
                        dat[0] = int.Parse(NetGrid.Rows[i].Cells[1].Value.ToString());
                        SourceDataClass.OutPutIntBit(dat, 6);  //邻节点
                        dat[0] = (int)(double.Parse(NetGrid.Rows[i].Cells[2].Value.ToString()) * 10);
                        SourceDataClass.OutPutIntBit(dat, 16); //距离
                        int value = Convert.ToInt32(Enum.Parse(typeof(SourceDataClass.ChannlValue), NetGrid.Rows[i].Cells[3].Value.ToString()));
                        dat[0] = value;
                        SourceDataClass.OutPutIntBit(dat, 2);//评价
                    }

                    //加入列表
                    MainForm.pMainForm.comlistwin.AddCmd("节点00", "网络表", SourceDataClass.packdata);
                    StatusLabel.Text = "网络表已加入命令列表";
                    MessageBox.Show("网络表已加入命令列表!");
                }
            }
            else
            {
                if (result == DialogResult.No)
                {
                    if (NodeBox.Text == "")
                    {
                        MessageBox.Show("请选择目标节点");
                        return;
                    }
                    int   nodenum = NetGrid.RowCount;
                    int[] dat     = new int[1];
                    if (nodenum > 0)
                    {
                        SourceDataClass.InitForPack(nodenum * 30 + 4 + 20);
                        dat[0] = 3;
                        SourceDataClass.OutPutIntBit(dat, 8);
                        dat[0] = nodenum * 30 + 4 + 20;
                        SourceDataClass.OutPutIntBit(dat, 12);
                        dat[0] = nodenum;
                        SourceDataClass.OutPutIntBit(dat, 4);//邻节点数
                        for (int i = 0; i < nodenum; i++)
                        {
                            dat[0] = int.Parse(NetGrid.Rows[i].Cells[1].Value.ToString());
                            SourceDataClass.OutPutIntBit(dat, 6);  //邻节点
                            dat[0] = (int)(double.Parse(NetGrid.Rows[i].Cells[2].Value.ToString()) * 10);
                            SourceDataClass.OutPutIntBit(dat, 16); //距离
                            int value = Convert.ToInt32(Enum.Parse(typeof(SourceDataClass.ChannlValue), NetGrid.Rows[i].Cells[3].Value.ToString()));
                            dat[0] = value;
                            SourceDataClass.OutPutIntBit(dat, 2);//评价
                        }

                        //加入列表
                        MainForm.pMainForm.comlistwin.AddCmd(NodeBox.Text, "网络表", SourceDataClass.packdata);
                        StatusLabel.Text = "网络表已加入命令列表";
                        MessageBox.Show("网络表已加入命令列表!");
                    }
                }
            }
        }
Example #14
0
        private void SendMsg()
        {
            try
            {
                int[] b        = new int[1];
                int   blocklen = 34 + 6 + 20;//
                SourceDataClass.InitForPack(blocklen);

                b[0] = 1;
                SourceDataClass.OutPutIntBit(b, 6);
                BitArray blockba = new BitArray(blocklen);
                b[0] = ComListForm.PackageIndex;
                ComListForm.PackageIndex++;
                SourceDataClass.OutPutIntBit(b, 10);
                b[0] = blocklen - 6;//仅包括块头定义,块长度不包括块数长度
                SourceDataClass.OutPutIntBit(b, 12);
                b[0] = linkid;
                SourceDataClass.OutPutIntBit(b, 6);
                currentid = int.Parse(testid[idindex]);
                idindex++;
                if (idindex == testid.Length)
                {
                    idindex = 0;
                }
                b[0] = currentid;
                SourceDataClass.OutPutIntBit(b, 6);


                if (command == "获取节点信息")
                {
                    b[0] = 103;
                    SourceDataClass.OutPutIntBit(b, 8);
                    b[0] = 20;
                    SourceDataClass.OutPutIntBit(b, 12);
                }
                else if (command == "获取路由信息")
                {
                    b[0] = 113;
                    SourceDataClass.OutPutIntBit(b, 8);
                    b[0] = 20;
                    SourceDataClass.OutPutIntBit(b, 12);
                }
                else if (command == "获取设备数据")
                {
                    b[0] = 115;
                    SourceDataClass.OutPutIntBit(b, 8);
                    b[0] = 28;
                    SourceDataClass.OutPutIntBit(b, 12);
                    b[0] = 2;
                    SourceDataClass.OutPutIntBit(b, 8);
                    blocklen += 8;
                }
                else if (command == "获取邻节点信息")
                {
                    b[0] = 111;
                    SourceDataClass.OutPutIntBit(b, 8);
                    b[0] = 20;
                    SourceDataClass.OutPutIntBit(b, 12);
                }
                else if (command == "获取网络简表")
                {
                    b[0] = 109;
                    SourceDataClass.OutPutIntBit(b, 8);
                    b[0] = 20;
                    SourceDataClass.OutPutIntBit(b, 12);
                }
                else if (command == "获取节点信息表")
                {
                    b[0] = 105;
                    SourceDataClass.OutPutIntBit(b, 8);
                    b[0] = 20;
                    SourceDataClass.OutPutIntBit(b, 12);
                }
                else if (command == "获取网络表")
                {
                    b[0] = 107;
                    SourceDataClass.OutPutIntBit(b, 8);
                    b[0] = 20;
                    SourceDataClass.OutPutIntBit(b, 12);
                }
                else if (command == "回环测试")
                {
                    b[0] = 101;
                    SourceDataClass.OutPutIntBit(b, 8);
                    b[0] = 20;
                    SourceDataClass.OutPutIntBit(b, 12);
                }
                else if (command == "获取节点状态")
                {
                    b[0] = 119;
                    SourceDataClass.OutPutIntBit(b, 8);
                    b[0] = 20;
                    SourceDataClass.OutPutIntBit(b, 12);
                }
                byte[] cmd = new byte[(int)Math.Ceiling(((double)blocklen) / 8)];
                SourceDataClass.packdata.CopyTo(cmd, 0);
                byte[] Serialcmd = SourceDataClass.CommPackage(171, cmd);
                //BinaryWriter bw = new BinaryWriter(new FileStream("ping.dat", FileMode.Create));
                //bw.Write(cmd);
                //bw.Close();
                if (MainForm.pMainForm.mapdoc.WriteMSPCommand(Serialcmd))
                {
                    MainForm.pMainForm.mapdoc.MSPCmdFile.OpenFile(MainForm.pMainForm.SerialCmdPathInfo);
                    MainForm.pMainForm.mapdoc.MSPCmdFile.BinaryWrite(Serialcmd);
                    MainForm.pMainForm.mapdoc.MSPCmdFile.close();
                    writelog("向节点" + currentid.ToString() + "发送串口命令:" + command);
                    times++;
                    Thread wait = new Thread(waitforans);
                    wait.Start();
                    testwait.Enabled = false;
                }
            }
            catch (Exception ex)
            {
                writelog(ex.Message);
                testwait.Enabled = true;
            }
        }
Example #15
0
        private void AddToList_Click(object sender, EventArgs e)
        {
            int[] dat = new int[1];
            if (DestNodeName.Text == "")
            {
                MessageBox.Show("未选择目标节点!!!");
                return;
            }
            if (HexCheck.Checked)
            {
                byte[] end = CRCHelper.ConvertHexToChar(parameter.Text);
                if (end == null)
                {
                    return;
                }
                int len = 20 + 8 + end.Length * 8;
                SourceDataClass.InitForPack(len);
                dat[0] = 119;
                SourceDataClass.OutPutIntBit(dat, 8);
                dat[0] = len;
                SourceDataClass.OutPutIntBit(dat, 12);
                dat[0] = 2;//默认值
                if (CommBox.SelectedIndex == 0)
                {
                    dat[0] = 2;
                }
                if (CommBox.SelectedIndex == 1)
                {
                    dat[0] = 3;
                }
                SourceDataClass.OutPutIntBit(dat, 8);
                for (int i = 0; i < end.Length; i++)
                {
                    dat[0] = end[i];
                    SourceDataClass.OutPutIntBit(dat, 8);
                }
                //SourceDataClass.OutPutIntBit(dat, endchar.Text.Length / 2 * 8);
            }
            else
            {
                int arraylen = parameter.Text.Length;//int[] 长度
                int len      = 20 + 8 + arraylen * 8;
                SourceDataClass.InitForPack(len);
                dat[0] = 119;
                SourceDataClass.OutPutIntBit(dat, 8);
                dat[0] = len;
                SourceDataClass.OutPutIntBit(dat, 12);
                dat[0] = 2;//默认值
                if (CommBox.SelectedIndex == 0)
                {
                    dat[0] = 2;
                }
                if (CommBox.SelectedIndex == 1)
                {
                    dat[0] = 3;
                }

                byte[] para = Encoding.Default.GetBytes(parameter.Text);
                for (int i = 0; i < arraylen; i++)
                {
                    dat[0] = para[i];
                    SourceDataClass.OutPutIntBit(dat, 8);
                }
            }
            //加入列表
            MainForm.pMainForm.comlistwin.AddCmd(DestNodeName.Text, "设备参数设置", SourceDataClass.packdata);

            MainForm.pMainForm.RefreshListStat();
            MessageBox.Show("设备参数设置命令已加入命令列表!");
        }