public static IdleMsg CreateNewMsg() { byte[] idleBytes = new byte[] { 0xFF,0xFF,0XFF,0XFF,0XFF}; IdleMsg msg = new IdleMsg(); msg.IpAndPort = ""; msg.ProtocolVersion = 0x01; msg.CycleNo = 0xFF; msg.Type = 0xFF; msg.SubType = 0xFF; msg.ErrorStatus = 0xFF; msg.DataLen = 1; msg.Encode(idleBytes); return msg; }
public static IdleMsg CreateNewMsg() { byte[] idleBytes = new byte[] { 0xFF, 0xFF, 0XFF, 0XFF, 0XFF }; IdleMsg msg = new IdleMsg(); msg.IpAndPort = ""; msg.ProtocolVersion = 0x01; msg.CycleNo = 0xFF; msg.Type = 0xFF; msg.SubType = 0xFF; msg.ErrorStatus = 0xFF; msg.DataLen = 1; msg.Encode(idleBytes); return(msg); }
public void ExecuteDecoderInternal() { LogHelper.GetLogger("job").Debug("Begin ProtocolFactory.ExecuteDecoderInternal()"); List <Original> originalData = rxQueue.PopAll(); if (originalData.Count != 0) { //先通信层解析,再应用层解析 foreach (Original original in originalData) { OriginalRxBytes oBytes = original as OriginalRxBytes; IPEndPoint ipEndPoint = oBytes.RemoteIpEndPoint; if (oBytes != null && oBytes.Data.Length > 9) { byte[] realData = frameProtocol.DePackage(oBytes.Data); if (realData != null && realData.Length > 10) { BaseMessage msg = null; byte type = realData[5]; if (decoders.ContainsKey(type)) { msg = decoders[type].Decode(realData, oBytes.RemoteIpEndPoint.ToString()); } else { //default } if (msg != null) { rxMsgQueue.Push(msg); } } } } } else { rxMsgQueue.Push(IdleMsg.CreateNewMsg()); } LogHelper.GetLogger("job").Debug("Finish ProtocolFactory.ExecuteDecoderInternal()"); }