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; }
public void ShowData() { SourceDataClass.GetData((CRCHelper.ConvertHexToChar(str))); ll = SourceDataClass.Parse(); InputGrid(); this.Show(); //this.TopMost = true; }
/// <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()); }
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; } }
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); } }