Example #1
0
 private void MessageTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
 {
     RetryTimer.Stop();
     if (retryCount >= 3)
     {
         return;
     }
     if (CommandState == DeviceState.EOESent)
     {
         if (LastCtxtForWhichSentEoE != null)
         {
             LastCtxtForWhichSentEoE.RequestContext.ResponseQCallback(LastCtxtForWhichSentEoE.Response);
             retryCount++;
             RetryTimer.Start();
         }
     }
     else
     {
         throw new ApplicationException("Invalid Retry control flow detected");
     }
 }
Example #2
0
        public void ProcessOther(CommandContext cmdCxt, BaseMessage categorizedCommand)
        {
            //if (AppConfiguration.useSequenceNumber)
            //{
            //    int sn = commandBeingProcessed.SeqNum.Value;

            //    if (CommandState == DeviceState.None || commandBeingProcessed.CommandName.Equals("INIT"))//first time or reinit
            //    {
            //        SeqNum = sn;
            //        //CommandState = DeviceState.Ready;
            //    }
            //    else
            //    {
            //        if (sn == SeqNum + 1)
            //        {
            //            SeqNum = sn;
            //        }
            //        else if (sn == SeqNum)
            //        {
            //            CommandState = DeviceState.ErrorSent;
            //            cmdCxt.ResponseQCallback($"Duplicate Sequence number. Received {sn}");
            //            return;
            //        }
            //        else
            //        {
            //            CommandState = DeviceState.ErrorSent;
            //            cmdCxt.ResponseQCallback($"Sequence number out of order. Received {sn}");
            //            return;
            //        }
            //    }

            //}
            commandBeingProcessed = categorizedCommand;

            if (IsError && !commandBeingProcessed.CommandName.Equals("INIT"))
            {
                cmdCxt.ResponseQCallback(ReceptionError.Generate("2001"));
                CommandState = DeviceState.ErrorSent;
                return;
            }

            if (commandBeingProcessed.Type == MessageType.Ack)
            {
                if (CommandState == DeviceState.Ready)
                {
                    return;//Duplicate ACK
                }
                while (CommandState != DeviceState.EOESent)
                {
                    Thread.Sleep(0);
                }

                RetryTimer.Stop();
                LastCtxtForWhichSentEoE = null;
                retryCount   = 0;
                CommandState = DeviceState.Ready;
                IsReady      = true;
                return;
            }

            if ((CommandState == DeviceState.EOESent || CommandState == DeviceState.CommandResponseSent) &&
                commandBeingProcessed.CommandName.Equals("INIT"))
            {
                RetryTimer.Stop();
                LastCtxtForWhichSentEoE = null;
                retryCount   = 0;
                CommandState = DeviceState.Ready;
                IsReady      = true;
            }
            else if (!(CommandState == DeviceState.None ||
                       CommandState == DeviceState.Ready ||
                       CommandState == DeviceState.CommandResponseSent ||
                       CommandState == DeviceState.ErrorSent ||
                       CommandState == DeviceState.EventSent))
            {
                cmdCxt.ResponseQCallback(ReceptionError.Generate("9001"));
                CommandState = DeviceState.ErrorSent;
                return;
            }

            commandBeingProcessed.PreProcess(cmdCxt, this);

            if (commandBeingProcessed.Type == MessageType.Action || commandBeingProcessed.Type == MessageType.Control)
            {
                commandBeingProcessed.Process(cmdCxt, this);
            }
        }