public nms_reprot_t GeneraterNmsPacket() { config_t config = new config_t(); cg_header_t header = new cg_header_t(); header.session_id = (uint)this.sessionId; header.message_type = (uint)rand.Next(0, 2); header.data_len = (uint)Marshal.SizeOf(config); header.pro_ver = 33333; header.message_type = (uint)rand.Next(0, 2); config.ethernet1_state = (uint)rand.Next(0, 2); config.ethernet2_state = (uint)rand.Next(0, 1); config.network_state = (uint)rand.Next(0, 2); config.external_power = (uint)rand.Next(0, 2); config.use_rx_amount = (uint)rand.Next(0, 2000); config.use_tx_amount = (uint)rand.Next(0, 2000); config.current_ip_address = String.Format("{0}({1})", this.inIp, this.exIp); config.current_time = DateTime.Now.ToString("yyMMddHHmmss"); //config.moduleband = (uint)rand.Next(0, 5); config.moduleband = (uint)rand.Next(0, 4); config.moduleservice = (uint)rand.Next(0, 6); config.modulesignal = rand.Next(-120, 0); config.devicestatus = (uint)rand.Next(0, 2); config.wifistatus = (uint)rand.Next(0, 2); config.vpnstatus = (uint)rand.Next(0, 2); config.newsms = rand.Next(5); config.sw_version = "ver 1.1.1"; config.rpt_time = (uint)rand.Next(0, 40); config.rsrqsignal = rand.Next(0, 97); config.rsrpsignal = rand.Next(-20, -3); config.hw_version = "celot ver 2.1.2"; config.rpt_port = this.rpt_port; config.rmt_port = this.rmt_port; int[] extDevice1 = new int[64]; extDevice1[0] = rand.Next(0, 400); config.ext_device1 = extDevice1; config.ext_device2 = "aaaaaaa"; nms_reprot_t report = new nms_reprot_t(); report.header = header; report.data = config; return report; }
public void Write(nms_reprot_t report) { byte[] buffer = new byte[1024]; TcpClient tcpClient = new TcpClient(); tcpClient.Connect("localhost", this.port); this.form.textBox1.AppendText((String.Format("\n[CONNECT] : {0} 번 Router have been connected to destination port {1}\n", report.header.session_id, this.port))); NetworkStream stream = tcpClient.GetStream(); unsafe { fixed (byte* fixed_buffer = buffer) { Marshal.StructureToPtr(report, (IntPtr)fixed_buffer, false); } } stream.Write(buffer, 0, Marshal.SizeOf(report)); this.form.textBox2.AppendText("\r\n"+ (String.Format("[WRITE PACKET] : {0} 번 Router Send Report packet to destination port {1} [ByteLength : {2}]\n ", report.header.session_id, this.port, Marshal.SizeOf(report)))); //this.form.textBox2.AppendText("\r\n" +report.data.current_time); tcpClient.Close(); this.form.textBox1.AppendText((String.Format("\n[DISCONNECTED] : {0} 번 Router disconnected\n", report.header.session_id))); }
public string Dump(nms_reprot_t report) { Type type = report.GetType(); FieldInfo[] fields = type.GetFields(); PropertyInfo[] properties = type.GetProperties(); Dictionary<string, object> values = new Dictionary<string, object>(); Array.ForEach(fields, (field) => values.Add(field.Name, field.GetValue(report))); return String.Join(", ", values); }