Ejemplo n.º 1
0
        public Calibration(Client cli)
        {
            client = cli;

            // Set default parameters
            calParams = new CalibrationParameters();
            calParams.SetDefaultParameters();
        }
Ejemplo n.º 2
0
        public Calibration(Client cli)
        {
            client = cli;

            // Set default parameters
            calParams = new CalibrationParameters();
            calParams.SetDefaultParameters();
        }
Ejemplo n.º 3
0
        public void ExtractParametersFromString(string parameterStr)
        {
            // Seperating commands
            char[]   sepCalibrationParameters = { ',' };
            string[] calibrationParams        = parameterStr.Split(sepCalibrationParameters, 20);

            // Seperating values/parameters
            char[] sepValues = { '=' };

            var calParams = new CalibrationParameters();

            for (int i = 0; i < calibrationParams.Length; i++)
            {
                string[] cmdString = calibrationParams[i].Split(sepValues, 5);
                string   subCmdStr = cmdString[0];
                string   value     = cmdString[1];

                switch (subCmdStr)
                {
                case strNumberOfPoints:
                    NumberOfPoints = int.Parse(value);
                    break;

                case strSpeed:
                    Speed = double.Parse(value);
                    break;

                case strBackgroundColor:
                    BackgroundColor = Converter.GetColorFromString(value);
                    break;

                case strPointColor:
                    PointColor = Converter.GetColorFromString(value);
                    break;

                case strUseInfantGraphics:
                    UseInfantGraphics = bool.Parse(value);
                    break;

                case strRandomizePointOrder:
                    RandomizePointOrder = bool.Parse(value);
                    break;

                case strAutoAcceptPoints:
                    AutoAcceptPoints = bool.Parse(value);
                    break;

                case strWaitForValidData:
                    WaitForValidData = bool.Parse(value);
                    break;
                }
            }
        }
Ejemplo n.º 4
0
 public void CalibrationParameters(CalibrationParameters calParams)
 {
     client.SendCommand(Commands.CalibrationParameters, calParams.ParametersAsString);
 }
Ejemplo n.º 5
0
        public void ExtractDataAndRaiseEvent(string data)
        {
            char[] seperator = {' '};
            string[] cmd = data.Split(seperator, 5);
            string command = cmd[0];

            string parameters = "";

            if (cmd.Length > 1)
                parameters = cmd[1];

            switch (command)
            {
                case Commands.CalibrationStart:
                    if (OnStart != null)
                        OnStart(Int32.Parse(parameters)); // Number of points
                    break;

                case Commands.CalibrationAcceptPoint:
                    // No returning parameter/data
                    break;

                case Commands.CalibrationAbort:
                    if (OnAbort != null)
                        OnAbort(true);
                    break;

                case Commands.CalibrationPointChange:
                    //OnCalibrationPointChange(Int32.Parse(cmd[1])); // Next point number
                    break;

                case Commands.CalibrationParameters:
                    if (OnParameters != null)
                    {
                        var calParams = new CalibrationParameters();
                        calParams.ExtractParametersFromString(parameters);
                        OnParameters(calParams);
                    }
                    break;

                case Commands.CalibrationAreaSize:
                    break;

                case Commands.CalibrationDefault:
                    break;

                case Commands.CalibrationEnd:
                    if (OnEnd != null)
                        OnEnd(Int32.Parse(parameters));
                    break;

                case Commands.CalibrationCheckLevel:
                    if (OnCheckLevel != null)
                        OnCheckLevel(Int32.Parse(parameters));
                    break;

                case Commands.CalibrationPoint:
                    break;

                case Commands.CalibrationStartDriftCorrection:
                    break;

                case Commands.CalibrationValidate:
                    if (OnValidate != null)
                        OnValidate(cmd[1], double.Parse(cmd[2]), double.Parse(cmd[3]), double.Parse(cmd[4]));
                    break;
            }
        }
Ejemplo n.º 6
0
 public void CalibrationParameters(CalibrationParameters calParams)
 {
     client.SendCommand(Commands.CalibrationParameters, calParams.ParametersAsString);
 }
Ejemplo n.º 7
0
        public void ExtractDataAndRaiseEvent(string data)
        {
            char[]   seperator = { ' ' };
            string[] cmd       = data.Split(seperator, 5);
            string   command   = cmd[0];

            string parameter1 = "";
            string parameter2 = "";


            if (cmd.Length == 2)
            {
                parameter1 = cmd[1];
            }

            else
            {
                parameter1 = cmd[1];
                parameter2 = cmd[2];
            }



            switch (command)
            {
            case Commands.CalibrationStart:
                if (OnStart != null)
                {
                    OnStart(Int32.Parse(parameter1));     // Number of points
                }
                break;

            case Commands.CalibrationAbort:
                if (OnAbort != null)
                {
                    OnAbort(true);
                }
                break;

            case Commands.CalibrationPoint:
                if (OnPointChange != null)
                {
                    OnPointChange(parameter1 + " " + parameter2); // Next point number
                }
                break;

            /*case Commands.CalibrationPointChange:
             *  if (OnPointChange != null)
             *  OnPointChange(parameter1 + " " + parameter2); // Next point number
             *  break;
             */
            case Commands.CalibrationParameters:
                if (OnParameters != null)
                {
                    var calParams = new CalibrationParameters();
                    calParams.ExtractParametersFromString(parameter1);
                    OnParameters(calParams);
                }
                break;

            case Commands.CalibrationEnd:
                if (OnEnd != null)
                {
                    OnEnd(Int32.Parse(parameter1));
                }
                break;

            case Commands.CalibrationCheckLevel:
                if (OnCheckLevel != null)
                {
                    OnCheckLevel(Int32.Parse(parameter1));
                }
                break;

            case Commands.CalibrationValidate:
                if (OnValidate != null)
                {
                    OnValidate(cmd[1], double.Parse(cmd[2]), double.Parse(cmd[3]), double.Parse(cmd[4]));
                }
                break;
            }
        }
 private void tcpipServer_OnCalibrationParameters(CalibrationParameters calParams)
 {
   // Todo: Should be sent from the tracker after applying settings everywhere..
   Tracker.Instance.Server.SendMessage(Commands.CalibrationParameters, calParams.ParametersAsString);
 }
Ejemplo n.º 9
0
        public void ExtractDataAndRaiseEvent(string data)
        {
            char[] seperator = {' '};
            string[] cmd = data.Split(seperator, 5);
            string command = cmd[0];

            string parameter1 = "";
            string parameter2 = "";
            string parameter3 = "";

            if (cmd.Length == 2)
                parameter1 = cmd[1];

            else if (cmd.Length == 3)
            {
                parameter1 = cmd[1];
                parameter2 = cmd[2];
            }
            else
            {
                parameter1 = cmd[1];
                parameter2 = cmd[2];
                parameter3 = cmd[3];
            }

            switch (command)
            {
                case Commands.CalibrationStart:
                    if (OnStart != null)
                        OnStart(Int32.Parse(parameter1)); // Number of points
                    break;

                case Commands.CalibrationAbort:
                    if (OnAbort != null)
                        OnAbort(true);
                    break;

                case Commands.CalibrationQuality:
                    if (OnQuality != null)
                        OnQuality(Int32.Parse(parameter1));
                    break;

                case Commands.CalibrationPointChange:
                    if (OnPointChange != null)
                    OnPointChange(parameter1 + " " + parameter2 + " " + parameter3); // Calibration point: Number, X, Y
                    break;

                case Commands.CalibrationParameters:
                    if (OnParameters != null)
                    {
                        var calParams = new CalibrationParameters();
                        calParams.ExtractParametersFromString(parameter1);
                        OnParameters(calParams);
                    }
                    break;

                case Commands.CalibrationEnd:
                    if (OnEnd != null)
                        OnEnd(Int32.Parse(parameter1));
                    break;

                case Commands.CalibrationCheckLevel:
                    if (OnCheckLevel != null)
                        OnCheckLevel(Int32.Parse(parameter1));
                    break;

                case Commands.CalibrationValidate:
                    if (OnValidate != null)
                        OnValidate(cmd[1], double.Parse(cmd[2]), double.Parse(cmd[3]), double.Parse(cmd[4]));
                    break;
            }
        }
Ejemplo n.º 10
0
        ///<summary>
        /// Event fired when a data is received from the Alchemy Websockets server instance.
        /// Parses data as JSON and calls the appropriate message or sends an error message.
        /// </summary>
        /// <param name="context">The user's connection context</param>
        public static void OnReceive(UserContext context)
        {
            try
            {
                cont = context;
                var json = context.DataFrame.ToString();
                Console.WriteLine(json);
                dynamic obj = JsonConvert.DeserializeObject(json);
                Console.WriteLine(obj.TYPE);
                if ((obj.TYPE) == ("IDENTIFICATION"))
                {
                    string name = "EyeTrackerClient";
                    var r = new Response { TYPE = "IDENTIFICATION", DATA = name };
                    context.Send(JsonConvert.SerializeObject(r));
                }

                if ((obj.TYPE) == ("IDENTIFICATION_COMPLETE"))
                {
                    // devo recuperare ID salvato su file ini per esempio!
                    // se è vuoto restituisco stringa vuota
                    // se c'è invece restituisco stringa con id: TYPE: MACHINE_ID, DATA: valore

                    XmlReader reader = XmlReader.Create("Settings.xml");
                    string ID = "";
                    while (reader.Read())
                    {
                        if (reader.NodeType == XmlNodeType.Element && reader.Name == "EyeTracker")
                        {
                            ID = reader.GetAttribute(0);
                        }
                    }
                    if (ID.Equals(""))
                    {
                        var r = new Response { TYPE = "MACHINE_ID", DATA = "" };
                        context.Send(JsonConvert.SerializeObject(r));
                    }
                    else
                    {
                        var r = new Response { TYPE = "MACHINE_ID", DATA = ID };
                        context.Send(JsonConvert.SerializeObject(r));
                    }
                }

                if ((obj.TYPE) == ("OFFSET_CALCULATION"))
                {
                    if ((obj.TODO) == ("true"))
                    {
                        var r = new Response { TYPE = "START_OFFSET_CALCULATION", DATA = "" };
                        context.Send(JsonConvert.SerializeObject(r));
                    }
                    else
                    {
                        var r = new Response { TYPE = "READY_TO_PLAY", DATA = "" };
                        context.Send(JsonConvert.SerializeObject(r));
                    }
                }

                if ((obj.TYPE) == ("CALCULATING"))
                {
                    // spedisco pacchetto TYPE: CALCULATING, DATA: data corrente in mill dal 1970
                    DateTime baseDate = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
                    TimeSpan diff = DateTime.UtcNow - baseDate;
                    var r = new Response { TYPE = "CALCULATING", DATA = (long)(diff.TotalMilliseconds) };
                    context.Send(JsonConvert.SerializeObject(r));
                }

                if ((obj.TYPE) == ("OFFSET_CALCULATION_COMPLETE"))
                {
                    int id = obj.MACHINE_ID;
                    //devo salvare valore ID dell'EyeTracker dentro il file xml
                    XmlWriterSettings settings = new XmlWriterSettings();
                    settings.Indent = true;
                    XmlWriter writer = XmlWriter.Create("Settings.xml", settings);
                    writer.WriteStartDocument();
                    writer.WriteComment("This file is generated by the program.");
                    writer.WriteStartElement("EyeTracker");
                    writer.WriteAttributeString("ID", id.ToString());
                    writer.WriteEndElement();
                    writer.WriteEndDocument();
                    writer.Flush();
                    writer.Close();
                    var r = new Response { TYPE = "READY_TO_PLAY", DATA = "" };
                    context.Send(JsonConvert.SerializeObject(r));
                }

                if ((obj.TYPE) == ("TRAINING_SESSION"))
                {
                    int pID = obj.PATIENT_ID;
                    if (IDSession == pID )
                    {
                        var r = new Response { TYPE = "TRAINING_SESSION", DATA = "false" };
                        context.Send(JsonConvert.SerializeObject(r));
                    }
                    else
                    {
                        IDSession = pID;
                        var r = new Response { TYPE = "TRAINING_SESSION", DATA = "true" };
                        context.Send(JsonConvert.SerializeObject(r));
                    }
                }

                if ((obj.TYPE) == ("SCREEN_MEASURES"))
                {
                    receivedWidth = obj.SCREEN_WIDTH;
                    receivedHeight = obj.SCREEN_HEIGHT;
                    gtClient.Calibration.AreaSize(receivedWidth, receivedHeight);
                }

                if ((obj.TYPE) == ("START_TRAINING"))
                {
                    CalibrationParameters parametri = new CalibrationParameters();
                    parametri.NumberOfPoints = obj.POINTS;
                    parametri.PointDiameter = obj.POINT_DIAMETER;
                    parametri.PointDuration = obj.POINT_DURATION;
                    parametri.PointTransitionDuration = obj.TRANSITION_DURATION;
                    gtClient.Calibration.CalibrationParameters(parametri);
                    gtClient.Calibration.Start();
                }

                if ((obj.TYPE) == ("TRAINING_VALIDATION"))
                {
                    if ((obj.DATA) == "true")
                        gtClient.Calibration.Validate();
                    else
                        gtClient.Calibration.Abort();
                }

                if ((obj.TYPE) == ("START_WORKING"))
                {
                    // Devo Partire tra START_TIME - ora attuale millisecondi
                    gtClient.Stream.StreamStart();
                    onStream = true;
                }

                if ((obj.TYPE) == ("STOP_GAME"))
                {
                    gtClient.Stream.StreamStop();
                    onStream = false;
                }


            }
            catch (Exception e) // Bad JSON! For shame.
            {
                var r = new Response { TYPE = "Errore: ", DATA = new { e.Message } };

                context.Send(JsonConvert.SerializeObject(r));
            }
        }
Ejemplo n.º 11
0
 private void Calibration_OnParameters(CalibrationParameters calParams)
 {
     Show("Calibration parameters changed.", calParams.ParametersAsString);
 }
        public void ExtractParametersFromString(string parameterStr)
        {
            // Seperating commands
            char[] sepCalibrationParameters = {','};
            string[] calibrationParams = parameterStr.Split(sepCalibrationParameters, 20);

            // Seperating values/parameters
            char[] sepValues = {'='};

            var calParams = new CalibrationParameters();

            for (int i = 0; i < calibrationParams.Length; i++)
            {
                string[] cmdString = calibrationParams[i].Split(sepValues, 5);
                string subCmdStr = cmdString[0];
                string value = cmdString[1];

                switch (subCmdStr)
                {
                    case strNumberOfPoints:
                        NumberOfPoints = int.Parse(value);
                        break;

                    case strSpeed:
                        Speed = double.Parse(value);
                        break;

                    case strBackgroundColor:
                        BackgroundColor = Converter.GetColorFromString(value);
                        break;

                    case strPointColor:
                        PointColor = Converter.GetColorFromString(value);
                        break;

                    case strUseInfantGraphics:
                        UseInfantGraphics = bool.Parse(value);
                        break;

                    case strRandomizePointOrder:
                        RandomizePointOrder = bool.Parse(value);
                        break;

                    case strAutoAcceptPoints:
                        AutoAcceptPoints = bool.Parse(value);
                        break;

                    case strWaitForValidData:
                        WaitForValidData = bool.Parse(value);
                        break;
                }
            }
        }
Ejemplo n.º 13
0
        public void ExtractDataAndRaiseEvent(string data)
        {
            char[]   seperator = { ' ' };
            string[] cmd       = data.Split(seperator, 5);
            string   command   = cmd[0];

            string parameters = "";

            if (cmd.Length > 1)
            {
                parameters = cmd[1];
            }

            switch (command)
            {
            case Commands.CalibrationStart:
                if (OnStart != null)
                {
                    OnStart(Int32.Parse(parameters));     // Number of points
                }
                break;

            case Commands.CalibrationAcceptPoint:
                // No returning parameter/data
                break;

            case Commands.CalibrationAbort:
                if (OnAbort != null)
                {
                    OnAbort(true);
                }
                break;

            case Commands.CalibrationPointChange:
                //OnCalibrationPointChange(Int32.Parse(cmd[1])); // Next point number
                break;

            case Commands.CalibrationParameters:
                if (OnParameters != null)
                {
                    var calParams = new CalibrationParameters();
                    calParams.ExtractParametersFromString(parameters);
                    OnParameters(calParams);
                }
                break;

            case Commands.CalibrationAreaSize:
                break;

            case Commands.CalibrationDefault:
                break;

            case Commands.CalibrationEnd:
                if (OnEnd != null)
                {
                    OnEnd(Int32.Parse(parameters));
                }
                break;

            case Commands.CalibrationCheckLevel:
                if (OnCheckLevel != null)
                {
                    OnCheckLevel(Int32.Parse(parameters));
                }
                break;

            case Commands.CalibrationPoint:
                break;

            case Commands.CalibrationStartDriftCorrection:
                break;

            case Commands.CalibrationValidate:
                if (OnValidate != null)
                {
                    OnValidate(cmd[1], double.Parse(cmd[2]), double.Parse(cmd[3]), double.Parse(cmd[4]));
                }
                break;
            }
        }
Ejemplo n.º 14
0
        private void SendCommand(string command)
        {
            UpdateCommandLog(InstanceCommand);

            char[] seperator = {' '};
            string[] cmds = command.Split(seperator, 2);
            string cmdStr = cmds[0];

            string paramStr = "";

            if (cmds.Length > 1)
                paramStr = cmds[1];

            switch (cmdStr)
            {
                    // Calibration

                case Commands.CalibrationStart:
                    client.Calibration.Start();
                    WindowState = WindowState.Minimized;
                    break;
                case Commands.CalibrationAbort:
                    client.Calibration.Abort();
                    break;

                case Commands.CalibrationParameters:
                    var calParams = new CalibrationParameters();
                    calParams.ExtractParametersFromString(paramStr);
                    client.Calibration.CalibrationParameters(calParams);
                    break;

                    // Stream

                case Commands.StreamStart:
                    client.Stream.StreamStart();
                    break;
                case Commands.StreamStop:
                    client.Stream.StreamStop();
                    break;

                    // Log

                case Commands.LogStart:
                    client.Log.Start();
                    break;

                case Commands.LogStop:
                    client.Log.Stop();
                    break;

                case Commands.LogPathSet:
                    client.Log.SetLogPath(paramStr);
                    break;
                case Commands.LogPathGet:
                    client.Log.GetLogPath();
                    break;

                case Commands.LogWriteLine:
                    client.Log.WriteLine(paramStr);
                    break;

                    // Camera 

                case Commands.CameraParameters:
                    client.Camera.ApplyParameters(paramStr);
                        // available as override w/ string, eg. Brightness=100,Contrast=255 etc.
                    break;


                    // U.I

                case Commands.UIMinimize:
                    client.UIControl.Minimize();
                    break;

                case Commands.UIRestore:
                    client.UIControl.Restore();
                    break;

                case Commands.UISettings:
                    client.UIControl.Settings();
                    break;

                case Commands.UISettingsCamera:
                    client.UIControl.SettingsCamera();
                    break;

                    // Mouse control

                case "MouseControl_Enable:":
                    client.MouseControl.IsEnabled = true;
                    break;
                case "MouseControl_Disable:":
                    client.MouseControl.IsEnabled = false;
                    break;
            }
        }