/// <summary> /// 请求时间输出 /// </summary> public void Send500CXSJ() { string text = Beidou500Helper.GetCXSJStr(); Debug.WriteLine("发送CXSJ:" + text); InvokeMessage("授时申请 " + text, "发送"); SendText(text); }
/// <summary> /// 状态检测($ZTJC) /// </summary> private void SendZTJC() { string text = Beidou500Helper.GetZTJCStr(); Debug.WriteLine("发送ZTJC:" + text); InvokeMessage("状态检测 " + text, "发送"); SendText(text); }
/// <summary> /// 获取用户信息 /// </summary> private void SendHQYH() { string text = Beidou500Helper.GetHQYHStr(); Debug.WriteLine("发送HQYH:" + text); InvokeMessage("获取用户信息 " + text, "发送"); SendText(text); }
/// <summary> /// 请求时间输出 /// </summary> private void SendCXSJ() { string text = Beidou500Helper.GetCXSJStr(); Debug.WriteLine("发送CXSJ:" + text); InvokeMessage("请求时间输出 " + text, "发送"); SendText(text); }
public String Send500TTCA(CBeiDouTTCA param) { string text = Beidou500Helper.GetTTCAStr(param); Debug.WriteLine("发送TTCA:" + text); InvokeMessage("自发自收 " + text, "发送"); SendText(text); // return SendBackTTCA(); return(""); }
// 处理时间信息 SJXX数据类型 private void DealSJXX(string msg) { InvokeMessage("时间信息 " + msg.Trim(), "接收"); var sjxx = Beidou500Helper.GetSJXXInfo(msg); if (null != Beidou500SJXXReceived) { Beidou500SJXXReceived(null, new Beidou500SJXXEventArgs() { SJXXInfo = sjxx, RawMsg = msg }); } }
// 处理状态检测 ZTXX数据类型 private void DealZTXX(string msg) { InvokeMessage("状态检测 " + msg.Trim(), "接收"); var ztxx = Beidou500Helper.GetZTXXInfo(msg); if (null != Beidou500ZTXXReceived) { Beidou500ZTXXReceived(null, new Beidou500ZTXXEventArgs() { ZTXXInfo = ztxx, RawMsg = msg }); } }
// 处理通信输出 COUT类型数据 private void DealCOUT(string msg) { InvokeMessage("通信输出 " + msg.Trim(), "接收"); string str = msg.Trim(); if (str.Contains("COUT")) { if (str.Contains("COUT")) { num = num + 1; FileStream fs = new FileStream("numbd.txt", FileMode.Create); StreamWriter sw = new StreamWriter(fs); //开始写入 sw.Write(num); //清空缓冲区 sw.Flush(); //关闭流 sw.Close(); fs.Close(); } } var cout = Beidou500Helper.GetCOUTInfo(msg); //InvokeMessage("gm1 " + "通过截取", "接收"); if (cout == null) { //InvokeMessage("gm2 " + "通过截取", "接收"); return; } // 解析通信输出中的内容 string content = cout.MsgContent; try { string rawMsg = content; //InvokeMessage("gm3 " + content, "接收"); string reportType = rawMsg.Substring(6, 2); //InvokeMessage("gm4 " + reportType, "接收"); if (reportType == "21" || reportType == "22") // 定时报,加报 { // YAC设备的墒情协议: string stationType = rawMsg.Substring(8, 2); //InvokeMessage("gm5 " + stationType, "接收"); switch (stationType) { // 站类为04时墒情站 05墒情雨量站 06,16墒情水位站 07,17墒情水文站 case "04": case "05": case "06": case "07": case "17": { //var station = FindStationByBeidouID(cout.SenderAddr); //string currentMsg = rawMsg.Insert(0, "$" + station.StationID + "1G"); //CEntitySoilData soil = new CEntitySoilData(); //CReportStruct soilReport = new CReportStruct(); //if (Soil.Parse(currentMsg, out soil, out soilReport)) //{ // soil.ChannelType = EChannelType.BeiDou; // if (null != this.SoilDataReceived) // this.SoilDataReceived(null, new CEventSingleArgs<CEntitySoilData>(soil)); // if (null != soilReport && null != this.UpDataReceived) // { // soilReport.ChannelType = EChannelType.BeiDou; // soilReport.ListenPort = "COM" + this.Port.PortName; // this.UpDataReceived(null, new UpEventArgs() { RawData = rawMsg, Value = soilReport }); // } //} // string newMsg = rawMsg.Substring(1, rawMsg.Length - 1); CEntitySoilData soil = new CEntitySoilData(); CReportStruct soilReport = new CReportStruct(); if (Soil.Parse(rawMsg, out soil, out soilReport)) { soilReport.ChannelType = EChannelType.BeiDou; if (null != this.SoilDataReceived) { this.SoilDataReceived(null, new CEventSingleArgs <CEntitySoilData>(soil)); } if (null != soilReport && null != this.UpDataReceived) { soilReport.ChannelType = EChannelType.BeiDou; soilReport.ListenPort = "COM" + this.Port.PortName; soilReport.flagId = cout.SenderAddr; this.UpDataReceived(null, new UpEventArgs() { RawData = rawMsg, Value = soilReport }); } } } break; // 站类为01,02,03,12,13时,不是墒情站 case "01": case "02": case "03": case "12": case "13": { //var station = FindStationByBeidouID(cout.SenderAddr); //rawMsg = rawMsg.Insert(0, station.StationID + " "); //CReportStruct report = new CReportStruct(); //if (Up.Parse(rawMsg, out report)) //{ // report.ChannelType = EChannelType.BeiDou; // report.ListenPort = "COM" + this.Port.PortName; // if (this.UpDataReceived != null) // this.UpDataReceived.Invoke(null, new UpEventArgs() { Value = report, RawData = msg }); //} //string newMsg = rawMsg.Substring(1, rawMsg.Length - 1); CReportStruct report = new CReportStruct(); if (Up.Parse(rawMsg, out report)) { //InvokeMessage("gm6 " + rawMsg, "接收"); //$60131G2201161111040003046112271367 report.ChannelType = EChannelType.BeiDou; report.ListenPort = "COM" + this.Port.PortName; report.flagId = cout.SenderAddr; if (this.UpDataReceived != null) { //InvokeMessage("Cout Test " + rawMsg, "接收"); this.UpDataReceived.Invoke(null, new UpEventArgs() { Value = report, RawData = rawMsg }); } } } break; default: break; } } else if (reportType == "11") // 人工水位 { } else if (reportType == "23") // 人工流量 { } else if (reportType == "25") { var station = FindStationByBeidouID(cout.SenderAddr); string currentMsg = rawMsg.Insert(0, "$" + station.StationID + "1G"); CEntitySoilData soil = new CEntitySoilData(); CReportStruct soilReport = new CReportStruct(); if (Soil.Parse(currentMsg, out soil, out soilReport)) { soil.ChannelType = EChannelType.BeiDou; if (null != this.SoilDataReceived) { this.SoilDataReceived(null, new CEventSingleArgs <CEntitySoilData>(soil)); } if (null != soilReport && null != this.UpDataReceived) { soilReport.ChannelType = EChannelType.BeiDou; soilReport.ListenPort = "COM" + this.Port.PortName; this.UpDataReceived(null, new UpEventArgs() { RawData = rawMsg, Value = soilReport }); } } } } catch (Exception exp) { System.Diagnostics.Debug.WriteLine("北斗卫星指挥机 数据解析出错 !" + content + "\r\n" + exp.Message); } }
// 处理通信输出 COUT类型数据 public void DealCOUT(string msg) { InvokeMessage("通信输出 " + msg, "接收"); string str = msg.Trim(); if (str.Contains("COUT")) { if (str.Contains("COUT")) { num = num + 1; FileStream fs = new FileStream("numbd.txt", FileMode.Create); StreamWriter sw = new StreamWriter(fs); //开始写入 sw.Write(num); //清空缓冲区 sw.Flush(); //关闭流 sw.Close(); fs.Close(); } } var cout = Beidou500Helper.GetCOUTInfo(msg); //InvokeMessage("gm1 " + "通过截取", "接收"); if (cout == null) { //InvokeMessage("gm2 " + "通过截取", "接收"); return; } //TODO //需要处理dealbcd码的走这里 // 解析通信输出中的内容 string content = cout.MsgContent; UpParser up = new UpParser(); List <CUpReport> reports = new List <CUpReport>(); //TODO //添加调用代码 try { string rawMsg = content; string sid = null; string dealMsg = ProtocolHelpers.dealBCD(rawMsg); WriteToFileClass writeClass = new WriteToFileClass("ReceivedLog"); Thread t = new Thread(new ParameterizedThreadStart(writeClass.WriteInfoToFile)); t.Start("COUT Message: " + " " + dealMsg + "\r\n"); //InvokeMessage("gm3 " + content, "接收"); //sid需要根据北斗卫星号获取 try { string bdid = cout.SenderAddr; sid = Manager.XmlStationDataSerializer.Instance.GetStationByBDID(bdid); } catch (Exception e) { sid = "5712"; Debug.WriteLine("获取站号失败" + e.Message); } EMessageType type = ProtocolMaps.MessageTypeMap.FindKey(dealMsg.Substring(0, 2)); string reportType = dealMsg.Substring(0, 2); //InvokeMessage("gm4 " + reportType, "接收"); if (reportType == "21" || reportType == "22") // 定时报,加报 { // YAC设备的墒情协议: string stationType = dealMsg.Substring(2, 2); //InvokeMessage("gm5 " + stationType, "接收"); switch (stationType) { // 站类为04时墒情站 05墒情雨量站 06,16墒情水位站 07,17墒情水文站 case "04": case "05": case "06": case "07": case "17": { //var station = FindStationByBeidouID(cout.SenderAddr); //string currentMsg = rawMsg.Insert(0, "$" + station.StationID + "1G"); //CEntitySoilData soil = new CEntitySoilData(); //CReportStruct soilReport = new CReportStruct(); //if (Soil.Parse(currentMsg, out soil, out soilReport)) //{ // soil.ChannelType = EChannelType.BeiDou; // if (null != this.SoilDataReceived) // this.SoilDataReceived(null, new CEventSingleArgs<CEntitySoilData>(soil)); // if (null != soilReport && null != this.UpDataReceived) // { // soilReport.ChannelType = EChannelType.BeiDou; // soilReport.ListenPort = "COM" + this.Port.PortName; // this.UpDataReceived(null, new UpEventArgs() { RawData = rawMsg, Value = soilReport }); // } //} // string newMsg = rawMsg.Substring(1, rawMsg.Length - 1); CEntitySoilData soil = new CEntitySoilData(); CReportStruct soilReport = new CReportStruct(); if (Soil.Parse(rawMsg, out soil, out soilReport)) { soilReport.ChannelType = EChannelType.BeiDou; if (null != this.SoilDataReceived) { this.SoilDataReceived(null, new CEventSingleArgs <CEntitySoilData>(soil)); } if (null != soilReport && null != this.UpDataReceived) { soilReport.ChannelType = EChannelType.GPRS; soilReport.ListenPort = "COM" + this.Port.PortName; this.UpDataReceived(null, new UpEventArgs() { RawData = rawMsg, Value = soilReport }); } } } break; // 站类为01,02,03,12,13时,不是墒情站 case "01": case "02": case "03": case "12": case "13": { //var station = FindStationByBeidouID(cout.SenderAddr); //rawMsg = rawMsg.Insert(0, station.StationID + " "); //CReportStruct report = new CReportStruct(); //if (Up.Parse(rawMsg, out report)) //{ // report.ChannelType = EChannelType.BeiDou; // report.ListenPort = "COM" + this.Port.PortName; // if (this.UpDataReceived != null) // this.UpDataReceived.Invoke(null, new UpEventArgs() { Value = report, RawData = msg }); //} //string newMsg = rawMsg.Substring(1, rawMsg.Length - 1); CReportStruct report = new CReportStruct(); UpParser Up1 = new UpParser(); if (Up1.Parse_beidou(sid, type, rawMsg, out report)) { //InvokeMessage("gm6 " + rawMsg, "接收"); //$60131G2201161111040003046112271367 report.ChannelType = EChannelType.BeiDou; report.ListenPort = "COM" + this.Port.PortName; if (this.UpDataReceived != null) { //InvokeMessage("gm7 " + rawMsg, "接收"); this.UpDataReceived.Invoke(null, new UpEventArgs() { Value = report, RawData = rawMsg }); } } } break; default: break; } } else if (reportType == "11") // 人工水位 { } else if (reportType == "23") // 人工流量 { } else if (reportType == "25") { var station = FindStationByBeidouID(cout.SenderAddr); string currentMsg = rawMsg.Insert(0, "$" + station.StationID + "1G"); CEntitySoilData soil = new CEntitySoilData(); CReportStruct soilReport = new CReportStruct(); if (Soil.Parse(currentMsg, out soil, out soilReport)) { soil.ChannelType = EChannelType.BeiDou; if (null != this.SoilDataReceived) { this.SoilDataReceived(null, new CEventSingleArgs <CEntitySoilData>(soil)); } if (null != soilReport && null != this.UpDataReceived) { soilReport.ChannelType = EChannelType.BeiDou; soilReport.ListenPort = "COM" + this.Port.PortName; this.UpDataReceived(null, new UpEventArgs() { RawData = rawMsg, Value = soilReport }); } } } } catch (Exception exp) { System.Diagnostics.Debug.WriteLine("北斗卫星指挥机 数据解析出错 !" + content + "\r\n" + exp.Message); } }