public byte[] HandResetDeviceCommand(MasProtocol masProtocol, ResetDeviceCommandRequest resetDevice, ref string deviceCode, ref int commPort) { DeviceInfo deviceinfoobject = null; DeviceTypeInfo devicetypeobject = null; NetworkDeviceInfo netmacobject = null; ResetDeviceRequestCommand commandobject = new ResetDeviceRequestCommand(); byte[] sendbuff = null; if (resetDevice == null) { return(sendbuff); } if (!GetDeviceObject(ref deviceinfoobject, ref devicetypeobject, ref netmacobject, ProtocolType.ResetDeviceCommandRequest, resetDevice.DeviceCode)) { return(sendbuff); } if (netmacobject.NetID > 0) { commPort = deviceinfoobject.K3; deviceCode = netmacobject.IP; //向下的发送的MAC地址 commandobject = Basic.Framework.Common.ObjectConverter.Copy <ResetDeviceCommandRequest, ResetDeviceRequestCommand>(resetDevice); //得到基础数据 commandobject.def = deviceinfoobject; //得到分站的对象必须是深度拷贝 sendbuff = commandobject.ToBytes(); //得到通讯命令的返回Buffer数组 } return(sendbuff); }
/// <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); }