Example #1
0
    /*
     * //onTimer allow to update progressbar_time every 50 milliseconds
     * //also can change platform state in simulated mode
     * //protected void onTimer( Object source, ElapsedEventArgs e )
     * protected override void onTimer( )
     * {
     *      timerCount = timerCount + .05; //0,05 segons == 50 milliseconds, time between each call of onTimer
     * }
     */


    public override void Manage()
    {
        //boolean to know if chronopic has been disconnected
        chronopicDisconnected = false;

        if (chronopics > 0)
        {
            platformState = chronopicInitialValue(cp);

            if (platformState == Chronopic.Plataforma.ON)
            {
                loggedState  = States.ON;
                cp1StartedIn = true;
            }
            else if (platformState == Chronopic.Plataforma.OFF)
            {
                loggedState  = States.OFF;
                cp1StartedIn = false;
            }
            else                 //UNKNOW (Chronopic disconnected, port changed, ...)
            {
                chronopicHasBeenDisconnected();
                return;
            }

            //prepare jump for being cancelled if desired
            cancel = false;

            //prepare jump for being finished earlier if desired
            finish = false;

            if (chronopics > 1)
            {
                platformState2 = chronopicInitialValue(cp2);

                if (platformState2 == Chronopic.Plataforma.ON)
                {
                    loggedState2 = States.ON;
                    cp2StartedIn = true;
                }
                else if (platformState2 == Chronopic.Plataforma.OFF)
                {
                    loggedState2 = States.OFF;
                    cp2StartedIn = false;
                }
                else                     //UNKNOW (Chronopic disconnected, port changed, ...)
                {
                    chronopicHasBeenDisconnected();
                    return;
                }

                if (chronopics > 2)
                {
                    platformState3 = chronopicInitialValue(cp3);

                    if (platformState3 == Chronopic.Plataforma.ON)
                    {
                        loggedState3 = States.ON;
                        cp3StartedIn = true;
                    }
                    else if (platformState3 == Chronopic.Plataforma.OFF)
                    {
                        loggedState3 = States.OFF;
                        cp3StartedIn = false;
                    }
                    else                         //UNKNOW (Chronopic disconnected, port changed, ...)
                    {
                        chronopicHasBeenDisconnected();
                        return;
                    }

                    if (chronopics > 3)
                    {
                        platformState4 = chronopicInitialValue(cp4);

                        if (platformState4 == Chronopic.Plataforma.ON)
                        {
                            loggedState4 = States.ON;
                            cp4StartedIn = true;
                        }
                        else if (platformState4 == Chronopic.Plataforma.OFF)
                        {
                            loggedState4 = States.OFF;
                            cp4StartedIn = false;
                        }
                        else                             //UNKNOW (Chronopic disconnected, port changed, ...)
                        {
                            chronopicHasBeenDisconnected();
                            return;
                        }
                    }
                }
            }
        }

        string platformsProblems = "";

        if (type == Constants.RunAnalysisName)
        {
            string sep = "";
            if (platformState == Chronopic.Plataforma.ON)
            {
                platformsProblems = Catalog.GetString("Photocells");
                sep = ", ";
            }
            if (platformState2 == Chronopic.Plataforma.ON)
            {
                platformsProblems += sep + Catalog.GetString("Platform");
            }
        }


        if (platformsProblems.Length > 0)
        {
            ConfirmWindow confirmWin;
            confirmWin = ConfirmWindow.Show(
                string.Format(Catalog.GetString("There's contact in {0}. Please leave."), platformsProblems), "", "");

            Util.PlaySound(Constants.SoundTypes.BAD, volumeOn, gstreamer);

            //we call again this function
            confirmWin.Button_accept.Clicked += new EventHandler(callAgainManage);

            //if confirmWin.Button_cancel is pressed retuen
            confirmWin.Button_cancel.Clicked += new EventHandler(cancel_event_before_start);
        }
        else
        {
            firstValue = true;
            //writingStarted = false;

            //start thread
            if (chronopics > 0)
            {
                //prepare variables to allow being cancelled or finished
                if (!simulated)
                {
                    Chronopic.InitCancelAndFinish();
                }

                thread = new Thread(new ThreadStart(waitEventPre));
                if (chronopics > 1)
                {
                    thread2 = new Thread(new ThreadStart(waitEventPre2));
                    if (chronopics > 2)
                    {
                        thread3 = new Thread(new ThreadStart(waitEventPre3));
                        if (chronopics > 3)
                        {
                            thread4 = new Thread(new ThreadStart(waitEventPre4));
                        }
                    }
                }
            }

            GLib.Idle.Add(new GLib.IdleHandler(PulseGTK));

            if (chronopics > 0)
            {
                LogB.ThreadStart();
                thread.Start();

                if (chronopics > 1)
                {
                    thread2.Start();
                    if (chronopics > 2)
                    {
                        thread3.Start();
                        if (chronopics > 4)
                        {
                            thread4.Start();
                        }
                    }
                }
            }
        }
    }
Example #2
0
    protected override void waitEvent()
    {
        double timestamp = 0;
        bool   success   = false;
        string equal     = "";

        bool ok;

        //prepare variables to allow being cancelled or finished
        if (!simulated)
        {
            Chronopic.InitCancelAndFinish();
        }

        do
        {
            if (simulated)
            {
                ok = true;
            }
            else
            {
                ok = cp.Read_event(out timestamp, out platformState);
            }


            if (ok && !cancel && !finish)
            {
                if (platformState == Chronopic.Plataforma.ON && loggedState == States.OFF)
                {
                    //has arrived

                    //if we arrive to the platform for the first time, don't record anything
                    if (pulsePhase == pulsePhases.WAIT_FIRST_EVENT)
                    {
                        pulsePhase = pulsePhases.DOING;
                        //pulse starts
                        initializeTimer();

                        feedbackMessage         = "";
                        needShowFeedbackMessage = true;
                    }
                    else
                    {
                        //is not the first pulse
                        if (totalPulsesNum == -1)
                        {
                            //if is "unlimited",
                            //then play with the progress bar until finish button is pressed
                            if (simulated)
                            {
                                timestamp = simulatedTimeLast * 1000;                                         //conversion to milliseconds
                            }
                            if (timesString.Length > 0)
                            {
                                equal = "=";
                            }
                            timesString = timesString + equal + (contactTime / 1000.0 + timestamp / 1000.0).ToString();
                            tracks++;

                            //update event progressbar
                            //progressBarEventOrTimePreExecution(
                            updateProgressBar = new UpdateProgressBar(
                                true,                                                 //isEvent
                                false,                                                //activityMode
                                tracks
                                );

                            needUpdateEventProgressBar = true;

                            //update graph
                            //preparePulseGraph(timestamp/1000.0, timesString);
                            PrepareEventGraphPulseObject = new PrepareEventGraphPulse(timestamp / 1000.0, timesString);
                            needUpdateGraphType          = eventType.PULSE;
                            needUpdateGraph = true;

                            //put button_finish as sensitive when first jump is done (there's something recordable)
                            if (tracks == 1)
                            {
                                needSensitiveButtonFinish = true;
                            }
                        }
                        else
                        {
                            //is not the first pulse, and it's limited by tracks (ticks)
                            tracks++;

                            if (simulated)
                            {
                                timestamp = simulatedTimeLast * 1000;                                         //conversion to milliseconds
                            }
                            if (timesString.Length > 0)
                            {
                                equal = "=";
                            }
                            timesString = timesString + equal + (contactTime / 1000.0 + timestamp / 1000.0).ToString();

                            if (tracks >= totalPulsesNum)
                            {
                                //finished
                                write();
                                success    = true;
                                pulsePhase = pulsePhases.DONE;
                            }

                            //update event progressbar
                            //progressBarEventOrTimePreExecution(
                            updateProgressBar = new UpdateProgressBar(
                                true,                                                 //isEvent
                                true,                                                 //PercentageMode
                                tracks
                                );
                            needUpdateEventProgressBar = true;

                            //update graph
                            //preparePulseGraph(timestamp/1000.0, timesString);
                            PrepareEventGraphPulseObject = new PrepareEventGraphPulse(timestamp / 1000.0, timesString);
                            needUpdateGraphType          = eventType.PULSE;
                            needUpdateGraph = true;

                            //put button_finish as sensitive when first jump is done (there's something recordable)
                            if (tracks == 1)
                            {
                                needSensitiveButtonFinish = true;
                            }
                        }
                    }

                    //change the automata state
                    loggedState = States.ON;
                }
                else if (platformState == Chronopic.Plataforma.OFF && loggedState == States.ON)
                {
                    //it's out, was inside (= has abandoned platform)

                    if (simulated)
                    {
                        timestamp = simulatedTimeLast * 1000;                                 //conversion to milliseconds
                    }
                    contactTime = timestamp;

                    //change the automata state
                    loggedState = States.OFF;
                }
            }
        } while (!success && !cancel && !finish);

        if (finish)
        {
            write();
            pulsePhase = pulsePhases.DONE;
        }
    }
Example #3
0
    protected override void waitEvent()
    {
        double timestamp = 0;
        bool   success   = false;

        bool ok;

        //prepare variables to allow being cancelled or finished
        if (!simulated)
        {
            Chronopic.InitCancelAndFinish();
        }

        LogB.Information("Inside waitEvent");
        do
        {
            if (simulated)
            {
                ok = true;
            }
            else
            {
                ok = cp.Read_event(out timestamp, out platformState);
            }

            LogB.Information("Inside do");
            LogB.Information("cancel == ");
            LogB.Information(cancel.ToString());
            LogB.Information("ok == ");
            LogB.Information(ok.ToString());

            //if (ok) {
            if (ok && !cancel)
            {
                LogB.Information("ok!");
                if (platformState == Chronopic.Plataforma.ON && loggedState == States.OFF)
                {
                    //LogB.Information("condition guai! hem entrat!");
                    //has landed
                    if (simulated)
                    {
                        timestamp = simulatedTimeLast * 1000;                         //conversion to milliseconds
                    }
                    LogB.Information(string.Format("t1:{0}", timestamp));

                    time = timestamp / 1000.0;
                    write();

                    success = true;

                    //update event progressbar
                    double percentageToPass = 2;                     //has two phases

                    //progressBarEventOrTimePreExecution(
                    //don't do it, put a boolean value and let the PulseGTK do it
                    updateProgressBar = new UpdateProgressBar(
                        true,                                 //isEvent
                        true,                                 //percentageMode
                        percentageToPass
                        );
                    needUpdateEventProgressBar = true;

                    loggedState = States.ON;
                }
                else if (platformState == Chronopic.Plataforma.OFF && loggedState == States.ON)
                {
                    //LogB.Information("condition hem sortit");

                    //it's out, was inside (= has released)

                    initializeTimer();

                    feedbackMessage         = "";
                    needShowFeedbackMessage = true;

                    //update event progressbar
                    //progressBarEventOrTimePreExecution(
                    //don't do it, put a boolean value and let the PulseGTK do it
                    updateProgressBar = new UpdateProgressBar(
                        true,                             //isEvent
                        true,                             //percentageMode
                        1                                 //normal jump, phase 1/2
                        );
                    needUpdateEventProgressBar = true;

                    //change the automata state
                    loggedState = States.OFF;
                }
            }
//Log.WriteLine("PREEXIT");
        } while (!success && !cancel);
//Log.WriteLine("EXIT");
    }
Example #4
0
    protected override void waitEvent()
    {
        double timestamp = 0;
        bool   success   = false;

        shouldFinishAtNextFall = false;

        bool ok;

        int countForSavingTempTable = 0;

        //prepare variables to allow being cancelled or finished
        if (!simulated)
        {
            Chronopic.InitCancelAndFinish();
        }

        do
        {
            if (simulated)
            {
                ok = true;
            }
            else
            {
                ok = cp.Read_event(out timestamp, out platformState);
            }


            //if chronopic signal is Ok and state has changed
            if (ok && (
                    (platformState == Chronopic.Plataforma.ON && loggedState == States.OFF) ||
                    (platformState == Chronopic.Plataforma.OFF && loggedState == States.ON)) &&
                !cancel && !finish)
            {
                if (simulated)
                {
                    timestamp = simulatedTimeLast * 1000;                     //conversion to milliseconds
                }
                LogB.Information(Util.GetTotalTime(tcString, tvString).ToString());



                string equal = "";

                //while no finished time or jumps, continue recording events
                if (!success)
                {
                    //don't record the time until the first event
                    if (firstRjValue)
                    {
                        firstRjValue = false;

                        //but start timer
                        initializeTimer();

                        feedbackMessage         = "";
                        needShowFeedbackMessage = true;
                    }
                    else
                    {
                        //reactive jump has not finished... record the next jump
                        LogB.Information(string.Format("tcCount: {0}, tvCount: {1}", tcCount, tvCount));
                        if (tcCount == tvCount)
                        {
                            lastTc = timestamp / 1000.0;

                            if (tcCount > 0)
                            {
                                equal = "=";
                            }
                            tcString = tcString + equal + lastTc.ToString();

                            updateTimerCountWithChronopicData(tcString, tvString);

                            tcCount = tcCount + 1;
                        }
                        else
                        {
                            //tcCount > tvCount
                            lastTv = timestamp / 1000.0;

                            if (tvCount > 0)
                            {
                                equal = "=";
                            }
                            tvString = tvString + equal + lastTv.ToString();

                            updateTimerCountWithChronopicData(tcString, tvString);
                            tvCount = tvCount + 1;

                            //update event progressbar
                            //app1.ProgressBarEventOrTimePreExecution(
                            updateProgressBar = new UpdateProgressBar(
                                true,                                         //isEvent
                                jumpsLimited,                                 //if jumpsLimited: do fraction; if time limited: do pulse
                                tvCount
                                );
                            needUpdateEventProgressBar = true;

                            //update graph
                            PrepareEventGraphJumpReactiveObject = new PrepareEventGraphJumpReactive(lastTv, lastTc, tvString, tcString);
                            needUpdateGraphType = eventType.JUMPREACTIVE;
                            needUpdateGraph     = true;

                            //put button_finish as sensitive when first jump is done (there's something recordable)
                            if (tvCount == 1)
                            {
                                needSensitiveButtonFinish = true;
                            }

                            //save temp table if needed
                            countForSavingTempTable++;
                            if (countForSavingTempTable == timesForSavingRepetitive)
                            {
                                writeRj(true);                                 //tempTable
                                countForSavingTempTable = 0;
                            }
                        }
                    }
                }

                //if we finish by time, and allowFinishAfterTime == true, when time passed, if the jumper is jumping
                //if flags the shouldFinishAtNextFall that will finish when he arrives to the platform
                if (shouldFinishAtNextFall && platformState == Chronopic.Plataforma.ON && loggedState == States.OFF)
                {
                    finish = true;
                }


                //check if reactive jump should finish
                if (jumpsLimited)
                {
                    if (limitAsDouble != -1)
                    {
                        if (Util.GetNumberOfJumps(tvString, false) >= limitAsDouble)
                        {
                            jumpPhase = jumpPhases.PLATFORM_END;

                            writeRj(false);                             //tempTable
                            success = true;

                            //update event progressbar
                            //app1.ProgressBarEventOrTimePreExecution(
                            updateProgressBar = new UpdateProgressBar(
                                true,                                         //isEvent
                                true,                                         //percentageMode
                                tvCount
                                );
                            needUpdateEventProgressBar = true;

                            //update graph
                            PrepareEventGraphJumpReactiveObject = new PrepareEventGraphJumpReactive(lastTv, lastTc, tvString, tcString);
                            needUpdateGraphType = eventType.JUMPREACTIVE;
                            needUpdateGraph     = true;
                        }
                    }
                }

                if (platformState == Chronopic.Plataforma.OFF)
                {
                    loggedState = States.OFF;
                }
                else
                {
                    loggedState = States.ON;
                }
            }
        } while (!success && !cancel && !finish);


        if (finish)
        {
            //write only if there's a jump at minimum
            if (Util.GetNumberOfJumps(tcString, false) >= 1 && Util.GetNumberOfJumps(tvString, false) >= 1)
            {
                jumpPhase = jumpPhases.PLATFORM_END;

                writeRj(false);                 //tempTable
            }
            else
            {
                //cancel a jump if clicked finish before any events done
                cancel = true;
            }
        }
    }
Example #5
0
    protected override void waitEvent()
    {
        double timestamp = 0;
        bool   success   = false;

        bool ok;
        int  phase = 0;

        //prepare variables to allow being cancelled or finished
        if (!simulated)
        {
            Chronopic.InitCancelAndFinish();
        }

        do
        {
            if (simulated)
            {
                ok = true;
            }
            else
            {
                LogB.Information("calling Read_event");
                ok = cp.Read_event(out timestamp, out platformState);
                LogB.Information("Read_event done!");
            }


            /*
             *           \()/            \()/
             *            \/              \/
             *   _()_     /\     _()_     /\     _()_
             *    \/              \/              \/
             * ___/\______________/\______________/\___
             *
             *  GraphA  graphB  graphC  graphD  graphE
             *  unused  jumps   lands   jumps   lands
             *
             *    ______start_______             end
             *
             *    DJ      DJ      SJ
             * hasFall  hasFall
             * fall -1
             *
             */

            //if (ok)
            if (ok && !cancel)
            {
                if (platformState == Chronopic.Plataforma.ON && loggedState == States.OFF)
                {
                    //has landed
                    if (hasFall && tc == 0)
                    {
                        //**** graphC ****

                        if (fall == -1)
                        {
                            if (simulated)
                            {
                                timestamp = simulatedTimeLast * 1000;                                 //conversion to milliseconds
                            }
                            //calculate the fall height using flight time
                            double tvPreJump = timestamp / 1000.0;
                            fall = Convert.ToDouble(Util.GetHeightInCentimeters(tvPreJump.ToString()));
                        }

                        //jump with fall, landed first time
                        initializeTimer();

                        //app1.ProgressBarEventOrTimePreExecution(
                        //don't do it, put a boolean value and let the PulseGTK do it
                        updateProgressBar = new UpdateProgressBar(
                            true,                                     //isEvent
                            true,                                     //jumpsLimited: percentageMode
                            ++phase
                            );
                        needUpdateEventProgressBar = true;

                        feedbackMessage         = "";
                        needShowFeedbackMessage = true;
                    }
                    else
                    {
                        //**** graphE **** jump with fall: second landed; or without fall first landing

                        if (simulated)
                        {
                            timestamp = simulatedTimeLast * 1000;                             //conversion to milliseconds
                        }
                        LogB.Information(string.Format("t1:{0}", timestamp));

                        tv = timestamp / 1000.0;

                        jumpPhase = jumpPhases.PLATFORM_END;

                        write();

                        success = true;

                        //app1.ProgressBarEventOrTimePreExecution(
                        //don't do it, put a boolean value and let the PulseGTK do it
                        updateProgressBar = new UpdateProgressBar(
                            true,                                     //isEvent
                            true,                                     //percentageMode
                            ++phase
                            );
                        needUpdateEventProgressBar = true;
                    }
                    loggedState = States.ON;
                }
                else if (platformState == Chronopic.Plataforma.OFF && loggedState == States.ON)
                {
                    //it's out, was inside (= has jumped)

                    //fall != -1 because if it was == -1, it will change once touching floor for the first time
                    if (hasFall && fall != -1)
                    {
                        //**** graphD ****

                        if (simulated)
                        {
                            timestamp = simulatedTimeLast * 1000;                             //conversion to milliseconds
                        }
                        LogB.Information(string.Format("t2:{0}", timestamp));

                        //record the TC
                        tc = timestamp / 1000.0;

                        //takeOff jump (only one TC)
                        //if(fixedValue == 0.5)
                        if (type == Constants.TakeOffName || type == Constants.TakeOffWeightName)
                        {
                            tv = 0;

                            jumpPhase = jumpPhases.PLATFORM_END;

                            write();
                            success = true;
                        }

                        //update event progressbar
                        //app1.ProgressBarEventOrTimePreExecution(
                        //don't do it, put a boolean value and let the PulseGTK do it
                        updateProgressBar = new UpdateProgressBar(
                            true,                                     //isEvent
                            true,                                     //percentageMode
                            ++phase
                            );
                        needUpdateEventProgressBar = true;
                    }
                    else
                    {
                        //**** graphD (if normal jump) ****
                        //**** graphB (if hasFall and fall == -1) ****

                        initializeTimer();

                        //update event progressbar
                        //app1.ProgressBarEventOrTimePreExecution(
                        //don't do it, put a boolean value and let the PulseGTK do it
                        updateProgressBar = new UpdateProgressBar(
                            true,                                     //isEvent
                            true,                                     //percentageMode
                            ++phase
                            );
                        needUpdateEventProgressBar = true;

                        feedbackMessage         = "";
                        needShowFeedbackMessage = true;
                    }

                    //change the automata state
                    loggedState = States.OFF;
                }
            }
        } while (!success && !cancel);

        LogB.Information("Exited waitEvent main bucle");
    }
Example #6
0
    protected override void waitEvent()
    {
        double timestamp = 0;
        bool   success   = false;
        string equal     = "";

        //initialize variables
        intervalTimesString = "";
        tracks = 0;
        bool ok;

        timerCount = 0;
        //bool initialized = false;
        int countForSavingTempTable = 0;

        lastTc = 0;
        distanceIntervalFixed = distanceInterval;

        double timestampDCFlightTimes  = -1; //sum of the flight times that happen in small time
        double timestampDCContactTimes = -1; //sum of the contact times that happen in small time
        double timestampDCn            = 0;  //number of flight times

        //prepare variables to allow being cancelled or finished
        if (!simulated)
        {
            Chronopic.InitCancelAndFinish();
        }

        do
        {
            if (simulated)
            {
                ok = true;
            }
            else
            {
                ok = cp.Read_event(out timestamp, out platformState);
            }


            if (ok && !cancel && !finish)
            {
                if (distanceInterval == -1)
                {
                    distanceIntervalFixed = Util.GetRunIVariableDistancesStringRow(distancesString, (int)tracks);
                }

                if (platformState == Chronopic.Plataforma.ON && loggedState == States.OFF)
                {
                    //has arrived
                    loggedState = States.ON;

                    //show RSA count down only on air
                    needShowCountDown = false;

                    //if we start out, and we arrive to the platform for the first time,
                    //don't record nothing
                    if (runPhase == runPhases.PRE_RUNNING)
                    {
                        if (speedStartArrival)
                        {
                            runPhase = runPhases.PLATFORM_INI_YES_TIME;
                            //run starts
                            initializeTimer();                             //timerCount = 0
                        }
                        else
                        {
                            runPhase = runPhases.PLATFORM_INI_NO_TIME;
                        }

                        feedbackMessage         = "";
                        needShowFeedbackMessage = true;
                    }
                    else
                    {
                        runPhase = runPhases.RUNNING;
                        //has arrived and not in the "running previous"

                        //if interval run is "unlimited" not limited by tracks, nor time,
                        //then play with the progress bar until finish button is pressed

                        if (simulated)
                        {
                            timestamp = simulatedTimeLast * 1000;                             //conversion to milliseconds
                        }
                        if (checkDoubleContactMode != Constants.DoubleContact.NONE)
                        {
                            if (timestamp <= checkDoubleContactTime)
                            {
                                /*
                                 * when checking double contact
                                 * first time that timestamp < checkDoubleContactTime
                                 * and we arrived (it's a flight time)
                                 * record this time as timestampDCFlightTimes
                                 */
                                timestampDCn++;
                                timestampDCFlightTimes += timestamp;
                                continue;
                            }
                            else
                            {
                                if (timestampDCn > 0)
                                {
                                    if (checkDoubleContactMode ==
                                        Constants.DoubleContact.FIRST)
                                    {
                                        /* user want first flight time,
                                         * then add all DC times*/
                                        timestamp += timestampDCFlightTimes +
                                                     timestampDCContactTimes;
                                    }
                                    else if (checkDoubleContactMode ==
                                             Constants.DoubleContact.LAST)
                                    {
                                        //user want last flight time, take that
                                        // so we don't need to change timestamp. Or we could do (it triggers a warning):
                                        // timestamp = timestamp;
                                    }
                                    else                                        /* do the avg of all flights and contacts
                                                                                 * then add to last timestamp */
                                    {
                                        timestamp +=
                                            (timestampDCFlightTimes +
                                             timestampDCContactTimes)
                                            / timestampDCn;
                                    }
                                }
                            }
                        }

                        double myRaceTime = lastTc + timestamp / 1000.0;

                        if (intervalTimesString.Length > 0)
                        {
                            equal = "=";
                        }
                        intervalTimesString = intervalTimesString + equal + myRaceTime.ToString();
                        updateTimerCountWithChronopicData(intervalTimesString);
                        tracks++;

                        //save temp table if needed
                        countForSavingTempTable++;
                        if (countForSavingTempTable == timesForSavingRepetitive)
                        {
                            writeRunInterval(true);                                     //tempTable
                            countForSavingTempTable = 0;
                        }

                        if (limitAsDouble == -1)
                        {
                            //has arrived, unlimited
                            updateProgressBar = new UpdateProgressBar(
                                true,                                         //isEvent
                                true,                                         //unlimited: activity mode
                                tracks
                                );
                            needUpdateEventProgressBar = true;
                        }
                        else
                        {
                            //has arrived, limited
                            if (tracksLimited)
                            {
                                //has arrived, limited by tracks
                                if (tracks >= limitAsDouble)
                                {
                                    runPhase = runPhases.PLATFORM_END;

                                    //finished
                                    writeRunInterval(false);                                     //tempTable = false
                                    success = true;
                                }
                                //progressBarEventOrTimePreExecution(
                                updateProgressBar = new UpdateProgressBar(
                                    true,                                             //isEvent
                                    true,                                             //tracksLimited: percentageMode
                                    tracks
                                    );
                                needUpdateEventProgressBar = true;
                            }
                            else
                            {
                                //has arrived, limited by time
                                updateProgressBar = new UpdateProgressBar(
                                    true,                                             //isEvent
                                    false,                                            //timeLimited: activity mode
                                    tracks
                                    );
                                needUpdateEventProgressBar = true;
                            }
                        }

                        distanceTotal = Util.GetRunITotalDistance(distanceInterval, distancesString, tracks);

                        //update graph
                        PrepareEventGraphRunIntervalObject = new PrepareEventGraphRunInterval(
                            distanceIntervalFixed, myRaceTime, intervalTimesString,
                            distanceTotal, distancesString, startIn);

                        needUpdateGraphType = eventType.RUNINTERVAL;
                        needUpdateGraph     = true;

                        //put button_finish as sensitive when first jump is done (there's something recordable)
                        if (tracks == 1)
                        {
                            needSensitiveButtonFinish = true;
                        }
                    }
                }
                else if (platformState == Chronopic.Plataforma.OFF && loggedState == States.ON)
                {
                    //it's out, was inside (= has abandoned platform)

                    if (runPhase == runPhases.PLATFORM_INI_NO_TIME)
                    {
                        //run starts
                        initializeTimer();
                        lastTc = 0;

                        feedbackMessage         = "";
                        needShowFeedbackMessage = true;
                    }
                    else if (runPhase == runPhases.PLATFORM_INI_YES_TIME)
                    {
                        lastTc = timestamp / 1000.0;

                        feedbackMessage         = "";
                        needShowFeedbackMessage = true;
                    }
                    else
                    {
                        if (checkDoubleContactMode != Constants.DoubleContact.NONE && timestampDCn > 0)
                        {
                            timestampDCContactTimes += timestamp;
                        }
                        else
                        {
                            lastTc = timestamp / 1000.0;
                        }


                        //RSA
                        double RSAseconds = Util.GetRunIVariableDistancesThisRowIsRSA(
                            distancesString, Convert.ToInt32(tracks));
                        if (RSAseconds > 0)
                        {
                            RSABellDone       = false;
                            needShowCountDown = true;
                        }
                        else
                        {
                            needShowCountDown       = false;
                            feedbackMessage         = "";
                            needShowFeedbackMessage = true;
                        }
                    }


                    runPhase = runPhases.RUNNING;

                    //change the automata state
                    loggedState = States.OFF;
                }
            }
        } while (!success && !cancel && !finish);

        if (finish)
        {
            runPhase = runPhases.PLATFORM_END;

            //write();
            //write only if there's a run at minimum
            if (Util.GetNumberOfJumps(intervalTimesString, false) >= 1)
            {
                writeRunInterval(false);                 //tempTable = false
            }
            else
            {
                //cancel a run if clicked finish before any events done, or ended by time without events
                cancel = true;
            }
        }
    }
Example #7
0
    protected override void waitEvent()
    {
        double timestamp             = 0;
        double timestampFirstContact = 0;    //used when runPhase == runPhases.PLATFORM_INI_YES_TIME;

        double timestampDCFlightTimes  = -1; //sum of the flight times that happen in small time
        double timestampDCContactTimes = -1; //sum of the contact times that happen in small time
        double timestampDCn            = 0;  //number of flight times

        bool success = false;
        bool ok;

        //prepare variables to allow being cancelled or finished
        if (!simulated)
        {
            Chronopic.InitCancelAndFinish();
        }

        do
        {
            if (simulated)
            {
                ok = true;
            }
            else
            {
                ok = cp.Read_event(out timestamp, out platformState);
            }

            //if (ok) {
            if (ok && !cancel)
            {
                //LogB.Information("timestamp:" + timestamp);
                if (platformState == Chronopic.Plataforma.ON && loggedState == States.OFF)
                {
                    //has arrived
                    loggedState = States.ON;

                    if (runPhase == runPhases.PRE_RUNNING)
                    {
                        if (speedStartArrival)
                        {
                            runPhase = runPhases.PLATFORM_INI_YES_TIME;
                            initializeTimer();                             //timerCount = 0
                        }
                        else
                        {
                            runPhase = runPhases.PLATFORM_INI_NO_TIME;
                        }

                        updateProgressBar = new UpdateProgressBar(
                            true,                                 //isEvent
                            true,                                 //tracksLimited: percentageMode
                            1                                     //just reached platform, phase 1/3
                            );
                        needUpdateEventProgressBar = true;
                    }
                    else
                    {
                        //run finished:
                        //if started outside (behind platform) it's the second arrive
                        //if started inside: it's the first arrive

                        if (simulated)
                        {
                            timestamp = simulatedTimeLast * 1000;                             //conversion to milliseconds
                        }
                        //prevent double contact stuff
                        if (checkDoubleContactMode != Constants.DoubleContact.NONE)
                        {
                            if (timestamp <= checkDoubleContactTime)
                            {
                                /*
                                 * when checking double contact
                                 * first time that timestamp < checkDoubleContactTime
                                 * and we arrived (it's a flight time)
                                 * record this time as timestampDCFlightTimes
                                 */
                                timestampDCn++;
                                timestampDCFlightTimes += timestamp;
                            }
                            else
                            {
                                if (timestampDCn > 0)
                                {
                                    if (checkDoubleContactMode ==
                                        Constants.DoubleContact.FIRST)
                                    {
                                        /* user want first flight time,
                                         * then add all DC times*/
                                        timestamp += timestampDCFlightTimes +
                                                     timestampDCContactTimes;
                                    }
                                    else if (checkDoubleContactMode ==
                                             Constants.DoubleContact.LAST)
                                    {
                                        //user want last flight time, take that
                                        // It doesn't change the timestamp so this is the same as:
                                        // timestamp = timestamp;
                                    }
                                    else                                        /* do the avg of all flights and contacts
                                                                                 * then add to last timestamp */
                                    {
                                        timestamp +=
                                            (timestampDCFlightTimes +
                                             timestampDCContactTimes)
                                            / timestampDCn;
                                    }
                                }
                                success = true;
                            }
                        }

                        if (checkDoubleContactMode == Constants.DoubleContact.NONE)
                        {
                            success = true;
                        }

                        if (success)
                        {
                            runPhase = runPhases.PLATFORM_END;

                            //add the first contact time if PLATFORM_INI_YES_TIME
                            if (timestampFirstContact > 0)
                            {
                                timestamp += timestampFirstContact;
                            }

                            time = timestamp / 1000.0;
                            write();

                            //success = true;

                            updateProgressBar = new UpdateProgressBar(
                                true,                                         //isEvent
                                true,                                         //percentageMode
                                //percentageToPass
                                3
                                );
                            needUpdateEventProgressBar = true;
                        }
                    }
                }
                else if (platformState == Chronopic.Plataforma.OFF && loggedState == States.ON)
                {
                    //it's out, was inside (= has abandoned platform)
                    //don't record time

                    //change the automata state
                    loggedState = States.OFF;

                    if (checkDoubleContactMode != Constants.DoubleContact.NONE && timestampDCn > 0)
                    {
                        timestampDCContactTimes += timestamp;
                    }
                    else
                    {
                        if (runPhase == runPhases.PLATFORM_INI_YES_TIME)
                        {
                            timestampFirstContact = timestamp;
                        }
                        else if (runPhase == runPhases.PLATFORM_INI_NO_TIME)
                        {
                            initializeTimer();                             //timerCount = 0
                        }
                        //update event progressbar
                        updateProgressBar = new UpdateProgressBar(
                            true,                                 //isEvent
                            true,                                 //percentageMode
                            2                                     //normal run, phase 2/3
                            );
                        needUpdateEventProgressBar = true;

                        feedbackMessage         = "";
                        needShowFeedbackMessage = true;

                        runPhase = runPhases.RUNNING;
                    }
                }
            }
        } while (!success && !cancel);
    }