public void DecodeInternal() { while (RunDecodeThread) { if (Decode) { List <Original> list = RxQueue.PopAll(); if (list != null && list.Count > 0) { foreach (var o in list) { OriginalBytes obytes = o as OriginalBytes; if (o != null) { LaserProtocol lp = laserProtocol.DePackage(obytes.Data); byte[] data = lp.Body; byte markHead = data[0]; byte type = GetMsgType(); byte[] appData = new byte[data.Length - 2]; Array.Copy(data, 1, appData, 0, data.Length - 2); LaserBasePackage bp = new LaserBasePackage(markHead, type, appData); List <LaserBaseResponse> responseList = Decoder.Decode(bp, obytes); if (responseList != null && responseList.Count > 0) { RxMsgQueue.Push(responseList); } LogHelper.GetLogger <LaserProtocolFactory>().Error(string.Format("接受到的原始数据为: {0}", ByteHelper.Byte2ReadalbeXstring(obytes.Data))); } } } } Thread.Sleep(10); } }
public LaserProtocolFactory() { InitializeDecoders(); TxQueue = new LaserTxQueue(); RxQueue = new LaserRxQueue(); RxMsgQueue = new LaserRxMsgQueue(); TxMsgQueue = new LaserTxMsgQueue(); LaserProtocol = new LaserProtocol(); }
public LaserProtocol DePackage(byte[] data) { LaserProtocol lp = new LaserProtocol(); if (data == null) { LogHelper.GetLogger <LaserProtocol>().Error("通信层接收到数据包为空或者数据长度不足,丢弃。"); return(null); } if (data[0] != deMarkHead) { LogHelper.GetLogger <LaserProtocol>().Error("通信层接收到数据包不是本应用需要接受的数据包,丢弃。"); return(null); } lp.Body = new byte[data.Length - 1]; Array.Copy(data, 1, lp.Body, 0, data.Length - 1); return(lp); }