示例#1
0
 public void InterruptListener(MRNetwork NW)
 {
     NW.ExecuteStatus   = false;
     this.ExecuteStatus = false;
     HOHEventObj.UpdateExerciseTimer(0);
     HOHEventObj.UpdateExerciseState(false);
 }
示例#2
0
        public void Execute(MRNetwork NW)
        {
            ExecuteStatus   = true;
            exerciseRunning = true;


            HOHEvent.ProtocolStateUpdated += OnHOHEventUpdate;
            HOHEvent.ExerciseStateUpdated += OnExerciseStateUpdated;

            this.NW = NW;
            for (int i = 0; i < this.Repetitions; i++)
            {
                HOHEventObj.UpdateLogMsg("EXERCISE: START!");
                HOHEventObj.UpdateLogMsg("Executing exercise: " + this.Name);

                if (this.PreState != null && ExecuteStatus)
                {
                    HOHEventObj.UpdateLogMsg("Setting Prestate: " + this.PreState.Name);
                    this.PreState.execute(NW);
                }

                if (this.TargetState != null && ExecuteStatus)
                {
                    HOHEventObj.UpdateLogMsg("Target State: " + this.TargetState.Name);
                    HOHEventObj.UpdateUsrMsg(this.UserMsg);
                    sf = new SFListener(this.TargetState, Int32.Parse(this.SFCode), this.ExerciseTime, this);
                    Thread SFThread = new Thread(() => sf.Execute(NW));
                    SFThread.Start();
                    exerciseRunning = true;
                    while (exerciseRunning)
                    {
                    }
                    // SFThread.Interrupt();
                    //Thread.Sleep(this.ExerciseTime * 1000);
                    sf.InterruptListener(NW);
                    //SFThread.Interrupt();
                    //sf = null;
                }

                if (this.PostState != null && ExecuteStatus)
                {
                    HOHEventObj.UpdateLogMsg("Setting PostState: " + this.PostState.Name);
                    this.PostState.execute(NW);
                }


                HOHEventObj.UpdateLogMsg("EXERCISE: DONE!");
            }
            HOHEvent.ProtocolStateUpdated -= OnHOHEventUpdate;
            HOHEvent.ExerciseStateUpdated -= OnExerciseStateUpdated;
            HOHEventObj.UpdateExerciseState(true);
            HOHEventObj.UpdateExerciseTimer(0);
        }
示例#3
0
        public void Execute(MRNetwork NW)
        {
            HOHEvent.ProtocolStateUpdated += OnHOHEventUpdate;

            HOHEventObj.UpdateLogMsg("PROTOCOL: START!");
            HOHEventObj.UpdateProtocolState("running");
            foreach (Exercise ex in Exercises)
            {
                if (!ExecuteStatus)
                {
                    break;
                }
                Random rnd = new Random();

                HOHEventObj.UpdateUsrMsg("\r\nPrepare for " + ex.TargetState.UserMsg.ToLower() + "...");
                HOHEventObj.UpdateExerciseName(ex.TargetState.Name);
                //adicionar opção para alterar este valor
                Thread.Sleep(5000);
                if (!ExecuteStatus)
                {
                    break;
                }

                ex.Execute(NW);

                if (!ExecuteStatus)
                {
                    break;
                }
                //HOHEventObj.UpdateUsrMsg(Rewards[rnd.Next(Rewards.Count)]);
                HOHEventObj.RewardLaunch(true);

                //adicionar opção para alterar este valor
                Thread.Sleep(5000);
            }
            HOHEventObj.UpdateProtocolState("stopped");
            HOHEventObj.UpdateUsrMsg("Well done! Protocol complete.");
            HOHEventObj.UpdateLogMsg("PROTOCOL: DONE!");
        }
示例#4
0
        public void Execute(MRNetwork NW)
        {
            ExecuteStatus = true;
            bool firstRun = true;

            System.Threading.Timer theTimer = new System.Threading.Timer(this.Tick, null, 0, 1000);
            //System.Threading.Timer theTimer2 = new System.Threading.Timer(this.Tick2, null, 0,100);
            this.TimerCounter = this.WaitTime;
            this.ExerciseTime = this.WaitTime * 1000;
            Debug.WriteLine("SFLISTENER : START!");
            AsyncServer.LastCMDReceived  = 0;
            AsyncServer.commandProcessed = true;
            previousCMDReceived          = 1;


            HOHEventObj.UpdateLogMsg("SFListener: START");
            while (ExecuteStatus && this.TimerCounter >= -1)
            {
                if (firstRun || NW.ExecuteStatus)
                {
                    if (AsyncServer.IsConnected())
                    {
                        LastCMDReceived  = AsyncServer.LastCMDReceived;
                        commandProcessed = AsyncServer.commandProcessed;

                        Debug.WriteLine("Last> " + LastCMDReceived + " | Process> " + commandProcessed + " | Firstrun> " + firstRun + " | ExecStatus " + NW.ExecuteStatus);
                        //Código a executar quando os testes estiverem concluídos.

                        if (LastCMDReceived == SFCode && LastCMDReceived != previousCMDReceived && !commandProcessed)
                        { //se sinal detectado indica o movimento desejado actua em conformidade
                            if (firstRun)
                            {
                                Debug.WriteLine("GOT IN!");
                                // this.TargetState.execute(NW);

                                Thread SFThread = new Thread(() => this.TargetState.execute(NW));
                                SFThread.Start();

                                firstRun = false;
                            }
                            else
                            {
                                //NW.ExecuteAndWait("r","AOk", null);
                                NW.Send("r");
                                Debug.WriteLine("Resuming (right signal)");
                                //Necessario para dar tempo à mão para processar a excepção
                                //Thread.Sleep(40);
                            }
                            // commandProcessed = true;    //certifica que não há comandos processados multiplas
                            AsyncServer.commandProcessed = true;
                            previousCMDReceived          = LastCMDReceived;
                        }
                        else if (LastCMDReceived != SFCode && !commandProcessed)
                        {
                            //NW.ExecuteAndWait("p", "Pausing",null);
                            NW.Send("p");
                            //Necessario para dar tempo à mão para processar a excepção
                            //Thread.Sleep(40);
                            Debug.WriteLine("Holding (wrong signal)");
                            //debug only
                            previousCMDReceived = 0;
                        }
                    }
                    else
                    {  //debug mode ... no clients connected
                        if (this.TargetState != null && !commandProcessed)
                        {
                            this.TargetState.execute(NW);
                            // commandProcessed = true;
                        }
                    }
                    //Thread.Sleep(100);
                }
                else if (!firstRun)
                {
                    //NW.ExecuteAndWait("p", "Pausing", null);
                    NW.Send("p");
                    //Thread.Sleep(40);
                    Debug.WriteLine("Holding (last 10%)");
                }
            }
            NW.Send("r");
            Thread.Sleep(40);
            NW.Send("x");
            previousCMDReceived = LastCMDReceived;
            commandProcessed    = true;
            theTimer.Dispose();

            Debug.WriteLine("SFLISTENER : END!");
            HOHEventObj.UpdateLogMsg("SFListener: END");
            HOHEventObj.UpdateExerciseState(false);
            // HOHEventObj.UpdateExerciseTimer(0);
        }
示例#5
0
 public void execute(MRNetwork NW)
 {
     //HOHEventObj.UpdateUsrMsg(this.UserMsg);
     NW.ExecuteAndWait(HOHCode, CallbackMsg, null);
 }