コード例 #1
0
        public static void ChangeBindwidth(string ip, int bindwidth)
        {
            MyTelnet tn = new MyTelnet(ip);

            try
            {
                string recvStr = tn.recvDataWaitWord("help", 1);
                tn.sendData(string.Format("bandwidth {0}", bindwidth));
                recvStr = tn.recvDataWaitWord("OK\n#user@/>", 1);
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog("在获取NODE信息时异常: " + ex.Message);
            }
            finally
            {
                tn.close();
            }
        }
コード例 #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
        public void UpdateFrequencyTelnetTelegram(string needupdateNodeIP, double newfrequency)
        {
            //需要在这里try catch finally 以关闭连接
            //必须关闭连接!!!!!! tn.close!!!!

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

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


            if (!string.IsNullOrEmpty(needupdateNodeIP))
            {
                MyTelnet tn = new MyTelnet(needupdateNodeIP);

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

                    LogHelper.WriteLog(recvStr);

                    Thread.Sleep(1);
                    string sendnewfrequency = "frequency " + newfrequency.ToString();

                    LogHelper.WriteLog(recvStr);

                    tn.sendData(sendnewfrequency);
                    Thread.Sleep(1);
                    recvStr = tn.recvDataWaitWord("MHz", 1);

                    LogHelper.WriteLog(recvStr);

                    string receive = recvStr.Replace("OK\n#user@/>", "").Replace("MHz", "");

                    double result = double.Parse(receive);

                    if (newfrequency.Equals(result))
                    {
                        LogHelper.WriteLog("IP 为" + needupdateNodeIP + "的设备Frequency 修改为 " + result.ToString() + "成功!!!");
                    }
                    else
                    {
                        LogHelper.WriteLog("IP 为" + needupdateNodeIP + "的设备Frequency 修改失败!!!" + " newfrequency : " + newfrequency.ToString() + " result :" + result.ToString());
                    }

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

                catch (Exception ex)
                {
                    LogHelper.WriteLog("在修改频率时出现异常: " + ex.Message);
                    throw ex;
                }
                finally
                {
                    tn.close();
                }
            }//if end
        }