Esempio n. 1
0
 public MotorProtocolFactory()
 {
     InitializeDecoders();
     TxQueue       = new MotorTxQueue();
     RxQueue       = new MotorRxQueue();
     RxMsgQueue    = new MotorRxMsgQueue();
     TxMsgQueue    = new MotorTxMsgQueue();
     MotorProtocol = new MotorProtocol();
 }
Esempio n. 2
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);
        }
Esempio n. 3
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)
                         {
                             if (obytes.Data[0] == 0x5D && obytes.Data[1] == 0x5B)
                             {
                                 MotorProtocol mp           = motorProtocol.DePackage(obytes.Data);
                                 byte[]        data         = mp.CodeRegion;
                                 byte          commandCode  = data[0];
                                 byte          additionCode = data[1];
                                 if (!Decoders.ContainsKey(commandCode))
                                 {
                                     return;
                                 }
                                 MotorBaseResponse mr = Decoders[commandCode].Decode(obytes);
                                 if (mr != null)
                                 {
                                     RxMsgQueue.Push(mr);
                                     //LogHelper.GetLogger<LaserProtocolFactory>().Error(string.Format("接受到的原始数据为: {0}",
                                     //    ByteHelper.Byte2ReadalbeXstring(obytes.Data)));
                                 }
                             }
                             else
                             {
                                 //LogHelper.GetLogger<LaserProtocolFactory>().Error(string.Format("接受到的原始数据非法: {0}",
                                 //    ByteHelper.Byte2ReadalbeXstring(obytes.Data)));
                             }
                         }
                     }
                 }
             }
         }
         Thread.Sleep(10);
     }
 }