//参数修改的命令确认rtu上报5(中心端不用处理) internal static void Process_05(DLYY.Protocol.Solution <DLYY.Model.WaterLevelInfo> solution, Service.ServiceEnum.NFOINDEX NFOINDEX, object Server) { try { string STCD = SetSTCD(solution, NFOINDEX, Server); #region tcp通知界面 if ((int)NFOINDEX == 1) { TcpService.TcpServer TS = Server as TcpService.TcpServer; List <TcpService.TcpSocket> Ts = TS.Ts; //回复通知界面 ServiceBussiness.WriteQUIM("TCP", TS.ServiceID, STCD, "RTU接收到修改参数命令[确认]", new byte[] { }, Service.ServiceEnum.EnCoderType.ASCII, Service.ServiceEnum.DataType.Text); } #endregion #region udp通知界面 if ((int)NFOINDEX == 2) { UdpService.UdpServer US = Server as UdpService.UdpServer; ServiceBussiness.WriteQUIM("UDP", US.ServiceID, STCD, "RTU接收到修改参数命令[确认]", new byte[] { }, Service.ServiceEnum.EnCoderType.ASCII, Service.ServiceEnum.DataType.Text); } #endregion #region gsm通知界面 if ((int)NFOINDEX == 3) { GsmService.GsmServer GS = Server as GsmService.GsmServer; ServiceBussiness.WriteQUIM("GSM", GS.ServiceID, STCD, "RTU接收到修改参数命令[确认]", new byte[] { }, Service.ServiceEnum.EnCoderType.ASCII, Service.ServiceEnum.DataType.Text); } #endregion #region com通知界面 if ((int)NFOINDEX == 4) { ComService.ComServer CS = Server as ComService.ComServer; Service.ServiceBussiness.WriteQUIM("COM", CS.ServiceID, STCD, "RTU接收到修改参数命令[确认]", new byte[] { }, Service.ServiceEnum.EnCoderType.HEX, Service.ServiceEnum.DataType.Text); } #endregion } catch (Exception ex) { log.Error(DateTime.Now + "05操作异常" + ex.ToString()); } }
public void SendCommand(GsmService.GsmServer GS) { //throw new NotImplementedException(); }
public void PacketArrived(GsmService.GsmServer GS) { //throw new NotImplementedException(); }
/// <summary> /// 上传状态报 /// </summary> /// <param name="data"></param> /// <param name="NFOINDEX"></param> /// <param name="Server"></param> internal static void Process_STAT(string data, Service.ServiceEnum.NFOINDEX NFOINDEX, object Server) { DataModel DM = pd.UnPack(data); DateTime DOWNDATE = DateTime.Now; #region tcp回复 if ((int)NFOINDEX == 1) { TcpService.TcpServer TS = Server as TcpService.TcpServer; List <TcpService.TcpSocket> Ts = TS.Ts; var tcps = from t in Ts where t.STCD == DM.Code && t.TCPSOCKET != null select t; List <TcpService.TcpSocket> Tcps = tcps.ToList <TcpService.TcpSocket>(); if (Tcps.Count() > 0) { byte[] sendData = Encoding.ASCII.GetBytes(DM.Reply); Tcps.First().TCPSOCKET.Send(sendData); //回复通知界面 Service.ServiceBussiness.WriteQUIM("TCP", TS.ServiceID, DM.Code, "回复数据", sendData, Service.ServiceEnum.EnCoderType.ASCII, Service.ServiceEnum.DataType.Text); } } #endregion #region udp回复 if ((int)NFOINDEX == 2) { UdpService.UdpServer US = Server as UdpService.UdpServer; List <UdpService.UdpSocket> Us = US.Us; var udps = from u in Us where u.STCD == DM.Code && u.IpEndPoint != null select u; if (udps.Count() > 0) { byte[] sendData = Encoding.ASCII.GetBytes(DM.Reply); US.UDPClient.Send(sendData, sendData.Length, udps.First().IpEndPoint); Service.ServiceBussiness.WriteQUIM("UDP", US.ServiceID, DM.Code, "回复数据", sendData, Service.ServiceEnum.EnCoderType.ASCII, Service.ServiceEnum.DataType.Text); } } #endregion if (DM.Item_data.Count() > 0) { for (int i = 0; i < DM.Item_data.Count(); i++) { string StateName = GetStateName(DM.Item_data[i].Item); #region //入状态表 Service.Model.YY_DATA_STATE model = new Service.Model.YY_DATA_STATE(); model.STCD = DM.Code; model.TM = DM.Datetime; //监测时间 model.STATEDATA = DM.Item_data[i].Item; //监测项 model.DOWNDATE = DOWNDATE; model.DATAVALUE = decimal.Parse(DM.Item_data[i].Data); //值 model.NFOINDEX = (int)NFOINDEX; Service.PublicBD.db.AddRTUState(model); ////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////// ///////////////////////////////////////////////////////// #region tcp通知界面 if ((int)NFOINDEX == 1) { TcpService.TcpServer TS = Server as TcpService.TcpServer; //回复通知界面 Service.ServiceBussiness.WriteQUIM("TCP", TS.ServiceID, DM.Code, "接收到状态报数据,数据特征[" + StateName + "-" + DM.Item_data[i].Item + "],时间[" + DM.Datetime + "],值[" + DM.Item_data[i].Data + "]", new byte[] { }, Service.ServiceEnum.EnCoderType.HEX, Service.ServiceEnum.DataType.Text); var list = from rtu in TS.Ts where rtu.STCD == DM.Code select rtu; if (list.Count() > 0) { list.First().CanSend = false; } } #endregion #region udp通知界面 if ((int)NFOINDEX == 2) { UdpService.UdpServer US = Server as UdpService.UdpServer; Service.ServiceBussiness.WriteQUIM("UDP", US.ServiceID, DM.Code, "接收到状态报数据,数据特征[" + StateName + "-" + DM.Item_data[i].Item + "],时间[" + DM.Datetime + "],值[" + DM.Item_data[i].Data + "]", new byte[] { }, Service.ServiceEnum.EnCoderType.HEX, Service.ServiceEnum.DataType.Text); var list = from rtu in US.Us where rtu.STCD == DM.Code select rtu; if (list.Count() > 0) { list.First().CanSend = false; } } #endregion #region gsm通知界面 if ((int)NFOINDEX == 3) { GsmService.GsmServer GS = Server as GsmService.GsmServer; Service.ServiceBussiness.WriteQUIM("GSM", GS.ServiceID, DM.Code, "接收到状态报数据,数据特征[" + StateName + "-" + DM.Item_data[i].Item + "],时间[" + DM.Datetime + "],值[" + DM.Item_data[i].Data + "]", new byte[] { }, Service.ServiceEnum.EnCoderType.HEX, Service.ServiceEnum.DataType.Text); } #endregion #region com通知界面 if ((int)NFOINDEX == 4) { ComService.ComServer CS = Server as ComService.ComServer; Service.ServiceBussiness.WriteQUIM("COM", CS.ServiceID, DM.Code, "接收到状态报数据,数据特征[" + StateName + "-" + DM.Item_data[i].Item + "],时间[" + DM.Datetime + "],值[" + DM.Item_data[i].Data + "]", new byte[] { }, Service.ServiceEnum.EnCoderType.HEX, Service.ServiceEnum.DataType.Text); } #endregion #endregion } } }
/// <summary> /// 上传监测数据报 /// </summary> /// <param name="data"></param> /// <param name="NFOINDEX"></param> /// <param name="Server"></param> internal static void Process_FD(string data, Service.ServiceEnum.NFOINDEX NFOINDEX, object Server) { DataModel DM = pd.UnPack(data); #region 数据报信息 string PacketType = ""; switch (DM.PacketType) { case "01": PacketType = "定时报"; break; case "02": PacketType = "加报"; break; default: PacketType = "手动召测"; break; } //TCP if ((int)NFOINDEX == 1) { TcpService.TcpServer TS = Server as TcpService.TcpServer; string Explain = "接收到数据报(" + PacketType + "),报头(" + DM.TiltleCode + "),RTU地址(" + DM.Code + ") 测量时间(" + DM.Datetime + ") 计算算法(" + DM.Algorithm + ") 测流历时(" + DM.Take + "秒) 左岸系数(" + DM.LeftBank + ") 右岸系数(" + DM.RightBank + ") 起算水位(" + DM.StartStage + ") 断面面积(" + DM.Section + "平方米) 参与计算的探头数量/探头数量(" + DM.ComputeSensorCount + "/" + DM.SensorCount + ")"; Service.ServiceBussiness.WriteQUIM("TCP", TS.ServiceID, DM.Code, Explain, new byte[] { }, Service.ServiceEnum.EnCoderType.HEX, Service.ServiceEnum.DataType.Text); } #endregion DateTime DOWNDATE = DateTime.Now; if (DM.Item_data.Count() > 0) { for (int i = 0; i < DM.Item_data.Count(); i++) { string ItemName = GetItemName(DM.Item_data[i].Item); #region //入实时表 Service.Model.YY_DATA_AUTO model = new Service.Model.YY_DATA_AUTO(); model.STCD = DM.Code; model.TM = DM.Datetime; //监测时间 model.ItemID = DM.Item_data[i].Item; //监测项 model.DOWNDATE = DOWNDATE; model.DATAVALUE = DM.Item_data[i].Data; //值 model.CorrectionVALUE = model.DATAVALUE; model.NFOINDEX = (int)NFOINDEX; Service.PublicBD.db.AddRealTimeData(model); ////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////// ///////////////////////////////////////////////////////// #region tcp通知界面 if ((int)NFOINDEX == 1) { TcpService.TcpServer TS = Server as TcpService.TcpServer; //回复通知界面 Service.ServiceBussiness.WriteQUIM("TCP", TS.ServiceID, DM.Code, "接收到数据报数据,数据特征[" + ItemName + "-" + DM.Item_data[i].Item + "],时间[" + DM.Datetime + "],值[" + DM.Item_data[i].Data + "]", new byte[] { }, Service.ServiceEnum.EnCoderType.HEX, Service.ServiceEnum.DataType.Text); var list = from rtu in TS.Ts where rtu.STCD == DM.Code select rtu; if (list.Count() > 0) { list.First().CanSend = false; } } #endregion #region udp通知界面 if ((int)NFOINDEX == 2) { UdpService.UdpServer US = Server as UdpService.UdpServer; Service.ServiceBussiness.WriteQUIM("UDP", US.ServiceID, DM.Code, "接收到数据报数据,数据特征[" + ItemName + "-" + DM.Item_data[i].Item + "],时间[" + DM.Datetime + "],值[" + DM.Item_data[i].Data + "]", new byte[] { }, Service.ServiceEnum.EnCoderType.HEX, Service.ServiceEnum.DataType.Text); var list = from rtu in US.Us where rtu.STCD == DM.Code select rtu; if (list.Count() > 0) { list.First().CanSend = false; } } #endregion #region gsm通知界面 if ((int)NFOINDEX == 3) { GsmService.GsmServer GS = Server as GsmService.GsmServer; Service.ServiceBussiness.WriteQUIM("GSM", GS.ServiceID, DM.Code, "接收到数据报数据,数据特征[" + ItemName + "-" + DM.Item_data[i].Item + "],时间[" + DM.Datetime + "],值[" + DM.Item_data[i].Data + "]", new byte[] { }, Service.ServiceEnum.EnCoderType.HEX, Service.ServiceEnum.DataType.Text); } #endregion #region com通知界面 if ((int)NFOINDEX == 4) { ComService.ComServer CS = Server as ComService.ComServer; Service.ServiceBussiness.WriteQUIM("COM", CS.ServiceID, DM.Code, "接收到数据报数据,数据特征[" + ItemName + "-" + DM.Item_data[i].Item + "],时间[" + DM.Datetime + "],值[" + DM.Item_data[i].Data + "]", new byte[] { }, Service.ServiceEnum.EnCoderType.HEX, Service.ServiceEnum.DataType.Text); } #endregion #endregion } } }
//提取固态时,无查询结果或发送查询结果至最后一条时rtu上报7(中心端不用处理) internal static void Process_07(DLYY.Protocol.Solution <DLYY.Model.WaterLevelInfo> solution, Service.ServiceEnum.NFOINDEX NFOINDEX, object Server) { try{ string STCD = SetSTCD(solution, NFOINDEX, Server); if (solution.IsUnpack) { int k = 0; if (solution.Items == null) { #region tcp通知界面 if ((int)NFOINDEX == 1) { TcpService.TcpServer TS = Server as TcpService.TcpServer; //回复通知界面 ServiceBussiness.WriteQUIM("TCP", TS.ServiceID, STCD, "召测时间段内没有数据[确认]", new byte[] { }, Service.ServiceEnum.EnCoderType.ASCII, Service.ServiceEnum.DataType.Text); } #endregion #region udp通知界面 if ((int)NFOINDEX == 2) { UdpService.UdpServer US = Server as UdpService.UdpServer; ServiceBussiness.WriteQUIM("UDP", US.ServiceID, STCD, "召测时间段内没有数据[确认]", new byte[] { }, Service.ServiceEnum.EnCoderType.ASCII, Service.ServiceEnum.DataType.Text); } #endregion #region gsm通知界面 if ((int)NFOINDEX == 3) { GsmService.GsmServer GS = Server as GsmService.GsmServer; ServiceBussiness.WriteQUIM("GSM", GS.ServiceID, STCD, "召测时间段内没有数据[确认]", new byte[] { }, Service.ServiceEnum.EnCoderType.ASCII, Service.ServiceEnum.DataType.Text); } #endregion #region com通知界面 if ((int)NFOINDEX == 4) { ComService.ComServer CS = Server as ComService.ComServer; Service.ServiceBussiness.WriteQUIM("COM", CS.ServiceID, STCD, "召测时间段内没有数据[确认]", new byte[] { }, Service.ServiceEnum.EnCoderType.HEX, Service.ServiceEnum.DataType.Text); } #endregion } else { foreach (DLYY.Model.WaterLevelInfo waterlevel in solution.Items) { int Milliseconds = (Convert.ToInt32(solution.N, 16) % 10) * 100 + (10 * k++); Service.Model.YY_DATA_REM model = new Model.YY_DATA_REM(); model.STCD = STCD; model.DATAVALUE = decimal.Parse(waterlevel.DATAVALUE); model.TM = DateTime.Parse(waterlevel.TM).AddMilliseconds(Milliseconds); model.DOWNDATE = DateTime.Now; model.NFOINDEX = (int)NFOINDEX; model.ItemID = waterlevel.ItemID; PublicBD.db.AddRemData(model); //k++; #region tcp通知界面 if ((int)NFOINDEX == 1) { TcpService.TcpServer TS = Server as TcpService.TcpServer; //回复通知界面 ServiceBussiness.WriteQUIM("TCP", TS.ServiceID, STCD, "提取到固态数据(最后一帧),数据特征[" + waterlevel.ItemID + "],时间[" + model.TM + "],值[" + model.DATAVALUE + "]", new byte[] { }, Service.ServiceEnum.EnCoderType.ASCII, Service.ServiceEnum.DataType.Text); } #endregion #region udp通知界面 if ((int)NFOINDEX == 2) { UdpService.UdpServer US = Server as UdpService.UdpServer; ServiceBussiness.WriteQUIM("UDP", US.ServiceID, STCD, "提取到固态数据(最后一帧),数据特征[" + waterlevel.ItemID + "],时间[" + model.TM + "],值[" + model.DATAVALUE + "]", new byte[] { }, Service.ServiceEnum.EnCoderType.ASCII, Service.ServiceEnum.DataType.Text); } #endregion #region gsm通知界面 if ((int)NFOINDEX == 3) { GsmService.GsmServer GS = Server as GsmService.GsmServer; ServiceBussiness.WriteQUIM("GSM", GS.ServiceID, STCD, "提取到固态数据(最后一帧),数据特征[" + waterlevel.ItemID + "],时间[" + model.TM + "],值[" + model.DATAVALUE + "]", new byte[] { }, Service.ServiceEnum.EnCoderType.ASCII, Service.ServiceEnum.DataType.Text); } #endregion #region com通知界面 if ((int)NFOINDEX == 4) { ComService.ComServer CS = Server as ComService.ComServer; Service.ServiceBussiness.WriteQUIM("COM", CS.ServiceID, STCD, "提取到固态数据(最后一帧),数据特征[" + waterlevel.ItemID + "],时间[" + model.TM + "],值[" + model.DATAVALUE + "]", new byte[] { }, Service.ServiceEnum.EnCoderType.HEX, Service.ServiceEnum.DataType.Text); } #endregion } } } } catch (Exception ex) { log.Error(DateTime.Now + "07操作异常" + ex.ToString()); } }
internal static void Process_06(DLYY.Protocol.Solution <DLYY.Model.WaterLevelInfo> solution, Service.ServiceEnum.NFOINDEX NFOINDEX, object Server) { try{ string STCD = SetSTCD(solution, NFOINDEX, Server); //打回复包 106=006A ---C string Answer = pack.GetAnswer(solution.N, "006A", GetAuto(STCD), GetWaterLevelOrder(STCD), GetRainfallOrder(STCD), GetPowerMode(STCD), GetCenterAddress(STCD), "FFFF", "FFFF", "FFFF"); #region tcp回复 if ((int)NFOINDEX == 1) { TcpService.TcpServer TS = Server as TcpService.TcpServer; List <TcpService.TcpSocket> Ts = TS.Ts; var tcps = from t in Ts where t.STCD == STCD && t.TCPSOCKET != null select t; List <TcpService.TcpSocket> Tcps = tcps.ToList <TcpService.TcpSocket>(); //没有该测站信息,不能向下执行,上“生成回复数据”没成功。 if (Answer == null) { ServiceBussiness.WriteQUIM("TCP", TS.ServiceID, STCD, "生成回复报出现异常!", new byte[] { }, Service.ServiceEnum.EnCoderType.ASCII, Service.ServiceEnum.DataType.Text); return; } if (Tcps.Count() > 0) { byte[] sendData = Encoding.ASCII.GetBytes(Answer); Tcps.First().TCPSOCKET.Send(sendData); //回复通知界面 ServiceBussiness.WriteQUIM("TCP", TS.ServiceID, STCD, "回复数据", sendData, Service.ServiceEnum.EnCoderType.ASCII, Service.ServiceEnum.DataType.Text); } } #endregion #region udp回复 if ((int)NFOINDEX == 2) { UdpService.UdpServer US = Server as UdpService.UdpServer; List <UdpService.UdpSocket> Us = US.Us; var udps = from u in Us where u.STCD == STCD && u.IpEndPoint != null select u; //没有该测站信息,不能向下执行,上“生成回复数据”没成功。 if (Answer == null) { ServiceBussiness.WriteQUIM("UDP", US.ServiceID, STCD, "生成回复报出现异常!", new byte[] { }, Service.ServiceEnum.EnCoderType.ASCII, Service.ServiceEnum.DataType.Text); return; } if (udps.Count() > 0) { byte[] sendData = Encoding.ASCII.GetBytes(Answer); US.UDPClient.Send(sendData, sendData.Length, udps.First().IpEndPoint); ServiceBussiness.WriteQUIM("UDP", US.ServiceID, STCD, "回复数据", sendData, Service.ServiceEnum.EnCoderType.ASCII, Service.ServiceEnum.DataType.Text); } } #endregion if (solution.IsUnpack) { int k = 0; foreach (DLYY.Model.WaterLevelInfo waterlevel in solution.Items) { int Milliseconds = (Convert.ToInt32(solution.N, 16) % 10) * 100 + (10 * k++); Service.Model.YY_DATA_REM model = new Model.YY_DATA_REM(); model.STCD = STCD; model.DATAVALUE = decimal.Parse(waterlevel.DATAVALUE); model.TM = DateTime.Parse(waterlevel.TM).AddMilliseconds(Milliseconds); model.DOWNDATE = DateTime.Now; model.NFOINDEX = (int)NFOINDEX; model.ItemID = waterlevel.ItemID; PublicBD.db.AddRemData(model); //k++; #region tcp通知界面 if ((int)NFOINDEX == 1) { TcpService.TcpServer TS = Server as TcpService.TcpServer; //回复通知界面 ServiceBussiness.WriteQUIM("TCP", TS.ServiceID, STCD, "提取到固态数据(有下一帧),数据特征[" + waterlevel.ItemID + "],时间[" + model.TM + "],值[" + model.DATAVALUE + "]", new byte[] { }, Service.ServiceEnum.EnCoderType.ASCII, Service.ServiceEnum.DataType.Text); } #endregion #region udp通知界面 if ((int)NFOINDEX == 2) { UdpService.UdpServer US = Server as UdpService.UdpServer; ServiceBussiness.WriteQUIM("UDP", US.ServiceID, STCD, "提取到固态数据(有下一帧),数据特征[" + waterlevel.ItemID + "],时间[" + model.TM + "],值[" + model.DATAVALUE + "]", new byte[] { }, Service.ServiceEnum.EnCoderType.ASCII, Service.ServiceEnum.DataType.Text); } #endregion #region gsm通知界面 if ((int)NFOINDEX == 3) { GsmService.GsmServer GS = Server as GsmService.GsmServer; ServiceBussiness.WriteQUIM("GSM", GS.ServiceID, STCD, "提取到固态数据(有下一帧),数据特征[" + waterlevel.ItemID + "],时间[" + model.TM + "],值[" + model.DATAVALUE + "]", new byte[] { }, Service.ServiceEnum.EnCoderType.ASCII, Service.ServiceEnum.DataType.Text); } #endregion #region com通知界面 if ((int)NFOINDEX == 4) { ComService.ComServer CS = Server as ComService.ComServer; Service.ServiceBussiness.WriteQUIM("COM", CS.ServiceID, STCD, "提取到固态数据(有下一帧),数据特征[" + waterlevel.ItemID + "],时间[" + model.TM + "],值[" + model.DATAVALUE + "]", new byte[] { }, Service.ServiceEnum.EnCoderType.HEX, Service.ServiceEnum.DataType.Text); } #endregion } } } catch (Exception ex) { log.Error(DateTime.Now + "06操作异常" + ex.ToString()); } }
//召测当前数据 internal static void Process_03(DLYY.Protocol.Solution <DLYY.Model.WaterLevelInfo> solution, Service.ServiceEnum.NFOINDEX NFOINDEX, object Server) { try{ string STCD = SetSTCD(solution, NFOINDEX, Server); #region //3上报后 中心端不做响应 //打回复包 103=0067 ---C //string Answer = pack.GetAnswer(solution.N, "0067", GetAuto(STCD), GetWaterLevelOrder(STCD), GetRainfallOrder(STCD), GetPowerMode(STCD), GetCenterAddress(STCD), "FFFF", "FFFF", "FFFF"); //#region tcp回复 //if ((int)NFOINDEX == 1) //{ // TcpService.TcpServer TS = Server as TcpService.TcpServer; // List<TcpService.TcpSocket> Ts = TS.Ts; // var tcps = from t in Ts where t.STCD == STCD && t.TCPSOCKET != null select t; // List<TcpService.TcpSocket> Tcps = tcps.ToList<TcpService.TcpSocket>(); // //没有该测站信息,不能向下执行,上“生成回复数据”没成功。 // if (Answer == null) // { // ServiceBussiness.WriteQUIM("TCP", TS.ServiceID, STCD, "生成回复报出现异常!", new byte[] { }, Service.ServiceEnum.EnCoderType.ASCII, Service.ServiceEnum.DataType.Text); // return; // } // if (Tcps.Count() > 0) // { // byte[] sendData = Encoding.ASCII.GetBytes(Answer); // Tcps.First().TCPSOCKET.Send(sendData); // //回复通知界面 // ServiceBussiness.WriteQUIM("TCP", TS.ServiceID, STCD, "回复数据", sendData, Service.ServiceEnum.EnCoderType.ASCII, Service.ServiceEnum.DataType.Text); // } //} //#endregion //#region udp回复 //if ((int)NFOINDEX == 2) //{ // UdpService.UdpServer US = Server as UdpService.UdpServer; // List<UdpService.UdpSocket> Us = US.Us; // var udps = from u in Us where u.STCD == STCD && u.IpEndPoint != null select u; // //没有该测站信息,不能向下执行,上“生成回复数据”没成功。 // if (Answer == null) // { // ServiceBussiness.WriteQUIM("UDP", US.ServiceID, STCD, "生成回复报出现异常!", new byte[] { }, Service.ServiceEnum.EnCoderType.ASCII, Service.ServiceEnum.DataType.Text); // return; // } // if (udps.Count() > 0) // { // byte[] sendData = Encoding.ASCII.GetBytes(Answer); // US.UDPClient.Send(sendData, sendData.Length, udps.First().IpEndPoint); // ServiceBussiness.WriteQUIM("UDP", US.ServiceID, STCD, "回复数据", sendData, Service.ServiceEnum.EnCoderType.ASCII, Service.ServiceEnum.DataType.Text); // } //} //#endregion #endregion if (solution.IsUnpack) { int k = 0; foreach (DLYY.Model.WaterLevelInfo waterlevel in solution.Items) { int Milliseconds = (Convert.ToInt32(solution.N, 16) % 10) * 100 + (10 * k++); PublicBD.db.AddRealTimeData(STCD, waterlevel.ItemID, DateTime.Parse(waterlevel.TM).AddMilliseconds(Milliseconds), DateTime.Now, (int)NFOINDEX, decimal.Parse(waterlevel.DATAVALUE)); //k++; string ItemName = GetItemName(waterlevel.ItemID); #region tcp通知界面 if ((int)NFOINDEX == 1) { TcpService.TcpServer TS = Server as TcpService.TcpServer; //回复通知界面 ServiceBussiness.WriteQUIM("TCP", TS.ServiceID, STCD, "召测到当前数据,数据特征[" + ItemName + "-" + waterlevel.ItemID + "],时间[" + waterlevel.TM + "],值[" + waterlevel.DATAVALUE + "]", new byte[] { }, Service.ServiceEnum.EnCoderType.ASCII, Service.ServiceEnum.DataType.Text); } #endregion #region udp通知界面 if ((int)NFOINDEX == 2) { UdpService.UdpServer US = Server as UdpService.UdpServer; ServiceBussiness.WriteQUIM("UDP", US.ServiceID, STCD, "召测到当前数据,数据特征[" + ItemName + "-" + waterlevel.ItemID + "],时间[" + waterlevel.TM + "],值[" + waterlevel.DATAVALUE + "]", new byte[] { }, Service.ServiceEnum.EnCoderType.ASCII, Service.ServiceEnum.DataType.Text); } #endregion #region gsm通知界面 if ((int)NFOINDEX == 3) { GsmService.GsmServer GS = Server as GsmService.GsmServer; ServiceBussiness.WriteQUIM("GSM", GS.ServiceID, STCD, "召测到当前数据,数据特征[" + ItemName + "-" + waterlevel.ItemID + "],时间[" + waterlevel.TM + "],值[" + waterlevel.DATAVALUE + "]", new byte[] { }, Service.ServiceEnum.EnCoderType.ASCII, Service.ServiceEnum.DataType.Text); } #endregion #region com通知界面 if ((int)NFOINDEX == 4) { ComService.ComServer CS = Server as ComService.ComServer; Service.ServiceBussiness.WriteQUIM("COM", CS.ServiceID, STCD, "召测到当前数据,数据特征[" + ItemName + "-" + waterlevel.ItemID + "],时间[" + waterlevel.TM + "],值[" + waterlevel.DATAVALUE + "]", new byte[] { }, Service.ServiceEnum.EnCoderType.HEX, Service.ServiceEnum.DataType.Text); } #endregion } } } catch (Exception ex) { log.Error(DateTime.Now + "03操作异常" + ex.ToString()); } }
/// <summary> /// 上传污染物小时数据 /// </summary> /// <param name="data"></param> /// <param name="NFOINDEX"></param> /// <param name="Server"></param> internal static void Process_2061(string data, Service.ServiceEnum.NFOINDEX NFOINDEX, object Server) { try { if (pd.GetValidataLength(data)) { string MN = pd.GetMN(data); DateTime DOWNDATE = DateTime.Now; CN_DataList CD = pd.GetValues(data); //获得回复---------------------------------- if (true) { #region tcp回复 if ((int)NFOINDEX == 1) { TcpService.TcpServer TS = Server as TcpService.TcpServer; List <TcpService.TcpSocket> Ts = TS.Ts; var tcps = from t in Ts where t.STCD == MN && t.TCPSOCKET != null select t; List <TcpService.TcpSocket> Tcps = tcps.ToList <TcpService.TcpSocket>(); //没有该测站信息,不能向下执行,上“生成回复数据”没成功。 if ("" == null)//生成回复报失败---------------------- { Service.ServiceBussiness.WriteQUIM("TCP", TS.ServiceID, MN, "生成回复报出现异常!", new byte[] { }, Service.ServiceEnum.EnCoderType.HEX, Service.ServiceEnum.DataType.Text); return; } if (Tcps.Count() > 0) { byte[] sendData = new byte[] { }; //回复报的内容------------------------------------- Tcps.First().TCPSOCKET.Send(sendData); //回复通知界面 Service.ServiceBussiness.WriteQUIM("TCP", TS.ServiceID, MN, "回复数据", sendData, Service.ServiceEnum.EnCoderType.HEX, Service.ServiceEnum.DataType.Text); } } #endregion #region udp回复 if ((int)NFOINDEX == 2) { UdpService.UdpServer US = Server as UdpService.UdpServer; List <UdpService.UdpSocket> Us = US.Us; var udps = from u in Us where u.STCD == MN && u.IpEndPoint != null select u; //没有该测站信息,不能向下执行,上“生成回复数据”没成功。 if ("" == null)//生成回复报失败---------------------- { Service.ServiceBussiness.WriteQUIM("UDP", US.ServiceID, MN, "生成回复报出现异常!", new byte[] { }, Service.ServiceEnum.EnCoderType.HEX, Service.ServiceEnum.DataType.Text); return; } if (udps.Count() > 0) { byte[] sendData = new byte[] { }; //回复报的内容------------------------------------- US.UDPClient.Send(sendData, sendData.Length, udps.First().IpEndPoint); Service.ServiceBussiness.WriteQUIM("UDP", US.ServiceID, MN, "回复数据", sendData, Service.ServiceEnum.EnCoderType.HEX, Service.ServiceEnum.DataType.Text); } } #endregion } if (CD.DM.Count() > 0) { for (int i = 0; i < CD.DM.Count(); i++) { string ItemName = null; #region //入实时表 Service.Model.YY_DATA_AUTO model = new Service.Model.YY_DATA_AUTO(); model.STCD = MN; model.TM = CD.TM; //监测时间 model.ItemID = CD.DM[i].ItemCode; //监测项 model.DOWNDATE = DOWNDATE; model.DATAVALUE = CD.DM[i].DATAVALUE; //值 model.CorrectionVALUE = CD.DM[i].DATAVALUE; //存入数据库,2015.8.25添加,请检查数据库YY_DATA_AUTO表是否建立STTYPE字段 model.STTYPE = CD.ST; model.NFOINDEX = (int)NFOINDEX; model.DATATYPE = int.Parse(CD.CN); #region //2061*100 + 1 =206101 =小时数据累计值 (参考HJT212_2005.ParseData.Key) model.DATATYPE = model.DATATYPE * 100 + Convert.ToInt32(Enum.Parse(typeof(HJT212_2005.ParseData.Key), CD.DM[i].KEY)); model.TM = model.TM.AddMilliseconds(10 * Convert.ToInt32(Enum.Parse(typeof(HJT212_2005.ParseData.Key), CD.DM[i].KEY))); //避免主键冲突 #endregion #region 环保212协议特殊添加 string s4 = model.DATATYPE.ToString().Substring(0, 4); string s2 = model.DATATYPE.ToString().Substring(4, 2); switch (s4) { case "2031": ItemName = "日"; break; case "2051": ItemName = "分钟"; break; case "2061": ItemName = "小时"; break; } switch (s2) { case "01": ItemName += "|累计|"; break; case "02": ItemName += "|最大|"; break; case "03": ItemName += "|最小|"; break; case "04": ItemName += "|平均|"; break; } #endregion ItemName += GetItemName(CD.DM[i].ItemCode); Service.PublicBD.db.AddRealTimeData(model); ////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////// ///////////////////////////////////////////////////////// #region tcp通知界面 if ((int)NFOINDEX == 1) { TcpService.TcpServer TS = Server as TcpService.TcpServer; //回复通知界面 Service.ServiceBussiness.WriteQUIM("TCP", TS.ServiceID, MN, "接收到小时数据,数据特征[" + ItemName + "-" + CD.DM[i].ItemCode + "],时间[" + CD.TM + "],值[" + CD.DM[i].DATAVALUE + "]", new byte[] { }, Service.ServiceEnum.EnCoderType.HEX, Service.ServiceEnum.DataType.Text); var list = from rtu in TS.Ts where rtu.STCD == MN select rtu; if (list.Count() > 0) { list.First().CanSend = false; } } #endregion #region udp通知界面 if ((int)NFOINDEX == 2) { UdpService.UdpServer US = Server as UdpService.UdpServer; Service.ServiceBussiness.WriteQUIM("UDP", US.ServiceID, MN, "接收到小时数据,数据特征[" + ItemName + "-" + CD.DM[i].ItemCode + "],时间[" + CD.TM + "],值[" + CD.DM[i].DATAVALUE + "]", new byte[] { }, Service.ServiceEnum.EnCoderType.HEX, Service.ServiceEnum.DataType.Text); var list = from rtu in US.Us where rtu.STCD == MN select rtu; if (list.Count() > 0) { list.First().CanSend = false; } } #endregion #region gsm通知界面 if ((int)NFOINDEX == 3) { GsmService.GsmServer GS = Server as GsmService.GsmServer; Service.ServiceBussiness.WriteQUIM("GSM", GS.ServiceID, MN, "接收到小时数据,数据特征[" + ItemName + "-" + CD.DM[i].ItemCode + "],时间[" + CD.TM + "],值[" + CD.DM[i].DATAVALUE + "]", new byte[] { }, Service.ServiceEnum.EnCoderType.HEX, Service.ServiceEnum.DataType.Text); } #endregion #region com通知界面 if ((int)NFOINDEX == 4) { ComService.ComServer CS = Server as ComService.ComServer; Service.ServiceBussiness.WriteQUIM("COM", CS.ServiceID, MN, "接收到小时数据,数据特征[" + ItemName + "-" + CD.DM[i].ItemCode + "],时间[" + CD.TM + "],值[" + CD.DM[i].DATAVALUE + "]", new byte[] { }, Service.ServiceEnum.EnCoderType.HEX, Service.ServiceEnum.DataType.Text); } #endregion #endregion } } } } catch (Exception ex) { log.Error(DateTime.Now + "2061操作异常" + ex.ToString()); } }