private static QueryBatteryRealDataRequest GetQueryBatteryRealDataRequest(Jc_MacInfo macInfo) { QueryBatteryRealDataRequest queryBatteryRealDataRequest = new QueryBatteryRealDataRequest(); try { queryBatteryRealDataRequest.DeviceCode = macInfo.MAC; queryBatteryRealDataRequest.BatteryControl = macInfo.BatteryControl; queryBatteryRealDataRequest.DevProperty = ItemDevProperty.Switches; queryBatteryRealDataRequest.PowerPercentum = Convert.ToByte(GetSettingByKeyStr("DevicePowerPercentum").StrValue); } catch (Exception ex) { queryBatteryRealDataRequest.PowerPercentum = 20; LogHelper.Error("配置项【DevicePowerPercentum】值错误!" + ex.Message); } queryBatteryRealDataRequest.DevProperty = ItemDevProperty.Switches; queryBatteryRealDataRequest.BatteryControl = macInfo.BatteryControl; return(queryBatteryRealDataRequest); }
/// <summary> /// 判断需要向交换机下发的命令, 修改支持命令同时发送 20171207 /// </summary> /// <param name="mac"></param> /// <param name="macItems"></param> /// <returns></returns> public static List <MasProtocol> GetMacSendData(string mac, List <Jc_MacInfo> macItems) { List <MasProtocol> masProtocolList = new List <MasProtocol>(); try { Jc_MacInfo macInfo = macItems.FirstOrDefault(a => a.MAC == mac); if (macInfo != null) { if ((macInfo.NCommandbz & 0x02) == 0x02) { #region ----下发模拟报警---- ResetDeviceCommandRequest resetDeviceCommandRequest = new ResetDeviceCommandRequest(); resetDeviceCommandRequest.DeviceCode = mac; resetDeviceCommandRequest.LastAcceptFlag = (byte)macInfo.testAlarmFlag; resetDeviceCommandRequest.Mac = mac; MasProtocol masProtocol = null; masProtocol = new MasProtocol(SystemType.Security, DirectionType.Down, ProtocolType.ResetNetWorkDeviceRequest); masProtocol.Protocol = resetDeviceCommandRequest; masProtocolList.Add(masProtocol); Dictionary <string, object> updateItems = new Dictionary <string, object>(); updateItems.Add("sendAlarmCount", macInfo.sendAlarmCount--); if (macInfo.sendAlarmCount <= 0) { updateItems.Add("NCommandbz", (macInfo.NCommandbz & 0xFD)); } CacheDataHelper.UpdateNetworkModeuleCacheByPropertys(macInfo.MAC, updateItems); LogHelper.Info(macInfo.MAC + "下发模拟报警,待下发" + macInfo.sendAlarmCount + "次"); #endregion } if (((macInfo.NCommandbz & 0x01) == 0x01) || macInfo.SendBatteryControlCount > 0) { #region ----获取智能电源箱数据---- if ((DateTime.Now - macInfo.SendDtime).TotalSeconds <= 15) { if (macInfo.Type == 0 && macInfo.Bz4 == "1")//Bz4 = 1表示带智能电源箱 { QueryBatteryRealDataRequest queryBatteryRealDataRequest = GetQueryBatteryRealDataRequest(macInfo); MasProtocol masProtocol = null; masProtocol = new MasProtocol(SystemType.Security, DirectionType.Down, ProtocolType.QueryBatteryRealDataRequest); masProtocol.Protocol = queryBatteryRealDataRequest; masProtocolList.Add(masProtocol); } } #endregion } #region ----人员定位呼叫命令(屏蔽 20180307) ---- //R_CallInfo tempCallInfo; //string[] startAndEnd; //int tempInt = 0; //string tempStr; //List<R_CallInfo> callItems = KJ237CacheHelper.GetCallItems().Where(a => a.CallType != 2).OrderBy(a => a.CallTime).ToList(); //if (callItems.Count > 0)//下发紧急呼叫及一般呼叫 20171206 //{ // //先查找人员的全员呼叫命令并下发(呼叫所有设备与呼叫所有人员为同一命令)(优先级最高) // List<R_CallInfo> sendCallList = callItems.FindAll(a => a.CallType == 1 && (a.CallPersonDefType == 0 || a.CallPersonDefType == 3)); // if (sendCallList.Count > 0)//全员呼叫下发 // { // if (sendCallList[0].SendCount > 0)//判断是否还需要下发 20171213 // { // CallPersonRequest request = new CallPersonRequest(); // request.HJ_Type = 0; // request.HJ_State = 2; // request.DeviceCode = mac; // request.HJ_KH = new ushort[12]; // MasProtocol masProtocol = null; // masProtocol = new MasProtocol(SystemType.Personnel, DirectionType.Down, ProtocolType.CallPersonRequest); // masProtocol.Protocol = request; // masProtocolList.Add(masProtocol); // } // } // else // { // #region//紧急呼叫井下设备 // List<R_CallInfo> sendCallListByPoint = callItems.FindAll(a => a.CallType == 1 && (a.CallPersonDefType == 4)); // if (sendCallListByPoint.Count > 0) // { // if (sendCallListByPoint[0].SendCount > 0)//判断是否还需要下发 20171213 // { // CallPersonRequest request = new CallPersonRequest(); // request.HJ_Type = 4; // request.HJ_State = 2; // request.DeviceCode = mac; // List<ushort> callContent = new List<ushort>(); // foreach (R_CallInfo call in sendCallListByPoint) // { // string[] callList = call.PointList.Split(','); // foreach (string tempCall in callList) // { // callContent.Add(Convert.ToUInt16(((Convert.ToInt64(tempCall.Substring(0, 3)) << 8)) + Convert.ToInt64(tempCall.Substring(4, 2)))); // if (callContent.Count == 12) // { // request.HJ_KH = callContent.ToArray(); // MasProtocol masProtocol = null; // masProtocol = new MasProtocol(SystemType.Personnel, DirectionType.Down, ProtocolType.CallPersonRequest); // masProtocol.Protocol = request; // masProtocolList.Add(masProtocol); // callContent = new List<ushort>(); // } // } // } // if (callContent.Count > 0) // { // request.HJ_KH = new ushort[12]; // for (int i = 0; i < callContent.Count; i++) // { // request.HJ_KH[i] = callContent[i]; // } // MasProtocol masProtocol = null; // masProtocol = new MasProtocol(SystemType.Personnel, DirectionType.Down, ProtocolType.CallPersonRequest); // masProtocol.Protocol = request; // masProtocolList.Add(masProtocol); // } // } // } // #endregion // #region//紧急呼叫指定人员及指定卡号段下发,卡号段也按指定人员下发 // List<R_CallInfo> sendCallListByPerson = callItems.FindAll(a => a.CallType == 1 && (a.CallPersonDefType == 1 || a.CallPersonDefType == 2)); // if (sendCallListByPerson.Count > 0) // { // if (sendCallListByPerson[0].SendCount > 0)//判断是否还需要下发 20171213 // { // CallPersonRequest request = new CallPersonRequest(); // request.HJ_Type = 2; // request.HJ_State = 2; // request.DeviceCode = mac; // List<ushort> callContent = new List<ushort>(); // foreach (R_CallInfo call in sendCallListByPerson) // { // if (call.BhContent.Contains("-")) // {//指定卡号段呼叫 // ushort sBh = ushort.Parse(call.BhContent.Split('-')[0]); // ushort eBh = ushort.Parse(call.BhContent.Split('-')[1]); // for (ushort i = sBh; i <= eBh; i++) // { // callContent.Add(i); // if (callContent.Count == 12) // { // request.HJ_KH = callContent.ToArray(); // MasProtocol masProtocol = null; // masProtocol = new MasProtocol(SystemType.Personnel, DirectionType.Down, ProtocolType.CallPersonRequest); // masProtocol.Protocol = request; // masProtocolList.Add(masProtocol); // callContent = new List<ushort>(); // } // } // } // else//指定卡号呼叫 // { // string[] callList = call.BhContent.Split(','); // foreach (string tempCall in callList) // { // callContent.Add(ushort.Parse(tempCall)); // if (callContent.Count == 12) // { // request.HJ_KH = callContent.ToArray(); // MasProtocol masProtocol = null; // masProtocol = new MasProtocol(SystemType.Personnel, DirectionType.Down, ProtocolType.CallPersonRequest); // masProtocol.Protocol = request; // masProtocolList.Add(masProtocol); // callContent = new List<ushort>(); // } // } // } // } // if (callContent.Count > 0) // { // request.HJ_KH = new ushort[12]; // for (int i = 0; i < callContent.Count; i++) // { // request.HJ_KH[i] = callContent[i]; // } // MasProtocol masProtocol = null; // masProtocol = new MasProtocol(SystemType.Personnel, DirectionType.Down, ProtocolType.CallPersonRequest); // masProtocol.Protocol = request; // masProtocolList.Add(masProtocol); // } // } // } // #endregion // if (sendCallListByPerson.Count == 0 && sendCallListByPoint.Count == 0) // {//如果不存在紧急呼叫,则判断一般呼叫并下发 // List<R_CallInfo> sendGeneralCallListAll = callItems.FindAll(a => a.CallType == 0 && (a.CallPersonDefType == 0 || a.CallPersonDefType == 3)); // if (sendGeneralCallListAll.Count > 0)//全员呼叫下发 // { // if (sendGeneralCallListAll[0].SendCount > 0)//判断是否还需要下发 20171213 // { // CallPersonRequest request = new CallPersonRequest(); // request.HJ_Type = 0; // request.HJ_State = 1; // request.DeviceCode = mac; // request.HJ_KH = new ushort[12]; // MasProtocol masProtocol = null; // masProtocol = new MasProtocol(SystemType.Personnel, DirectionType.Down, ProtocolType.CallPersonRequest); // masProtocol.Protocol = request; // masProtocolList.Add(masProtocol); // } // } // #region//一般呼叫井下设备 // List<R_CallInfo> sendGeneralCallListByPoint = callItems.FindAll(a => a.CallType == 0 && (a.CallPersonDefType == 4)); // if (sendGeneralCallListByPoint.Count > 0) // { // if (sendGeneralCallListByPoint[0].SendCount > 0)//判断是否还需要下发 20171213 // { // CallPersonRequest request = new CallPersonRequest(); // request.HJ_Type = 4; // request.HJ_State = 1; // request.DeviceCode = mac; // List<ushort> callContent = new List<ushort>(); // foreach (R_CallInfo call in sendGeneralCallListByPoint) // { // string[] callList = call.PointList.Split(','); // foreach (string tempCall in callList) // { // callContent.Add(Convert.ToUInt16(((Convert.ToInt64(tempCall.Substring(0, 3)) << 8)) + Convert.ToInt64(tempCall.Substring(4, 2)))); // if (callContent.Count == 12) // { // request.HJ_KH = callContent.ToArray(); // MasProtocol masProtocol = null; // masProtocol = new MasProtocol(SystemType.Personnel, DirectionType.Down, ProtocolType.CallPersonRequest); // masProtocol.Protocol = request; // masProtocolList.Add(masProtocol); // callContent = new List<ushort>(); // } // } // } // if (callContent.Count > 0) // { // request.HJ_KH = new ushort[12]; // for (int i = 0; i < callContent.Count; i++) // { // request.HJ_KH[i] = callContent[i]; // } // MasProtocol masProtocol = null; // masProtocol = new MasProtocol(SystemType.Personnel, DirectionType.Down, ProtocolType.CallPersonRequest); // masProtocol.Protocol = request; // masProtocolList.Add(masProtocol); // } // } // } // #endregion // #region//一般呼叫指定人员及指定卡号段下发,卡号段也按指定人员下发 // List<R_CallInfo> sendGeneralCallListByPerson = callItems.FindAll(a => a.CallType == 0 && (a.CallPersonDefType == 1 || a.CallPersonDefType == 2)); // if (sendGeneralCallListByPerson.Count > 0) // { // if (sendGeneralCallListByPerson[0].SendCount > 0)//判断是否还需要下发 20171213 // { // CallPersonRequest request = new CallPersonRequest(); // request.HJ_Type = 2; // request.HJ_State = 1; // request.DeviceCode = mac; // List<ushort> callContent = new List<ushort>(); // foreach (R_CallInfo call in sendGeneralCallListByPerson) // { // if (call.BhContent.Contains("-")) // {//指定卡号段呼叫 // ushort sBh = ushort.Parse(call.BhContent.Split('-')[0]); // ushort eBh = ushort.Parse(call.BhContent.Split('-')[1]); // for (ushort i = sBh; i <= eBh; i++) // { // callContent.Add(i); // if (callContent.Count == 12) // { // request.HJ_KH = callContent.ToArray(); // MasProtocol masProtocol = null; // masProtocol = new MasProtocol(SystemType.Personnel, DirectionType.Down, ProtocolType.CallPersonRequest); // masProtocol.Protocol = request; // masProtocolList.Add(masProtocol); // callContent = new List<ushort>(); // } // } // } // else//指定卡号呼叫 // { // string[] callList = call.BhContent.Split(','); // foreach (string tempCall in callList) // { // callContent.Add(ushort.Parse(tempCall)); // if (callContent.Count == 12) // { // request.HJ_KH = callContent.ToArray(); // MasProtocol masProtocol = null; // masProtocol = new MasProtocol(SystemType.Personnel, DirectionType.Down, ProtocolType.CallPersonRequest); // masProtocol.Protocol = request; // masProtocolList.Add(masProtocol); // callContent = new List<ushort>(); // } // } // } // } // if (callContent.Count > 0) // { // request.HJ_KH = new ushort[12]; // for (int i = 0; i < callContent.Count; i++) // { // request.HJ_KH[i] = callContent[i]; // } // MasProtocol masProtocol = null; // masProtocol = new MasProtocol(SystemType.Personnel, DirectionType.Down, ProtocolType.CallPersonRequest); // masProtocol.Protocol = request; // masProtocolList.Add(masProtocol); // } // } // } // #endregion // } // } //} //else//如果不存在紧急呼叫和一般呼叫命令则下发解除呼叫命令 20171206 //{ // callItems = KJ237CacheHelper.GetCallItems().Where(a => a.CallType == 2).OrderBy(a => a.CallTime).ToList(); // if (callItems.Count > 0) // { // CallPersonRequest request = new CallPersonRequest(); // request.HJ_Type = 0; // request.HJ_State = 0; // request.DeviceCode = mac; // request.HJ_KH = new ushort[12]; // MasProtocol masProtocol = null; // masProtocol = new MasProtocol(SystemType.Personnel, DirectionType.Down, ProtocolType.CallPersonRequest); // masProtocol.Protocol = request; // masProtocolList.Add(masProtocol); // } //} #endregion } } catch (Exception ex) { LogHelper.Error("获取向交换机下发的命令失败,原因:" + ex); } return(masProtocolList); }
public byte[] HandQueryBatteryRealData(MasProtocol masProtocol, QueryBatteryRealDataRequest batteryRealData, ref string deviceCode, ref int commPort) { List <NetworkDeviceInfo> lstNet = new List <NetworkDeviceInfo>(); DeviceInfo deviceinfoobject = null; DeviceTypeInfo devicetypeobject = null; NetworkDeviceInfo netmacobject = null; BatteryRealDataRequestCommand commandobject = new BatteryRealDataRequestCommand(); byte[] sendbuff = null; if (batteryRealData == null) { return(sendbuff); } if (batteryRealData.DevProperty == ItemDevProperty.Switches) {//如果是交换机的操作,仅获取对应的网络地址即可。 lstNet = Cache.CacheManager.Query <NetworkDeviceInfo>(p => (p.MAC == batteryRealData.DeviceCode) && (p.Upflag == "1"), true); if (lstNet.Count > 0) { netmacobject = lstNet[0]; } //netmacobject = Cache.CacheManager.GetItemByKey<NetworkDeviceInfo>(batteryRealData.DeviceCode, true);//按照MAC搜索对象 if (netmacobject == null) { LogHelper.Error("查询交换机的电源,未找到对应的IP地址【" + batteryRealData.DeviceCode + "】"); return(sendbuff); } lock (Cache.LockWorkNet)//用缓存的连接号和接收时间进行更新 { CacheNetWork curnet = Cache.LstWorkNet.Find(delegate(CacheNetWork p) { return(p.IP == netmacobject.Bz6); }); if (curnet != null) { netmacobject.NetID = curnet.NetID; } } } else { if (!GetDeviceObject(ref deviceinfoobject, ref devicetypeobject, ref netmacobject, ProtocolType.QueryBatteryRealDataRequest, batteryRealData.DeviceCode)) { return(sendbuff); } } if (netmacobject.NetID > 0) { if (batteryRealData.DevProperty == ItemDevProperty.Switches) { deviceCode = netmacobject.Bz6;//向下的发送的MAC地址 commPort = 1; } else { commPort = deviceinfoobject.K3; deviceCode = netmacobject.IP; //向下的发送的MAC地址 } commandobject = Basic.Framework.Common.ObjectConverter.Copy <QueryBatteryRealDataRequest, BatteryRealDataRequestCommand>(batteryRealData); //得到基础数据 if (devicetypeobject != null) { commandobject.OrderVersion = (byte)devicetypeobject.LC2; } commandobject.def = deviceinfoobject; // Framework.Common.ObjectConverter.DeepCopy<DeviceInfo>(deviceinfoobject);//得到分站的对象必须是深度拷贝 commandobject.NetMacObject = netmacobject; sendbuff = commandobject.ToBytes(); //得到通讯命令的返回Buffer数组 } return(sendbuff); }