/// <summary> /// 发送网络命令包 /// </summary> /// <param name="command"></param> /// <returns></returns> /// public bool SendData(byte[] command) { try { if (Dstream != null) { if (Dstream.CanWrite) { Dstream.Write(command, 0, command.Length); NetCmdFile.OpenFile(MainForm.pMainForm.NetCmdDataPathInfo); NetCmdFile.BinaryWrite(command); NetCmdFile.close(); return(true); } return(false); } return(false); } catch (Exception MyEx) { SendStatusLabel(MyEx.Message); AddtoBox(Color.Black, MyEx.Message + ":" + MyEx.StackTrace + "\r\n"); return(false); } }
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; } }