Example #1
0
    private void writeOptionsFile(int graphWidth, int graphHeight)
    {
        string scriptsPath = UtilEncoder.GetSprintPath();

        if (UtilAll.IsWindows())
        {
            scriptsPath = scriptsPath.Replace("\\", "/");
        }

        System.Globalization.NumberFormatInfo localeInfo = new System.Globalization.NumberFormatInfo();
        localeInfo = System.Globalization.NumberFormatInfo.CurrentInfo;

        string scriptOptions =
            "#scriptsPath\n" + UtilEncoder.GetScriptsPath() + "\n" +
            "#filename\n" + UtilEncoder.GetRaceAnalyzerCSVFileName() + "\n" +
            "#mass\n" + Util.ConvertToPoint(mass) + "\n" +
            "#personHeight\n" + Util.ConvertToPoint(personHeight / 100.0) + "\n" +                         //send it in meters
            "#tempC\n" + tempC + "\n" +
            "#testLength\n" + testLength.ToString() + "\n" +
            "#os\n" + UtilEncoder.OperatingSystemForRGraphs() + "\n" +
            "#graphWidth\n" + graphWidth.ToString() + "\n" +
            "#graphHeight\n" + graphHeight.ToString();


        TextWriter writer = File.CreateText(Path.GetTempPath() + "Roptions.txt");

        writer.Write(scriptOptions);
        writer.Flush();
        writer.Close();
        ((IDisposable)writer).Dispose();
    }
    /*
     * VIDEO
     */

    public static List <string> GetVideoDevices()
    {
        /*
         * TODO: reimplement this with ffmpeg
         *
         * List<LongoMatch.Video.Utils.Device> devices = LongoMatch.Video.Utils.Device.ListVideoDevices();
         * string [] devicesStr = new String[devices.Count];
         * int count = 0;
         * LogB.Information("Searching video devices");
         * foreach(LongoMatch.Video.Utils.Device dev in devices) {
         *      devicesStr[count++] = dev.ID.ToString();
         *      LogB.Information(dev.ID.ToString());
         * }
         * return devicesStr;
         */


        //on Linux search for video0, video1, ...
        if (UtilAll.GetOSEnum() == UtilAll.OperatingSystems.LINUX)
        {
            return(GetVideoDevicesLinux());
        }
        else if (UtilAll.GetOSEnum() == UtilAll.OperatingSystems.WINDOWS)
        {
            return(GetVideoDevicesWindows());
        }
        else
        {
            return(new List <string>());
        }
    }
Example #3
0
    public override Result PlayFile(string filename)
    {
        if (process != null || filename == "")
        {
            return(new Result(false, ""));
        }

        executable = "mplayer";
        List <string> parameters = new List <string>();

        parameters.Insert(0, filename);
        //parameters.Insert (0, "-noborder"); //on X11 can be: title "Chronojump"". -noborder makes no accept 's', or 'q'
        if (UtilAll.GetOSEnum() == UtilAll.OperatingSystems.LINUX)
        {
            parameters.Insert(0, "-title");              //on X11 can be: title "Chronojump"". -noborder makes no accept 's', or 'q'
            parameters.Insert(1, "Chronojump video");
        }
        else
        {
            parameters.Insert(0, "-noborder");
        }


        process = new Process();
        bool success = ExecuteProcess.RunAtBackground(ref process, executable, parameters, false, true, false, true, true);

        if (!success)
        {
            process = null;
            return(new Result(false, "", programMplayerNotInstalled));
        }

        Running = true;
        return(new Result(true, ""));
    }
Example #4
0
    public static bool CheckPort(string port)
    {
        if (File.Exists(UtilAll.GetECapSimSignalFileName()))          //simulatedEncoder
        {
            simulated = true;
            return(true);
        }

        simulated = false;

        LogB.Information("testing encoder port: ", port);
        sp          = new SerialPort(port);
        sp.BaudRate = 115200;
        LogB.Information("testing 1: sp created");
        try {
            sp.Open();
            LogB.Information("testing 2: sp opened");
            sp.Close();
            LogB.Information("testing 3: sp closed. Success!");
        } catch {
            LogB.Error("testing encoder port failed");
            return(false);
        }
        return(true);
    }
Example #5
0
    private void createButtons()
    {
        FakeButtonCloseSerialPort = new Gtk.Button();
        Gtk.Button button_close_serial_port = new Gtk.Button("Close serial port (debug)");
        button_close_serial_port.Clicked += new EventHandler(on_button_close_serial_port_clicked);

        Gtk.Button button_OSX_readme = new Gtk.Button("MacOSX Readme");
        button_OSX_readme.Clicked += new EventHandler(on_button_OSX_readme_clicked);

        //---- button close start --->
        Gtk.Button button_close = new Gtk.Button("Close Window");
        button_close.Clicked += new EventHandler(on_button_close_clicked);

        Gtk.AccelGroup ag = new Gtk.AccelGroup();          //button can be called clicking Escape key
        chronopic_register_win.AddAccelGroup(ag);

        button_close.AddAccelerator
            ("activate", ag, new Gtk.AccelKey
                (Gdk.Key.Escape, Gdk.ModifierType.None,
                Gtk.AccelFlags.Visible));
        //<---- button close end

        //add buttons to containers
        Gtk.HButtonBox hbox = new Gtk.HButtonBox();
        //hbox.Add(button_close_serial_port);

        if (UtilAll.GetOSEnum() == UtilAll.OperatingSystems.MACOSX)
        {
            hbox.Add(button_OSX_readme);
        }

        hbox.Add(button_close);

        vbox_main.Add(hbox);
    }
    static void printSyntaxAndQuit()
    {
        Console.WriteLine(Catalog.GetString("Invalid args. Use:"));

        if (UtilAll.IsWindows())
        {
            Console.WriteLine("chronojump_mini.bat [PORT=portName>] [FILE=outputFile]");
            Console.WriteLine(Catalog.GetString("Examples:"));
            Console.WriteLine("chronojump_mini.bat");
            Console.WriteLine("chronojump_mini.bat PORT=COM1");
            Console.WriteLine("chronojump_mini.bat FILE=myFile.csv");
            Console.WriteLine("chronojump_mini.bat PORT=COM1 FILE=myFile.csv");
        }
        else
        {
            Console.WriteLine("./chronojump_mini.sh [PORT=portName>] [FILE=outputFile]");
            Console.WriteLine(Catalog.GetString("Examples:"));
            Console.WriteLine("./chronojump_mini.sh");
            Console.WriteLine("./chronojump_mini.sh PORT=/dev/ttyS0");
            Console.WriteLine("./chronojump_mini.sh FILE=myFile.csv");
            Console.WriteLine("./chronojump_mini.sh PORT=/dev/ttyUSB0 FILE=myFile.csv");
        }

        Environment.Exit(1);
    }
Example #7
0
    //Not used on encoder
    private void playVideo(string fileName)
    {
        //constructor for playpreview
        webcamPlay = new WebcamFfmpeg(Webcam.Action.PLAYFILE, UtilAll.GetOSEnum(), "", "", "");
        Webcam.Result result = webcamPlay.PlayFile(fileName);

        /*
         * TODO: reimplement this with ffmpeg
         *
         * if(File.Exists(fileName)) {
         *      LogB.Information("Play video starting...");
         *      PlayerBin player = new PlayerBin();
         *      player.Open(fileName);
         *
         *      //without these lines works also but has less functionalities (speed, go to ms)
         *      Gtk.Window d = new Gtk.Window(Catalog.GetString("Playing video"));
         *      d.Add(player);
         *      d.Modal = true;
         *      d.SetDefaultSize(500,400);
         *      d.ShowAll();
         *      d.DeleteEvent += delegate(object sender, DeleteEventArgs e) {player.Close(); player.Dispose();};
         *
         *      if(play) {
         *              LogB.Information("Play video playing...");
         *              player.Play();
         *      }
         *      return true;
         * }
         */
    }
Example #8
0
    void on_button_logs_folder_open_clicked(object o, EventArgs args)
    {
        string dir = UtilAll.GetLogsDir();

        LogB.Information(dir);

        if (!new System.IO.DirectoryInfo(dir).Exists)
        {
            try {
                Directory.CreateDirectory(dir);
            } catch {
                new DialogMessage(Constants.MessageTypes.WARNING,
                                  Catalog.GetString("Cannot create directory.") + "\n\n" + dir);
                return;
            }
        }

        try {
            System.Diagnostics.Process.Start(dir);
        }
        catch {
            new DialogMessage(Constants.MessageTypes.WARNING,
                              Constants.DirectoryCannotOpen + "\n\n" + dir);
        }
    }
Example #9
0
    private void writeOptionsFile(int graphWidth, int graphHeight)
    {
        string scriptsPath = UtilEncoder.GetSprintPath();

        if (UtilAll.IsWindows())
        {
            scriptsPath = scriptsPath.Replace("\\", "/");
        }

        System.Globalization.NumberFormatInfo localeInfo = new System.Globalization.NumberFormatInfo();
        localeInfo = System.Globalization.NumberFormatInfo.CurrentInfo;

        string scriptOptions =
            "#os\n" + UtilEncoder.OperatingSystemForRGraphs() + "\n" +
            "#decimalChar\n" + localeInfo.NumberDecimalSeparator + "\n" +
            "#graphWidth\n" + graphWidth.ToString() + "\n" +
            "#graphHeight\n" + graphHeight.ToString() + "\n" +
            "#averageLength\n" + Util.ConvertToPoint(averageLength) + "\n" +
            "#percentChange\n" + Util.ConvertToPoint(percentChange) + "\n" +
            "#vlineT0\n" + Util.BoolToRBool(vlineT0) + "\n" +
            "#vline50fmax.raw\n" + Util.BoolToRBool(vline50fmax_raw) + "\n" +
            "#vline50fmax.fitted\n" + Util.BoolToRBool(vline50fmax_fitted) + "\n" +
            "#hline50fmax.raw\n" + Util.BoolToRBool(hline50fmax_raw) + "\n" +
            "#hline50fmax.fitted\n" + Util.BoolToRBool(hline50fmax_fitted) + "\n" +
            "#RFDs";

        foreach (ForceSensorRFD rfd in rfdList)
        {
            if (rfd.active)
            {
                scriptOptions += "\n" + rfd.ToR();
            }
            else
            {
                scriptOptions += "\n-1";
            }
        }

        if (impulse.active)
        {
            scriptOptions += "\n" + impulse.ToR();
        }
        else
        {
            scriptOptions += "\n-1";
        }

        scriptOptions +=
            "\n#testLength\n" + testLength.ToString() + "\n" +
            "#title\n" + title + "\n" +
            "#scriptsPath\n" + UtilEncoder.GetScriptsPath() + "\n";

        TextWriter writer = File.CreateText(Path.GetTempPath() + "Roptions.txt");

        writer.Write(scriptOptions);
        writer.Flush();
        writer.Close();
        ((IDisposable)writer).Dispose();
    }
Example #10
0
    //get a string of last month
    public static string GetCurrentYearLastMonthStr()
    {
        DateTime dt = DateTime.Now;

        dt = dt.AddMonths(-1);

        return(UtilAll.DigitsCreate(dt.Year, 4) + "-" + Catalog.GetString(dt.ToString("MMMM")));
    }
Example #11
0
    void openPresentation()
    {
        //presentationOpenStatic("file:///home/...html#" + presentation_slide_current.ToString());
        string file = Path.Combine(UtilAll.GetApplicationDataDir() + Path.DirectorySeparatorChar + "Chronojump-Boscosystem.html");

        if (File.Exists(file))
        {
            presentationOpenStatic("file://" + file + "#" + presentation_slide_current.ToString());
        }
    }
Example #12
0
    /*
     * DEPRECATED, now use always RDotNet. Until 1.5.0 where RDotNet is not used anymore. Neither this Pyton method.
     * public static void RunEncoderCapturePython(string title, EncoderStruct es, string port)
     * {
     *      CancelRScript = false;
     *
     *      ProcessStartInfo pinfo;
     *      Process p;
     *      //Old comment:
     *      //If output file is not given, R will try to write in the running folder
     *      //in which we may haven't got permissions
     *
     *      string pBin="";
     *      pinfo = new ProcessStartInfo();
     *
     *      string outputFileCheck = "";
     *
     *
     *      //on Windows (py2exe) we execute a exe with the py file that contains python
     *      //on linux we execute python and call to the py file
     *      //also on windows we need the full path to find R
     *      if (UtilAll.IsWindows()) {
     *              pBin=getEncoderScriptCapturePython();
     *              pinfo.Arguments = title + " " + es.OutputData1 + " " + es.Ep.ToString1() + " " + port
     + " " + changeSpaceToSpaceMark(
     +                              System.IO.Path.Combine(Util.GetPrefixDir(), "bin" + Path.DirectorySeparatorChar + "R.exe"));
     +      }
     +      else {
     +              pBin="python";
     +              pinfo.Arguments = getEncoderScriptCapturePython() + " " + title + " " +
     +                      es.OutputData1 + " " + es.Ep.ToString1() + " " + port;
     +      }
     +
     +      outputFileCheck = es.OutputData1;
     +
     +      pinfo.FileName=pBin;
     +
     +      pinfo.CreateNoWindow = true;
     +      pinfo.UseShellExecute = false;
     +
     +      Console.WriteLine(outputFileCheck);
     +      if (File.Exists(outputFileCheck))
     +              File.Delete(outputFileCheck);
     +
     +      p = new Process();
     +      p.StartInfo = pinfo;
     +      p.Start();
     +      Log.WriteLine(p.Id.ToString());
     +
     +      p.WaitForExit();
     +      while ( ! ( File.Exists(outputFileCheck) || CancelRScript) );
     + }
     */

    //R plots on Windows using Cairo, need to know if it's windows or not
    public static string OperatingSystemForRGraphs()
    {
        string operatingSystem = "Linux";

        if (UtilAll.IsWindows())
        {
            operatingSystem = "Windows";
        }

        return(operatingSystem);
    }
Example #13
0
    public FfmpegCapture(string[] args)
    {
        if (args.Length != 1)
        {
            Console.WriteLine("Need to pass the videoDevice");
            return;
        }

        os          = UtilAll.GetOSEnum();
        videoDevice = args[0];

        if (os == UtilAll.OperatingSystems.WINDOWS)
        {
            captureExecutable = System.IO.Path.Combine(Util.GetPrefixDir(), "bin/ffmpeg.exe");
        }

        process = new Process();
        List <string> parameters = createParametersOnlyCapture();
        //List<string> parameters = createParametersCaptureAndDelayedView();
        bool success = ExecuteProcess.RunAtBackground(ref process, captureExecutable, parameters,
                                                      true, false, true); //createNoWindow, useShellExecute, redirectInput

        if (!success)
        {
            streamWriter = null;
            process      = null;
            //return new Result (false, "", programFfmpegNotInstalled);
            return;
        }

        processID    = process.Id;
        streamWriter = process.StandardInput;
        Running      = true;

        Console.WriteLine("Recording 5 seconds ...");
        for (int countA = 4; countA >= 0; countA--)
        {
            System.Threading.Thread.Sleep(1000);
            Console.WriteLine(countA.ToString());
        }

        int sessionID = 0;

        Constants.TestTypes testType = Constants.TestTypes.RUN;
        int testID = 1;

        ExitAndFinish(sessionID, testType, testID);

        Console.WriteLine("Recorded, copied, and deleted ok. Now we are going to play it");

        PlayFile(Util.GetVideoFileName(sessionID, testType, testID));

        //return new Result (true, "");
    }
Example #14
0
    private bool initSimulated()
    {
        if (!File.Exists(UtilAll.GetECapSimSignalFileName()))
        {
            return(false);
        }

        string filename = Util.ReadFile(UtilAll.GetECapSimSignalFileName(), true);

        simulatedInts = Util.ReadFileAsInts(filename);
        return(true);
    }
Example #15
0
    private void on_button_video_debug_clicked(object o, EventArgs args)
    {
        string executable = "debug";

        if (UtilAll.GetOSEnum() == UtilAll.OperatingSystems.WINDOWS)
        {
            executable = System.IO.Path.Combine(Util.GetPrefixDir(), "bin/debug.bat");
        }

        LogB.Information("Calling debug: " + executable);
        ExecuteProcess.Result execute_result = ExecuteProcess.run(executable, true, true);
        LogB.Information("Called debug.");
    }
    private void createButtons()
    {
        Frame frame = new Frame();

        frame.ShadowType  = ShadowType.In;
        frame.LabelXalign = 0f;
        frame.LabelYalign = 0.5f;

        frame.Label = Catalog.GetString("There is a known problem on macOS:");
        Gtk.Label label_macOS = new Gtk.Label(
            Catalog.GetString("If Chronopic is disconnected after jumps or runs execution,\nthat port will be blocked until restart of machine."));

        Gtk.VBox vbox_m = new Gtk.VBox();
        vbox_m.PackStart(label_macOS, false, false, 8);

        Gtk.HBox hbox_m = new Gtk.HBox();
        hbox_m.PackStart(vbox_m, false, false, 8);

        if (UtilAll.GetOSEnum() == UtilAll.OperatingSystems.MACOSX)
        {
            frame.Add(hbox_m);
            vbox_main.Add(frame);
        }

        FakeButtonCloseSerialPort = new Gtk.Button();
        Gtk.Button button_close_serial_port = new Gtk.Button("Close serial port (debug)");
        button_close_serial_port.Clicked += new EventHandler(on_button_close_serial_port_clicked);

        //---- button close start --->
        Gtk.Button button_close = new Gtk.Button("Close Window");
        button_close.CanFocus = true;
        button_close.IsFocus  = true;
        button_close.Clicked += new EventHandler(on_button_close_clicked);

        Gtk.AccelGroup ag = new Gtk.AccelGroup();          //button can be called clicking Escape key
        chronopic_register_win.AddAccelGroup(ag);

        button_close.AddAccelerator
            ("activate", ag, new Gtk.AccelKey
                (Gdk.Key.Escape, Gdk.ModifierType.None,
                Gtk.AccelFlags.Visible));
        //<---- button close end

        //add buttons to containers
        Gtk.HButtonBox hbox = new Gtk.HButtonBox();
        //hbox.Add(button_close_serial_port);

        hbox.Add(button_close);

        vbox_main.Add(hbox);
    }
Example #17
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 #18
0
    public static List <string> GetDevices()
    {
        string executable = "ffmpeg";

        if (UtilAll.GetOSEnum() == UtilAll.OperatingSystems.WINDOWS)
        {
            executable = System.IO.Path.Combine(Util.GetPrefixDir(), "bin/ffmpeg.exe");
        }

        List <string> parameters = createParameters();

        ExecuteProcess.Result execute_result = ExecuteProcess.run(executable, parameters);

        Console.WriteLine("---- stdout: ----");
        Console.WriteLine(execute_result.stdout);
        Console.WriteLine("---- stderr: ----");
        Console.WriteLine(execute_result.stderr);
        Console.WriteLine("-----------------");

        if (!execute_result.success)
        {
            Console.WriteLine("WebcamFfmpegGetDevicesWindows error: " + execute_result.stderr);

            /*
             * on Windows the -i dummy produces an error, so stderr exists and success is false
             * stdout has the list of devices and stderr also
             * check if in stdout there's the: "DirectShow video devices" string and if not exists, really we have an error
             */
            if (execute_result.stdout != null && execute_result.stdout != "" &&
                execute_result.stdout.Contains("DirectShow video devices"))
            {
                Console.WriteLine("Calling parse with stdout");
                return(parse(execute_result.stdout));
            }

            if (execute_result.stderr != null && execute_result.stderr != "" &&
                execute_result.stderr.Contains("DirectShow video devices"))
            {
                Console.WriteLine("Calling parse with stderr");
                return(parse(execute_result.stderr));
            }

            return(new List <string>());
        }
        else
        {
            return(parse(execute_result.stdout));
        }
    }
Example #19
0
 public static string [] GetPorts()
 {
     if (UtilAll.GetOSEnum() == UtilAll.OperatingSystems.LINUX)
     {
         return(Directory.GetFiles("/dev/", "ttyUSB*"));
     }
     else if (UtilAll.GetOSEnum() == UtilAll.OperatingSystems.MACOSX)
     {
         return(Directory.GetFiles("/dev/", "tty.usbserial*"));
     }
     else         // WINDOWS
     {
         return(SerialPort.GetPortNames());
     }
 }
Example #20
0
 public ChronopicRegister Do()
 {
     if (UtilAll.GetOSEnum() == UtilAll.OperatingSystems.LINUX)
     {
         return(new ChronopicRegisterLinux());
     }
     else if (UtilAll.GetOSEnum() == UtilAll.OperatingSystems.MACOSX)
     {
         return(new ChronopicRegisterMac());
     }
     else         // WINDOWS
     {
         return(new ChronopicRegisterWindows());
     }
 }
Example #21
0
    private string addHtmlIfNeeded(string myFile)
    {
        int posOfDot = myFile.LastIndexOf('.');

        if (posOfDot == -1)
        {
            if (UtilAll.IsWindows())
            {
                myFile += ".htm";
            }
            else
            {
                myFile += ".html";
            }
        }
        return(myFile);
    }
    private static Result executeChronojumpImporter(List <string> parameters)
    {
        string importer_executable;

        if (UtilAll.IsWindows())
        {
            // On Windows we execute the .exe file (it's the Python with py2exe)
            importer_executable = System.IO.Path.Combine(Util.GetPrefixDir(), "bin\\chronojump-importer\\chronojump_importer.exe");
        }
        else
        {
            // On Linux and OSX we execute Python and we pass the path to the script as a first argument

            importer_executable = "python";                     // chronojump_importer.py works on Python 2 and Python 3

            string importer_script_path = System.IO.Path.Combine(Util.GetPrefixDir(), "bin/chronojump_importer.py");

            // first argument of the Python: the path to the script
            parameters.Insert(0, importer_script_path);
        }

        ExecuteProcess.Result execute_result = ExecuteProcess.run(importer_executable, parameters, true, true);

        if (execute_result.exitCode != 0)
        {
            // Python interpretar was executed but the Python file wasn't found or the script failed
            string errorMessage = "";

            if (execute_result.errorMessage == "")
            {
                // The Python script has been executed and failed (syntax error, crashed).
                // The error message will be in the output:
                errorMessage  = execute_result.allOutput;
                errorMessage += "\nArguments: " + String.Join(" ", parameters);
            }
            else
            {
                // The Python script has not been executed, return the error message from ExecuteProcess
                errorMessage = execute_result.errorMessage;
            }
            return(new Result(false, execute_result.allOutput, errorMessage));
        }

        // All good, returns the output
        return(new Result(true, execute_result.allOutput));
    }