Esempio n. 1
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;
            }
        }
Esempio n. 2
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("全路由表已加入命令列表!");
        }
Esempio n. 3
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("设备数据定时回传开关命令已加入命令列表!");
            }
        }
Esempio n. 4
0
 private void ViaComm_Click(object sender, EventArgs e)
 {
     if (DestNodeName.Text != "")
     {
         byte[] cmd = Pack();
         if (cmd.Length == 0)
         {
             return;
         }
         byte[] Serialcmd = SourceDataClass.CommPackage(171, cmd);
         if (MainForm.pMainForm.mapdoc.WriteMSPCommand(Serialcmd))
         {
             BackText.Clear();
             Commparelabel.Text = "---";
             MainForm.pMainForm.mapdoc.MSPCmdFile.OpenFile(MainForm.pMainForm.SerialCmdPathInfo);
             MainForm.pMainForm.mapdoc.MSPCmdFile.BinaryWrite(Serialcmd);
             MainForm.pMainForm.mapdoc.MSPCmdFile.close();
             MessageBox.Show("命令已发送!");
         }
     }
     else
     {
         MessageBox.Show("请选择一个正确的目的地址!");
     }
 }
Esempio n. 5
0
 private void ViaSerial_Click(object sender, EventArgs e)
 {
     if (CmdList.Items.Count > 0)
     {
         if (SourceNodeBox.Text != "")
         {
             byte[] cmd = pack();
             if (cmd.Length > 1024)
             {
                 MessageBox.Show("命令过长,请删除部分命令!");
                 return;
             }
             byte[] Serialcmd = SourceDataClass.CommPackage(171, cmd);
             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();
                 //Clear();
                 RefreshList();
                 MessageBox.Show("命令已发送!");
             }
         }
         else
         {
             MessageBox.Show("请选择一个正确的源地址!");
         }
     }
 }
Esempio n. 6
0
        public void DataViewForm_ShowData()
        {
            try
            {
                SourceDataClass.isNodeTick = false;

                MainForm.ParseLock.WaitOne();
                if (str.StartsWith("01EE"))
                {
                    str = str.Substring(8);
                }
                SourceDataClass.GetData((CRCHelper.ConvertHexToChar(str)));
                ll = SourceDataClass.Parse();


                MainForm.ParseLock.ReleaseMutex();
                SourceDataClass.isNodeTick = true;
                InputGrid();

                this.Show();
            }
            catch (Exception e)
            {
                MainForm.ParseLock.ReleaseMutex();
                SourceDataClass.isNodeTick = true;
                MessageBox.Show("无法解析文件:" + e.StackTrace);
            }
            //this.TopMost = true;
        }
Esempio n. 7
0
 private void ViaNet_Click(object sender, EventArgs e)
 {
     if (CmdList.Items.Count > 0)
     {
         if (SourceNodeBox.Text != "")
         {
             byte[] cmd = pack();
             if (cmd.Length > 985)
             {
                 MessageBox.Show("命令过长,请删除部分命令!");
                 return;
             }
             byte[] netcmd = SourceDataClass.NetPackage(cmd);
             MainForm.pMainForm.CommandLineWin.SendCommand("gd -n");
             if (MainForm.pMainForm.CommandLineWin.SendData(netcmd))//正确发送
             {
                 //Clear();
                 RefreshList();
                 MessageBox.Show("命令已发送!");
             }
         }
         else
         {
             MessageBox.Show("请选择一个正确的源地址!");
         }
     }
 }
Esempio n. 8
0
File: Form1.cs Progetto: BJFX/UWACN
        private void TranslateWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            List <FileInfo>  lf     = (List <FileInfo>)e.Argument;
            BackgroundWorker worker = sender as BackgroundWorker;

            for (int i = 0; i < lf.Count; i++)
            {
                using (BinaryReader br = new BinaryReader(lf[i].OpenRead()))
                {
                    byte[] b = br.ReadBytes((int)lf[i].Length);

                    try
                    {
                        byte[] outcmd     = SourceDataClass.CommPackage(170, b);
                        string timestring = lf[i].Name.Replace("NetRecvData", "");
                        timestring = timestring.TrimEnd('.', 'd', 'a', 't');
                        string filename = ADPathInfo.FullName + "\\MSPPackageData" + timestring + ".dat";
                        using (BinaryWriter bw = new BinaryWriter(File.Open(filename, FileMode.OpenOrCreate)))
                        {
                            bw.Write(outcmd);
                        }
                        worker.ReportProgress(i * 100 / (lf.Count - 1));
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.Message);
                        worker.ReportProgress(i * 100 / (lf.Count - 1));
                        continue;
                    }
                }
            }
        }
Esempio n. 9
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("邻节点表已加入命令列表!");
            }
        }
Esempio n. 10
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("通信制式开关命令已加入命令列表!");
        }
Esempio n. 11
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);
        }
Esempio n. 12
0
        public void ShowData()
        {
            SourceDataClass.GetData((CRCHelper.ConvertHexToChar(str)));
            ll = SourceDataClass.Parse();

            InputGrid();



            this.Show();
            //this.TopMost = true;
        }
Esempio n. 13
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();
                }
            }
        }
Esempio n. 14
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("收发自动调节命令已加入命令列表!");
            }
        }
Esempio n. 15
0
 //解EB90协议,读出源节点,串口收到时间,转发类型id及解开协议后的数据体。
 private bool DepackData(byte[] indata, out int NodeId, out string time, out byte[] data)
 {
     try
     {
         string   strcmd = Encoding.ASCII.GetString(indata);//字符形式的命令,用于读取EB90协议的数据,内部数据用cmd存取。
         string[] str    = strcmd.Split(',');
         NodeId = int.Parse(str[2]);
         int id;
         if (!SourceDataClass.DepackCommData(indata, out time, out id, out data))
         {
             throw new Exception("数据校验错误");
         }
         return(true);
     }
     catch (Exception e)
     {
         NodeId = 0;
         time   = null;
         data   = null;
         Debug.WriteLine(e.ToString());
         return(false);
     }
 }
Esempio n. 16
0
 private void ViaNet_Click(object sender, EventArgs e)
 {
     if (DestNodeName.Text != "")
     {
         byte[] cmd = Pack();
         if (cmd.Length == 0)
         {
             return;
         }
         byte[] netcmd = SourceDataClass.NetPackage(cmd);
         MainForm.pMainForm.CommandLineWin.SendCommand("gd -n");
         if (MainForm.pMainForm.CommandLineWin.SendData(netcmd))//正确发送
         {
             BackText.Clear();
             Commparelabel.Text = "---";
             MessageBox.Show("命令已发送!");
         }
     }
     else
     {
         MessageBox.Show("请选择一个正确的目的地址!");
     }
 }
Esempio n. 17
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("路由表已加入命令列表!");
            }
        }
Esempio n. 18
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;
            }
        }
Esempio n. 19
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("获取设备状态命令已加入命令列表!");
                }
            }
        }
Esempio n. 20
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("设备参数设置命令已加入命令列表!");
        }
Esempio n. 21
0
File: Form1.cs Progetto: BJFX/UWACN
        private void FilesWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            List <FileInfo>  lf = (List <FileInfo>)e.Argument;
            DataTimeComparer dc = new DataTimeComparer();

            lf.Sort(dc);
            BackgroundWorker worker = sender as BackgroundWorker;

            for (int i = 0; i < lf.Count; i++)
            {
                using (BinaryReader br = new BinaryReader(lf[i].OpenRead()))
                {
                    byte[] b = br.ReadBytes((int)lf[i].Length);

                    int    NodeId;
                    string time;
                    byte[] data;

                    if (isCommType)//串口数据
                    {
                        if (DepackData(b, out NodeId, out time, out data))
                        {
                            if (NodeId != 0)//收到的节点号
                            {
                                try
                                {
                                    SourceDataClass.GetData(data);
                                    SourceDataClass.ParseToLst();
                                    if (SourceDataClass.datalist.Count > 0)
                                    {
                                        foreach (string[] s in SourceDataClass.datalist)
                                        {
                                            s[2] = time;
                                        }
                                        DetailLstOfData.AddRange(SourceDataClass.datalist);
                                    }
                                    if (SourceDataClass.statuslist.Count > 0)
                                    {
                                        foreach (string[] s in SourceDataClass.statuslist)
                                        {
                                            s[1] = time;
                                        }

                                        DetailLstOfStatus.AddRange(SourceDataClass.statuslist);
                                    }
                                    TimeLst.Add(time);
                                    TimeData.Add(time, data);
                                }
                                catch (Exception ex)
                                {
                                    Debug.WriteLine(ex.Message);
                                    worker.ReportProgress((i + 1) * 100 / lf.Count);
                                    continue;
                                }
                            }
                        }
                        else
                        {
                            FileInfo f = new FileInfo(lf[i].FullName);
                            Debug.WriteLine(lf[i].FullName + "解析错误");
                        }
                    }
                    else//网络数据
                    {
                        try
                        {
                            SourceDataClass.GetData(b);
                            int ret = SourceDataClass.ParseToLst();
                            time = lf[i].LastWriteTime.ToString();
                            if (ret == 1)
                            {
                                time += "(回环应答)";
                            }
                            if (SourceDataClass.datalist.Count > 0)
                            {
                                foreach (string[] s in SourceDataClass.datalist)
                                {
                                    s[2] = time;
                                }
                                DetailLstOfData.AddRange(SourceDataClass.datalist);
                            }
                            if (SourceDataClass.statuslist.Count > 0)
                            {
                                foreach (string[] s in SourceDataClass.statuslist)
                                {
                                    s[1] = time;
                                }

                                DetailLstOfStatus.AddRange(SourceDataClass.statuslist);
                            }
                            TimeLst.Add(time);
                            TimeData.Add(time, b);
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine(ex.StackTrace);
                            worker.ReportProgress((i + 1) * 100 / lf.Count);
                            continue;
                        }
                    }
                }
                worker.ReportProgress((i + 1) * 100 / lf.Count);
            }
        }
Esempio n. 22
0
        /// <summary>
        /// 解析数据并显示在对话框中,如果shown为真,则同时在对话框的设置项中显示单独数据
        /// </summary>
        /// <param name="ba"></param>
        private string ParseDataAndDisplay(BitArray ba, bool shown)
        {
            MainForm.ParseLock.WaitOne();
            SourceDataClass.GetData(ba);
            int    nodeid   = SourceDataClass.GetIntValueFromBit(6);
            int    nodetype = SourceDataClass.GetIntValueFromBit(1);
            int    emit     = SourceDataClass.GetIntValueFromBit(3);
            int    set1     = SourceDataClass.GetIntValueFromBit(8);
            int    set2     = SourceDataClass.GetIntValueFromBit(8);
            int    energy   = SourceDataClass.GetIntValueFromBit(3);
            Int16  commtype = (short)SourceDataClass.GetIntValueFromBit(16);
            int    n        = SourceDataClass.GetIntValueFromBit(28);
            double lang     = 0;

            if (n >> 27 == 1)//西经
            {
                n   &= 0x7ffffff;
                lang = (double)n / 10000 / 60;
                lang = -lang;
            }
            else//北纬
            {
                n   &= 0x7ffffff;
                lang = (double)n / 10000 / 60;
            }
            n = SourceDataClass.GetIntValueFromBit(28);
            double lat = 0;

            if (n >> 27 == 1)//南纬
            {
                n  &= 0x7ffffff;
                lat = (double)n / 10000 / 60;
                lat = -lang;
            }
            else//北纬
            {
                n  &= 0x7ffffff;
                lat = (double)n / 10000 / 60;
            }
            double depth = SourceDataClass.GetIntValueFromBit(14) * 0.5;

            SourceDataClass.clear();
            MainForm.ParseLock.ReleaseMutex();
            if (shown)
            {
                NodeNameBox.Text = "节点" + nodeid;
                Nodetypebox.Text = nodetype == 1?"移动节点":"静态节点";
                EmitSet.Value    = emit;
                Set1Box.Text     = Enum.GetName(typeof(SourceDataClass.DeviceAddr), set1);
                Set2Box.Text     = Enum.GetName(typeof(SourceDataClass.DeviceAddr), set2);
                if (energy == 0)
                {
                    leftenergy.Value = 5;
                }
                else if (energy == 1)
                {
                    leftenergy.Value = 20;
                }
                else if (energy == 2)
                {
                    leftenergy.Value = 35;
                }
                else if (energy == 3)
                {
                    leftenergy.Value = 50;
                }
                else if (energy == 4)
                {
                    leftenergy.Value = 65;
                }
                else if (energy == 5)
                {
                    leftenergy.Value = 80;
                }
                else if (energy == 6)
                {
                    leftenergy.Value = 95;
                }
                byte[]   b = BitConverter.GetBytes(commtype);
                BitArray a = new BitArray(b);
                for (int i = 0; i < 16; i++)
                {
                    CommType.SetItemChecked(i, false);
                }
                for (int i = 0; i < a.Count; i++)
                {
                    CommType.SetItemChecked(i, a[i]);
                }
                Lat.Value        = lat;
                Lang.Value       = lang;
                DepthInput.Value = depth;
            }
            return("节点" + nodeid + ":" + ((nodetype == 1) ? " 移动节点" : " 静态节点") + " 换能器数" + emit.ToString()
                   + " " + Enum.GetName(typeof(SourceDataClass.DeviceAddr), set1) + " " + Enum.GetName(typeof(SourceDataClass.DeviceAddr), set2)
                   + " 能量 " + energy.ToString() + " 纬度 " + lat.ToString() + " 经度 " + lang.ToString() + " 深度 "
                   + depth.ToString());
        }
Esempio n. 23
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);
            }
        }
Esempio n. 24
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("网络表已加入命令列表!");
                    }
                }
            }
        }
Esempio n. 25
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]);
            }
        }
Esempio n. 26
0
        public void ParseNetworkPacket(byte[] netpacket, int length)
        {
            byte[] data = new byte[length];
            Buffer.BlockCopy(netpacket, 4, data, 0, length);
            switch (BitConverter.ToUInt16(netpacket, 0))
            {
            case 0xABCD:
            {
                object nodetime = new UtilityClass.UtcTime();
                nodetime = UtilityClass.RawDeserialize(data, (Type)nodetime.GetType());
                ShowNodeTime(nodetime.ToString());
                break;
            }

            case 0xAD01:
            {
                if (ch1AdFile.adfile.writeOpened == false)
                {
                    ch1AdFile.OpenFile(MainForm.pMainForm.ADPathInfo);
                }
                ch1AdFile.BinaryWrite(data);
                ADEventHandler            handler = ADDataEvent;
                EventsClass.DataEventArgs e       = new EventsClass.DataEventArgs("1", data, length, "");
                if (handler != null)
                {
                    handler(this, e);
                }
                if (ch1AdFile.FileLen > 1024 * 1024 * 100)
                {
                    ch1AdFile.close();
                    ch1AdFile.OpenFile(MainForm.pMainForm.ADPathInfo);
                }
                break;
            }

            case 0xAD02:
            {
                if (ch2AdFile.adfile.writeOpened == false)
                {
                    ch2AdFile.OpenFile(MainForm.pMainForm.ADPathInfo);
                }
                ch2AdFile.BinaryWrite(data);
                ADEventHandler            handler = ADDataEvent;
                EventsClass.DataEventArgs e       = new EventsClass.DataEventArgs("2", data, length, "");
                if (handler != null)
                {
                    handler(this, e);
                }
                if (ch2AdFile.FileLen > 1024 * 1024 * 100)
                {
                    ch2AdFile.close();
                    ch2AdFile.OpenFile(MainForm.pMainForm.ADPathInfo);
                }
                break;
            }

            case 0xAD03:
            {
                if (ch3AdFile.adfile.writeOpened == false)
                {
                    ch3AdFile.OpenFile(MainForm.pMainForm.ADPathInfo);
                }
                ch3AdFile.BinaryWrite(data);
                ADEventHandler            handler = ADDataEvent;
                EventsClass.DataEventArgs e       = new EventsClass.DataEventArgs("3", data, length, "");
                if (handler != null)
                {
                    handler(this, e);
                }
                if (ch3AdFile.FileLen > 1024 * 1024 * 100)
                {
                    ch3AdFile.close();
                    ch3AdFile.OpenFile(MainForm.pMainForm.ADPathInfo);
                }
                break;
            }

            case 0xAD04:
            {
                if (ch4AdFile.adfile.writeOpened == false)
                {
                    ch4AdFile.OpenFile(MainForm.pMainForm.ADPathInfo);
                }
                ch4AdFile.BinaryWrite(data);
                ADEventHandler            handler = ADDataEvent;
                EventsClass.DataEventArgs e       = new EventsClass.DataEventArgs("4", data, length, "");
                if (handler != null)
                {
                    handler(this, e);
                }
                if (ch4AdFile.FileLen > 1024 * 1024 * 100)
                {
                    ch4AdFile.close();
                    ch4AdFile.OpenFile(MainForm.pMainForm.ADPathInfo);
                }
                break;
            }

            case 0xEDED:
            {
                ch1AdFile.close();
                ch2AdFile.close();
                ch3AdFile.close();
                ch4AdFile.close();
            }
            break;

            case 0xBB01:
            {
                if (!hasRecv)
                {
                    WaveFile.OpenFile(MainForm.pMainForm.NetRecvDataPathInfo);
                    hasRecv = true;
                }
                WaveFile.BinaryWrite(data);
                if (WaveFile.FileLen > 1024 * 1024 * 100)
                {
                    WaveFile.close();
                    WaveFile.OpenFile(MainForm.pMainForm.NetRecvDataPathInfo);
                }

                WaveEventHandler          handler = WaveDisplEvent;
                EventsClass.WaveEventArgs e       = new EventsClass.WaveEventArgs(data, length);
                if (handler != null)
                {
                    handler(this, e);
                }
                break;
            }

            case 0xEE01:
            {
                NetTCPFile.OpenFile(MainForm.pMainForm.NetRecvTCPPathInfo);
                string filename = NetTCPFile.adfile.fileName;
                NetTCPFile.BinaryWrite(data);
                NetTCPFile.close();
                try
                {
                    MainForm.ParseLock.WaitOne();
                    SourceDataClass.GetData(data);
                    SourceDataClass.Parse();
                    MainForm.ParseLock.ReleaseMutex();
                }
                catch (Exception ex)
                {
                    MainForm.ParseLock.ReleaseMutex();
                }
                DataEventHandler          handler = NetDataEvent;
                EventsClass.DataEventArgs e       = new EventsClass.DataEventArgs(Dclient.Client.RemoteEndPoint.ToString().Split(':')[0], data, length, filename);
                if (handler != null)
                {
                    handler(this, e);
                }
                break;
            }

            case 0xACAC:
            {
                ACPacketHandle.Set();
                //Debug.WriteLine("收到包号:" + BitConverter.ToUInt16(netpacket,4));
                break;
            }

            //4500test
            case 0x45FF:
            {
                var    cmd    = new byte[260];
                byte[] netcmd = SourceDataClass.NetPackage(cmd);
                MainForm.pMainForm.CommandLineWin.SendCommand("gd -n");
                if (MainForm.pMainForm.CommandLineWin.SendData(netcmd))    //正确发送
                {
                    MainForm.pMainForm.mapdoc.WriteNetLog("数据已发送!");
                }
                break;
            }

            default:

                break;
            }
        }