Ejemplo n.º 1
0
        //对解出的帧,分命令进行处理
        private void CmdProcess(Package resp)
        {
            switch (resp.CMD)
            {
            case CmdEnum.CMD_INVENTORY:
                if ((InvReqFlg == false) && (AntiReqFlg == false) && (AutoReadHandler != null) && (resp.DataLen == UIDLEN))
                {
                    AutoReadEventArgs args = new AutoReadEventArgs();
                    args.comm.ReaderID = resp.ReaderID;
                    args.comm.addr     = AddrStr;
                    args.comm.port     = port_baud;
                    args.ant           = resp.Ant;
                    for (int i = 0; i < UIDLEN; i++)
                    {
                        args.UID[i] = resp.Datas[i];
                    }
                    AutoReadHandler.BeginInvoke(this, args, null, null);
                    return;
                }
                else if ((AntiReqFlg == true) && (resp.DataLen == UIDLEN))
                {
                    AntiResult.add(resp.Datas, resp.Ant);
                    return;
                }
                break;

            case CmdEnum.CMD_GPI_TRRIGER:
                if (GPITriggerHandler != null)
                {
                    GPITriggerEventArgs args = new GPITriggerEventArgs();
                    args.comm.ReaderID = resp.ReaderID;
                    args.comm.addr     = AddrStr;
                    args.comm.port     = port_baud;
                    if (resp.DataLen == 0)    //兼容前期未返回端口号的读写器软件
                    {
                        args.Gpi = GpiEnum.GPI_1;
                    }
                    else
                    {
                        args.Gpi = (GpiEnum)resp.Datas[0];
                    }
                    GPITriggerHandler.BeginInvoke(this, args, null, null);
                }
                return;

            default:
                break;
            }
            lock (Resp)
            {
                if (!WaitHeartBeatCmdResp || resp.CMD != HeartBeatCmd)
                {
                    Resp.copy(resp);
                }
                else
                {
                    HeartBeatResp.copy(resp);
                }
            }
        }
 private void HandlerHeatBeatResp(HeartBeatResp resp)
 {
     if (resp.OneWay)
     {
         ExchangeClient client = endpoint as ExchangeClient;
         client.Request(new HeartBeatReq(true));
     }
 }
Ejemplo n.º 3
0
        public HeartBeatResp S1_009(HeartBeatReq heartBeatReq)
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();

            try
            {
                string strhbReq = LogHelper.GetObjectMemberString(heartBeatReq);
                string strLog   = String.Format("Req:{0}:{{{1}}}", RequestIP, strhbReq);
                _log.Info(strLog);
            }
            catch (Exception ex)
            {
                string strLogErr = String.Format("Req Log Exception:{0}", ex.Message);
                _log.Error(strLogErr);
            }

            HeartBeatResp hbResponce = new HeartBeatResp();

            hbResponce.respCode = "9999";
            try
            {
                if (!String.IsNullOrEmpty(heartBeatReq.reqSysDate) && !String.IsNullOrEmpty(heartBeatReq.operationCode) && !String.IsNullOrEmpty(heartBeatReq.cityCode) && !String.IsNullOrEmpty(heartBeatReq.deviceId) && !String.IsNullOrEmpty(heartBeatReq.channelType))
                {
                    hbResponce.respCode = "0000";
                }
                else
                {
                    hbResponce.respCode = "0001";
                }
            }
            catch (Exception ex)
            {
                _log.Error(ex.Message);
                if (null != ex.InnerException)
                {
                    _log.Error(ex.InnerException.Message);
                }
            }

            try
            {
                string strhbResp = LogHelper.GetObjectMemberString(hbResponce);
                string strLog    = String.Format("Resp:{{{0}}}", strhbResp);

                _log.Info(strLog);
            }
            catch (Exception ex)
            {
                string strLogErr = String.Format("Resp Log Exception:{0}", ex.Message);
                _log.Error(strLogErr);
            }

            sw.Stop();
            TimeSpan ts = sw.Elapsed;

            _log.Debug(ts.TotalMilliseconds);

            return(hbResponce);
        }
Ejemplo n.º 4
0
        public object Decode(Remoting.Channel ch, Packet packet)
        {
            BinaryDataInput input = new BinaryDataInput(packet.Content);
            int             type  = packet.Header.Type;

            if (type == Packet.FLAG_HANDSNAKE)
            {
                HandSnakeResp resp = new HandSnakeResp();
                resp.DeserializeTo(input);
                return(resp);
            }
            else if (type == Packet.FLAG_HEARTBEAT)
            {
                HeartBeatResp req = new HeartBeatResp();
                req.DeserializeTo(input);
                return(req);
            }
            else if (type == Packet.FLAG_KICK)
            {
                KickClient kick = new KickClient();
                kick.DeserializeTo(input);
                return(kick);
            }
            else if (type == Packet.FLAG_MESSAGE)
            {
                int  mid   = input.ReadInt();
                byte mType = input.ReadByte();
                if (mType == AbstractMessage.TYPE_RESPONSE)
                {
                    Response response = new Response(mid);
                    response.Sequence  = input.ReadInt();
                    response.ErrorCode = input.ReadInt();
                    response.ErrorDes  = input.ReadUTF();
                    if (response.ErrorCode == Response.OK)
                    {
                        ResponseArg respArg = ResponseMappingInfo.Instance.CreateResponseMapping(mid) as ResponseArg;
                        if (respArg == null)
                        {
                            log.Error("Failed to handle response message,Cause : Cloud not found response mapper id :" + mid);
                        }
                        respArg.DeserializeTo(input);
                        response.Content = respArg;
                    }
                    return(response);
                }
                else if (mType == AbstractMessage.TYPE_PUSH)
                {
                    Push push = new Push(mid);
                    push.Identity = input.ReadInt();
                    ResponseArg respArg = ResponseMappingInfo.Instance.CreateResponseMapping(mid) as ResponseArg;
                    if (respArg == null)
                    {
                        log.Error("Failed to handle push message,Cause : Cloud not found response mapper id :" + mid);
                    }
                    respArg.DeserializeTo(input);
                    push.Content = respArg;
                    return(push);
                }
                else if (mType == AbstractMessage.TYPE_BROADCAST)
                {
                    BroadCast broadcast = new BroadCast(mid);
                    broadcast.Identity = input.ReadInt();
                    ResponseArg respArg = ResponseMappingInfo.Instance.CreateResponseMapping(mid) as ResponseArg;
                    if (respArg == null)
                    {
                        log.Error("Failed to handle broadcast message,Cause : Cloud not found response mapper id :" + mid);
                    }
                    respArg.DeserializeTo(input);
                    broadcast.Content = respArg;
                    return(broadcast);
                }
            }
            return(null);
        }