Exemplo n.º 1
0
        //----------------------------------------
        #region SimpleActivePart overridden methods

        /// <summary>
        /// Implemenation for for required GoOnline Action: runs the corresponding command on the related IPort instance and returns its result
        /// </summary>
        protected override string PerformGoOnlineAction(bool andInitialize)
        {
            IBasicAction iba = (IBasicAction)port.CreateGoOnlineAction(andInitialize);
            string       rc  = iba.Run();

            PerformMainLoopService();
            return(rc);
        }
Exemplo n.º 2
0
 /// <summary>Provides the implementation of the Standard GoOnline Action.  Runs a pass through GoOnline action on the contained Port object.</summary>
 protected override string PerformGoOnlineAction(bool andInitialize)
 {
     return(InnerRunRelayAction(port.CreateGoOnlineAction(andInitialize), "GoOnline" + (andInitialize ? "+Init" : "")));
 }
Exemplo n.º 3
0
            public void Service(bool sampleTimerTriggered)
            {
                TimeSpan stateAge = stateTimeStamp.Age;
                string   ec       = string.Empty;

                for (;;)
                {
                    switch (state)
                    {
                    case State.RequestFlush:
                        if (!port.BaseState.IsConnected)
                        {
                            ec = port.CreateGoOnlineAction(andInitialize: true).Run();
                        }

                        if (ec.IsNullOrEmpty())
                        {
                            ec = portFlushAction.Start();
                        }

                        if (ec.IsNullOrEmpty())
                        {
                            SetState(State.WaitUntilForFlushComplete, "Flush requested");
                        }
                        else
                        {
                            SetState(State.EchoTestFailed, "Flush.Start failed: {0}".CheckedFormat(ec));
                        }

                        return;

                    case State.WaitUntilForFlushComplete:
                        if (portFlushAction.ActionState.IsComplete)
                        {
                            SetState(State.WriteTestPattern, "Flush {0}".CheckedFormat(portFlushAction.ActionState.ToString()));
                        }

                        return;

                    case State.WriteTestPattern:
                        portWriteActionParam.BufferAsStr = currentTestPattern = GetNextTestDataPattern();

                        ec = portWriteAction.Start();

                        if (ec.IsNullOrEmpty())
                        {
                            SetState(State.WaitForEcho, "Write requested");
                        }
                        else
                        {
                            SetState(State.EchoTestFailed, "Write.Start failed: {0}".CheckedFormat(ec));
                        }

                        return;

                    case State.WaitForEcho:
                        lastEchoTestPeriod = stateAge;

                        if (port.HasPacket)
                        {
                            ec = portGetNextPacketAction.Run();
                            Packet p = portGetNextPacketAction.ResultValue;

                            if (ec.IsNullOrEmpty() && p == null)
                            {
                                ec = "successful {0} action gave null packet".CheckedFormat(portGetNextPacketAction.ToString(ToStringSelect.JustMesg));
                            }

                            if (ec.IsNullOrEmpty() && !p.IsData)
                            {
                                ec = "successful {0} action gave unexpected packet '{1}'".CheckedFormat(portGetNextPacketAction.ToString(ToStringSelect.JustMesg), p);
                            }

                            if (ec.IsNullOrEmpty() && p.DataStr != currentTestPattern)
                            {
                                ec = "Received unexpected echo [rx:'{0}' != expected:'{1}']".CheckedFormat(p.DataStr, currentTestPattern);
                            }

                            if (ec.IsNullOrEmpty())
                            {
                                h.Add(lastEchoTestPeriod.TotalSeconds);
                                SetState(State.EchoTestSucceeded, "Echo test succeeded after {0:f6} sec".CheckedFormat(stateAge.TotalSeconds));
                                return;
                            }
                            else
                            {
                                failureCount++;
                                SetState(State.EchoTestFailed, "Echo response failed: {0} [after {0:f6} sec]".CheckedFormat(stateAge.TotalSeconds));
                                return;
                            }
                        }
                        else if (stateAge > Config.ResponseTimeLimit)
                        {
                            timeoutCount++;
                            SetState(State.EchoTestFailed, "Echo response time limit reached after {0:f6} sec".CheckedFormat(stateAge.TotalSeconds));
                            return;
                        }

                        break;

                    case State.EchoTestSucceeded:
                        if (!lastEchoTestSucceeded)
                        {
                            Logger.Debug.Emit("{0}: Echo test on '{1}' succeeded after {2:f6} seconds [Prior test failed]", portConfig.Name, PortTargetSpec, lastEchoTestPeriod.TotalSeconds);

                            lastEchoTestSucceeded = true;
                        }

                        if (!sampleTimerTriggered)
                        {
                            return;
                        }

                        SetState(State.WriteTestPattern, "Starting next sample");

                        break;

                    case State.EchoTestFailed:
                        if (lastEchoTestSucceeded)
                        {
                            Logger.Debug.Emit("{0}: Echo test on '{1}' failed after {2:f6} seconds [Prior test succeeded]", portConfig.Name, PortTargetSpec, lastEchoTestPeriod.TotalSeconds);

                            lastEchoTestSucceeded = true;
                        }

                        if (!sampleTimerTriggered)
                        {
                            return;
                        }

                        SetState(State.RequestFlush, "Starting next sample (with Flush first)");

                        break;

                    default:
                        Logger.Error.Emit("{0}: Reached unexpected state {1}", portConfig.Name, state);

                        SetState(State.RequestFlush, "Recovery from unknown state");

                        break;
                    }
                }
            }