Пример #1
0
        public void AddGobject(int x1, int y1, int x2, int y2, MeshRelation prelation)
        {
            #region 为了防止刷新,不在此时画线!!! urinatedong  20170322

            //Graphics g = this.panel2.CreateGraphics();//this.CreateGraphics();
            //g.SmoothingMode = SmoothingMode.AntiAlias;  //使绘图质量最高,即消除锯齿
            //g.InterpolationMode = InterpolationMode.HighQualityBicubic;
            //g.CompositingQuality = CompositingQuality.HighQuality;

            //AdjustableArrowCap lineCap = new AdjustableArrowCap(5, 6, true);

            //Pen p;

            //if (prelation.Findtimes == 2)
            //{
            //     p = new Pen(Color.Blue,3);
            //}
            //else
            //{
            //     p = new Pen(Color.Orange,3);
            //     p.DashStyle = DashStyle.Custom;
            //     p.DashPattern = new float[] { 6, 3 };
            //}

            //p.CustomEndCap = lineCap;

            //g.DrawLine(p, x1, y1, x2, y2);

            #endregion

            ///新需求中不再强调这些信息
            ///urinatedong 20170314
            //int xm = (x1 + x2) / 2;
            //int ym = (y1 + y2) / 2;
            string relationinfo = "Localport " + prelation.Localport +
                                  "\nTxsnr" + prelation.Txsnr +
                                  "\nTxspeed " + prelation.Txspeed +
                                  "\nRemoteport " + prelation.Remoteport +
                                  "\nRxsnr " + prelation.Rxsnr +
                                  "\nRxspeed " + prelation.Rxspeed +
                                  "\nFindTimes " + prelation.Findtimes;
            //AddText(xm, ym, relationinfo, false);

            //AddText(xm, ym, "Rx Tx", false);

            GObject TempGObject = new GObject();

            //在数组中查找是否已经有该关系了
            GNetwork.FindGObjectByName(prelation.Localnode.MacAddress + prelation.Remotenode.MacAddress, ref TempGObject);

            if (TempGObject.Type == "")
            {
                GNetwork.AddGObject(prelation.Localnode.MacAddress + prelation.Remotenode.MacAddress, "Line", x1, y1, x2, y2, relationinfo);
            }
            else
            {
                ///更新关系信息!!!
                TempGObject.AddInfo = relationinfo;
            }
        }
Пример #2
0
        public void TestSendTelnetTelegram(string needInfoNode)
        {
            //需要在这里try catch finally 以关闭连接
            //必须关闭连接!!!!!! tn.close!!!!

            LogHelper.WriteLog("开始获取MAC为:" + needInfoNode + " 的NODE的信息!!! ");

            MeshNode TheNode = MYBlockNodes.Nodelist.Where(n => n.MacAddress.Equals(needInfoNode)).ToList().First();


            if (TheNode != null)
            {
                MyTelnet tn = new MyTelnet(TheNode.IpAddress);

                try
                {
                    string recvStr = tn.recvDataWaitWord("help", 1);

                    //Thread.Sleep(1);
                    tn.sendData("battery");
                    //Thread.Sleep(1);
                    recvStr         = tn.recvDataWaitWord("V", 1);
                    TheNode.Battery = double.Parse(recvStr.Replace("OK\n#user@/>", "").Replace("V", ""));

                    Thread.Sleep(1);
                    tn.sendData("frequency");
                    recvStr           = tn.recvDataWaitWord("MHz", 1);
                    TheNode.Frequency = double.Parse(recvStr.Replace("OK\n#user@/>", "").Replace("MHz", ""));

                    //Thread.Sleep(1);
                    tn.sendData("txpower");
                    recvStr         = tn.recvDataWaitWord("dBm", 1);
                    TheNode.TxPower = double.Parse(recvStr.Replace("OK\n#user@/>", "").Replace("dBm", ""));
                    //Thread.Sleep(1);
                    tn.sendData("bandwidth");
                    recvStr           = tn.recvDataWaitWord("MHz", 1);
                    TheNode.BandWidth = double.Parse(recvStr.Replace("OK\n#user@/>", "").Replace("MHz", ""));

                    //Thread.Sleep(1);
                    tn.sendData("mesh");
                    recvStr = tn.recvDataWaitWord("OK", 1);
                    string[] tempmesh = recvStr.Replace("OK\n#user@/>", "").Split(":".ToArray());

                    if (tempmesh.Length > 1)
                    {
                        int i = int.Parse(tempmesh[0]);
                        if (i > 0)
                        {
                            string[] mymesh = tempmesh[1].Split(";".ToArray());



                            TheNode.Haschild = true;



                            //3:
                            //9,6C6126100328,14,12,45,19,6C6126100327
                            //
                            //11,6C6126100328,13,12,57,21,6C612610035C.

                            for (int j = 0; j < mymesh.Length; j++)
                            {
                                /////在这里增加新节点
                                //1
                                //\r\n9,6C612610034D,82,26,85,27,6C612610031D.\n
                                ///在这里建立新的Relation
                                //if (j % 2 == 1)
                                //{
                                if (mymesh[j] == "\r\n\n")
                                {
                                    break;
                                }

                                string   SplitNewNode = mymesh[j].Replace("\r", "").Replace("\n", "").Replace(".", "");
                                string[] MeshInfo     = SplitNewNode.Split(",".ToCharArray());

                                ///如果用子节点登录?不再访问其根节点
                                string NeedToCheckMac = MeshInfo[6].Substring(0, 12);
                                string NeedToCheckIP  = mOperateNode.getIPaddress(NeedToCheckMac, MyARPLIST);

                                if (MYBlockNodes.Nodelist.Count > 1)
                                {
                                    int samenode = MYBlockNodes.Nodelist.Where(x => x.MacAddress.Equals(NeedToCheckMac) && x.IpAddress.Equals(NeedToCheckIP)).ToList().Count;

                                    if (samenode == 0)         //这是首次发现的NODE
                                    {
                                        MeshNode NewNode = new MeshNode(NeedToCheckMac);

                                        NewNode.IpAddress = NeedToCheckIP;

                                        MeshRelation NewRelation = new MeshRelation(TheNode, NewNode);

                                        NewRelation.Localport = int.Parse(MeshInfo[0]);
                                        NewRelation.Txspeed   = int.Parse(MeshInfo[2]);

                                        NewRelation.Txsnr = int.Parse(MeshInfo[3]);

                                        NewRelation.Rxspeed = int.Parse(MeshInfo[4]);

                                        NewRelation.Rxsnr = int.Parse(MeshInfo[5]);


                                        NewRelation.Findtimes = 1;

                                        this.MYBlockNodes.Nodelist.Add(NewNode);

                                        this.MYBlockNodes.Relationlist.Add(NewRelation);



                                        this.NeedResearchMac.Add(NeedToCheckMac);
                                    }
                                    else         //找到了根节点,这时候跟新与根节点的端口关系
                                    {
                                        //对关系是否需要增加则需要判断一下是否有该关系
                                        if (MYBlockNodes.Relationlist.Count > 0)
                                        {
                                            //


                                            var needupdaterelation = MYBlockNodes.Relationlist.Where(x => x.Localnode.MacAddress.Equals(NeedToCheckMac) && x.Localnode.IpAddress.Equals(NeedToCheckIP) && x.Remotenode.MacAddress.Equals(TheNode.MacAddress) && x.Remotenode.IpAddress.Equals(TheNode.IpAddress)).ToList();

                                            if (needupdaterelation.Count > 0)
                                            {
                                                MeshRelation TheRelation = needupdaterelation.FirstOrDefault();
                                                TheRelation.Remoteport = int.Parse(MeshInfo[0]);

                                                TheRelation.Findtimes = 2;

                                                //这里需要确认以下是否需要跟新RX和TX的信息!!!
                                            }
                                            else
                                            {
                                                var theOtherNode = MYBlockNodes.Nodelist.Where(x => x.MacAddress.Equals(NeedToCheckMac) && x.IpAddress.Equals(NeedToCheckIP)).ToList().First();

                                                MeshRelation NewRelation = new MeshRelation(TheNode, theOtherNode);

                                                NewRelation.Localport = int.Parse(MeshInfo[0]);
                                                NewRelation.Txspeed   = int.Parse(MeshInfo[2]);

                                                NewRelation.Txsnr = int.Parse(MeshInfo[3]);

                                                NewRelation.Rxspeed = int.Parse(MeshInfo[4]);

                                                NewRelation.Rxsnr = int.Parse(MeshInfo[5]);

                                                NewRelation.Findtimes = 1;

                                                this.MYBlockNodes.Relationlist.Add(NewRelation);
                                            }
                                        }
                                    }
                                }
                                else         //刚开始从根目录查找
                                {
                                    MeshNode NewNode = new MeshNode(NeedToCheckMac);

                                    NewNode.IpAddress = NeedToCheckIP;

                                    MeshRelation NewRelation = new MeshRelation(TheNode, NewNode);

                                    NewRelation.Localport = int.Parse(MeshInfo[0]);
                                    NewRelation.Txspeed   = int.Parse(MeshInfo[2]);

                                    NewRelation.Txsnr = int.Parse(MeshInfo[3]);

                                    NewRelation.Rxspeed = int.Parse(MeshInfo[4]);

                                    NewRelation.Rxsnr = int.Parse(MeshInfo[5]);

                                    NewRelation.Findtimes = 1;

                                    this.MYBlockNodes.Nodelist.Add(NewNode);

                                    this.MYBlockNodes.Relationlist.Add(NewRelation);

                                    this.NeedResearchMac.Add(NeedToCheckMac);
                                }



                                //0 ->  端口号
                                //1 ->  本地MAC
                                //2 ->  TX Speed
                                //3 ->  TX SNR
                                //4 ->  RX Speed
                                //5 ->  RX SNR
                                //6 ->  REMOTE MAC ADDRESS 子节点MAC地址



                                // }
                            }
                        }
                        else
                        {
                            //     //此时只有根节点
                            //     //需要告知用户
                            LogHelper.WriteLog("此拓扑只发现单一节点,未发现子节点!!!");
                        }
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.WriteLog("在获取NODE信息时异常: " + ex.Message);
                }
                finally
                {
                    tn.close();
                }
            }    //if end
        }
Пример #3
0
        /// <summary>
        /// urinatedong 20170314
        /// 新增离线测试功能,用来测试绘图部分的优化
        /// </summary>
        private void DrawNodeTest()
        {
            while (true)
            {
                ///随机增加层数和NODE数量,关系
                MeshNode TestNode1 = new MeshNode("AAAAAAAAAAAA");

                TestNode1.IpAddress = "192.168.0.9";

                TestNode1.Battery = 1900;

                MeshNode TestNode2 = new MeshNode("AAAAAAAAAAAB");

                TestNode2.IpAddress = "192.168.0.10";

                TestNode2.Battery = 1900;

                MeshNode TestNode3 = new MeshNode("AAAAAAAAAAAC");

                TestNode3.IpAddress = "192.168.0.11";

                TestNode3.Battery = 1900;

                MeshNode TestNode4 = new MeshNode("AAAAAAAAAAAD");

                TestNode4.IpAddress = "192.168.0.18";


                this.MYBlockNodes.Nodelist.Add(TestNode1);
                this.MYBlockNodes.Nodelist.Add(TestNode2);
                this.MYBlockNodes.Nodelist.Add(TestNode3);
                this.MYBlockNodes.Nodelist.Add(TestNode4);


                MeshRelation relation1 = new MeshRelation(TestNode1, TestNode2);

                relation1.Findtimes = 2;

                MeshRelation relation2 = new MeshRelation(TestNode2, TestNode3);

                relation2.Findtimes = 2;

                MeshRelation relation3 = new MeshRelation(TestNode2, TestNode4);

                relation3.Findtimes = 1;


                this.MYBlockNodes.Relationlist.Add(relation1);
                this.MYBlockNodes.Relationlist.Add(relation2);
                this.MYBlockNodes.Relationlist.Add(relation3);

                this.RepeatTime = 3;

                this.EveryColumnNodeCount = new List <int>()
                {
                    1, 1, 2
                };



                LogHelper.WriteLog("DrawNodeTest全部拓扑信息读取完成");


                // this.PrintStatues(this.MYBlockNodes.Nodelist.ToList(), this.MYBlockNodes.Relationlist.ToList(), true);



                ///锁定信息并进行复制
                _rwlock.AcquireWriterLock(100);

                ///全部复制
                this.RepeatTimeForRead           = this.RepeatTime;
                this.EveryColumnNodeCountForRead = this.EveryColumnNodeCount.ToArray().ToList();
                this.ShowBlockNodes.Nodelist     = this.MYBlockNodes.Nodelist.ToArray().ToList();
                this.ShowBlockNodes.Relationlist = this.MYBlockNodes.Relationlist.ToArray().ToList();

                // = new List<string>(NeedResearchMac.ToArray());

                _rwlock.ReleaseWriterLock();

                ///打印信息


                ///清除所有内容
                this.MYBlockNodes.Nodelist.Clear();
                this.MYBlockNodes.Relationlist.Clear();


                ///将所有实时的拓扑节点复制到MYBlockNodes用于显示
                ///清空实时拓扑用于显示



                //初步定为每隔1分钟总体扫描1次
                Thread.Sleep(this.ScanRate * 1000);
            }
        }