Example #1
0
    //execution
    public PulseExecute(int personID, string personName, int sessionID, string type, double fixedPulse, int totalPulsesNum,
                        Chronopic cp, Gtk.Window app, int pDN,
                        bool volumeOn, Preferences.GstreamerTypes gstreamer,
                        //double progressbarLimit,
                        ExecutingGraphData egd
                        )
    {
        this.personID       = personID;
        this.personName     = personName;
        this.sessionID      = sessionID;
        this.type           = type;
        this.fixedPulse     = fixedPulse;
        this.totalPulsesNum = totalPulsesNum;


        this.cp  = cp;
        this.app = app;

        this.pDN       = pDN;
        this.volumeOn  = volumeOn;
        this.gstreamer = gstreamer;
//		this.progressbarLimit = progressbarLimit;
        this.egd = egd;

        fakeButtonUpdateGraph = new Gtk.Button();
        fakeButtonThreadDyed  = new Gtk.Button();

        simulated = false;

        needUpdateEventProgressBar = false;
        needUpdateGraph            = false;

        //initialize eventDone as a Pulse
        eventDone = new Pulse();
    }
Example #2
0
    //run execution
    public RunExecute(int personID, int sessionID, string type, double distance,   
			Chronopic cp, Gtk.TextView event_execute_textview_message, Gtk.Window app, int pDN, bool metersSecondsPreferred, bool volumeOn,
			double progressbarLimit, ExecutingGraphData egd 
			)
    {
        this.personID = personID;
        this.sessionID = sessionID;
        this.type = type;
        this.distance = distance;

        this.cp = cp;
        this.event_execute_textview_message = event_execute_textview_message;
        this.app = app;

        this.pDN = pDN;
        this.metersSecondsPreferred = metersSecondsPreferred;
        this.volumeOn = volumeOn;
        this.progressbarLimit = progressbarLimit;
        this.egd = egd;

        fakeButtonUpdateGraph = new Gtk.Button();
        fakeButtonEventEnded = new Gtk.Button();
        fakeButtonFinished = new Gtk.Button();

        simulated = false;

        needUpdateEventProgressBar = false;
        needUpdateGraph = false;

        //initialize eventDone as a Run
        eventDone = new Run();
    }
Example #3
0
    //this is called on AutoDetect
    static public ChronopicWindow Create(Chronopic cpDetected, ArrayList myCpd, string myEncoderPort, bool recreate, bool volumeOn)
    {
        LogB.Debug("enter create");
        if (ChronopicWindowBox != null && recreate)
        {
            ChronopicWindowBox.chronopic_window.Hide();
        }
        if (ChronopicWindowBox == null || recreate)
        {
            ChronopicWindowBox = new ChronopicWindow(cpDetected, myCpd);
        }

        LogB.Information("create cp is null? " + (ChronopicWindowBox.cp == null).ToString());

        //don't show until View is called
        //ChronopicWindowBox.chronopic_window.Show ();

        ChronopicWindowBox.volumeOn = volumeOn;

        ChronopicWindowBox.setEncoderPort(myEncoderPort);

        ChronopicWindowBox.fakeWindowDone = new Gtk.Button();
        //ChronopicWindowBox.fakeWindowReload = new Gtk.Button();

        return(ChronopicWindowBox);
    }
Example #4
0
    public MultiChronopicExecute(int personID, string personName, int sessionID, string type,
                                 Chronopic cp, Chronopic cp2, Chronopic cp3, Chronopic cp4, bool syncFirst, bool deleteFirst, string vars,
                                 Gtk.Window app,
                                 //double progressbarLimit,
                                 ExecutingGraphData egd

                                 )
    {
        this.personID   = personID;
        this.personName = personName;
        this.sessionID  = sessionID;
        this.type       = type;

        this.cp          = cp;
        this.cp2         = cp2;
        this.cp3         = cp3;
        this.cp4         = cp4;
        this.syncFirst   = syncFirst;
        this.deleteFirst = deleteFirst;
        this.vars        = vars;

        this.app = app;
//		this.progressbarLimit = progressbarLimit;
        this.egd = egd;

        chronopics = 4;
        initValues();
    }
Example #5
0
    public static void Main()
    {
        Application.Init();

        //-- Crear el interfaz
        Window w  = new Window("Prueba");
        Button b1 = new Button("Test 1");
        Button b2 = new Button("Test 2");
        HBox   h  = new HBox();

        w.DeleteEvent += new DeleteEventHandler(Window_Delete);
        b1.Clicked    += new EventHandler(Button_Clicked);
        b2.Clicked    += new EventHandler(Button2_Clicked);

        h.PackStart(b1, false, false, 0);
        h.PackStart(b2, false, false, 0);

        w.Add(h);
        w.SetDefaultSize(100, 100);
        w.ShowAll();

        //-- Inicializar chronopic
        cp = new Chronopic("/dev/ttyUSB0");

        //-- Inicializar otras cosas
        Cola = new Queue();

        //-- Inicializar temporizador
        GLib.Timeout.Add(100, new GLib.TimeoutHandler(Time_Out));

        Application.Run();
    }
Example #6
0
    public static void Main()
    {
        Application.Init();

        //-- Crear el interfaz
        Window w = new Window("Prueba");
        Button b1 = new Button("Test 1");
        Button b2 = new Button("Test 2");
        HBox h= new HBox();
        w.DeleteEvent += new DeleteEventHandler(Window_Delete);
        b1.Clicked += new EventHandler(Button_Clicked);
        b2.Clicked += new EventHandler(Button2_Clicked);

        h.PackStart(b1,false,false,0);
        h.PackStart(b2,false,false,0);

        w.Add(h);
        w.SetDefaultSize(100,100);
        w.ShowAll();

        //-- Inicializar chronopic
        cp = new Chronopic("/dev/ttyUSB0");

        //-- Inicializar otras cosas
        Cola = new Queue();

        //-- Inicializar temporizador
        GLib.Timeout.Add(100, new GLib.TimeoutHandler(Time_Out));

        Application.Run();
    }
Example #7
0
    //reactionTime execution
    public ReactionTimeExecute(int personID, string personName, int sessionID,   
			Chronopic cp, Gtk.TextView event_execute_textview_message, Gtk.Window app, int pDN, bool volumeOn,
			double progressbarLimit, ExecutingGraphData egd 
			)
    {
        this.personID = personID;
        this.personName = personName;
        this.sessionID = sessionID;

        this.cp = cp;
        this.event_execute_textview_message = event_execute_textview_message;
        this.app = app;

        this.pDN = pDN;
        this.volumeOn = volumeOn;
        this.progressbarLimit = progressbarLimit;
        this.egd = egd;

        fakeButtonUpdateGraph = new Gtk.Button();
        fakeButtonEventEnded = new Gtk.Button();
        fakeButtonFinished = new Gtk.Button();

        simulated = false;

        needUpdateEventProgressBar = false;
        needUpdateGraph = false;

        //initialize eventDone as a ReactionTime
        eventDone = new ReactionTime();

        //updateProgressBar = new UpdateProgressBar();
    }
Example #8
0
    //jump execution
    public JumpRjExecute(int personID, string personName,
                         int sessionID, string type, double fall, double weight,
                         double limitAsDouble, bool jumpsLimited,
                         Chronopic cp, Gtk.Window app, int pDN, bool allowFinishAfterTime,
                         bool volumeOn, Preferences.GstreamerTypes gstreamer,
                         RepetitiveConditionsWindow repetitiveConditionsWin,
                         double progressbarLimit, ExecutingGraphData egd
                         )
    {
        this.personID      = personID;
        this.personName    = personName;
        this.sessionID     = sessionID;
        this.type          = type;
        this.fall          = fall;
        this.weight        = weight;
        this.limitAsDouble = limitAsDouble;

        this.jumpsLimited = jumpsLimited;
        if (jumpsLimited)
        {
            this.limited = limitAsDouble.ToString() + "J";
        }
        else
        {
            //this.limited = limitAsDouble.ToString() + "T"; define later, because it can be higher if allowFinishRjAfterTime is defined
        }

        this.cp  = cp;
        this.app = app;

        this.pDN = pDN;
        this.allowFinishAfterTime    = allowFinishAfterTime;
        this.volumeOn                = volumeOn;
        this.gstreamer               = gstreamer;
        this.repetitiveConditionsWin = repetitiveConditionsWin;
        this.progressbarLimit        = progressbarLimit;
        this.egd = egd;

        if (TypeHasFall)
        {
            hasFall = true;
        }
        else
        {
            hasFall = false;
        }

        fakeButtonUpdateGraph = new Gtk.Button();
        fakeButtonThreadDyed  = new Gtk.Button();

        simulated = false;

        needUpdateEventProgressBar = false;
        needUpdateGraph            = false;

        timesForSavingRepetitive = 10;         //number of times that this repetive event needs for being recorded in temporal table

        //initialize eventDone as a JumpRj
        eventDone = new JumpRj();
    }
Example #9
0
    //execution
    public PulseExecute(int personID, string personName, int sessionID, string type, double fixedPulse, int totalPulsesNum,  
			Chronopic cp, Gtk.TextView event_execute_textview_message, Gtk.Window app, int pDN, bool volumeOn,
			//double progressbarLimit, 
			ExecutingGraphData egd 
			)
    {
        this.personID = personID;
        this.personName = personName;
        this.sessionID = sessionID;
        this.type = type;
        this.fixedPulse = fixedPulse;
        this.totalPulsesNum = totalPulsesNum;

        this.cp = cp;
        this.event_execute_textview_message = event_execute_textview_message;
        this.app = app;

        this.pDN = pDN;
        this.volumeOn = volumeOn;
        //		this.progressbarLimit = progressbarLimit;
        this.egd = egd;

        fakeButtonUpdateGraph = new Gtk.Button();
        fakeButtonEventEnded = new Gtk.Button();
        fakeButtonFinished = new Gtk.Button();

        simulated = false;

        needUpdateEventProgressBar = false;
        needUpdateGraph = false;

        //initialize eventDone as a Pulse
        eventDone = new Pulse();
    }
Example #10
0
    // <----- change multitest firmware END

    //nullify only when exit software
    public void SerialPortsCloseIfNeeded(bool nullify)
    {
        if (sp != null && sp.IsOpen)
        {
            LogB.Information("Closing sp");
            sp.Close();

            LogB.Information("Flushing cp to see if helps on OSX port busy");
            cp.FlushByTimeOut();

            if (nullify)
            {
                LogB.Information("Disposing cp to see if helps on OSX port busy");
                cp = null;
            }
        }

        if (sp2 != null && sp2.IsOpen)
        {
            LogB.Information("Closing sp2");
            sp2.Close();

            LogB.Information("Flushing cp2 to see if helps on OSX port busy");
            cp2.FlushByTimeOut();

            if (nullify)
            {
                LogB.Information("Disposing cp2 to see if helps on OSX port busy");
                cp2 = null;
            }
        }
    }
Example #11
0
    //chronopic init should not touch  gtk, for the threads
    public bool Do(int currentCp, out Chronopic myCp, out SerialPort mySp, Chronopic.Plataforma myPS, string myPort, out string returnString, out bool success)
    {
        LogB.Information("starting connection with chronopic");

        CancelledByUser = false;
        success         = true;

        LogB.Information("chronopicInit-1");
        LogB.Information(string.Format("chronopic port: {0}", myPort));
        mySp = new SerialPort(myPort);
        try {
            mySp.Open();
            LogB.Information("chronopicInit-2");
            //-- Create chronopic object, for accessing chronopic
            myCp = new Chronopic(mySp);

            LogB.Information("chronopicInit-2.1");
            myCp.Flush();

            //if myCp has been cancelled
            if (myCp.AbortFlush)
            {
                LogB.Information("chronopicInit-2.2 cancelled");
                success = false;
                myCp    = new Chronopic();              //fake constructor
            }
            else
            {
                LogB.Information("chronopicInit-3");
                //on windows, this check make a crash
                //i think the problem is: as we don't really know the Timeout on Windows (.NET) and this variable is not defined on chronopic.cs
                //the Read_platform comes too much soon (when cp is not totally created), and this makes crash

                //-- Obtener el estado inicial de la plataforma

                bool ok = false;
                LogB.Information("chronopicInit-4");
                do
                {
                    LogB.Information("chronopicInit-5");
                    ok = myCp.Read_platform(out myPS);
                    LogB.Information("chronopicInit-6");
                } while(!ok && !CancelledByUser);
                LogB.Information("chronopicInit-7");
                if (!ok)
                {
                    //-- Si hay error terminar
                    LogB.Error(string.Format("Error: {0}", myCp.Error));
                    success = false;
                }
            }
        } catch {
            LogB.Error("chronopicInit-2.a catched");
            success = false;
            myCp    = new Chronopic();          //fake constructor
        }

        returnString = "";
        return(success);
    }
Example #12
0
    public ChronopicWindow(Chronopic cpDetected, ArrayList myCpd)
    {
        LogB.Debug("constructor");

        Glade.XML gxml;
        gxml = Glade.XML.FromAssembly(Util.GetGladePath() + "chronojump.glade", "chronopic_window", "chronojump");
        gxml.Autoconnect(this);

        cpd = myCpd;

        if (cpDetected != null)
        {
            cp = cpDetected;
            sp = new SerialPort(((ChronopicPortData)cpd[0]).Port);
        }

        UtilGtk.IconWindow(chronopic_window);

        if (UtilAll.IsWindows())
        {
            isWindows = true;
        }
        else
        {
            isWindows = false;
        }

        setDefaultValues();

        chronopicInit = new ChronopicInit();

        //Pixbuf pixbuf = new Pixbuf (null, Util.GetImagePath(false) + "chronopic_128.png");
        //chronopic_image.Pixbuf = pixbuf;

        /*
         * Pixbuf pixbuf;
         * pixbuf = new Pixbuf (null, Util.GetImagePath(true) + Constants.FileNameContactPlatformModular);
         * image_contact_modular.Pixbuf = pixbuf;
         * pixbuf = new Pixbuf (null, Util.GetImagePath(true) + Constants.FileNameInfrared);
         * image_infrared.Pixbuf = pixbuf;
         */

        /*
         * if(chronopicPort1 != Constants.ChronopicDefaultPortWindows &&
         *              (chronopicPort1 != Constants.ChronopicDefaultPortLinux && File.Exists(chronopicPort1))
         * ) {
         *      ConfirmWindow confirmWin = ConfirmWindow.Show(Catalog.GetString("Do you want to connect to Chronopic now?"), "", "");
         *      confirmWin.Button_accept.Clicked += new EventHandler(chronopicAtStart);
         * }
         */
    }
Example #13
0
    //jump execution
    public JumpExecute(int personID, string personName, int sessionID, string type, double fall, double weight,
                       Chronopic cp, Gtk.Window app, int pDN,
                       bool volumeOn, Preferences.GstreamerTypes gstreamer,
                       double progressbarLimit, ExecutingGraphData egd, string description,
                       bool avoidGraph  //on configChronojump.Exhibition do not show graph because it gets too slow with big database
                       )
    {
        this.personID   = personID;
        this.personName = personName;
        this.sessionID  = sessionID;
        this.type       = type;
        this.fall       = fall;   //-1 means has to be calculated with a previous jump
        this.weight     = weight;

        this.cp  = cp;
        this.app = app;

        this.pDN              = pDN;
        this.volumeOn         = volumeOn;
        this.gstreamer        = gstreamer;
        this.progressbarLimit = progressbarLimit;
        this.egd              = egd;
        this.description      = description;
        this.avoidGraph       = avoidGraph;

        if (TypeHasFall)
        {
            hasFall = true;
        }
        else
        {
            hasFall = false;
        }

        fakeButtonUpdateGraph = new Gtk.Button();
        fakeButtonThreadDyed  = new Gtk.Button();

        simulated = false;

        needUpdateEventProgressBar = false;
        needUpdateGraph            = false;

        //initialize eventDone as a Jump
        eventDone = new Jump();
    }
Example #14
0
    //jump execution
    public JumpExecute(int personID, string personName, int sessionID, string type, double fall, double weight,
                       Chronopic cp, Gtk.Label event_execute_label_message, Gtk.Window app, int pDN, bool volumeOn,
                       double progressbarLimit, ExecutingGraphData egd, string description
                       )
    {
        this.personID   = personID;
        this.personName = personName;
        this.sessionID  = sessionID;
        this.type       = type;
        this.fall       = fall;   //-1 means has to be calculated with a previous jump
        this.weight     = weight;

        this.cp = cp;
        this.event_execute_label_message = event_execute_label_message;
        this.app = app;

        this.pDN              = pDN;
        this.volumeOn         = volumeOn;
        this.progressbarLimit = progressbarLimit;
        this.egd              = egd;
        this.description      = description;

        if (TypeHasFall)
        {
            hasFall = true;
        }
        else
        {
            hasFall = false;
        }

        fakeButtonUpdateGraph = new Gtk.Button();
        fakeButtonEventEnded  = new Gtk.Button();
        fakeButtonFinished    = new Gtk.Button();
        fakeButtonThreadDyed  = new Gtk.Button();

        simulated = false;

        needUpdateEventProgressBar = false;
        needUpdateGraph            = false;

        //initialize eventDone as a Jump
        eventDone = new Jump();
    }
Example #15
0
    //jump execution
    public JumpExecute(int personID, string personName, int sessionID, string type, double fall, double weight,  
			Chronopic cp, Gtk.Label event_execute_label_message, Gtk.Window app, int pDN, bool volumeOn,
			double progressbarLimit, ExecutingGraphData egd, string description
			)
    {
        this.personID = personID;
        this.personName = personName;
        this.sessionID = sessionID;
        this.type = type;
        this.fall = fall; //-1 means has to be calculated with a previous jump
        this.weight = weight;

        this.cp = cp;
        this.event_execute_label_message = event_execute_label_message;
        this.app = app;

        this.pDN = pDN;
        this.volumeOn = volumeOn;
        this.progressbarLimit = progressbarLimit;
        this.egd = egd;
        this.description = description;

        if(TypeHasFall) {
            hasFall = true;
        } else {
            hasFall = false;
        }

        fakeButtonUpdateGraph = new Gtk.Button();
        fakeButtonEventEnded = new Gtk.Button();
        fakeButtonFinished = new Gtk.Button();
        fakeButtonThreadDyed = new Gtk.Button();

        simulated = false;

        needUpdateEventProgressBar = false;
        needUpdateGraph = false;

        //initialize eventDone as a Jump
        eventDone = new Jump();
    }
Example #16
0
    protected Chronopic.Plataforma chronopicInitialValue(Chronopic cp)
    {
        Chronopic.Plataforma myPlatformState = Chronopic.Plataforma.UNKNOW; //on (in platform), off (jumping), or unknow
        bool ok        = false;
        int  timeWait  = 50;                                                //wait 50ms between calls to Read_platform
        int  timeLimit = 1000;
        int  count     = 0;

        do
        {
            try {
                ok = cp.Read_platform(out myPlatformState);
            } catch {
                LogB.Warning("Manage called after finishing constructor, do later");
            }
            Thread.Sleep(timeWait);             //wait 50ms
            count += timeWait;
        } while (!ok && count < timeLimit);

        return(myPlatformState);
    }
Example #17
0
    //jump execution
    public JumpExecute(int personID, string personName, int sessionID, string type, double fall, double weight,  
			Chronopic cp, Gtk.TextView event_execute_textview_message, Gtk.Window app, int pDN, bool volumeOn,
			double progressbarLimit, ExecutingGraphData egd 
			)
    {
        this.personID = personID;
        this.personName = personName;
        this.sessionID = sessionID;
        this.type = type;
        this.fall = fall;
        this.weight = weight;

        this.cp = cp;
        this.event_execute_textview_message = event_execute_textview_message;
        this.app = app;

        this.pDN = pDN;
        this.volumeOn = volumeOn;
        this.progressbarLimit = progressbarLimit;
        this.egd = egd;

        if(TypeHasFall) {
            hasFall = true;
        } else {
            hasFall = false;
        }

        fakeButtonUpdateGraph = new Gtk.Button();
        fakeButtonEventEnded = new Gtk.Button();
        fakeButtonFinished = new Gtk.Button();

        simulated = false;

        needUpdateEventProgressBar = false;
        needUpdateGraph = false;

        //initialize eventDone as a Jump
        eventDone = new Jump();
    }
Example #18
0
    //run execution
    public RunExecute(int personID, int sessionID, string type, double distance,
                      Chronopic cp, Gtk.Label event_execute_label_message, Gtk.Window app,
                      int pDN, bool metersSecondsPreferred, bool volumeOn,
                      double progressbarLimit, ExecutingGraphData egd,
                      Constants.DoubleContact checkDoubleContactMode, int checkDoubleContactTime,
                      bool speedStartArrival
                      )
    {
        this.personID  = personID;
        this.sessionID = sessionID;
        this.type      = type;
        this.distance  = distance;

        this.cp = cp;
        this.event_execute_label_message = event_execute_label_message;
        this.app = app;

        this.pDN = pDN;
        this.metersSecondsPreferred = metersSecondsPreferred;
        this.volumeOn         = volumeOn;
        this.progressbarLimit = progressbarLimit;
        this.egd = egd;
        this.checkDoubleContactMode = checkDoubleContactMode;
        this.checkDoubleContactTime = checkDoubleContactTime;
        this.speedStartArrival      = speedStartArrival;

        fakeButtonUpdateGraph = new Gtk.Button();
        fakeButtonEventEnded  = new Gtk.Button();
        fakeButtonFinished    = new Gtk.Button();
        fakeButtonThreadDyed  = new Gtk.Button();

        simulated = false;

        needUpdateEventProgressBar = false;
        needUpdateGraph            = false;

        //initialize eventDone as a Run
        eventDone = new Run();
    }
Example #19
0
    //run execution
    public RunExecute(int personID, int sessionID, string type, double distance,   
			Chronopic cp, Gtk.Label event_execute_label_message, Gtk.Window app, 
			int pDN, bool metersSecondsPreferred, bool volumeOn,
			double progressbarLimit, ExecutingGraphData egd,
			Constants.DoubleContact checkDoubleContactMode, int checkDoubleContactTime, 
			bool speedStartArrival
			)
    {
        this.personID = personID;
        this.sessionID = sessionID;
        this.type = type;
        this.distance = distance;

        this.cp = cp;
        this.event_execute_label_message = event_execute_label_message;
        this.app = app;

        this.pDN = pDN;
        this.metersSecondsPreferred = metersSecondsPreferred;
        this.volumeOn = volumeOn;
        this.progressbarLimit = progressbarLimit;
        this.egd = egd;
        this.checkDoubleContactMode = checkDoubleContactMode;
        this.checkDoubleContactTime = checkDoubleContactTime;
        this.speedStartArrival = speedStartArrival;

        fakeButtonUpdateGraph = new Gtk.Button();
        fakeButtonEventEnded = new Gtk.Button();
        fakeButtonFinished = new Gtk.Button();
        fakeButtonThreadDyed = new Gtk.Button();

        simulated = false;

        needUpdateEventProgressBar = false;
        needUpdateGraph = false;

        //initialize eventDone as a Run
        eventDone = new Run();
    }
Example #20
0
    //----------------------------------------
    //-- Obtener el estado de la plataforma
    //----------------------------------------
    public Respuesta Read_platform(out Plataforma plataforma)
    {
        int       error;
        int       estado;
        Respuesta resp;

        //-- Enviar trama de estado
        error = Chronopic.estado(this.serial_fd, out estado);

        //-- Convertir el error al tipo Respueta
        switch (error)
        {
        case 0:
            resp       = Respuesta.Timeout;
            plataforma = Plataforma.UNKNOW;
            break;

        case 1:
            resp = Respuesta.Ok;
            if (estado == 0)
            {
                plataforma = Plataforma.OFF;
            }
            else
            {
                plataforma = Plataforma.ON;
            }
            break;

        default:
            resp       = Respuesta.Error;
            plataforma = Plataforma.UNKNOW;
            break;
        }

        //-- Devolver Respuesta
        return(resp);
    }
Example #21
0
    //execution
    public MultiChronopicExecute(int personID, string personName, int sessionID, string type, 
			Chronopic cp, bool syncFirst, bool deleteFirst, string vars, Gtk.Window app,
			//double progressbarLimit, 
			ExecutingGraphData egd
			)
    {
        this.personID = personID;
        this.personName = personName;
        this.sessionID = sessionID;
        this.type = type;

        this.cp = cp;
        this.syncFirst = syncFirst;
        this.deleteFirst = deleteFirst;
        this.vars = vars;

        this.app = app;
        //		this.progressbarLimit = progressbarLimit;
        this.egd = egd;

        chronopics = 1;
        initValues();
    }
Example #22
0
    //reactionTime execution
    public ReactionTimeExecute(int personID, string personName, int sessionID, string type,
			Chronopic cp, Gtk.Label event_execute_label_message, Gtk.Window app, int pDN, bool volumeOn,
			double progressbarLimit, ExecutingGraphData egd, string description
			)
    {
        this.personID = personID;
        this.personName = personName;
        this.sessionID = sessionID;
        this.type = type;

        this.cp = cp;
        this.event_execute_label_message = event_execute_label_message;
        this.app = app;

        this.pDN = pDN;
        this.volumeOn = volumeOn;
        this.progressbarLimit = progressbarLimit;
        this.egd = egd;
        this.description = description;

        fakeButtonUpdateGraph = new Gtk.Button();
        fakeButtonEventEnded = new Gtk.Button();
        fakeButtonFinished = new Gtk.Button();
        fakeButtonThreadDyed = new Gtk.Button();

        FakeButtonReactionTimeStart = new Gtk.Button();

        simulated = false;

        needUpdateEventProgressBar = false;
        needUpdateGraph = false;

        //initialize eventDone as a ReactionTime
        eventDone = new ReactionTime();

        //updateProgressBar = new UpdateProgressBar();
    }
Example #23
0
    //reactionTime execution
    public ReactionTimeExecute(int personID, string personName, int sessionID, string type,
                               Chronopic cp, Gtk.Window app, int pDN,
                               bool volumeOn, Preferences.GstreamerTypes gstreamer,
                               double progressbarLimit, ExecutingGraphData egd, string description
                               )
    {
        this.personID   = personID;
        this.personName = personName;
        this.sessionID  = sessionID;
        this.type       = type;

        this.cp  = cp;
        this.app = app;

        this.pDN              = pDN;
        this.volumeOn         = volumeOn;
        this.gstreamer        = gstreamer;
        this.progressbarLimit = progressbarLimit;
        this.egd              = egd;
        this.description      = description;

        fakeButtonUpdateGraph = new Gtk.Button();
        fakeButtonThreadDyed  = new Gtk.Button();

        FakeButtonReactionTimeStart = new Gtk.Button();

        simulated = false;

        needUpdateEventProgressBar = false;
        needUpdateGraph            = false;


        //initialize eventDone as a ReactionTime
        eventDone = new ReactionTime();

        //updateProgressBar = new UpdateProgressBar();
    }
Example #24
0
    //reactionTime execution
    public ReactionTimeExecute(int personID, string personName, int sessionID,
                               Chronopic cp, Gtk.Label event_execute_label_message, Gtk.Window app, int pDN, bool volumeOn,
                               double progressbarLimit, ExecutingGraphData egd, string description
                               )
    {
        this.personID   = personID;
        this.personName = personName;
        this.sessionID  = sessionID;

        this.cp = cp;
        this.event_execute_label_message = event_execute_label_message;
        this.app = app;

        this.pDN              = pDN;
        this.volumeOn         = volumeOn;
        this.progressbarLimit = progressbarLimit;
        this.egd              = egd;
        this.description      = description;

        fakeButtonUpdateGraph = new Gtk.Button();
        fakeButtonEventEnded  = new Gtk.Button();
        fakeButtonFinished    = new Gtk.Button();
        fakeButtonThreadDyed  = new Gtk.Button();

        FakeButtonReactionTimeStart = new Gtk.Button();

        simulated = false;

        needUpdateEventProgressBar = false;
        needUpdateGraph            = false;


        //initialize eventDone as a ReactionTime
        eventDone = new ReactionTime();

        //updateProgressBar = new UpdateProgressBar();
    }
Example #25
0
    //run execution
    public RunIntervalExecute(int personID, int sessionID, string type, double distanceInterval, double limitAsDouble, bool tracksLimited,  
			Chronopic cp, Gtk.Label event_execute_label_message, Gtk.Window app, int pDN, bool metersSecondsPreferred, 
			bool volumeOn, RepetitiveConditionsWindow repetitiveConditionsWin,
			double progressbarLimit, ExecutingGraphData egd ,
			Constants.DoubleContact checkDoubleContactMode, int checkDoubleContactTime, 
			bool speedStartArrival
			)
    {
        this.personID = personID;
        this.sessionID = sessionID;
        this.type = type;
        this.distanceInterval = distanceInterval;
        this.limitAsDouble = limitAsDouble;
        this.tracksLimited = tracksLimited;

        //if distances are variable
        distancesString = "";
        if(distanceInterval == -1) {
            RunType runType = SqliteRunIntervalType.SelectAndReturnRunIntervalType(type, false);
            distancesString = runType.DistancesString;
        }

        if(tracksLimited) {
            this.limited = limitAsDouble.ToString() + "R"; //'R'uns (don't put 'T'racks for not confusing with 'T'ime)
        } else {
            this.limited = limitAsDouble.ToString() + "T";
            timeTotal = limitAsDouble;
        }

        this.cp = cp;
        this.event_execute_label_message = event_execute_label_message;
        this.app = app;

        this.metersSecondsPreferred = metersSecondsPreferred;
        this.pDN = pDN;
        this.volumeOn = volumeOn;
        this.repetitiveConditionsWin = repetitiveConditionsWin;
        this.progressbarLimit = progressbarLimit;
        this.egd = egd;
        this.checkDoubleContactMode = checkDoubleContactMode;
        this.checkDoubleContactTime = checkDoubleContactTime;
        this.speedStartArrival = speedStartArrival;

        fakeButtonUpdateGraph = new Gtk.Button();
        fakeButtonEventEnded = new Gtk.Button();
        fakeButtonFinished = new Gtk.Button();
        fakeButtonThreadDyed = new Gtk.Button();

        simulated = false;

        needUpdateEventProgressBar = false;
        needUpdateGraph = false;

        timesForSavingRepetitive = 1; //number of times that this repetive event needs for being recorded in temporal table

        //initialize eventDone as a RunInterval
        eventDone = new RunInterval();
    }
Example #26
0
    //run execution
    public RunIntervalExecute(int personID, int sessionID, string type, double distanceInterval, double limitAsDouble, bool tracksLimited,
                              Chronopic cp, Gtk.Label event_execute_label_message, Gtk.Window app, int pDN, bool metersSecondsPreferred,
                              bool volumeOn, RepetitiveConditionsWindow repetitiveConditionsWin,
                              double progressbarLimit, ExecutingGraphData egd,
                              Constants.DoubleContact checkDoubleContactMode, int checkDoubleContactTime,
                              bool speedStartArrival
                              )
    {
        this.personID         = personID;
        this.sessionID        = sessionID;
        this.type             = type;
        this.distanceInterval = distanceInterval;
        this.limitAsDouble    = limitAsDouble;
        this.tracksLimited    = tracksLimited;

        //if distances are variable
        distancesString = "";
        if (distanceInterval == -1)
        {
            RunType runType = SqliteRunIntervalType.SelectAndReturnRunIntervalType(type, false);
            distancesString = runType.DistancesString;
        }


        if (tracksLimited)
        {
            this.limited = limitAsDouble.ToString() + "R";             //'R'uns (don't put 'T'racks for not confusing with 'T'ime)
        }
        else
        {
            this.limited = limitAsDouble.ToString() + "T";
            timeTotal    = limitAsDouble;
        }


        this.cp = cp;
        this.event_execute_label_message = event_execute_label_message;
        this.app = app;

        this.metersSecondsPreferred = metersSecondsPreferred;
        this.pDN      = pDN;
        this.volumeOn = volumeOn;
        this.repetitiveConditionsWin = repetitiveConditionsWin;
        this.progressbarLimit        = progressbarLimit;
        this.egd = egd;
        this.checkDoubleContactMode = checkDoubleContactMode;
        this.checkDoubleContactTime = checkDoubleContactTime;
        this.speedStartArrival      = speedStartArrival;

        fakeButtonUpdateGraph = new Gtk.Button();
        fakeButtonEventEnded  = new Gtk.Button();
        fakeButtonFinished    = new Gtk.Button();
        fakeButtonThreadDyed  = new Gtk.Button();

        simulated = false;

        needUpdateEventProgressBar = false;
        needUpdateGraph            = false;

        timesForSavingRepetitive = 1;         //number of times that this repetive event needs for being recorded in temporal table

        //initialize eventDone as a RunInterval
        eventDone = new RunInterval();
    }
Example #27
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 #28
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 #29
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 #30
0
    //jump execution
    public JumpRjExecute(int personID, string personName, 
			int sessionID, string type, double fall, double weight, 
			double limitAsDouble, bool jumpsLimited, 
			Chronopic cp, Gtk.TextView event_execute_textview_message, Gtk.Window app, int pDN, bool allowFinishAfterTime, 
			bool volumeOn, RepetitiveConditionsWindow repetitiveConditionsWin,
			double progressbarLimit, ExecutingGraphData egd 
			)
    {
        this.personID = personID;
        this.personName = personName;
        this.sessionID = sessionID;
        this.type = type;
        this.fall = fall;
        this.weight = weight;
        this.limitAsDouble = limitAsDouble;

        this.jumpsLimited = jumpsLimited;
        if(jumpsLimited) {
            this.limited = limitAsDouble.ToString() + "J";
        } else {
            //this.limited = limitAsDouble.ToString() + "T"; define later, because it can be higher if allowFinishRjAfterTime is defined
        }

        this.cp = cp;
        this.event_execute_textview_message = event_execute_textview_message;
        this.app = app;

        this.pDN = pDN;
        this.allowFinishAfterTime = allowFinishAfterTime;
        this.volumeOn = volumeOn;
        this.repetitiveConditionsWin = repetitiveConditionsWin;
        this.progressbarLimit = progressbarLimit;
        this.egd = egd;

        if(TypeHasFall) { hasFall = true; }
        else { hasFall = false; }

        fakeButtonUpdateGraph = new Gtk.Button();
        fakeButtonEventEnded = new Gtk.Button();
        fakeButtonFinished = new Gtk.Button();

        simulated = false;

        needUpdateEventProgressBar = false;
        needUpdateGraph = false;

        timesForSavingRepetitive = 10; //number of times that this repetive event needs for being recorded in temporal table

        //initialize eventDone as a JumpRj
        eventDone = new JumpRj();
    }
Example #31
0
    /**********************/
    /* PROGRAMA PRINCIPAL */
    /**********************/
    public static void Main()
    {
        Chronopic.Plataforma estado_plataforma;
        Chronopic.Respuesta  respuesta;
        Automata             estado_automata;
        double timestamp;
        double toff;

        //-- Crear objeto chronopic, para acceder al chronopic
        Chronopic cp = new Chronopic("/dev/ttyUSB0");

        //-- Obtener el estado inicial de la plataforma
        respuesta = cp.Read_platform(out estado_plataforma);
        switch (respuesta)
        {
        case Chronopic.Respuesta.Error:
            Console.WriteLine("Error en comunicacion con Chronopic");
            return;

        case Chronopic.Respuesta.Timeout:
            Console.WriteLine("Chronopic no responde");
            return;

        default:
            break;
        }

        Console.WriteLine("Estado plataforma: {0}", estado_plataforma);

        //-- Establecer el estado inicial del automata
        if (estado_plataforma == Chronopic.Plataforma.ON)
        {
            estado_automata = Automata.ON;
        }
        else
        {
            Console.WriteLine("Suba a la plataforma para realizar el salto");

            //-- Esperar a que llegue una trama con el estado de la plataforma
            //-- igual a ON. Esto indica que el usuario se ha subido
            do
            {
                respuesta = cp.Read_event(out timestamp, out estado_plataforma);
            } while (respuesta != Chronopic.Respuesta.Ok);

            //-- Se han subido a la plataforma
            estado_automata = Automata.ON;
        }

        Console.WriteLine("");
        Console.WriteLine("Puede saltar cuando quiera");
        Console.WriteLine("Pulse control-c para finalizar la sesion");
        Console.WriteLine("-----------------------------------------");

        while (true)
        {
            //-- Esperar a que llegue una trama
            do
            {
                respuesta = cp.Read_event(out timestamp, out estado_plataforma);
            } while (respuesta != Chronopic.Respuesta.Ok);


            //-- Segun el estado del automata
            switch (estado_automata)
            {
            case Automata.OFF: //-- Usuario estaba en el aire

                //-- Si ha aterrizado
                if (estado_plataforma == Chronopic.Plataforma.ON)
                {
                    //-- Pasar al estado ON
                    estado_automata = Automata.ON;

                    //-- Registrar tiempo de vuelo
                    toff = timestamp;

                    //-- Imprimir informacion
                    Console.WriteLine("Tiempo: {0:f1} ms", toff);
                }
                break;

            case Automata.ON: //-- Usuario estaba en la plataforma

                //-- Si ahora esta en el aire...
                if (estado_plataforma == Chronopic.Plataforma.OFF)
                {
                    //-- Pasar al estado OFF
                    estado_automata = Automata.OFF;
                }
                break;
            }
        }
    }
    /**********************/
    /* PROGRAMA PRINCIPAL */
    /**********************/
    public static void Main(string[] args)
    {
        Chronopic.Plataforma estado_plataforma;
        Automata             estado_automata;
        double     timestamp;
        double     toff;
        double     ton;
        bool       ok;
        string     portName = "";
        string     fileName = "";
        TextWriter writer;

        //always output to a file, but if not specified, output here and rewrite it every chronojump_mini execution
        string defaultFileName = Path.Combine(getOutputDir(), "output");


        System.Threading.Thread.CurrentThread.CurrentCulture   = new System.Globalization.CultureInfo("es-ES");
        System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("es-ES");

        //connect with catalog.cs for using gettext translation
        Catalog.Init("chronojump", "./locale");

        //parameters passing only on linux
        if (!UtilAll.IsWindows())
        {
            if (args.Length > 2)
            {
                printSyntaxAndQuit();
            }

            for (int i = 0; i != args.Length; ++i)
            {
                Console.WriteLine("param[{0}]: {1}", i, args[i]);
                if (args[i].StartsWith("PORT="))
                {
                    portName = args[i].Substring(5);
                }
                else if (args[i].StartsWith("FILE="))
                {
                    fileName = args[i].Substring(5);
                    fileName = getOutputDir() + Path.DirectorySeparatorChar + fileName;
                }
                else
                {
                    printSyntaxAndQuit();
                }
            }
        }

        //detection of ports
        string messageInfo;

        //string messageDetected ="";

        if (UtilAll.IsWindows())
        {
            messageInfo = Constants.PortNamesWindows;

            /*
             * messageDetected = Catalog.GetString("Detected ports:") + "\n";
             *
             * string jumpLine = "";
             * foreach (string s in SerialPort.GetPortNames()) {
             *      messageDetected += jumpLine + s;
             *      jumpLine = "\n";
             * }
             */
        }
        else
        {
            messageInfo = Constants.PortNamesLinux;
        }

        messageInfo += string.Format("\n" + Catalog.GetString("More information on Chronojump manual"));

        Console.WriteLine("---------------------------");
        Console.WriteLine(messageInfo);
        Console.WriteLine("---------------------------");

        if (portName == "")
        {
            if (!UtilAll.IsWindows())
            {
                Console.WriteLine(UtilAll.DetectPortsLinux(false));                 //formatting
            }
            Console.WriteLine(Catalog.GetString("Print the port name where chronopic is connected:"));
            portName = Console.ReadLine();
        }

        //output file stuff
        fileName = manageFileName(fileName);
        if (fileName == "")
        {
            fileName = defaultFileName + "-" + portName.Replace("/", "") + ".csv";
        }

        writer = File.CreateText(fileName);


        Console.WriteLine(Catalog.GetString("Opening port...") + " " +
                          Catalog.GetString("Please touch the platform or click Chronopic TEST button"));
        //-- Crear puerto serie
        SerialPort sp;

        sp = new SerialPort(portName);

        //-- Abrir puerto serie. Si ocurre algun error
        //-- Se lanzara una excepcion
        try {
            sp.Open();
        } catch (Exception e) {
            Console.WriteLine(Catalog.GetString("Error opening serial port"));
            Console.WriteLine(e);
            Environment.Exit(1);
        }



        //-- Crear objeto chronopic, para acceder al chronopic
        Chronopic cp = new Chronopic(sp);

        cp.Flush();


        //-- Obtener el estado inicial de la plataforma
        // this do...while is here because currently there's no timeout on chronopic.cs on windows
        do
        {
            ok = cp.Read_platform(out estado_plataforma);
        } while(!ok);
        if (!ok)
        {
            //-- Si hay error terminar
            Console.WriteLine(string.Format(Catalog.GetString("Error: {0}"), cp.Error));
            System.Environment.Exit(-1);
        }
        Console.WriteLine(string.Format(Catalog.GetString("Platform state: {0}"), estado_plataforma));


        //Console.WriteLine("Automatic variables: ");
        //cp.Read_variables_automatic();


        //-- Establecer el estado inicial del automata
        if (estado_plataforma == Chronopic.Plataforma.ON)
        {
            estado_automata = Automata.ON;
        }
        else
        {
            Console.WriteLine(Catalog.GetString("Go up platform for jumping"));

            //-- Esperar a que llegue una trama con el estado de la plataforma
            //-- igual a ON. Esto indica que el usuario se ha subido
            do
            {
                ok = cp.Read_event(out timestamp, out estado_plataforma);
            } while (!ok);

            //-- Se han subido a la plataforma
            estado_automata = Automata.ON;
        }

        Console.WriteLine("");
        Console.WriteLine(Catalog.GetString("Jump when prepared"));
        Console.WriteLine(Catalog.GetString("Press CTRL-c for ending session"));
        Console.WriteLine("-----------------------------------------");

        double count = 1.0;

        Console.WriteLine("  TC(ms) TF(ms)");
        writer.WriteLine("count;TC(ms);TF(ms)");

        while (true)
        {
            //-- Esperar a que llegue una trama
            do
            {
                ok = cp.Read_event(out timestamp, out estado_plataforma);
            } while (ok == false);


            //-- Segun el estado del automata
            switch (estado_automata)
            {
            case Automata.OFF:                     //-- Usuario estaba en el aire

                //-- Si ha aterrizado
                if (estado_plataforma == Chronopic.Plataforma.ON)
                {
                    //-- Pasar al estado ON
                    estado_automata = Automata.ON;

                    //-- Registrar tiempo de vuelo
                    toff = timestamp;

                    //-- Imprimir informacion
                    Console.WriteLine("{0:f1}", toff);
                    writer.WriteLine("{0:f1}", toff);
                }
                break;

            case Automata.ON:                     //-- Usuario estaba en la plataforma

                //-- Si ahora esta en el aire...
                if (estado_plataforma == Chronopic.Plataforma.OFF)
                {
                    //-- Pasar al estado OFF
                    estado_automata = Automata.OFF;

                    //-- Registrar tiempo de contacto
                    ton = timestamp;

                    //-- Imprimir informacion
                    Console.Write(count + " {0:f1} ", ton);
                    writer.Write(count + ";{0:f1};", ton);
                }
                break;
            }

            writer.Flush();

            count += .5;
        }
    }
Example #33
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 #34
0
    //chronopic init should not touch  gtk, for the threads
    public bool Do(int currentCp, out Chronopic myCp, out SerialPort mySp, Chronopic.Plataforma myPS, string myPort, out string returnString, out bool success)
    {
        LogB.Information("starting connection with chronopic");

        CancelledByUser = false;
        success         = true;

        LogB.Information("chronopicInit-1");
        LogB.Information(string.Format("chronopic port: {0}", myPort));
        mySp = new SerialPort(myPort);
        try {
            mySp.Open();
            LogB.Information("chronopicInit-2");
            //-- Create chronopic object, for accessing chronopic
            myCp = new Chronopic(mySp);

            LogB.Information("chronopicInit-2.1");
            myCp.Flush();

            //if myCp has been cancelled
            if (myCp.AbortFlush)
            {
                LogB.Information("chronopicInit-2.2 cancelled");
                success = false;
                myCp    = new Chronopic();              //fake constructor
            }
            else
            {
                LogB.Information("chronopicInit-3");
                //on windows, this check make a crash
                //i think the problem is: as we don't really know the Timeout on Windows (.NET) and this variable is not defined on chronopic.cs
                //the Read_platform comes too much soon (when cp is not totally created), and this makes crash

                //-- Obtener el estado inicial de la plataforma

                bool ok = false;
                LogB.Information("chronopicInit-4");
                do
                {
                    LogB.Information("chronopicInit-5");
                    ok = myCp.Read_platform(out myPS);
                    LogB.Information("chronopicInit-6");
                } while(!ok && !CancelledByUser);
                LogB.Information("chronopicInit-7");
                if (!ok)
                {
                    //-- Si hay error terminar
                    LogB.Error(string.Format("Error: {0}", myCp.Error));
                    success = false;
                }
            }
        } catch {
            LogB.Error("chronopicInit-2.a catched");
            success = false;
            myCp    = new Chronopic();          //fake constructor
        }

        bool connected = false;

        returnString = "";
        if (success)
        {
            if (currentCp == 1)
            {
                connected = true;
            }
            returnString = string.Format(Catalog.GetString("<b>Connected</b> to Chronopic on port: {0}"), myPort);
        }
        else
        {
            returnString = Catalog.GetString("Problems communicating to chronopic.");
            if (currentCp == 1)
            {
                returnString += " " + Catalog.GetString("Changed platform to 'Simulated'");
                returnString += Catalog.GetString("\n\nWe recommend to remove and connect USB cable.");
            }

            //this will raise on_radiobutton_simulated_ativate and
            //will put cpRunning to false, and simulated to true and cp.Close()
            if (currentCp == 1)
            {
                connected = false;
            }
        }

        return(connected);
    }
Example #35
0
    // <----- change multitest firmware END
    public void SerialPortsCloseIfNeeded()
    {
        if(sp != null && sp.IsOpen) {
            LogB.Information("Closing sp");
            sp.Close();

            LogB.Information("Flushing cp to see if helps on OSX port busy");
            cp.FlushByTimeOut();

            LogB.Information("Disposing cp to see if helps on OSX port busy");
            cp = null;
        }

        if(sp2 != null && sp2.IsOpen) {
            LogB.Information("Closing sp2");
            sp2.Close();

            LogB.Information("Flushing cp2 to see if helps on OSX port busy");
            cp2.FlushByTimeOut();

            LogB.Information("Disposing cp2 to see if helps on OSX port busy");
            cp2 = null;
        }
    }
Example #36
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 #37
0
    protected Chronopic.Plataforma chronopicInitialValue(Chronopic cp)
    {
        Chronopic.Plataforma myPlatformState  = Chronopic.Plataforma.UNKNOW; //on (in platform), off (jumping), or unknow
        bool ok = false;
        int timeWait = 50; //wait 50ms between calls to Read_platform
        int timeLimit = 1000;
        int count = 0;

        do {
            try {
                ok = cp.Read_platform(out myPlatformState);
            } catch {
                Log.WriteLine("Manage called after finishing constructor, do later");
            }
            Thread.Sleep(timeWait); //wait 50ms
            count += timeWait;
        } while (! ok && count < timeLimit);

        return myPlatformState;
    }
Example #38
0
    protected void waitChronopicStart()
    {
        chronopicConnectionWin.Button_cancel.Clicked += new EventHandler(on_chronopic_cancelled);

        if(currentCp == 1) {
        //	simulated = false;
        //	SqlitePreferences.Update("simulated", simulated.ToString(), false);
            if(connected)
                return;
        }

        SerialPort sp2;
        SerialPort sp3;
        SerialPort sp4;

        string message = "";
        string myPort = "";
        bool success = false;

        if(currentCp == 1) {
            myPort = ((ChronopicPortData) cpd[0]).Port;
            cpDoing = cp;
            chronopicInit(out cpDoing, out sp, platformState, myPort, out message, out success);
            cp = cpDoing;
            if(success) {
                ((ChronopicPortData) cpd[0]).Connected=true;
                button_connect_cp1.Sensitive = false;
                image_cp1_no.Hide();
                image_cp1_yes.Show();

                if(isWindows) {
                    combo_windows1.Sensitive = false;
                    combo_windows2.Sensitive = true;
                    UtilGtk.ComboDelThisValue(combo_windows2, myPort);
                    combo_windows2.Active = 0; //first option
                    UtilGtk.ComboDelThisValue(combo_windows3, myPort);
                    combo_windows3.Active = 0;
                    UtilGtk.ComboDelThisValue(combo_windows4, myPort);
                    combo_windows4.Active = 0;
                } else {
                    combo_linux1.Sensitive = false;
                    combo_linux2.Sensitive = true;
                    UtilGtk.ComboDelThisValue(combo_linux2, myPort);
                    combo_linux2.Active = 0; //first option
                    UtilGtk.ComboDelThisValue(combo_linux3, myPort);
                    combo_linux3.Active = 0;
                    UtilGtk.ComboDelThisValue(combo_linux4, myPort);
                    combo_linux4.Active = 0;
                }
            }
        }
        else if(currentCp == 2) {
            myPort = ((ChronopicPortData) cpd[1]).Port;
            cpDoing = cp2;
            chronopicInit(out cpDoing, out sp2, platformState2, myPort, out message, out success);
            cp2 = cpDoing;
            if(success) {
                ((ChronopicPortData) cpd[1]).Connected=true;
                button_connect_cp2.Sensitive = false;
                image_cp2_no.Hide();
                image_cp2_yes.Show();

                if(isWindows) {
                    combo_windows2.Sensitive = false;
                    combo_windows3.Sensitive = true;
                    UtilGtk.ComboDelThisValue(combo_windows3, myPort);
                    combo_windows3.Active = 0;
                    UtilGtk.ComboDelThisValue(combo_windows4, myPort);
                    combo_windows4.Active = 0;
                } else {
                    combo_linux2.Sensitive = false;
                    combo_linux3.Sensitive = true;
                    UtilGtk.ComboDelThisValue(combo_linux3, myPort);
                    combo_linux3.Active = 0;
                    UtilGtk.ComboDelThisValue(combo_linux4, myPort);
                    combo_linux4.Active = 0;
                }
            }
        }
        else if(currentCp == 3) {
            myPort = ((ChronopicPortData) cpd[2]).Port;
            cpDoing = cp3;
            chronopicInit(out cpDoing, out sp3, platformState3, myPort, out message, out success);
            cp3 = cpDoing;
            if(success) {
                ((ChronopicPortData) cpd[2]).Connected=true;
                button_connect_cp3.Sensitive = false;
                image_cp3_no.Hide();
                image_cp3_yes.Show();

                if(isWindows) {
                    combo_windows3.Sensitive = false;
                    combo_windows4.Sensitive = true;
                    UtilGtk.ComboDelThisValue(combo_windows4, myPort);
                    combo_windows4.Active = 0;
                } else {
                    combo_linux3.Sensitive = false;
                    combo_linux4.Sensitive = true;
                    UtilGtk.ComboDelThisValue(combo_linux4, myPort);
                    combo_linux4.Active = 0;
                }
            }
        }
        else if(currentCp == 4) {
            myPort = ((ChronopicPortData) cpd[3]).Port;
            cpDoing = cp4;
            chronopicInit(out cpDoing, out sp4, platformState4, myPort, out message, out success);
            cp4 = cpDoing;
            if(success) {
                ((ChronopicPortData) cpd[3]).Connected=true;
                button_connect_cp4.Sensitive = false;
                image_cp4_no.Hide();
                image_cp4_yes.Show();

                if(isWindows)
                    combo_windows4.Sensitive = false;
                else
                    combo_linux4.Sensitive = false;
            }
        }

        Log.WriteLine(string.Format("wait_chronopic_start {0}", message));

        if(success) {
            Util.PlaySound(Constants.SoundTypes.GOOD, volumeOn);
            updateChronopicWinValuesState= true; //connected
            updateChronopicWinValuesMessage= message;
        } else {
            Util.PlaySound(Constants.SoundTypes.BAD, volumeOn);
            updateChronopicWinValuesState= false; //disconnected
            updateChronopicWinValuesMessage= message;
        }

        foreach(ChronopicPortData a in cpd)
            Log.WriteLine(a.Num + ", " + a.Port + ", " + a.Connected);

        fakeWindowDone.Click();
        needUpdateChronopicWin = true;
    }
    protected void waitEvent(Chronopic myCP, Chronopic.Plataforma myPS, States myLS, out string inStr, out string outStr, int cpNum)
    {
        double timestamp = 0;
        bool success = false;
        bool ok;
        string inEqual = "";
        string outEqual = "";

        inStr = ""; outStr = "";
        int runAnalysisTcCount = 0;
        int runAnalysisTfCount = 0;

        bool isFirstOut = true;
        bool isFirstIn = true;

        syncStates syncing = syncStates.DONE;
        if(syncFirst) {
            syncing = syncStates.NOTHING;
            feedbackMessage = Catalog.GetString("Press and mantain Test button in all Chronopics simultaneously.");
            needShowFeedbackMessage = true;
        }

        do {
            ok = myCP.Read_event(out timestamp, out myPS);

            //if chronopic signal is Ok and state has changed
            if (ok && (
                    (myPS == Chronopic.Plataforma.ON && myLS == States.OFF) ||
                    (myPS == Chronopic.Plataforma.OFF && myLS == States.ON) )
                        && !cancel && !finish) {

                //while no finished time or jumps, continue recording events
                if ( ! success) {
                    //don't record the time until the first event of the first Chronopic
                    //this is only executed on the first chronopic that receives a change
                    if (firstValue) {
                        firstValue = false;
                        initializeTimer(); //this is for first Chronopic and only for simulated

                        feedbackMessage = "";
                        needShowFeedbackMessage = true;
                    }

                    if(syncing == syncStates.NOTHING && myPS == Chronopic.Plataforma.ON && myLS == States.OFF) {
                        syncing = syncStates.CONTACTED;
                        feedbackMessage = Catalog.GetString("Release Test button in all Chronopics simultaneously.");
                        needShowFeedbackMessage = true;
                    }
                    else if (syncing == syncStates.CONTACTED && myPS == Chronopic.Plataforma.OFF && myLS == States.ON) {
                        syncing = syncStates.DONE;
                        feedbackMessage = Catalog.GetString("Synchronization done.") + "\n" +
                            Catalog.GetString("Test starts now.");
                        needShowFeedbackMessage = true;
                    }
                    else {
                        if(type != Constants.RunAnalysisName)
                            needSensitiveButtonFinish = true;

                        if(myPS == Chronopic.Plataforma.ON && myLS == States.OFF) {
                            //this is for runAnalysis, delete first tf on 2nd cp (jump cp)
                            if(cpNum == 2 && type == Constants.RunAnalysisName && runAnalysisTfCount == 0)
                                runAnalysisTfCount ++;
                            //this is for multiChronopic, not for runAnalysis
                            else if(deleteFirst && isFirstOut)
                                isFirstOut = false;
                            else {
                                double lastOut = timestamp/1000.0;
                                Log.WriteLine(cpNum.ToString() + " landed: " + lastOut.ToString());
                                outStr = outStr + outEqual + lastOut.ToString();
                                outEqual = "=";
                            }
                            /*
                               if it's a runAnalysis,
                               should end when arrive at 2n photocell (controlled by cp1)
                               */
                            if(cpNum == 1 && type == Constants.RunAnalysisName) {
                                runAnalysisTcCount ++;
                                if(runAnalysisTcCount >= 2) {
                                    success = true;
                                    //better call also finish
                                    //then all cps know about ending
                                    finish = true;
                                }
                            }
                        }
                        else if(myPS == Chronopic.Plataforma.OFF && myLS == States.ON) {
                            //this is for multiChronopic, not for runAnalysis
                            if(deleteFirst && isFirstIn)
                                isFirstIn = false;
                            else {
                                double lastIn = timestamp/1000.0;
                                Log.WriteLine(cpNum.ToString() + " jumped: " + lastIn.ToString());
                                inStr = inStr + inEqual + lastIn.ToString();
                                inEqual = "=";
                            }
                        }

                        PrepareEventGraphMultiChronopicObject = new PrepareEventGraphMultiChronopic(
                                //timestamp/1000.0,
                                cp1StartedIn, cp2StartedIn, cp3StartedIn, cp4StartedIn,
                                cp1InStr, cp1OutStr, cp2InStr, cp2OutStr,
                                cp3InStr, cp3OutStr, cp4InStr, cp4OutStr);
                        needUpdateGraphType = eventType.MULTICHRONOPIC;
                        needUpdateGraph = true;

                        updateProgressBar = new UpdateProgressBar (
                                true, //isEvent
                                false, //means activity mode
                                -1 //don't show text
                                );
                        needUpdateEventProgressBar = true;
                    }
                }

                if(myPS == Chronopic.Plataforma.OFF)
                    myLS = States.OFF;
                else
                    myLS = States.ON;

            }
        } while ( ! success && ! cancel && ! finish );

        if (finish) {
            finishThisCp(cpNum);

            //call write on gui/chronojump.cs, because if done in execute/MultiChronopic,
            //will be called n times if n chronopics are working
            //write(false); //tempTable

            //event will be raised, and managed in chronojump.cs
            //only one call (that comes from first chronopic)
            if(cpNum == 1)
                fakeButtonFinished.Click();
        }
        if(cancel) {
            //event will be raised, and managed in chronojump.cs
            fakeButtonFinished.Click();
            cancelThisCp(cpNum);
        }
    }
Example #40
0
    //chronopic init should not touch  gtk, for the threads
    public bool Do(int currentCp, out Chronopic myCp, out SerialPort mySp, Chronopic.Plataforma myPS, string myPort, out string returnString, out bool success)
    {
        LogB.Information("starting connection with chronopic");

        CancelledByUser = false;
        success = true;

        LogB.Information("chronopicInit-1");
        LogB.Information(string.Format("chronopic port: {0}", myPort));
        mySp = new SerialPort(myPort);
        try {
            mySp.Open();
            LogB.Information("chronopicInit-2");
            //-- Create chronopic object, for accessing chronopic
            myCp = new Chronopic(mySp);

            LogB.Information("chronopicInit-2.1");
            myCp.Flush();

            //if myCp has been cancelled
            if(myCp.AbortFlush) {
                LogB.Information("chronopicInit-2.2 cancelled");
                success = false;
                myCp = new Chronopic(); //fake constructor
            } else {
                LogB.Information("chronopicInit-3");
                //on windows, this check make a crash
                //i think the problem is: as we don't really know the Timeout on Windows (.NET) and this variable is not defined on chronopic.cs
                //the Read_platform comes too much soon (when cp is not totally created), and this makes crash

                //-- Obtener el estado inicial de la plataforma

                bool ok=false;
                LogB.Information("chronopicInit-4");
                do {
                    LogB.Information("chronopicInit-5");
                    ok = myCp.Read_platform(out myPS);
                    LogB.Information("chronopicInit-6");
                } while(! ok && ! CancelledByUser);
                LogB.Information("chronopicInit-7");
                if (!ok) {
                    //-- Si hay error terminar
                    LogB.Error(string.Format("Error: {0}", myCp.Error));
                    success = false;
                }
            }
        } catch {
            LogB.Error("chronopicInit-2.a catched");
            success = false;
            myCp = new Chronopic(); //fake constructor
        }

        bool connected = false;
        returnString = "";
        if(success) {
            if(currentCp == 1)
                connected = true;
            returnString = string.Format(Catalog.GetString("<b>Connected</b> to Chronopic on port: {0}"), myPort);
        }
        else {
            returnString = Catalog.GetString("Problems communicating to chronopic.");
            if(currentCp == 1) {
                returnString += " " + Catalog.GetString("Changed platform to 'Simulated'");
                returnString += Catalog.GetString("\n\nWe recommend to remove and connect USB cable.");
            }

            //this will raise on_radiobutton_simulated_ativate and
            //will put cpRunning to false, and simulated to true and cp.Close()
            if(currentCp == 1) {
                connected = false;
            }
        }

        return connected;
    }
Example #41
0
    //***************************************
    //  METODOS PRIVADOS
    //***************************************

    //-- Apertura del puerto serie
    private int Open(string disp)
    {
        return(Chronopic.open(disp));
    }
Example #42
0
    protected void waitEvent(Chronopic myCP, Chronopic.Plataforma myPS, States myLS, out string inStr, out string outStr, int cpNum)
    {
        double timestamp = 0;
        bool   success   = false;
        bool   ok;
        string inEqual  = "";
        string outEqual = "";

        inStr = ""; outStr = "";
        int runAnalysisTcCount = 0;
        int runAnalysisTfCount = 0;

        bool isFirstOut = true;
        bool isFirstIn  = true;

        syncStates syncing = syncStates.DONE;

        if (syncFirst)
        {
            syncing                 = syncStates.NOTHING;
            feedbackMessage         = Catalog.GetString("Press and maintain Test button in all Chronopics simultaneously.");
            needShowFeedbackMessage = true;
        }

        do
        {
            ok = myCP.Read_event(out timestamp, out myPS);

            //if chronopic signal is Ok and state has changed
            if (ok && (
                    (myPS == Chronopic.Plataforma.ON && myLS == States.OFF) ||
                    (myPS == Chronopic.Plataforma.OFF && myLS == States.ON)) &&
                !cancel && !finish)
            {
                //while no finished time or jumps, continue recording events
                if (!success)
                {
                    //don't record the time until the first event of the first Chronopic
                    //this is only executed on the first chronopic that receives a change
                    if (firstValue)
                    {
                        firstValue = false;
                        initializeTimer();                         //this is for first Chronopic and only for simulated

                        feedbackMessage         = "";
                        needShowFeedbackMessage = true;
                    }

                    if (syncing == syncStates.NOTHING && myPS == Chronopic.Plataforma.ON && myLS == States.OFF)
                    {
                        syncing                 = syncStates.CONTACTED;
                        feedbackMessage         = Catalog.GetString("Release Test button in all Chronopics simultaneously.");
                        needShowFeedbackMessage = true;
                    }
                    else if (syncing == syncStates.CONTACTED && myPS == Chronopic.Plataforma.OFF && myLS == States.ON)
                    {
                        syncing         = syncStates.DONE;
                        feedbackMessage = Catalog.GetString("Synchronization done.") + "\n" +
                                          Catalog.GetString("Test starts now.");
                        needShowFeedbackMessage = true;
                    }
                    else
                    {
                        if (type != Constants.RunAnalysisName)
                        {
                            needSensitiveButtonFinish = true;
                        }

                        if (myPS == Chronopic.Plataforma.ON && myLS == States.OFF)
                        {
                            //this is for runAnalysis, delete first tf on 2nd cp (jump cp)
                            if (cpNum == 2 && type == Constants.RunAnalysisName && runAnalysisTfCount == 0)
                            {
                                runAnalysisTfCount++;
                            }
                            //this is for multiChronopic, not for runAnalysis
                            else if (deleteFirst && isFirstOut)
                            {
                                isFirstOut = false;
                            }
                            else
                            {
                                double lastOut = timestamp / 1000.0;
                                LogB.Information(cpNum.ToString() + " landed: " + lastOut.ToString());
                                outStr   = outStr + outEqual + lastOut.ToString();
                                outEqual = "=";
                            }

                            /*
                             * if it's a runAnalysis,
                             * should end when arrive at 2n photocell (controlled by cp1)
                             */
                            if (cpNum == 1 && type == Constants.RunAnalysisName)
                            {
                                runAnalysisTcCount++;
                                if (runAnalysisTcCount >= 2)
                                {
                                    success = true;
                                    //better call also finish
                                    //then all cps know about ending
                                    finish = true;
                                }
                            }
                        }
                        else if (myPS == Chronopic.Plataforma.OFF && myLS == States.ON)
                        {
                            //this is for multiChronopic, not for runAnalysis
                            if (deleteFirst && isFirstIn)
                            {
                                isFirstIn = false;
                            }
                            else
                            {
                                double lastIn = timestamp / 1000.0;
                                LogB.Information(cpNum.ToString() + " jumped: " + lastIn.ToString());
                                inStr   = inStr + inEqual + lastIn.ToString();
                                inEqual = "=";
                            }
                        }

                        PrepareEventGraphMultiChronopicObject = new PrepareEventGraphMultiChronopic(
                            //timestamp/1000.0,
                            cp1StartedIn, cp2StartedIn, cp3StartedIn, cp4StartedIn,
                            cp1InStr, cp1OutStr, cp2InStr, cp2OutStr,
                            cp3InStr, cp3OutStr, cp4InStr, cp4OutStr);
                        needUpdateGraphType = eventType.MULTICHRONOPIC;
                        needUpdateGraph     = true;


                        updateProgressBar = new UpdateProgressBar(
                            true,                                  //isEvent
                            false,                                 //means activity mode
                            -1                                     //don't show text
                            );
                        needUpdateEventProgressBar = true;
                    }
                }

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

        if (finish)
        {
            finishThisCp();

            //call write on gui/chronojump.cs, because if done in execute/MultiChronopic,
            //will be called n times if n chronopics are working
            //write(false); //tempTable
        }
    }
Example #43
0
    protected void waitChronopicStart()
    {
        if (currentCp == 1)
        {
            //	simulated = false;
            //	SqlitePreferences.Update("simulated", simulated.ToString(), false);
            if (connected)
            {
                return;
            }
        }

        SerialPort sp2;
        SerialPort sp3;
        SerialPort sp4;

        string message = "";
        string myPort  = "";
        bool   success = false;

        if (currentCp == 1)
        {
            myPort    = ((ChronopicPortData)cpd[0]).Port;
            cpDoing   = cp;
            connected = chronopicInit.Do(currentCp, out cpDoing, out sp, platformState, myPort, out message, out success);
            cp        = cpDoing;
            if (success)
            {
                connectionSucceded(1, true);
            }
        }
        else if (currentCp == 2)
        {
            myPort    = ((ChronopicPortData)cpd[1]).Port;
            cpDoing   = cp2;
            connected = chronopicInit.Do(currentCp, out cpDoing, out sp2, platformState2, myPort, out message, out success);
            cp2       = cpDoing;
            if (success)
            {
                connectionSucceded(2, true);
            }
        }
        else if (currentCp == 3)
        {
            myPort    = ((ChronopicPortData)cpd[2]).Port;
            cpDoing   = cp3;
            connected = chronopicInit.Do(currentCp, out cpDoing, out sp3, platformState3, myPort, out message, out success);
            cp3       = cpDoing;
            if (success)
            {
                connectionSucceded(3, true);
            }
        }
        else if (currentCp == 4)
        {
            myPort    = ((ChronopicPortData)cpd[3]).Port;
            cpDoing   = cp4;
            connected = chronopicInit.Do(currentCp, out cpDoing, out sp4, platformState4, myPort, out message, out success);
            cp4       = cpDoing;
            if (success)
            {
                connectionSucceded(4, true);
            }
        }


        LogB.Information(string.Format("wait_chronopic_start {0}", message));

        if (success)
        {
            Util.PlaySound(Constants.SoundTypes.GOOD, volumeOn);
            updateChronopicWinValuesState   = true;          //connected
            updateChronopicWinValuesMessage = message;
        }
        else
        {
            Util.PlaySound(Constants.SoundTypes.BAD, volumeOn);
            updateChronopicWinValuesState   = false;          //disconnected
            updateChronopicWinValuesMessage = message;
        }

        foreach (ChronopicPortData a in cpd)
        {
            LogB.Information(a.Num + ", " + a.Port + ", " + a.Connected);
        }

        needUpdateChronopicWin = true;
    }
Example #44
0
    public ChronopicWindow(Chronopic cpDetected, ArrayList myCpd)
    {
        LogB.Debug("constructor");

        Glade.XML gxml;
        gxml = Glade.XML.FromAssembly (Util.GetGladePath() + "chronopic_window.glade", "chronopic_window", "chronojump");
        gxml.Autoconnect(this);

        cpd = myCpd;

        if(cpDetected != null) {
            cp = cpDetected;
            sp = new SerialPort( ((ChronopicPortData) cpd[0]).Port );
        }

        UtilGtk.IconWindow(chronopic_window);

        if(UtilAll.IsWindows())
            isWindows = true;
        else
            isWindows = false;

        setDefaultValues();

        chronopicInit = new ChronopicInit();

        //Pixbuf pixbuf = new Pixbuf (null, Util.GetImagePath(false) + "chronopic_128.png");
        //chronopic_image.Pixbuf = pixbuf;
        /*
        Pixbuf pixbuf;
        pixbuf = new Pixbuf (null, Util.GetImagePath(true) + Constants.FileNameContactPlatformModular);
        image_contact_modular.Pixbuf = pixbuf;
        pixbuf = new Pixbuf (null, Util.GetImagePath(true) + Constants.FileNameInfrared);
        image_infrared.Pixbuf = pixbuf;
        */

        /*
        if(chronopicPort1 != Constants.ChronopicDefaultPortWindows &&
                (chronopicPort1 != Constants.ChronopicDefaultPortLinux && File.Exists(chronopicPort1))
          ) {
            ConfirmWindow confirmWin = ConfirmWindow.Show(Catalog.GetString("Do you want to connect to Chronopic now?"), "", "");
            confirmWin.Button_accept.Clicked += new EventHandler(chronopicAtStart);
        }
        */
    }
Example #45
0
    /**********************/
    /* PROGRAMA PRINCIPAL */
    /**********************/
    public static void Main()
    {
        Chronopic.Plataforma estado_plataforma;
        Chronopic.Respuesta respuesta;
        Automata estado_automata;
        double timestamp;
        double toff;

        //-- Crear objeto chronopic, para acceder al chronopic
        Chronopic cp = new Chronopic("/dev/ttyUSB0");

        //-- Obtener el estado inicial de la plataforma
        respuesta=cp.Read_platform(out estado_plataforma);
        switch(respuesta) {
          case Chronopic.Respuesta.Error:
        Console.WriteLine("Error en comunicacion con Chronopic");
        return;
          case Chronopic.Respuesta.Timeout:
        Console.WriteLine("Chronopic no responde");
        return;
          default:
        break;
        }

        Console.WriteLine("Estado plataforma: {0}",estado_plataforma);

        //-- Establecer el estado inicial del automata
        if (estado_plataforma==Chronopic.Plataforma.ON)
          estado_automata=Automata.ON;
        else {
          Console.WriteLine("Suba a la plataforma para realizar el salto");

          //-- Esperar a que llegue una trama con el estado de la plataforma
          //-- igual a ON. Esto indica que el usuario se ha subido
          do {
          respuesta = cp.Read_event(out timestamp, out estado_plataforma);
          } while (respuesta!=Chronopic.Respuesta.Ok);

          //-- Se han subido a la plataforma
          estado_automata = Automata.ON;
        }

        Console.WriteLine("");
        Console.WriteLine("Puede saltar cuando quiera");
        Console.WriteLine("Pulse control-c para finalizar la sesion");
        Console.WriteLine("-----------------------------------------");

        while(true) {

          //-- Esperar a que llegue una trama
          do {
        respuesta = cp.Read_event(out timestamp, out estado_plataforma);
          } while (respuesta!=Chronopic.Respuesta.Ok);

          //-- Segun el estado del automata
          switch(estado_automata) {

        case Automata.OFF: //-- Usuario estaba en el aire

          //-- Si ha aterrizado
          if (estado_plataforma==Chronopic.Plataforma.ON) {

            //-- Pasar al estado ON
            estado_automata=Automata.ON;

            //-- Registrar tiempo de vuelo
            toff = timestamp;

            //-- Imprimir informacion
            Console.WriteLine("Tiempo: {0:f1} ms",toff);
          }
          break;

        case Automata.ON: //-- Usuario estaba en la plataforma

          //-- Si ahora esta en el aire...
          if (estado_plataforma==Chronopic.Plataforma.OFF) {

            //-- Pasar al estado OFF
            estado_automata=Automata.OFF;
          }
          break;
          }

        }
    }
Example #46
0
    //***************************************
    //  METODOS PUBLICOS
    //***************************************

    //----------------------------
    //-- Cerrar el puerto serie
    //----------------------------
    public void Close()
    {
        Chronopic.close(this.serial_fd);
        this.serial_fd = -1;
    }
Example #47
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);
    }
Example #48
0
    //this is called on AutoDetect
    public static ChronopicWindow Create(Chronopic cpDetected, ArrayList myCpd, string myEncoderPort, bool recreate, bool volumeOn)
    {
        LogB.Debug("enter create");
        if (ChronopicWindowBox != null && recreate) {
            ChronopicWindowBox.chronopic_window.Hide();
        }
        if (ChronopicWindowBox == null || recreate) {
            ChronopicWindowBox = new ChronopicWindow (cpDetected, myCpd);
        }

        LogB.Information("create cp is null? " + (ChronopicWindowBox.cp == null).ToString());

        //don't show until View is called
        //ChronopicWindowBox.chronopic_window.Show ();

        ChronopicWindowBox.volumeOn = volumeOn;

        ChronopicWindowBox.setEncoderPort(myEncoderPort);

        ChronopicWindowBox.fakeWindowDone = new Gtk.Button();
        //ChronopicWindowBox.fakeWindowReload = new Gtk.Button();

        return ChronopicWindowBox;
    }
Example #49
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 #50
0
    /**********************/
    /* PROGRAMA PRINCIPAL */
    /**********************/
    public static void Main(string[] args)
    {
        Chronopic.Plataforma estado_plataforma;
        Automata estado_automata;
        double timestamp;
        double toff;
        double ton;
        bool ok;
        string portName = "";
        string fileName = "";
        TextWriter writer;

        //always output to a file, but if not specified, output here and rewrite it every chronojump_mini execution
        string defaultFileName = Path.Combine(getOutputDir(), "output");

        System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("es-ES");
        System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("es-ES");

        //connect with catalog.cs for using gettext translation
        Catalog.Init ("chronojump", "./locale");

        //parameters passing only on linux
        if(! UtilAll.IsWindows()) {
            if(args.Length > 2)
                printSyntaxAndQuit();

            for( int i = 0; i != args.Length; ++i ) {
                Console.WriteLine("param[{0}]: {1}", i, args[i]);
                if(args[i].StartsWith("PORT="))
                    portName = args[i].Substring(5);
                else if (args[i].StartsWith("FILE=")) {
                    fileName = args[i].Substring(5);
                    fileName= getOutputDir() + Path.DirectorySeparatorChar + fileName;
                }
                else
                    printSyntaxAndQuit();
            }
        }

        //detection of ports
        string messageInfo;
        //string messageDetected ="";

        if(UtilAll.IsWindows()) {
            messageInfo = Constants.PortNamesWindows;
            /*
            messageDetected = Catalog.GetString("Detected ports:") + "\n";

            string jumpLine = "";
            foreach (string s in SerialPort.GetPortNames()) {
                messageDetected += jumpLine + s;
                jumpLine = "\n";
            }
            */
        } else {
            messageInfo = Constants.PortNamesLinux;
        }

        messageInfo += string.Format("\n" + Catalog.GetString("More information on Chronojump manual"));

        Console.WriteLine("---------------------------");
        Console.WriteLine(messageInfo);
        Console.WriteLine("---------------------------");

        if(portName == "") {
            if( ! UtilAll.IsWindows()) {
                Console.WriteLine(UtilAll.DetectPortsLinux(false)); //formatting
            }
            Console.WriteLine(Catalog.GetString("Print the port name where chronopic is connected:"));
            portName=Console.ReadLine();
        }

        //output file stuff
        fileName = manageFileName(fileName);
        if(fileName == "")
            fileName = defaultFileName + "-" + portName.Replace("/","") + ".csv";

        writer = File.CreateText(fileName);

        Console.WriteLine(Catalog.GetString("Opening port...") + " " +
                   Catalog.GetString("Please touch the platform or click Chronopic TEST button"));
        //-- Crear puerto serie
        SerialPort sp;
        sp = new SerialPort(portName);

        //-- Abrir puerto serie. Si ocurre algun error
        //-- Se lanzara una excepcion
        try {
            sp.Open();
        } catch (Exception e){
            Console.WriteLine(Catalog.GetString("Error opening serial port"));
            Console.WriteLine(e);
            Environment.Exit(1);
        }

        //-- Crear objeto chronopic, para acceder al chronopic
        Chronopic cp = new Chronopic(sp);
        cp.Flush();

        //-- Obtener el estado inicial de la plataforma
        // this do...while is here because currently there's no timeout on chronopic.cs on windows
        do {
            ok=cp.Read_platform(out estado_plataforma);
        } while(!ok);
        if (!ok) {
            //-- Si hay error terminar
            Console.WriteLine(string.Format(Catalog.GetString("Error: {0}"),cp.Error));
            System.Environment.Exit(-1);
        }
        Console.WriteLine(string.Format(Catalog.GetString("Platform state: {0}"), estado_plataforma));

        //Console.WriteLine("Automatic variables: ");
            //cp.Read_variables_automatic();

        //-- Establecer el estado inicial del automata
        if (estado_plataforma==Chronopic.Plataforma.ON)
            estado_automata=Automata.ON;
        else {
            Console.WriteLine(Catalog.GetString("Go up platform for jumping"));

            //-- Esperar a que llegue una trama con el estado de la plataforma
            //-- igual a ON. Esto indica que el usuario se ha subido
            do {
                ok = cp.Read_event(out timestamp, out estado_plataforma);
            } while (!ok);

            //-- Se han subido a la plataforma
            estado_automata = Automata.ON;
        }

        Console.WriteLine("");
        Console.WriteLine(Catalog.GetString("Jump when prepared"));
        Console.WriteLine(Catalog.GetString("Press CTRL-c for ending session"));
        Console.WriteLine("-----------------------------------------");

        double count = 1.0;

        Console.WriteLine("  TC(ms) TF(ms)");
        writer.WriteLine("count;TC(ms);TF(ms)");

        while(true) {
            //-- Esperar a que llegue una trama
            do {
                ok = cp.Read_event(out timestamp, out estado_plataforma);
            } while (ok==false);

            //-- Segun el estado del automata
            switch(estado_automata) {

                case Automata.OFF: //-- Usuario estaba en el aire

                    //-- Si ha aterrizado
                    if (estado_plataforma==Chronopic.Plataforma.ON) {

                        //-- Pasar al estado ON
                        estado_automata=Automata.ON;

                        //-- Registrar tiempo de vuelo
                        toff = timestamp;

                        //-- Imprimir informacion
                        Console.WriteLine("{0:f1}",toff);
                        writer.WriteLine("{0:f1}",toff);
                    }
                    break;

                case Automata.ON: //-- Usuario estaba en la plataforma

                    //-- Si ahora esta en el aire...
                    if (estado_plataforma==Chronopic.Plataforma.OFF) {

                        //-- Pasar al estado OFF
                        estado_automata=Automata.OFF;

                        //-- Registrar tiempo de contacto
                        ton = timestamp;

                        //-- Imprimir informacion
                        Console.Write(count + " {0:f1} ",ton);
                        writer.Write(count + ";{0:f1};",ton);
                    }
                    break;
            }

            writer.Flush();

            count += .5;
        }
    }
Example #51
0
    protected void waitChronopicStart()
    {
        if(currentCp == 1) {
        //	simulated = false;
        //	SqlitePreferences.Update("simulated", simulated.ToString(), false);
            if(connected)
                return;
        }

        SerialPort sp2;
        SerialPort sp3;
        SerialPort sp4;

        string message = "";
        string myPort = "";
        bool success = false;

        if(currentCp == 1) {
            myPort = ((ChronopicPortData) cpd[0]).Port;
            cpDoing = cp;
            connected = chronopicInit.Do(currentCp, out cpDoing, out sp, platformState, myPort, out message, out success);
            cp = cpDoing;
            if(success)
                connectionSucceded(1, true);
        }
        else if(currentCp == 2) {
            myPort = ((ChronopicPortData) cpd[1]).Port;
            cpDoing = cp2;
            connected = chronopicInit.Do(currentCp, out cpDoing, out sp2, platformState2, myPort, out message, out success);
            cp2 = cpDoing;
            if(success)
                connectionSucceded(2, true);
        }
        else if(currentCp == 3) {
            myPort = ((ChronopicPortData) cpd[2]).Port;
            cpDoing = cp3;
            connected = chronopicInit.Do(currentCp, out cpDoing, out sp3, platformState3, myPort, out message, out success);
            cp3 = cpDoing;
            if(success)
                connectionSucceded(3, true);
        }
        else if(currentCp == 4) {
            myPort = ((ChronopicPortData) cpd[3]).Port;
            cpDoing = cp4;
            connected = chronopicInit.Do(currentCp, out cpDoing, out sp4, platformState4, myPort, out message, out success);
            cp4 = cpDoing;
            if(success)
                connectionSucceded(4, true);
        }

        LogB.Information(string.Format("wait_chronopic_start {0}", message));

        if(success) {
            Util.PlaySound(Constants.SoundTypes.GOOD, volumeOn);
            updateChronopicWinValuesState= true; //connected
            updateChronopicWinValuesMessage= message;
        } else {
            Util.PlaySound(Constants.SoundTypes.BAD, volumeOn);
            updateChronopicWinValuesState= false; //disconnected
            updateChronopicWinValuesMessage= message;
        }

        foreach(ChronopicPortData a in cpd)
            LogB.Information(a.Num + ", " + a.Port + ", " + a.Connected);

        needUpdateChronopicWin = true;
    }