public void GetDtuList(int uID, string sID, string cmds, string gprsNum, bool isset) { try { DownRequest request = new DownRequest { StationId = sID, Cmds = cmds, GprsNum = gprsNum, IsSet = isset }; DownConf info = grpcClient.GetDownConf(request); downConfList = new CDictionary <int, DownConf>(); if (info != null) { if (downConfList.ContainsKey(uID)) { downConfList[uID] = info; } else { downConfList.Add(uID, info); } } } catch (Exception exp) { Debug.WriteLine("RPC failed" + exp); throw; } }
/// <summary> /// 检查上行数据列表中是否存在对应请求的数据 /// </summary> /// <param name="DownRequest"></param> /// <returns></returns> private DownConf CheckDownConf(DownRequest DownRequest) { DownConf checkedDownConf = new DownConf(); List <DownConf> downDataList = this.downConfList; foreach (var downdata in downDataList) { if (downdata.TRU == true) { checkedDownConf = downdata; checkedDownConf.IsOL = true; downdataGet = true; break; } if (downdata.StationCmdID == DownRequest.StationId) { checkedDownConf = downdata; checkedDownConf.IsOL = true; downdataGet = true; break; } } return(checkedDownConf); }
/// <summary> /// 处理请求方法,向终端发送请求并返回上行数据 /// </summary> /// <param name="DownRequest"></param> /// <returns></returns> private DownConf GetDownConf(DownRequest DownRequest) { m_timer.Start(); DownConf result = new DownConf(); downConfList = null; downConfList = new List <DownConf>(); downdataGet = false; string downQuery = string.Empty; gprsNum = DownRequest.GprsNum; stationId = DownRequest.StationId; cmds = DownRequest.Cmds; isSet = DownRequest.IsSet; if (isSet == false) { List <EDownParam> query = new List <EDownParam>(); for (int i = cmds.Length; i > 0; i = i - 2) { string downParamValue = cmds.Substring(0, 2); EDownParam downParamKey = ProtocolMaps.DownParamMap.FindKey(downParamValue); query.Add(downParamKey); cmds = cmds.Substring(2); } downQuery = CPortDataMgr.Instance.SendGprsRead_BS(gprsNum, stationId, query); if (downQuery == "") { result.IsOL = false; return(result); } } else if (isSet == true) { StringBuilder query = new StringBuilder(); query.Append(ProtocolMaps.ChannelProtocolStartCharMap.FindValue(EChannelType.GPRS)); query.Append(String.Format("{0:D4}", Int32.Parse(stationId.Trim()))); query.Append("0S"); query.Append(cmds); //while(cmds.Length > 0) //{ // try // { // query.Append(CSpecialChars.BALNK_CHAR); // string downParamValue = cmds.Substring(0, 2); // query.Append(downParamValue); // EDownParam downParamKey = ProtocolMaps.DownParamMap.FindKey(downParamValue); // int downParamLength = int.Parse(ProtocolMaps.DownParamLengthMap.FindValue(downParamKey)); // string downData = cmds.Substring(2, downParamLength); // query.Append(downData); // cmds = cmds.Substring(2 + downParamLength); // } // catch (Exception e) // { // Debug.WriteLine("下行指令解析失败" + e.Message); // } //} query.Append(CSpecialChars.ENTER_CHAR); var gprs = CPortDataMgr.Instance.FindGprsByUserid(gprsNum); if (gprs != null) { uint dtuID = 0; if (gprs.FindByID(gprsNum, out dtuID)) { gprs.SendDataTwice(dtuID, query.ToString()); } else { result.IsOL = false; return(result); } } else { result.IsOL = false; return(result); } } result = CheckDownConf(DownRequest); while (!downdataGet) { Thread.Sleep(1000); result = CheckDownConf(DownRequest); if (timeDown) { timeDown = false; break; } } m_timer.Stop(); return(result); }
/// <summary> /// get方法 据说是客户端可以调用的 /// </summary> /// <param name="DownRequest"></param> /// <param name="context"></param> /// <returns></returns> public override Task <DownConf> GetFeature(DownRequest DownRequest, ServerCallContext context) { return(Task.FromResult(GetDownConf(DownRequest))); }