/// <summary> /// 获取交换机的基础信息 /// </summary> /// <param name="masProtocol"></param> /// <param name="deviceControl"></param> /// <param name="deviceCode"></param> /// <param name="commPort"></param> /// <returns></returns> public byte[] HandGetSwitchInfo(MasProtocol masProtocol, GetSwitchboardParamCommRequest getswicthInfo, ref string deviceCode) { NetworkDeviceInfo netmacobject = null; GetSwitchboardParamCommRequestCommand commandobject = new GetSwitchboardParamCommRequestCommand(); byte[] sendbuff = null; if (getswicthInfo == null) { return(sendbuff); } netmacobject = Cache.CacheManager.GetItemByKey <NetworkDeviceInfo>(getswicthInfo.DeviceCode, true);//按照IP搜索对象 if (netmacobject == null) { LogHelper.Error("获取交换机的基础信息,未找到对应的IP地址【" + getswicthInfo.DeviceCode + "】"); return(sendbuff); } lock (Cache.LockWorkNet)//用缓存的连接号和接收时间进行更新 { CacheNetWork curnet = Cache.LstWorkNet.Find(delegate(CacheNetWork p) { return(p.IP == netmacobject.IP); }); if (curnet != null) { netmacobject.NetID = curnet.NetID; } } if (netmacobject.NetID > 0) { deviceCode = netmacobject.IP; commandobject = Basic.Framework.Common.ObjectConverter.Copy <GetSwitchboardParamCommRequest, GetSwitchboardParamCommRequestCommand>(getswicthInfo); //得到基础数据 sendbuff = commandobject.ToBytes(); //得到通讯命令的返回Buffer数组 } return(sendbuff); }
/// <summary> /// 回发网络模块的状态至核心业务逻辑层 /// </summary> /// <param name="net">网络模块IP</param> private void SendNetStateToCenter(NetworkDeviceInfo net) { ProtocolDataCreatedEventArgs upData = new ProtocolDataCreatedEventArgs(); NetworkDeviceDataRequest cData = new NetworkDeviceDataRequest(); //网络模块自身的实时值数据 lock (Cache.LockWorkNet) //用缓存的网络设备进行操作 { CacheNetWork curnet = Cache.LstWorkNet.Find(delegate(CacheNetWork p) { return(p.IP == net.IP); }); if (curnet != null) { net.NetID = curnet.NetID; net.State = curnet.State; } } upData.DeviceCode = net.IP; upData.DriverCode = this.DriverCode; upData.MasProtocol = new MasProtocol(SystemType.Security, DirectionType.Up, ProtocolType.NetworkDeviceDataRequest); cData.DeviceCode = net.IP; cData.RealData = net.NetID.ToString(); cData.Address = net.IP; cData.Channel = net.MAC; if (net.State == 4) //直流 { cData.State = ItemState.EquipmentDC; } else if (net.State == 3) //交流 { cData.State = ItemState.EquipmentAC;; } upData.MasProtocol.Protocol = cData; OnProtocolData(upData); }
private int GetMacConnectionID(string mac) { int result = -1; lock (Cache.LockWorkNet) { CacheNetWork curnet = Cache.LstWorkNet.Find(delegate(CacheNetWork p) { return(p.MAC == mac); }); if (curnet != null) { result = curnet.NetID; } } return(result); }
private DateTime SetNetWorkNetID(NetworkDeviceInfo net) { DateTime result = DateTime.Now; lock (Cache.LockWorkNet) { CacheNetWork curnet = Cache.LstWorkNet.Find(delegate(CacheNetWork p) { return(p.IP == net.IP); }); if (curnet != null) { net.NetID = curnet.NetID; result = curnet.DttBridgeReceiveTime; } } return(result); }
public byte[] HandTimeSynchronization(MasProtocol masProtocol, TimeSynchronizationRequest timeSynchronization, ref string deviceCode, ref int commPort) { DeviceTypeInfo devicetypeobject = null; DeviceInfo deviceinfoobject = null; NetworkDeviceInfo netmacobject = null; TimeSynchronizationRequestCommand commandobject = new TimeSynchronizationRequestCommand(); byte[] sendbuff = null; if (timeSynchronization == null) { return(sendbuff); } if (timeSynchronization.DeviceCode.Length < 4) {//服务端只发下了分站号,自动生成分站的测点号 timeSynchronization.DeviceCode = timeSynchronization.DeviceCode.PadLeft(3, '0') + "0000"; } if (!GetDeviceObject(ref deviceinfoobject, ref devicetypeobject, ref netmacobject, ProtocolType.TimeSynchronizationRequest, timeSynchronization.DeviceCode)) { return(sendbuff); } lock (Cache.LockWorkNet)//用缓存的连接号和接收时间进行更新 { CacheNetWork curnet = Cache.LstWorkNet.Find(delegate(CacheNetWork p) { return(p.IP == netmacobject.IP); }); if (curnet != null) { netmacobject.NetID = curnet.NetID; } } if (netmacobject.NetID > 0) { commPort = timeSynchronization.CommPort; deviceCode = netmacobject.IP; //向下的发送的MAC地址 commandobject = Basic.Framework.Common.ObjectConverter.Copy <TimeSynchronizationRequest, TimeSynchronizationRequestCommand>(timeSynchronization); //得到基础数据 commandobject.def = deviceinfoobject; //得到分站的对象必须是深度拷贝 sendbuff = commandobject.ToBytes(); //得到通讯命令的返回Buffer数组 } return(sendbuff); }
private bool GetDeviceObject(ref DeviceInfo deviceInfoObject, ref DeviceTypeInfo deviceTypeObject, ref NetworkDeviceInfo netMacObject, ProtocolType pType, string deviceCode) { string ipstr = ""; List <NetworkDeviceInfo> lstNet = new List <NetworkDeviceInfo>(); deviceInfoObject = Cache.CacheManager.GetItemByKey <DeviceInfo>(deviceCode, true);//得到对应的分站对象 if (deviceInfoObject == null) { LogHelper.Info("未找到分站【" + deviceCode + "】:" + pType.ToString()); return(false); } Point = deviceInfoObject.Point; //用于外部显示分站号 ipstr = deviceInfoObject.Jckz2; //获取IP lstNet = Cache.CacheManager.Query <NetworkDeviceInfo>(p => (p.IP == ipstr) && (p.Upflag == "0"), true); if (lstNet.Count > 0) { netMacObject = lstNet[0]; } else { LogHelper.Info("未找到分站【" + deviceCode + "】对应的网络地址【" + deviceInfoObject.Jckz2 + "】:" + pType.ToString()); return(false); } lock (Cache.LockWorkNet)//用缓存的连接号进行更新 { CacheNetWork curnet = Cache.LstWorkNet.Find(delegate(CacheNetWork p) { return(p.IP == ipstr); }); if (curnet != null) { netMacObject.NetID = curnet.NetID; } } deviceTypeObject = Cache.CacheManager.GetItemByKey <DeviceTypeInfo>(deviceInfoObject.Devid, true);//按照devid搜索对象 if (deviceTypeObject == null) { LogHelper.Info("未找到分站【" + deviceCode + "】对应的设备类型【" + deviceInfoObject.Devid + "】:" + pType.ToString()); return(false); } return(true); }
public byte[] HandCallPersonCommand(MasProtocol masProtocol, CallPersonRequest callPerson, ref string deviceCode) { DeviceInfo deviceinfoobject = null; NetworkDeviceInfo netmacobject = null; CallPersonRequestCommand commandobject = new CallPersonRequestCommand(); byte[] sendbuff = null; if (callPerson == null) { return(sendbuff); } netmacobject = Cache.CacheManager.GetItemByKey <NetworkDeviceInfo>(callPerson.DeviceCode, true);//按照MAC搜索对象 if (netmacobject == null) { LogHelper.Error("呼叫命令,未找到对应的MAC地址【" + callPerson.DeviceCode + "】"); return(sendbuff); } lock (Cache.LockWorkNet)//用缓存的连接号和接收时间进行更新 { CacheNetWork curnet = Cache.LstWorkNet.Find(delegate(CacheNetWork p) { return(p.IP == netmacobject.IP); }); if (curnet != null) { netmacobject.NetID = curnet.NetID; } } if (netmacobject.NetID > 0) { deviceCode = netmacobject.IP; //向下的发送的MAC地址 commandobject = Basic.Framework.Common.ObjectConverter.Copy <CallPersonRequest, CallPersonRequestCommand>(callPerson); //得到基础数据 sendbuff = commandobject.ToBytes(); //得到通讯命令的返回Buffer数组 //if (sendbuff != null) //{ // sendbuff = Cache.GetPackages(sendbuff, netmacobject, deviceinfoobject, 2, CommandCodes.CallPersonCommand, 0);//通过当前网络模块进行打包 //} } return(sendbuff); }
/// <summary> /// 外包解包处理 /// </summary> /// <param name="data">收到的网络数据包</param> /// <returns></returns> public static KJ73NCommand ToCommand(byte[] data, NetworkDeviceInfo net) { KJ73NCommand command = new Commands.KJ73NCommand(); try { if (data.Length > 999 || data.Length < 4) { command.IsSuccess = false; command.errorMessage = "数据包总长度错误:【" + data.Length + "】"; return(command); } if (data[0] == 0x7F && (data[1] == 0x03 || data[1] == 0x10)) { if (data[1] == 0x03 && data.Length >= 40) { //数据回发 command.IsSuccess = true; command.PackageType = 2; //表示包类型---data[4] lock (Cache.LockWorkNet) //用缓存的网络设备进行操作 { CacheNetWork curnet = Cache.LstWorkNet.Find(delegate(CacheNetWork p) { return(p.IP == net.IP); }); if (curnet != null) { curnet.State = 3; } } } else if (data[1] == 0x10 && data.Length >= 7) { //控制回发 command.IsSuccess = true; command.PackageType = 2; //表示包类型---data[4] lock (Cache.LockWorkNet) //用缓存的网络设备进行操作 { CacheNetWork curnet = Cache.LstWorkNet.Find(delegate(CacheNetWork p) { return(p.IP == net.IP); }); if (curnet != null) { curnet.State = 3; } } } else { command.IsSuccess = false; command.errorMessage = string.Format("交换机回发错误:{0}-{1}-{2}-{3}", data[0], data[1], data[2], data.Length); return(command); } } else { if ((data[0] != 0x3E) && (data[1] != 0xE3) && (data[2] != 0x90) && (data[3] != 0x09)) { command.IsSuccess = false; command.errorMessage = string.Format("引导符错误:{0}-{1}-{2}-{3}", data[0], data[1], data[2], data[3]); return(command); } command.IsSuccess = true; command.PackageType = 1;//表示包类型---data[4] if (data[4] == 252) { command.PackageType = 2; //表示为交换机的状态信息数据包 } lock (Cache.LockWorkNet) //用缓存的网络设备进行操作 { CacheNetWork curnet = Cache.LstWorkNet.Find(delegate(CacheNetWork p) { return(p.IP == net.IP); }); if (curnet != null) { curnet.State = 3; } } } } catch (Exception ex) { command.IsSuccess = false; command.errorMessage = ex.Message; } return(command); }
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); }