Пример #1
0
 /// <summary>
 /// 处理泵端响应的命令机制为:
 /// 1、如果不是等待队列中第一条命令,丢弃
 /// 2、如果等待队列中第一条命令超时,丢弃
 /// </summary>
 /// <param name="cmd"></param>
 private void HandleReceivedCommand(long ip, BaseCommand cmd)
 {
     if (cmd == null)
     {
         Logger.Instance().Error("HandleReceivedCommand Failed! Because cmd is null");
         return;
     }
     if (cmd.Direction == 1)
     {
         //客户端的回应消息
         #region
         lock (m_WaitQueue)
         {
             BaseCommand currentCommand = m_WaitQueue.Peek(ip);
             if (currentCommand != null)
             {
                 if (cmd.MessageID == currentCommand.MessageID)
                 {
                     //命令匹配,执行回函数
                     currentCommand.Copy(cmd);           //需要全拷贝吗?这里只需要泵端传入的数据而已
                     currentCommand.InvokeResponse();
                     m_WaitQueue.Dequeue(ip, currentCommand);
                 }
                 else
                 {
                     if ((DateTime.Now.Ticks - currentCommand.TimeStamp) > (long)m_Timeout * 10000)
                     {
                         //超时了向上层发送超时信息
                         m_WaitQueue.Dequeue(ip, currentCommand);
                     }
                 }
             }
         }
         #endregion
     }
     else
     {
         //客户端主动上报的消息
         //这里要处理目前只有一个命令是主动上报的,就是上传报警信息
         if (UploadAlarm != null)
         {
             UploadAlarm(this, cmd);
         }
     }
 }