Пример #1
0
 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);
     }
 }
Пример #2
0
 public MotorProtocolFactory()
 {
     InitializeDecoders();
     TxQueue       = new MotorTxQueue();
     RxQueue       = new MotorRxQueue();
     RxMsgQueue    = new MotorRxMsgQueue();
     TxMsgQueue    = new MotorTxMsgQueue();
     MotorProtocol = new MotorProtocol();
 }
Пример #3
0
        public MotorProtocol DePackage(byte[] data)
        {
            MotorProtocol mp = new MotorProtocol();

            if (data.Length < 8)
            {
                LogHelper.GetLogger <MotorProtocol>().Error("通信层待编码数据为空,丢弃。");
                return(null);
            }
            mp.CodeRegion = new byte[data.Length - 8];
            Array.Copy(data, 6, mp.CodeRegion, 0, mp.CodeRegion.Length);
            return(mp);
        }