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("请选择一个正确的源地址!"); } } }
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("请选择一个正确的目的地址!"); } }
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; } }