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) { MotorProtocol mp = motorProtocol.DePackage(obytes.Data); byte[] data = mp.CodeRegion; byte commandCode = data[0]; byte additionCode = data[1]; MotorBaseResponse mr = Decoders[commandCode].Decode(obytes); if (mr != null) { RxMsgQueue.Push(mr); LogHelper.GetLogger <LaserProtocolFactory>().Error(string.Format("接受到的原始数据为: {0}", ByteHelper.Byte2ReadalbeXstring(obytes.Data))); } } } } } } Thread.Sleep(10); } }
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 virtual MotorBaseResponse Decode(OriginalBytes obytes) { if (obytes.Data.Length < 10) { LogHelper.GetLogger <LaserBaseResponse>().Error(string.Format("消息类型为 : {0} 长度不足!", obytes.Data[1])); return(null); } return(null); }
public void EncodeInternal() { while (RunEncodeThread) { if (Encode) { List <MotorBaseRequest> list = txMsgQueue.PopAll(); if (list != null && list.Count > 0) { foreach (var mr in list) { CIIBasePackage bp = mr.Encode(); OriginalBytes ob = new OriginalBytes(); ob.Data = motorProtocol.EnPackage(bp); txQueue.Push(ob); } } } Thread.Sleep(10); } }
public virtual List <LaserBaseResponse> Decode(LaserBasePackage bp, OriginalBytes obytes) { if (obytes.Data.Length != 6) { LogHelper.GetLogger <LaserBaseResponse>().Error(string.Format("消息类型为 : {0} 长度不足!", obytes.Data[1])); return(null); } byte oddCheck = obytes.Data[1]; for (int i = 2; i < obytes.Data.Length - 2; i++) { oddCheck ^= obytes.Data[i]; } if (oddCheck != obytes.Data[obytes.Data.Length - 2]) { LogHelper.GetLogger <LaserBaseResponse>().Error(string.Format("消息类型为 : {0} 的奇偶校验位错误!", obytes.Data[1])); return(null); } else { return(Decode(bp, obytes)); } }
public void EncodeInternal() { while (RunEncodeThread) { if (Encode) { List <LaserBaseRequest> list = txMsgQueue.PopAll(); if (list != null && list.Count > 0) { foreach (var br in list) { List <LaserBasePackage> bps = br.Encode(); foreach (LaserBasePackage bp in bps) { OriginalBytes ob = new OriginalBytes(); ob.Data = laserProtocol.EnPackage(bp); txQueue.Push(ob); } } } } Thread.Sleep(10); } }