예제 #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 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 && obytes.Data.Count() == 6)
                     {
                         LaserBaseResponse responseList = Decoder.Decode(obytes);
                         if (responseList != null)
                         {
                             RxMsgQueue.Push(responseList);
                         }
                         //LogHelper.GetLogger<LaserProtocolFactory>().Error(string.Format("接受到的原始数据为: {0}",
                         //        ByteHelper.Byte2ReadalbeXstring(obytes.Data)));
                     }
                 }
             }
         }
         Thread.Sleep(10);
     }
 }
예제 #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)
                     {
                         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);
     }
 }
예제 #4
0
        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()");
        }