Esempio n. 1
0
	void Update(){ // Called every video frame
		#if !NOSERVICESCONTROLLER && UNITY_ANDROID && !UNITY_EDITOR
		if (androidDevice && inMenu) {
			if (updateServer){
				string serverUptimeNew = FieldtripServicesControlerInterface.getBufferUptime ();
				if (serverUptimeNew != serverUptime) {
					serverUptime = serverUptimeNew;
					serverDowntime = 0;
					ServerStatusIcon.color = themeGreen;
				} else {
					serverDowntime += 1;
					if (serverDowntime > 120) {
						ServerStatusIcon.color = themeRed;
						systemIsReady = false;
					}
				}
			}
		}
       #endif
	   if (clientIsConnected) {
			float qch1 = getQualityCh1();
			float qch2 = getQualityCh2();
			if (qch1 >= Config.qualityLimit) {
				SignalAStatusIcon.color = themeRed;
			} else {
				SignalAStatusIcon.color = themeGreen;
			}
			if (qch2 >= Config.qualityLimit) {
				SignalBStatusIcon.color = themeRed;
			} else {
				SignalBStatusIcon.color = themeGreen;
			}
		}
	}
Esempio n. 2
0
	void Start () {
		#if !NOSERVICESCONTROLLER && UNITY_ANDROID && !UNITY_EDITOR
		FieldtripServicesControlerInterface.Initialize();
		androidDevice = true;
		#endif

		currentAlphaLat = new double[] {0, 0, 0, 0};
		resetStatus();
	}
Esempio n. 3
0
    void Start()
    {
                #if UNITY_ANDROID && !UNITY_EDITOR
        FieldtripServicesControlerInterface.Initialize();
        androidDevice = true;
                #endif

        StartCoroutine(startServerAndAllClients());
    }
Esempio n. 4
0
    // System Startup and Shutdown

    public IEnumerator startServerAndAllClients()
    {
        updateStatus = true;         // show status in loading screen
                #if UNITY_ANDROID && !UNITY_EDITOR
        //Start Server
        logStatus("Server opstarten...");
        Debug.Log("Started: " + FieldtripServicesControlerInterface.startServer());
        yield return(new WaitForSeconds(4));                //These waits are for the Services to have time to pass around their intents. Used to be 10.

        //Start Clients
        logStatus("Client opstarten...");
        Debug.Log("Started: " + FieldtripServicesControlerInterface.startClients());
        yield return(new WaitForSeconds(2));

        for (int i = 0; i < Config.bufferClientThreadList.Length; i++)
        {
            string clientname = Config.bufferClientThreadList[i];
            logStatus(clientname + "\nopstarten");
            FieldtripServicesControlerInterface.startThread(clientname);
            yield return(new WaitForSeconds(1));                    //These waits are for the Services to have time to pass around their intents.
        }
                #endif
        //Start Buffer
        logStatus("Verbinden met buffer...");
        bool inited = false;
        while (!inited)
        {
            inited = initializeBuffer();
            if (!inited)
            {
                yield return(new WaitForSeconds(1));
            }
        }

        logStatus("Wachten...");
        yield return(new WaitForSeconds(1));

        logStatus("Gereed!");
        updateStatus = false;
        LoadingButton.SetActive(true);
    }
Esempio n. 5
0
    public IEnumerator stopClientAndServer()
    {
                #if UNITY_ANDROID && !UNITY_EDITOR
        //Stop Threads
        for (int i = 0; i < Config.bufferClientThreadList.Length; i++)
        {
            string clientname = Config.bufferClientThreadList[i];
            logStatus(clientname + "\nstoppen");
            FieldtripServicesControlerInterface.stopThread(clientname);
            yield return(new WaitForSeconds(1));                    //These waits are for the Services to have time to pass around their intents.
        }
                #endif

        //Stop buffer
        logStatus("Buffer stoppen...");
        if (bufferIsOn)
        {
            buffer.disconnect();
            bufferIsOn = false;
        }
        yield return(new WaitForSeconds(1));

                #if UNITY_ANDROID && !UNITY_EDITOR
        //Stop Clients
        logStatus("Client stoppen...");
        Debug.Log("Stopped: " + FieldtripServicesControlerInterface.stopClients());
        yield return(new WaitForSeconds(2));

        //Stop Server
        logStatus("Server stoppen...");
        Debug.Log("Stopped: " + FieldtripServicesControlerInterface.stopServer());
        yield return(new WaitForSeconds(2));
        #endif

        //Update Status
        systemIsReady = false;         //signals Unity it is safe to close down as well
        logStatus("Systeem offline");
    }
Esempio n. 6
0
	public IEnumerator stopClientAndServer(){
		systemIsReady = false;
		#if !NOSERVICESCONTROLLER && UNITY_ANDROID && !UNITY_EDITOR
			//Stop Clients
			clientIsConnected = false;
			logStatus ("stopping classifier...");
			FieldtripServicesControlerInterface.stopThread (ccThreadID);
			yield return new WaitForSeconds (1);
			logStatus ("stopping muse...");
			FieldtripServicesControlerInterface.stopThread (museThreadID);
			yield return new WaitForSeconds (1);
			logStatus ("shutting down clients...");
			Debug.Log ("Stopped Clients = " + FieldtripServicesControlerInterface.stopClients ());
			yield return new WaitForSeconds (1);
		#endif

		//Stop buffer
		logStatus ("removing buffer...");
		if ( bufferIsOn ){
			buffer.disconnect ();
			bufferIsOn = false;
		}
		yield return new WaitForSeconds (1);

		#if !NOSERVICESCONTROLLER && UNITY_ANDROID && !UNITY_EDITOR
			//Stop Server
			logStatus ("shutting down server...");
			updateServer = false;
			Debug.Log ("Stopped Server = " + FieldtripServicesControlerInterface.stopServer ());
			yield return new WaitForSeconds (1);

      #endif
		//Update Status
		clientIsConnected = false;
		logStatus ("system offline");
		resetStatus ();
	}
Esempio n. 7
0
	// System Startup and Shutdown

	public IEnumerator startServerAndAllClients(){
		#if !NOSERVICESCONTROLLER && UNITY_ANDROID && !UNITY_EDITOR
			//Start Server
			logStatus ("starting server...");
			Debug.Log ("Started: " + FieldtripServicesControlerInterface.startServer ());
			ServerStatusIcon.color = themeRed;
			yield return new WaitForSeconds (4);//These waits are for the Services to have time to pass around their intents. Used to be 10.
			updateServer = true;


			//Start Clients
			logStatus ("starting client...");
			Debug.Log ("Started: " + FieldtripServicesControlerInterface.startClients ());
			yield return new WaitForSeconds (1);

			//Start Threads
			logStatus ("loading threads...");
			bool museIsAvailable = false;
			string[] result = FieldtripServicesControlerInterface.getAllThreadsNamesAndIDs ();
			while (result.Length==0) {//Wait until the ClientsService updates the controller with all the available threads
				yield return new WaitForSeconds (1);
				result = FieldtripServicesControlerInterface.getAllThreadsNamesAndIDs ();
			}
			for (int i=0; i<result.Length; ++i) {
				if (result [i].Split (':') [1].Contains ("Muse")) {
					logStatus ("connecting to muse...");
					museIsAvailable = true;
					MuseStatusIcon.color = themeRed;
					museThreadID = int.Parse (result [i].Split (':') [0]);
					if (verbose) {
						Debug.Log ("Starting MuseConnection @ thread: " + museThreadID.ToString ());
					}
					FieldtripServicesControlerInterface.startThread (museThreadID);
				}
			}

			if (museIsAvailable) {
				//Start Buffer
				logStatus ("creating buffer...");
				initializeBuffer ();

				//Check Muse connection
				logStatus ("waiting for muse...");
				int museClientID = 0;
				int currentSamples = FieldtripServicesControlerInterface.getClientSamplesPut (museClientID);
				int samplesPut = currentSamples;
				while (samplesPut < 100) {//Wait for Muse to put some samples in the buffer
					yield return new WaitForSeconds (1);
					samplesPut = FieldtripServicesControlerInterface.getClientSamplesPut (museClientID);
				}
				MuseStatusIcon.color = themeGreen;

				logStatus ("sending events to buffer...");
				for (int i=0; i<result.Length; ++i) {
					if (result [i].Split (':') [1].Contains ("AlphaLat")) {
						ccThreadID = int.Parse (result [i].Split (':') [0]);
						Debug.Log ("Starting ContinuousClassifier @ thread: " + ccThreadID.ToString ());
						FieldtripServicesControlerInterface.startThread (ccThreadID);
					}
				}
				while (!clientIsConnected) {
					yield return new WaitForSeconds(0.5f);
				}

				logStatus ("check signal quality...");
				yield return new WaitForSeconds (2f);
			J

		#else
			//Start Buffer
			logStatus ("Connecting to buffer...");
			while ( ! bufferIsOn ){
				initializeBuffer ();
				if ( ! bufferIsOn ){
					//logStatus ("Couldnt connect, waiting");
					yield return new WaitForSeconds(1);
				}
			}
			logStatus ("Connected!");
			yield return new WaitForSeconds(1);
      #endif
		buttonColors.normalColor = themeGreen;
		buttonColors.highlightedColor = themeGreen;
		StatusButton.colors = buttonColors;
		logStatus ("beginnen");
		systemIsReady = true;
	}